blob: d0901f473b6d45e3b8cd2d92daf4c25f850834ed [file] [log] [blame]
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * alloc.c: functions for memory management
12 */
13
14#include "vim.h"
15
16/**********************************************************************
17 * Various routines dealing with allocation and deallocation of memory.
18 */
19
20#if defined(MEM_PROFILE) || defined(PROTO)
21
22# define MEM_SIZES 8200
23static long_u mem_allocs[MEM_SIZES];
24static long_u mem_frees[MEM_SIZES];
25static long_u mem_allocated;
26static long_u mem_freed;
27static long_u mem_peak;
28static long_u num_alloc;
29static long_u num_freed;
30
31 static void
32mem_pre_alloc_s(size_t *sizep)
33{
34 *sizep += sizeof(size_t);
35}
36
37 static void
38mem_pre_alloc_l(size_t *sizep)
39{
40 *sizep += sizeof(size_t);
41}
42
43 static void
44mem_post_alloc(
45 void **pp,
46 size_t size)
47{
48 if (*pp == NULL)
49 return;
50 size -= sizeof(size_t);
51 *(long_u *)*pp = size;
52 if (size <= MEM_SIZES-1)
53 mem_allocs[size-1]++;
54 else
55 mem_allocs[MEM_SIZES-1]++;
56 mem_allocated += size;
57 if (mem_allocated - mem_freed > mem_peak)
58 mem_peak = mem_allocated - mem_freed;
59 num_alloc++;
60 *pp = (void *)((char *)*pp + sizeof(size_t));
61}
62
63 static void
64mem_pre_free(void **pp)
65{
66 long_u size;
67
68 *pp = (void *)((char *)*pp - sizeof(size_t));
69 size = *(size_t *)*pp;
70 if (size <= MEM_SIZES-1)
71 mem_frees[size-1]++;
72 else
73 mem_frees[MEM_SIZES-1]++;
74 mem_freed += size;
75 num_freed++;
76}
77
78/*
79 * called on exit via atexit()
80 */
81 void
82vim_mem_profile_dump(void)
83{
84 int i, j;
85
86 printf("\r\n");
87 j = 0;
88 for (i = 0; i < MEM_SIZES - 1; i++)
89 {
90 if (mem_allocs[i] || mem_frees[i])
91 {
92 if (mem_frees[i] > mem_allocs[i])
93 printf("\r\n%s", _("ERROR: "));
94 printf("[%4d / %4lu-%-4lu] ", i + 1, mem_allocs[i], mem_frees[i]);
95 j++;
96 if (j > 3)
97 {
98 j = 0;
99 printf("\r\n");
100 }
101 }
102 }
103
104 i = MEM_SIZES - 1;
105 if (mem_allocs[i])
106 {
107 printf("\r\n");
108 if (mem_frees[i] > mem_allocs[i])
109 puts(_("ERROR: "));
110 printf("[>%d / %4lu-%-4lu]", i, mem_allocs[i], mem_frees[i]);
111 }
112
113 printf(_("\n[bytes] total alloc-freed %lu-%lu, in use %lu, peak use %lu\n"),
114 mem_allocated, mem_freed, mem_allocated - mem_freed, mem_peak);
115 printf(_("[calls] total re/malloc()'s %lu, total free()'s %lu\n\n"),
116 num_alloc, num_freed);
117}
118
119#endif // MEM_PROFILE
120
121#ifdef FEAT_EVAL
122 int
123alloc_does_fail(size_t size)
124{
125 if (alloc_fail_countdown == 0)
126 {
127 if (--alloc_fail_repeat <= 0)
128 alloc_fail_id = 0;
129 do_outofmem_msg(size);
130 return TRUE;
131 }
132 --alloc_fail_countdown;
133 return FALSE;
134}
135#endif
136
137/*
138 * Some memory is reserved for error messages and for being able to
139 * call mf_release_all(), which needs some memory for mf_trans_add().
140 */
141#define KEEP_ROOM (2 * 8192L)
142#define KEEP_ROOM_KB (KEEP_ROOM / 1024L)
143
144/*
145 * The normal way to allocate memory. This handles an out-of-memory situation
146 * as well as possible, still returns NULL when we're completely out.
147 */
148 void *
149alloc(size_t size)
150{
151 return lalloc(size, TRUE);
152}
153
154/*
155 * alloc() with an ID for alloc_fail().
156 */
157 void *
158alloc_id(size_t size, alloc_id_T id UNUSED)
159{
160#ifdef FEAT_EVAL
161 if (alloc_fail_id == id && alloc_does_fail(size))
162 return NULL;
163#endif
164 return lalloc(size, TRUE);
165}
166
167/*
168 * Allocate memory and set all bytes to zero.
169 */
170 void *
171alloc_clear(size_t size)
172{
173 void *p;
174
175 p = lalloc(size, TRUE);
176 if (p != NULL)
177 (void)vim_memset(p, 0, size);
178 return p;
179}
180
181/*
182 * Same as alloc_clear() but with allocation id for testing
183 */
184 void *
185alloc_clear_id(size_t size, alloc_id_T id UNUSED)
186{
187#ifdef FEAT_EVAL
188 if (alloc_fail_id == id && alloc_does_fail(size))
189 return NULL;
190#endif
191 return alloc_clear(size);
192}
193
194/*
195 * Allocate memory like lalloc() and set all bytes to zero.
196 */
197 void *
198lalloc_clear(size_t size, int message)
199{
200 void *p;
201
202 p = lalloc(size, message);
203 if (p != NULL)
204 (void)vim_memset(p, 0, size);
205 return p;
206}
207
208/*
209 * Low level memory allocation function.
210 * This is used often, KEEP IT FAST!
211 */
212 void *
213lalloc(size_t size, int message)
214{
215 void *p; // pointer to new storage space
216 static int releasing = FALSE; // don't do mf_release_all() recursive
217 int try_again;
218#if defined(HAVE_AVAIL_MEM)
219 static size_t allocated = 0; // allocated since last avail check
220#endif
221
222 // Safety check for allocating zero bytes
223 if (size == 0)
224 {
225 // Don't hide this message
226 emsg_silent = 0;
227 iemsg(_("E341: Internal error: lalloc(0, )"));
228 return NULL;
229 }
230
231#ifdef MEM_PROFILE
232 mem_pre_alloc_l(&size);
233#endif
234
Yegappan Lakshmanan8ee52af2021-08-09 19:59:06 +0200235 // Loop when out of memory: Try to release some memfile blocks and
236 // if some blocks are released call malloc again.
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200237 for (;;)
238 {
Yegappan Lakshmanan8ee52af2021-08-09 19:59:06 +0200239 // Handle three kind of systems:
240 // 1. No check for available memory: Just return.
241 // 2. Slow check for available memory: call mch_avail_mem() after
242 // allocating KEEP_ROOM amount of memory.
243 // 3. Strict check for available memory: call mch_avail_mem()
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200244 if ((p = malloc(size)) != NULL)
245 {
246#ifndef HAVE_AVAIL_MEM
247 // 1. No check for available memory: Just return.
248 goto theend;
249#else
250 // 2. Slow check for available memory: call mch_avail_mem() after
251 // allocating (KEEP_ROOM / 2) amount of memory.
252 allocated += size;
253 if (allocated < KEEP_ROOM / 2)
254 goto theend;
255 allocated = 0;
256
257 // 3. check for available memory: call mch_avail_mem()
258 if (mch_avail_mem(TRUE) < KEEP_ROOM_KB && !releasing)
259 {
260 free(p); // System is low... no go!
261 p = NULL;
262 }
263 else
264 goto theend;
265#endif
266 }
Yegappan Lakshmanan8ee52af2021-08-09 19:59:06 +0200267 // Remember that mf_release_all() is being called to avoid an endless
268 // loop, because mf_release_all() may call alloc() recursively.
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200269 if (releasing)
270 break;
271 releasing = TRUE;
272
273 clear_sb_text(TRUE); // free any scrollback text
274 try_again = mf_release_all(); // release as many blocks as possible
275
276 releasing = FALSE;
277 if (!try_again)
278 break;
279 }
280
281 if (message && p == NULL)
282 do_outofmem_msg(size);
283
284theend:
285#ifdef MEM_PROFILE
286 mem_post_alloc(&p, size);
287#endif
288 return p;
289}
290
291/*
292 * lalloc() with an ID for alloc_fail().
293 */
294#if defined(FEAT_SIGNS) || defined(PROTO)
295 void *
296lalloc_id(size_t size, int message, alloc_id_T id UNUSED)
297{
298#ifdef FEAT_EVAL
299 if (alloc_fail_id == id && alloc_does_fail(size))
300 return NULL;
301#endif
302 return (lalloc(size, message));
303}
304#endif
305
306#if defined(MEM_PROFILE) || defined(PROTO)
307/*
308 * realloc() with memory profiling.
309 */
310 void *
311mem_realloc(void *ptr, size_t size)
312{
313 void *p;
314
315 mem_pre_free(&ptr);
316 mem_pre_alloc_s(&size);
317
318 p = realloc(ptr, size);
319
320 mem_post_alloc(&p, size);
321
322 return p;
323}
324#endif
325
326/*
327* Avoid repeating the error message many times (they take 1 second each).
328* Did_outofmem_msg is reset when a character is read.
329*/
330 void
331do_outofmem_msg(size_t size)
332{
333 if (!did_outofmem_msg)
334 {
335 // Don't hide this message
336 emsg_silent = 0;
337
338 // Must come first to avoid coming back here when printing the error
339 // message fails, e.g. when setting v:errmsg.
340 did_outofmem_msg = TRUE;
341
342 semsg(_("E342: Out of memory! (allocating %lu bytes)"), (long_u)size);
343
344 if (starting == NO_SCREEN)
345 // Not even finished with initializations and already out of
346 // memory? Then nothing is going to work, exit.
347 mch_exit(123);
348 }
349}
350
351#if defined(EXITFREE) || defined(PROTO)
352
353/*
354 * Free everything that we allocated.
355 * Can be used to detect memory leaks, e.g., with ccmalloc.
356 * NOTE: This is tricky! Things are freed that functions depend on. Don't be
357 * surprised if Vim crashes...
358 * Some things can't be freed, esp. things local to a library function.
359 */
360 void
361free_all_mem(void)
362{
363 buf_T *buf, *nextbuf;
364
365 // When we cause a crash here it is caught and Vim tries to exit cleanly.
366 // Don't try freeing everything again.
367 if (entered_free_all_mem)
368 return;
369 entered_free_all_mem = TRUE;
370 // Don't want to trigger autocommands from here on.
371 block_autocmds();
372
373 // Close all tabs and windows. Reset 'equalalways' to avoid redraws.
374 p_ea = FALSE;
375 if (first_tabpage != NULL && first_tabpage->tp_next != NULL)
376 do_cmdline_cmd((char_u *)"tabonly!");
377 if (!ONE_WINDOW)
378 do_cmdline_cmd((char_u *)"only!");
379
380# if defined(FEAT_SPELL)
381 // Free all spell info.
382 spell_free_all();
383# endif
384
385# if defined(FEAT_BEVAL_TERM)
386 ui_remove_balloon();
387# endif
388# ifdef FEAT_PROP_POPUP
389 if (curwin != NULL)
390 close_all_popups(TRUE);
391# endif
392
393 // Clear user commands (before deleting buffers).
394 ex_comclear(NULL);
395
396 // When exiting from mainerr_arg_missing curbuf has not been initialized,
397 // and not much else.
398 if (curbuf != NULL)
399 {
400# ifdef FEAT_MENU
401 // Clear menus.
402 do_cmdline_cmd((char_u *)"aunmenu *");
403# ifdef FEAT_MULTI_LANG
404 do_cmdline_cmd((char_u *)"menutranslate clear");
405# endif
406# endif
407 // Clear mappings, abbreviations, breakpoints.
408 do_cmdline_cmd((char_u *)"lmapclear");
409 do_cmdline_cmd((char_u *)"xmapclear");
410 do_cmdline_cmd((char_u *)"mapclear");
411 do_cmdline_cmd((char_u *)"mapclear!");
412 do_cmdline_cmd((char_u *)"abclear");
413# if defined(FEAT_EVAL)
414 do_cmdline_cmd((char_u *)"breakdel *");
415# endif
416# if defined(FEAT_PROFILE)
417 do_cmdline_cmd((char_u *)"profdel *");
418# endif
419# if defined(FEAT_KEYMAP)
420 do_cmdline_cmd((char_u *)"set keymap=");
421# endif
422 }
423
424# ifdef FEAT_TITLE
425 free_titles();
426# endif
427# if defined(FEAT_SEARCHPATH)
428 free_findfile();
429# endif
430
431 // Obviously named calls.
432 free_all_autocmds();
433 clear_termcodes();
434 free_all_marks();
435 alist_clear(&global_alist);
436 free_homedir();
437 free_users();
438 free_search_patterns();
439 free_old_sub();
440 free_last_insert();
441 free_insexpand_stuff();
442 free_prev_shellcmd();
443 free_regexp_stuff();
444 free_tag_stuff();
445 free_cd_dir();
446# ifdef FEAT_SIGNS
447 free_signs();
448# endif
449# ifdef FEAT_EVAL
450 set_expr_line(NULL, NULL);
451# endif
452# ifdef FEAT_DIFF
453 if (curtab != NULL)
454 diff_clear(curtab);
455# endif
456 clear_sb_text(TRUE); // free any scrollback text
457
458 // Free some global vars.
459 free_username();
460# ifdef FEAT_CLIPBOARD
461 vim_regfree(clip_exclude_prog);
462# endif
463 vim_free(last_cmdline);
464 vim_free(new_last_cmdline);
465 set_keep_msg(NULL, 0);
466
467 // Clear cmdline history.
468 p_hi = 0;
469 init_history();
470# ifdef FEAT_PROP_POPUP
471 clear_global_prop_types();
472# endif
473
474# ifdef FEAT_QUICKFIX
475 {
476 win_T *win;
477 tabpage_T *tab;
478
479 qf_free_all(NULL);
480 // Free all location lists
481 FOR_ALL_TAB_WINDOWS(tab, win)
482 qf_free_all(win);
483 }
484# endif
485
486 // Close all script inputs.
487 close_all_scripts();
488
489 if (curwin != NULL)
490 // Destroy all windows. Must come before freeing buffers.
491 win_free_all();
492
493 // Free all option values. Must come after closing windows.
494 free_all_options();
495
496 // Free all buffers. Reset 'autochdir' to avoid accessing things that
497 // were freed already.
498# ifdef FEAT_AUTOCHDIR
499 p_acd = FALSE;
500# endif
501 for (buf = firstbuf; buf != NULL; )
502 {
503 bufref_T bufref;
504
505 set_bufref(&bufref, buf);
506 nextbuf = buf->b_next;
507 close_buffer(NULL, buf, DOBUF_WIPE, FALSE, FALSE);
508 if (bufref_valid(&bufref))
509 buf = nextbuf; // didn't work, try next one
510 else
511 buf = firstbuf;
512 }
513
514# ifdef FEAT_ARABIC
515 free_arshape_buf();
516# endif
517
518 // Clear registers.
519 clear_registers();
520 ResetRedobuff();
521 ResetRedobuff();
522
523# if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11)
524 vim_free(serverDelayedStartName);
525# endif
526
527 // highlight info
528 free_highlight();
529
530 reset_last_sourcing();
531
532 if (first_tabpage != NULL)
533 {
534 free_tabpage(first_tabpage);
535 first_tabpage = NULL;
536 }
537
538# ifdef UNIX
539 // Machine-specific free.
540 mch_free_mem();
541# endif
542
543 // message history
544 for (;;)
545 if (delete_first_msg() == FAIL)
546 break;
547
548# ifdef FEAT_JOB_CHANNEL
549 channel_free_all();
550# endif
551# ifdef FEAT_TIMERS
552 timer_free_all();
553# endif
554# ifdef FEAT_EVAL
555 // must be after channel_free_all() with unrefs partials
556 eval_clear();
557# endif
558# ifdef FEAT_JOB_CHANNEL
559 // must be after eval_clear() with unrefs jobs
560 job_free_all();
561# endif
562
563 free_termoptions();
Bram Moolenaarb3a29552021-11-19 11:28:04 +0000564 free_cur_term();
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200565
566 // screenlines (can't display anything now!)
567 free_screenlines();
568
569# if defined(FEAT_SOUND)
570 sound_free();
571# endif
572# if defined(USE_XSMP)
573 xsmp_close();
574# endif
575# ifdef FEAT_GUI_GTK
576 gui_mch_free_all();
577# endif
578 clear_hl_tables();
579
580 vim_free(IObuff);
581 vim_free(NameBuff);
582# ifdef FEAT_QUICKFIX
583 check_quickfix_busy();
584# endif
585}
586#endif
587
588/*
589 * Copy "p[len]" into allocated memory, ignoring NUL characters.
590 * Returns NULL when out of memory.
591 */
592 char_u *
593vim_memsave(char_u *p, size_t len)
594{
595 char_u *ret = alloc(len);
596
597 if (ret != NULL)
598 mch_memmove(ret, p, len);
599 return ret;
600}
601
602/*
603 * Replacement for free() that ignores NULL pointers.
604 * Also skip free() when exiting for sure, this helps when we caught a deadly
605 * signal that was caused by a crash in free().
606 * If you want to set NULL after calling this function, you should use
607 * VIM_CLEAR() instead.
608 */
609 void
610vim_free(void *x)
611{
612 if (x != NULL && !really_exiting)
613 {
614#ifdef MEM_PROFILE
615 mem_pre_free(&x);
616#endif
617 free(x);
618 }
619}
620
621/************************************************************************
622 * Functions for handling growing arrays.
623 */
624
625/*
626 * Clear an allocated growing array.
627 */
628 void
629ga_clear(garray_T *gap)
630{
631 vim_free(gap->ga_data);
632 ga_init(gap);
633}
634
635/*
636 * Clear a growing array that contains a list of strings.
637 */
638 void
639ga_clear_strings(garray_T *gap)
640{
641 int i;
642
643 if (gap->ga_data != NULL)
644 for (i = 0; i < gap->ga_len; ++i)
645 vim_free(((char_u **)(gap->ga_data))[i]);
646 ga_clear(gap);
647}
648
649/*
650 * Copy a growing array that contains a list of strings.
651 */
652 int
653ga_copy_strings(garray_T *from, garray_T *to)
654{
655 int i;
656
657 ga_init2(to, sizeof(char_u *), 1);
658 if (ga_grow(to, from->ga_len) == FAIL)
659 return FAIL;
660
661 for (i = 0; i < from->ga_len; ++i)
662 {
663 char_u *orig = ((char_u **)from->ga_data)[i];
664 char_u *copy;
665
666 if (orig == NULL)
667 copy = NULL;
668 else
669 {
670 copy = vim_strsave(orig);
671 if (copy == NULL)
672 {
673 to->ga_len = i;
674 ga_clear_strings(to);
675 return FAIL;
676 }
677 }
678 ((char_u **)to->ga_data)[i] = copy;
679 }
680 to->ga_len = from->ga_len;
681 return OK;
682}
683
684/*
685 * Initialize a growing array. Don't forget to set ga_itemsize and
686 * ga_growsize! Or use ga_init2().
687 */
688 void
689ga_init(garray_T *gap)
690{
691 gap->ga_data = NULL;
692 gap->ga_maxlen = 0;
693 gap->ga_len = 0;
694}
695
696 void
697ga_init2(garray_T *gap, int itemsize, int growsize)
698{
699 ga_init(gap);
700 gap->ga_itemsize = itemsize;
701 gap->ga_growsize = growsize;
702}
703
704/*
705 * Make room in growing array "gap" for at least "n" items.
706 * Return FAIL for failure, OK otherwise.
707 */
708 int
709ga_grow(garray_T *gap, int n)
710{
711 if (gap->ga_maxlen - gap->ga_len < n)
712 return ga_grow_inner(gap, n);
713 return OK;
714}
715
716 int
717ga_grow_inner(garray_T *gap, int n)
718{
719 size_t old_len;
720 size_t new_len;
721 char_u *pp;
722
723 if (n < gap->ga_growsize)
724 n = gap->ga_growsize;
725
726 // A linear growth is very inefficient when the array grows big. This
727 // is a compromise between allocating memory that won't be used and too
728 // many copy operations. A factor of 1.5 seems reasonable.
729 if (n < gap->ga_len / 2)
730 n = gap->ga_len / 2;
731
732 new_len = gap->ga_itemsize * (gap->ga_len + n);
733 pp = vim_realloc(gap->ga_data, new_len);
734 if (pp == NULL)
735 return FAIL;
736 old_len = gap->ga_itemsize * gap->ga_maxlen;
737 vim_memset(pp + old_len, 0, new_len - old_len);
738 gap->ga_maxlen = gap->ga_len + n;
739 gap->ga_data = pp;
740 return OK;
741}
742
743/*
744 * For a growing array that contains a list of strings: concatenate all the
745 * strings with a separating "sep".
746 * Returns NULL when out of memory.
747 */
748 char_u *
749ga_concat_strings(garray_T *gap, char *sep)
750{
751 int i;
752 int len = 0;
753 int sep_len = (int)STRLEN(sep);
754 char_u *s;
755 char_u *p;
756
757 for (i = 0; i < gap->ga_len; ++i)
758 len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + sep_len;
759
760 s = alloc(len + 1);
761 if (s != NULL)
762 {
763 *s = NUL;
764 p = s;
765 for (i = 0; i < gap->ga_len; ++i)
766 {
767 if (p != s)
768 {
769 STRCPY(p, sep);
770 p += sep_len;
771 }
772 STRCPY(p, ((char_u **)(gap->ga_data))[i]);
773 p += STRLEN(p);
774 }
775 }
776 return s;
777}
778
779/*
780 * Make a copy of string "p" and add it to "gap".
781 * When out of memory nothing changes and FAIL is returned.
782 */
783 int
784ga_add_string(garray_T *gap, char_u *p)
785{
786 char_u *cp = vim_strsave(p);
787
788 if (cp == NULL)
789 return FAIL;
790
791 if (ga_grow(gap, 1) == FAIL)
792 {
793 vim_free(cp);
794 return FAIL;
795 }
796 ((char_u **)(gap->ga_data))[gap->ga_len++] = cp;
797 return OK;
798}
799
800/*
801 * Concatenate a string to a growarray which contains bytes.
802 * When "s" is NULL does not do anything.
803 * Note: Does NOT copy the NUL at the end!
804 */
805 void
806ga_concat(garray_T *gap, char_u *s)
807{
808 int len;
809
810 if (s == NULL || *s == NUL)
811 return;
812 len = (int)STRLEN(s);
813 if (ga_grow(gap, len) == OK)
814 {
815 mch_memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len);
816 gap->ga_len += len;
817 }
818}
819
820/*
821 * Concatenate 'len' bytes from string 's' to a growarray.
822 * When "s" is NULL does not do anything.
823 */
824 void
825ga_concat_len(garray_T *gap, char_u *s, size_t len)
826{
827 if (s == NULL || *s == NUL)
828 return;
829 if (ga_grow(gap, (int)len) == OK)
830 {
831 mch_memmove((char *)gap->ga_data + gap->ga_len, s, len);
832 gap->ga_len += (int)len;
833 }
834}
835
836/*
837 * Append one byte to a growarray which contains bytes.
838 */
839 void
840ga_append(garray_T *gap, int c)
841{
842 if (ga_grow(gap, 1) == OK)
843 {
844 *((char *)gap->ga_data + gap->ga_len) = c;
845 ++gap->ga_len;
846 }
847}
848
849#if (defined(UNIX) && !defined(USE_SYSTEM)) || defined(MSWIN) \
850 || defined(PROTO)
851/*
852 * Append the text in "gap" below the cursor line and clear "gap".
853 */
854 void
855append_ga_line(garray_T *gap)
856{
857 // Remove trailing CR.
858 if (gap->ga_len > 0
859 && !curbuf->b_p_bin
860 && ((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR)
861 --gap->ga_len;
862 ga_append(gap, NUL);
863 ml_append(curwin->w_cursor.lnum++, gap->ga_data, 0, FALSE);
864 gap->ga_len = 0;
865}
866#endif
867