4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Can't properly check memory leaks while running tests.
12 Solution: Add an argument to garbagecollect(). Delete functions and
13 variables in the test scripts.
14 Files: runtime/doc/eval.txt, src/eval.c, src/globals.h, src/main.c,
15 src/testdir/Makefile, src/testdir/test14.in,
16 src/testdir/test26.in, src/testdir/test34.in,
17 src/testdir/test45.in, src/testdir/test47.in,
18 src/testdir/test49.in, src/testdir/test55.in,
19 src/testdir/test56.in, src/testdir/test58.in,
20 src/testdir/test59.in, src/testdir/test60.in,
21 src/testdir/test60.vim, src/testdir/test62.in,
22 src/testdir/test63.in, src/testdir/test64.in
25 *** ../vim-7.1.119/runtime/doc/eval.txt Thu Jul 26 22:55:11 2007
26 --- runtime/doc/eval.txt Tue Sep 25 17:40:30 2007
29 ! *eval.txt* For Vim version 7.1. Last change: 2007 Jul 25
32 VIM REFERENCE MANUAL by Bram Moolenaar
34 ! *eval.txt* For Vim version 7.1. Last change: 2007 Sep 25
37 VIM REFERENCE MANUAL by Bram Moolenaar
40 foldtextresult( {lnum}) String text for closed fold at {lnum}
41 foreground( ) Number bring the Vim window to the foreground
42 function( {name}) Funcref reference to function {name}
43 ! garbagecollect() none free memory, breaking cyclic references
44 get( {list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
45 get( {dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
46 getbufline( {expr}, {lnum} [, {end}])
48 foldtextresult( {lnum}) String text for closed fold at {lnum}
49 foreground( ) Number bring the Vim window to the foreground
50 function( {name}) Funcref reference to function {name}
51 ! garbagecollect( [at_exit]) none free memory, breaking cyclic references
52 get( {list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
53 get( {dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
54 getbufline( {expr}, {lnum} [, {end}])
57 {name} can be a user defined function or an internal function.
60 ! garbagecollect() *garbagecollect()*
61 Cleanup unused |Lists| and |Dictionaries| that have circular
62 references. There is hardly ever a need to invoke this
63 function, as it is automatically done when Vim runs out of
65 {name} can be a user defined function or an internal function.
68 ! garbagecollect([at_exit]) *garbagecollect()*
69 Cleanup unused |Lists| and |Dictionaries| that have circular
70 references. There is hardly ever a need to invoke this
71 function, as it is automatically done when Vim runs out of
75 This is useful if you have deleted a very big |List| and/or
76 |Dictionary| with circular references in a script that runs
78 + When the optional "at_exit" argument is one, garbage
79 + collection will also be done when exiting Vim, if it wasn't
80 + done before. This is useful when checking for memory leaks.
82 get({list}, {idx} [, {default}]) *get()*
83 Get item {idx} from |List| {list}. When this item is not
84 *** ../vim-7.1.119/src/eval.c Tue Sep 25 12:50:00 2007
85 --- src/eval.c Sun Sep 16 19:24:49 2007
89 /* Only do this once. */
90 want_garbage_collect = FALSE;
91 may_garbage_collect = FALSE;
92 + garbage_collect_at_exit = FALSE;
95 * 1. Go through all accessible variables and mark all lists and dicts
98 {"foldtextresult", 1, 1, f_foldtextresult},
99 {"foreground", 0, 0, f_foreground},
100 {"function", 1, 1, f_function},
101 ! {"garbagecollect", 0, 0, f_garbagecollect},
102 {"get", 2, 3, f_get},
103 {"getbufline", 2, 3, f_getbufline},
104 {"getbufvar", 2, 2, f_getbufvar},
106 {"foldtextresult", 1, 1, f_foldtextresult},
107 {"foreground", 0, 0, f_foreground},
108 {"function", 1, 1, f_function},
109 ! {"garbagecollect", 0, 1, f_garbagecollect},
110 {"get", 2, 3, f_get},
111 {"getbufline", 2, 3, f_getbufline},
112 {"getbufvar", 2, 2, f_getbufvar},
116 /* This is postponed until we are back at the toplevel, because we may be
117 * using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */
118 want_garbage_collect = TRUE;
120 + if (argvars[0].v_type != VAR_UNKNOWN && get_tv_number(&argvars[0]) == 1)
121 + garbage_collect_at_exit = TRUE;
125 *** ../vim-7.1.119/src/globals.h Thu Aug 30 13:51:52 2007
126 --- src/globals.h Sun Sep 16 18:42:41 2007
132 ! /* Garbage collection can only take place when we are sure there are no Lists
133 * or Dictionaries being used internally. This is flagged with
134 * "may_garbage_collect" when we are at the toplevel.
135 * "want_garbage_collect" is set by the garbagecollect() function, which means
136 ! * we do garbage collection before waiting for a char at the toplevel. */
137 EXTERN int may_garbage_collect INIT(= FALSE);
138 EXTERN int want_garbage_collect INIT(= FALSE);
140 /* ID of script being sourced or was sourced to define the current function. */
141 EXTERN scid_T current_SID INIT(= 0);
147 ! * Garbage collection can only take place when we are sure there are no Lists
148 * or Dictionaries being used internally. This is flagged with
149 * "may_garbage_collect" when we are at the toplevel.
150 * "want_garbage_collect" is set by the garbagecollect() function, which means
151 ! * we do garbage collection before waiting for a char at the toplevel.
152 ! * "garbage_collect_at_exit" indicates garbagecollect(1) was called.
154 EXTERN int may_garbage_collect INIT(= FALSE);
155 EXTERN int want_garbage_collect INIT(= FALSE);
156 + EXTERN int garbage_collect_at_exit INIT(= FALSE);
158 /* ID of script being sourced or was sourced to define the current function. */
159 EXTERN scid_T current_SID INIT(= 0);
160 *** ../vim-7.1.119/src/main.c Thu Sep 6 17:38:06 2007
161 --- src/main.c Sun Sep 16 18:44:54 2007
169 + if (garbage_collect_at_exit)
175 *** ../vim-7.1.119/src/testdir/Makefile Tue Aug 14 17:28:14 2007
176 --- src/testdir/Makefile Mon Sep 17 20:04:13 2007
180 # Uncomment this line for using valgrind.
181 # The output goes into a file "valgrind.$PID" (sorry, no test number).
182 ! # VALGRIND = valgrind --tool=memcheck --num-callers=15 --logfile=valgrind
184 SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
185 test7.out test8.out test9.out test10.out test11.out \
188 # Uncomment this line for using valgrind.
189 # The output goes into a file "valgrind.$PID" (sorry, no test number).
190 ! # VALGRIND = valgrind --tool=memcheck --leak-check=yes --num-callers=15 --logfile=valgrind
192 SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
193 test7.out test8.out test9.out test10.out test11.out \
196 $(SCRIPTS) $(SCRIPTS_GUI): $(VIMPROG)
199 ! -rm -rf *.out *.failed *.rej *.orig test.log tiny.vim small.vim mbyte.vim test.ok X* viminfo
202 -rm -f $*.failed tiny.vim small.vim mbyte.vim test.ok X* viminfo
204 $(SCRIPTS) $(SCRIPTS_GUI): $(VIMPROG)
207 ! -rm -rf *.out *.failed *.rej *.orig test.log tiny.vim small.vim mbyte.vim test.ok X* valgrind.pid* viminfo
210 -rm -f $*.failed tiny.vim small.vim mbyte.vim test.ok X* viminfo
214 else echo $* NO OUTPUT >>test.log; \
216 -rm -rf X* test.ok viminfo
218 + test49.out: test49.vim
220 + test60.out: test60.vim
223 -echo Test results: >test.log
224 *** ../vim-7.1.119/src/testdir/test14.in Sun Jun 13 20:24:08 2004
225 --- src/testdir/test14.in Sun Sep 16 15:57:54 2007
229 : let tt = "o\<C-V>65\<C-V>x42\<C-V>o103 \<C-V>33a\<C-V>xfg\<C-V>o78\<Esc>"
236 *** ../vim-7.1.119/src/testdir/test26.in Sun Jun 13 17:05:48 2004
237 --- src/testdir/test26.in Sun Sep 16 16:54:19 2007
248 *** ../vim-7.1.119/src/testdir/test34.in Sun Apr 30 20:46:14 2006
249 --- src/testdir/test34.in Sun Sep 16 21:25:47 2007
255 ! [(one again
\e:$-5,$wq! test.out
263 ! [(one again
\e:$-5,$w! test.out
270 ! :unlet retval counter
275 *** ../vim-7.1.119/src/testdir/test45.in Sun Jun 13 19:57:02 2004
276 --- src/testdir/test45.in Sun Sep 16 18:27:20 2007
281 :call append("$", foldlevel("."))
282 :/^last/+1,$w! test.out
287 *** ../vim-7.1.119/src/testdir/test47.in Sun Jun 13 18:40:29 2004
288 --- src/testdir/test47.in Sun Sep 16 18:32:03 2007
292 :call append("$", two)
293 :call append("$", three)
295 + :unlet one two three
299 *** ../vim-7.1.119/src/testdir/test49.in Sun Jun 13 18:10:00 2004
300 --- src/testdir/test49.in Sun Sep 16 23:30:35 2007
303 This is a test of the script language.
305 If after adding a new test, the test output doesn't appear properly in
306 ! test49.failed, try to add one ore more "G"s at the line before ENDTEST.
310 :se nocp nomore viminfo+=nviminfo
312 ! GGGGGGGGGG"rp:.-,$wq! test.out
315 Results of test49.vim:
317 This is a test of the script language.
319 If after adding a new test, the test output doesn't appear properly in
320 ! test49.failed, try to add one ore more "G"s at the line ending in "test.out"
324 :se nocp nomore viminfo+=nviminfo
326 ! GGGGGGGGGGGGGG"rp:.-,$w! test.out
328 ! :" make valgrind happy
332 ! :for line in split(funclist, "\n")
333 ! : let name = matchstr(line, 'function \zs[A-Z]\w*\ze(')
335 ! : exe "delfunc " . name
339 ! : silent! exe "unlet " . v
345 Results of test49.vim:
346 *** ../vim-7.1.119/src/testdir/test55.in Sat May 5 20:03:56 2007
347 --- src/testdir/test55.in Mon Sep 17 19:53:48 2007
352 :call Test(1, 2, [3, 4], {5: 6}) " This may take a while
356 + :call garbagecollect(1)
358 :/^start:/,$wq! test.out
361 *** ../vim-7.1.119/src/testdir/test56.in Tue Sep 5 13:36:02 2006
362 --- src/testdir/test56.in Sun Sep 16 17:54:20 2007
366 call append(line('$'), "nothing line")
368 ! nnoremap <buffer> _x :call <SID>DoNothing()<bar>call <SID>DoLast()<cr>
372 call append(line('$'), "nothing line")
374 ! nnoremap <buffer> _x :call <SID>DoNothing()<bar>call <SID>DoLast()<bar>delfunc <SID>DoNothing<bar>delfunc <SID>DoLast<cr>
376 *** ../vim-7.1.119/src/testdir/test58.in Wed Apr 5 22:38:56 2006
377 --- src/testdir/test58.in Sun Sep 16 18:17:03 2007
382 `m]s:let [str, a] = spellbadword()
386 :" Postponed prefixes
387 :call TestOne('2', '1')
393 :call TestOne('8', '8')
395 + :" clean up for valgrind
397 + :set spl= enc=latin1
399 gg:/^test output:/,$wq! test.out
401 *** ../vim-7.1.119/src/testdir/test59.in Wed Apr 5 22:27:11 2006
402 --- src/testdir/test59.in Sun Sep 16 18:17:23 2007
407 `m]s:let [str, a] = spellbadword()
411 :" Postponed prefixes
412 :call TestOne('2', '1')
416 :call TestOne('5', '5')
417 :call TestOne('6', '6')
418 :call TestOne('7', '7')
420 + :" clean up for valgrind
422 + :set spl= enc=latin1
424 gg:/^test output:/,$wq! test.out
426 *** ../vim-7.1.119/src/testdir/test60.in Fri May 5 23:11:11 2006
427 --- src/testdir/test60.in Mon Sep 17 19:58:43 2007
434 + :delfunc TestExists
436 + :delfunc TestFuncArg
440 *** ../vim-7.1.119/src/testdir/test60.vim Fri Jan 13 00:14:55 2006
441 --- src/testdir/test60.vim Mon Sep 17 19:56:02 2007
450 *** ../vim-7.1.119/src/testdir/test62.in Sun Apr 30 20:28:14 2006
451 --- src/testdir/test62.in Sun Sep 16 17:24:04 2007
455 :let nr = tabpagenr()
457 :call append(line('$'), 'tab page ' . nr)
460 :" Open three tab pages and use ":tabdo"
466 :call append(line('$'), line1)
467 :call append(line('$'), line2)
471 :/^Results/,$w! test.out
472 *** ../vim-7.1.119/src/testdir/test63.in Thu Jul 26 22:55:11 2007
473 --- src/testdir/test63.in Sun Sep 16 17:11:07 2007
477 : let @r .= "FAILED\n"
479 ! :" --- Check that "matchdelete()" returns 0 if succesfull and otherwise -1.
480 :let @r .= "*** Test 6: "
481 :let m = matchadd("MyGroup1", "TODO")
482 :let r1 = matchdelete(m)
485 : let @r .= "FAILED\n"
487 ! :" --- Check that "matchdelete()" returns 0 if successful and otherwise -1.
488 :let @r .= "*** Test 6: "
489 :let m = matchadd("MyGroup1", "TODO")
490 :let r1 = matchdelete(m)
493 :" --- Check that "setmatches()" will not add two matches with the same ID. The
494 :" --- expected behaviour (for now) is to add the first match but not the
495 :" --- second and to return 0 (even though it is a matter of debate whether
496 ! :" --- this can be considered succesfull behaviour).
497 :let @r .= "*** Test 9: "
498 :let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])
499 :if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}] && r1 == 0
501 :" --- Check that "setmatches()" will not add two matches with the same ID. The
502 :" --- expected behaviour (for now) is to add the first match but not the
503 :" --- second and to return 0 (even though it is a matter of debate whether
504 ! :" --- this can be considered successful behaviour).
505 :let @r .= "*** Test 9: "
506 :let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])
507 :if getmatches() == [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}] && r1 == 0
513 ! :" --- Check that "setmatches()" returns 0 if succesfull and otherwise -1.
514 :" --- (A range of valid and invalid input values are tried out to generate the
515 :" --- return values.)
516 :let @r .= "*** Test 10: "
521 ! :" --- Check that "setmatches()" returns 0 if successful and otherwise -1.
522 :" --- (A range of valid and invalid input values are tried out to generate the
523 :" --- return values.)
524 :let @r .= "*** Test 10: "
525 *** ../vim-7.1.119/src/testdir/test64.in Tue Aug 14 17:28:14 2007
526 --- src/testdir/test64.in Sun Sep 16 17:43:03 2007
530 : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
537 :/^Results/,$wq! test.out
540 *** ../vim-7.1.119/src/version.c Tue Sep 25 14:50:19 2007
541 --- src/version.c Tue Sep 25 17:36:22 2007
545 { /* Add new patch number below this line */
551 BEDEVERE: How do you know so much about swallows?
552 ARTHUR: Well you have to know these things when you're a king, you know.
553 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
555 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
556 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
557 \\\ download, build and distribute -- http://www.A-A-P.org ///
558 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///