blob: 42caa418019711f9e1860fb5b933e2fce324ca91 [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
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200424 free_titles();
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200425# if defined(FEAT_SEARCHPATH)
426 free_findfile();
427# endif
428
429 // Obviously named calls.
430 free_all_autocmds();
431 clear_termcodes();
432 free_all_marks();
433 alist_clear(&global_alist);
434 free_homedir();
435 free_users();
436 free_search_patterns();
437 free_old_sub();
438 free_last_insert();
439 free_insexpand_stuff();
440 free_prev_shellcmd();
441 free_regexp_stuff();
442 free_tag_stuff();
443 free_cd_dir();
444# ifdef FEAT_SIGNS
445 free_signs();
446# endif
447# ifdef FEAT_EVAL
448 set_expr_line(NULL, NULL);
449# endif
450# ifdef FEAT_DIFF
451 if (curtab != NULL)
452 diff_clear(curtab);
453# endif
454 clear_sb_text(TRUE); // free any scrollback text
455
456 // Free some global vars.
457 free_username();
458# ifdef FEAT_CLIPBOARD
459 vim_regfree(clip_exclude_prog);
460# endif
461 vim_free(last_cmdline);
462 vim_free(new_last_cmdline);
463 set_keep_msg(NULL, 0);
464
465 // Clear cmdline history.
466 p_hi = 0;
467 init_history();
468# ifdef FEAT_PROP_POPUP
469 clear_global_prop_types();
470# endif
471
472# ifdef FEAT_QUICKFIX
473 {
474 win_T *win;
475 tabpage_T *tab;
476
477 qf_free_all(NULL);
478 // Free all location lists
479 FOR_ALL_TAB_WINDOWS(tab, win)
480 qf_free_all(win);
481 }
482# endif
483
484 // Close all script inputs.
485 close_all_scripts();
486
487 if (curwin != NULL)
488 // Destroy all windows. Must come before freeing buffers.
489 win_free_all();
490
491 // Free all option values. Must come after closing windows.
492 free_all_options();
493
494 // Free all buffers. Reset 'autochdir' to avoid accessing things that
495 // were freed already.
496# ifdef FEAT_AUTOCHDIR
497 p_acd = FALSE;
498# endif
499 for (buf = firstbuf; buf != NULL; )
500 {
501 bufref_T bufref;
502
503 set_bufref(&bufref, buf);
504 nextbuf = buf->b_next;
505 close_buffer(NULL, buf, DOBUF_WIPE, FALSE, FALSE);
506 if (bufref_valid(&bufref))
507 buf = nextbuf; // didn't work, try next one
508 else
509 buf = firstbuf;
510 }
511
512# ifdef FEAT_ARABIC
513 free_arshape_buf();
514# endif
515
516 // Clear registers.
517 clear_registers();
518 ResetRedobuff();
519 ResetRedobuff();
520
521# if defined(FEAT_CLIENTSERVER) && defined(FEAT_X11)
522 vim_free(serverDelayedStartName);
523# endif
524
525 // highlight info
526 free_highlight();
527
528 reset_last_sourcing();
529
530 if (first_tabpage != NULL)
531 {
532 free_tabpage(first_tabpage);
533 first_tabpage = NULL;
534 }
535
536# ifdef UNIX
537 // Machine-specific free.
538 mch_free_mem();
539# endif
540
541 // message history
542 for (;;)
543 if (delete_first_msg() == FAIL)
544 break;
545
546# ifdef FEAT_JOB_CHANNEL
547 channel_free_all();
548# endif
549# ifdef FEAT_TIMERS
550 timer_free_all();
551# endif
552# ifdef FEAT_EVAL
553 // must be after channel_free_all() with unrefs partials
554 eval_clear();
555# endif
556# ifdef FEAT_JOB_CHANNEL
557 // must be after eval_clear() with unrefs jobs
558 job_free_all();
559# endif
560
561 free_termoptions();
Bram Moolenaarb3a29552021-11-19 11:28:04 +0000562 free_cur_term();
Yegappan Lakshmanancbae5802021-08-06 21:51:55 +0200563
564 // screenlines (can't display anything now!)
565 free_screenlines();
566
567# if defined(FEAT_SOUND)
568 sound_free();
569# endif
570# if defined(USE_XSMP)
571 xsmp_close();
572# endif
573# ifdef FEAT_GUI_GTK
574 gui_mch_free_all();
575# endif
576 clear_hl_tables();
577
578 vim_free(IObuff);
579 vim_free(NameBuff);
580# ifdef FEAT_QUICKFIX
581 check_quickfix_busy();
582# endif
583}
584#endif
585
586/*
587 * Copy "p[len]" into allocated memory, ignoring NUL characters.
588 * Returns NULL when out of memory.
589 */
590 char_u *
591vim_memsave(char_u *p, size_t len)
592{
593 char_u *ret = alloc(len);
594
595 if (ret != NULL)
596 mch_memmove(ret, p, len);
597 return ret;
598}
599
600/*
601 * Replacement for free() that ignores NULL pointers.
602 * Also skip free() when exiting for sure, this helps when we caught a deadly
603 * signal that was caused by a crash in free().
604 * If you want to set NULL after calling this function, you should use
605 * VIM_CLEAR() instead.
606 */
607 void
608vim_free(void *x)
609{
610 if (x != NULL && !really_exiting)
611 {
612#ifdef MEM_PROFILE
613 mem_pre_free(&x);
614#endif
615 free(x);
616 }
617}
618
619/************************************************************************
620 * Functions for handling growing arrays.
621 */
622
623/*
624 * Clear an allocated growing array.
625 */
626 void
627ga_clear(garray_T *gap)
628{
629 vim_free(gap->ga_data);
630 ga_init(gap);
631}
632
633/*
634 * Clear a growing array that contains a list of strings.
635 */
636 void
637ga_clear_strings(garray_T *gap)
638{
639 int i;
640
641 if (gap->ga_data != NULL)
642 for (i = 0; i < gap->ga_len; ++i)
643 vim_free(((char_u **)(gap->ga_data))[i]);
644 ga_clear(gap);
645}
646
647/*
648 * Copy a growing array that contains a list of strings.
649 */
650 int
651ga_copy_strings(garray_T *from, garray_T *to)
652{
653 int i;
654
655 ga_init2(to, sizeof(char_u *), 1);
656 if (ga_grow(to, from->ga_len) == FAIL)
657 return FAIL;
658
659 for (i = 0; i < from->ga_len; ++i)
660 {
661 char_u *orig = ((char_u **)from->ga_data)[i];
662 char_u *copy;
663
664 if (orig == NULL)
665 copy = NULL;
666 else
667 {
668 copy = vim_strsave(orig);
669 if (copy == NULL)
670 {
671 to->ga_len = i;
672 ga_clear_strings(to);
673 return FAIL;
674 }
675 }
676 ((char_u **)to->ga_data)[i] = copy;
677 }
678 to->ga_len = from->ga_len;
679 return OK;
680}
681
682/*
683 * Initialize a growing array. Don't forget to set ga_itemsize and
684 * ga_growsize! Or use ga_init2().
685 */
686 void
687ga_init(garray_T *gap)
688{
689 gap->ga_data = NULL;
690 gap->ga_maxlen = 0;
691 gap->ga_len = 0;
692}
693
694 void
695ga_init2(garray_T *gap, int itemsize, int growsize)
696{
697 ga_init(gap);
698 gap->ga_itemsize = itemsize;
699 gap->ga_growsize = growsize;
700}
701
702/*
703 * Make room in growing array "gap" for at least "n" items.
704 * Return FAIL for failure, OK otherwise.
705 */
706 int
707ga_grow(garray_T *gap, int n)
708{
709 if (gap->ga_maxlen - gap->ga_len < n)
710 return ga_grow_inner(gap, n);
711 return OK;
712}
713
714 int
715ga_grow_inner(garray_T *gap, int n)
716{
717 size_t old_len;
718 size_t new_len;
719 char_u *pp;
720
721 if (n < gap->ga_growsize)
722 n = gap->ga_growsize;
723
724 // A linear growth is very inefficient when the array grows big. This
725 // is a compromise between allocating memory that won't be used and too
726 // many copy operations. A factor of 1.5 seems reasonable.
727 if (n < gap->ga_len / 2)
728 n = gap->ga_len / 2;
729
730 new_len = gap->ga_itemsize * (gap->ga_len + n);
731 pp = vim_realloc(gap->ga_data, new_len);
732 if (pp == NULL)
733 return FAIL;
734 old_len = gap->ga_itemsize * gap->ga_maxlen;
735 vim_memset(pp + old_len, 0, new_len - old_len);
736 gap->ga_maxlen = gap->ga_len + n;
737 gap->ga_data = pp;
738 return OK;
739}
740
741/*
742 * For a growing array that contains a list of strings: concatenate all the
743 * strings with a separating "sep".
744 * Returns NULL when out of memory.
745 */
746 char_u *
747ga_concat_strings(garray_T *gap, char *sep)
748{
749 int i;
750 int len = 0;
751 int sep_len = (int)STRLEN(sep);
752 char_u *s;
753 char_u *p;
754
755 for (i = 0; i < gap->ga_len; ++i)
756 len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + sep_len;
757
758 s = alloc(len + 1);
759 if (s != NULL)
760 {
761 *s = NUL;
762 p = s;
763 for (i = 0; i < gap->ga_len; ++i)
764 {
765 if (p != s)
766 {
767 STRCPY(p, sep);
768 p += sep_len;
769 }
770 STRCPY(p, ((char_u **)(gap->ga_data))[i]);
771 p += STRLEN(p);
772 }
773 }
774 return s;
775}
776
777/*
778 * Make a copy of string "p" and add it to "gap".
779 * When out of memory nothing changes and FAIL is returned.
780 */
781 int
782ga_add_string(garray_T *gap, char_u *p)
783{
784 char_u *cp = vim_strsave(p);
785
786 if (cp == NULL)
787 return FAIL;
788
789 if (ga_grow(gap, 1) == FAIL)
790 {
791 vim_free(cp);
792 return FAIL;
793 }
794 ((char_u **)(gap->ga_data))[gap->ga_len++] = cp;
795 return OK;
796}
797
798/*
799 * Concatenate a string to a growarray which contains bytes.
800 * When "s" is NULL does not do anything.
801 * Note: Does NOT copy the NUL at the end!
802 */
803 void
804ga_concat(garray_T *gap, char_u *s)
805{
806 int len;
807
808 if (s == NULL || *s == NUL)
809 return;
810 len = (int)STRLEN(s);
811 if (ga_grow(gap, len) == OK)
812 {
813 mch_memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len);
814 gap->ga_len += len;
815 }
816}
817
818/*
819 * Concatenate 'len' bytes from string 's' to a growarray.
820 * When "s" is NULL does not do anything.
821 */
822 void
823ga_concat_len(garray_T *gap, char_u *s, size_t len)
824{
825 if (s == NULL || *s == NUL)
826 return;
827 if (ga_grow(gap, (int)len) == OK)
828 {
829 mch_memmove((char *)gap->ga_data + gap->ga_len, s, len);
830 gap->ga_len += (int)len;
831 }
832}
833
834/*
835 * Append one byte to a growarray which contains bytes.
836 */
837 void
838ga_append(garray_T *gap, int c)
839{
840 if (ga_grow(gap, 1) == OK)
841 {
842 *((char *)gap->ga_data + gap->ga_len) = c;
843 ++gap->ga_len;
844 }
845}
846
847#if (defined(UNIX) && !defined(USE_SYSTEM)) || defined(MSWIN) \
848 || defined(PROTO)
849/*
850 * Append the text in "gap" below the cursor line and clear "gap".
851 */
852 void
853append_ga_line(garray_T *gap)
854{
855 // Remove trailing CR.
856 if (gap->ga_len > 0
857 && !curbuf->b_p_bin
858 && ((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR)
859 --gap->ga_len;
860 ga_append(gap, NUL);
861 ml_append(curwin->w_cursor.lnum++, gap->ga_data, 0, FALSE);
862 gap->ga_len = 0;
863}
864#endif
865