To: vim_dev@googlegroups.com Subject: Patch 7.4.1838 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1838 Problem: Functions specifically for testing do not sort together. Solution: Rename garbagecollect_for_testing() to test_garbagecollect_now(). Add test_null_list(), test_null_dict(), etc. Files: src/eval.c, src/testdir/test_expr.vim, src/testdir/test_channel.vim, runtime/doc/eval.txt *** ../vim-7.4.1837/src/eval.c 2016-05-24 15:43:46.699296634 +0200 --- src/eval.c 2016-05-24 16:26:04.979261718 +0200 *************** *** 583,589 **** static void f_foreground(typval_T *argvars, typval_T *rettv); static void f_function(typval_T *argvars, typval_T *rettv); static void f_garbagecollect(typval_T *argvars, typval_T *rettv); - static void f_garbagecollect_for_testing(typval_T *argvars, typval_T *rettv); static void f_get(typval_T *argvars, typval_T *rettv); static void f_getbufline(typval_T *argvars, typval_T *rettv); static void f_getbufvar(typval_T *argvars, typval_T *rettv); --- 583,588 ---- *************** *** 806,812 **** static void f_taglist(typval_T *argvars, typval_T *rettv); static void f_tagfiles(typval_T *argvars, typval_T *rettv); static void f_tempname(typval_T *argvars, typval_T *rettv); ! static void f_test(typval_T *argvars, typval_T *rettv); #ifdef FEAT_FLOAT static void f_tan(typval_T *argvars, typval_T *rettv); static void f_tanh(typval_T *argvars, typval_T *rettv); --- 805,821 ---- static void f_taglist(typval_T *argvars, typval_T *rettv); static void f_tagfiles(typval_T *argvars, typval_T *rettv); static void f_tempname(typval_T *argvars, typval_T *rettv); ! static void f_test_garbagecollect_now(typval_T *argvars, typval_T *rettv); ! #ifdef FEAT_JOB_CHANNEL ! static void f_test_null_channel(typval_T *argvars, typval_T *rettv); ! #endif ! static void f_test_null_dict(typval_T *argvars, typval_T *rettv); ! #ifdef FEAT_JOB_CHANNEL ! static void f_test_null_job(typval_T *argvars, typval_T *rettv); ! #endif ! static void f_test_null_list(typval_T *argvars, typval_T *rettv); ! static void f_test_null_partial(typval_T *argvars, typval_T *rettv); ! static void f_test_null_string(typval_T *argvars, typval_T *rettv); #ifdef FEAT_FLOAT static void f_tan(typval_T *argvars, typval_T *rettv); static void f_tanh(typval_T *argvars, typval_T *rettv); *************** *** 6925,6931 **** /* * Do garbage collection for lists and dicts. ! * When "testing" is TRUE this is called from garbagecollect_for_testing(). * Return TRUE if some memory was freed. */ int --- 6934,6940 ---- /* * Do garbage collection for lists and dicts. ! * When "testing" is TRUE this is called from test_garbagecollect_now(). * Return TRUE if some memory was freed. */ int *************** *** 8451,8457 **** {"foreground", 0, 0, f_foreground}, {"function", 1, 3, f_function}, {"garbagecollect", 0, 1, f_garbagecollect}, - {"garbagecollect_for_testing", 0, 0, f_garbagecollect_for_testing}, {"get", 2, 3, f_get}, {"getbufline", 2, 3, f_getbufline}, {"getbufvar", 2, 3, f_getbufvar}, --- 8460,8465 ---- *************** *** 8681,8687 **** {"tanh", 1, 1, f_tanh}, #endif {"tempname", 0, 0, f_tempname}, ! {"test", 1, 1, f_test}, #ifdef FEAT_TIMERS {"timer_start", 2, 3, f_timer_start}, {"timer_stop", 1, 1, f_timer_stop}, --- 8689,8705 ---- {"tanh", 1, 1, f_tanh}, #endif {"tempname", 0, 0, f_tempname}, ! {"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now}, ! #ifdef FEAT_JOB_CHANNEL ! {"test_null_channel", 0, 0, f_test_null_channel}, ! #endif ! {"test_null_dict", 0, 0, f_test_null_dict}, ! #ifdef FEAT_JOB_CHANNEL ! {"test_null_job", 0, 0, f_test_null_job}, ! #endif ! {"test_null_list", 0, 0, f_test_null_list}, ! {"test_null_partial", 0, 0, f_test_null_partial}, ! {"test_null_string", 0, 0, f_test_null_string}, #ifdef FEAT_TIMERS {"timer_start", 2, 3, f_timer_start}, {"timer_stop", 1, 1, f_timer_stop}, *************** *** 12374,12390 **** } /* - * "garbagecollect_for_testing()" function - */ - static void - f_garbagecollect_for_testing(typval_T *argvars UNUSED, typval_T *rettv UNUSED) - { - /* This is dangerous, any Lists and Dicts used internally may be freed - * while still in use. */ - garbage_collect(TRUE); - } - - /* * "get()" function */ static void --- 12392,12397 ---- *************** *** 20602,20636 **** } while (x == 'I' || x == 'O'); } - /* - * "test(list)" function: Just checking the walls... - */ - static void - f_test(typval_T *argvars UNUSED, typval_T *rettv UNUSED) - { - /* Used for unit testing. Change the code below to your liking. */ - #if 0 - listitem_T *li; - list_T *l; - char_u *bad, *good; - - if (argvars[0].v_type != VAR_LIST) - return; - l = argvars[0].vval.v_list; - if (l == NULL) - return; - li = l->lv_first; - if (li == NULL) - return; - bad = get_tv_string(&li->li_tv); - li = li->li_next; - if (li == NULL) - return; - good = get_tv_string(&li->li_tv); - rettv->vval.v_number = test_edit_score(bad, good); - #endif - } - #ifdef FEAT_FLOAT /* * "tan()" function --- 20609,20614 ---- *************** *** 20663,20668 **** --- 20641,20703 ---- } #endif + /* + * "test_garbagecollect_now()" function + */ + static void + f_test_garbagecollect_now(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + /* This is dangerous, any Lists and Dicts used internally may be freed + * while still in use. */ + garbage_collect(TRUE); + } + + #ifdef FEAT_JOB_CHANNEL + static void + f_test_null_channel(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + rettv->v_type = VAR_CHANNEL; + rettv->vval.v_channel = NULL; + } + #endif + + static void + f_test_null_dict(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + rettv->v_type = VAR_DICT; + rettv->vval.v_dict = NULL; + } + + #ifdef FEAT_JOB_CHANNEL + static void + f_test_null_job(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + rettv->v_type = VAR_JOB; + rettv->vval.v_job = NULL; + } + #endif + + static void + f_test_null_list(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + rettv->v_type = VAR_LIST; + rettv->vval.v_list = NULL; + } + + static void + f_test_null_partial(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + rettv->v_type = VAR_PARTIAL; + rettv->vval.v_partial = NULL; + } + + static void + f_test_null_string(typval_T *argvars UNUSED, typval_T *rettv UNUSED) + { + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; + } + #if defined(FEAT_JOB_CHANNEL) || defined(FEAT_TIMERS) || defined(PROTO) /* * Get a callback from "arg". It can be a Funcref or a function name. *** ../vim-7.4.1837/src/testdir/test_expr.vim 2016-05-01 23:05:49.674360477 +0200 --- src/testdir/test_expr.vim 2016-05-24 16:18:05.627268312 +0200 *************** *** 85,91 **** endfunc func Test_loop_over_null_list() ! let null_list = submatch(1, 1) for i in null_list call assert_true(0, 'should not get here') endfor --- 85,91 ---- endfunc func Test_loop_over_null_list() ! let null_list = test_null_list() for i in null_list call assert_true(0, 'should not get here') endfor *** ../vim-7.4.1837/src/testdir/test_channel.vim 2016-04-30 17:06:27.167577887 +0200 --- src/testdir/test_channel.vim 2016-05-24 16:29:47.783258653 +0200 *************** *** 183,189 **** call assert_equal('got it', s:responseMsg) " Collect garbage, tests that our handle isn't collected. ! call garbagecollect_for_testing() " check setting options (without testing the effect) call ch_setoptions(handle, {'callback': 's:NotUsed'}) --- 183,189 ---- call assert_equal('got it', s:responseMsg) " Collect garbage, tests that our handle isn't collected. ! call test_garbagecollect_now() " check setting options (without testing the effect) call ch_setoptions(handle, {'callback': 's:NotUsed'}) *************** *** 1302,1308 **** func Test_using_freed_memory() let g:a = job_start(['ls']) sleep 10m ! call garbagecollect_for_testing() endfunc --- 1302,1308 ---- func Test_using_freed_memory() let g:a = job_start(['ls']) sleep 10m ! call test_garbagecollect_now() endfunc *** ../vim-7.4.1837/runtime/doc/eval.txt 2016-05-24 15:43:46.703296634 +0200 --- runtime/doc/eval.txt 2016-05-24 17:14:31.495221737 +0200 *************** *** 1936,1942 **** function({name} [, {arglist}] [, {dict}]) Funcref reference to function {name} garbagecollect([{atexit}]) none free memory, breaking cyclic references - garbagecollect_for_testing() none free memory right now get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def} get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def} getbufline({expr}, {lnum} [, {end}]) --- 1955,1960 ---- *************** *** 2181,2186 **** --- 2202,2214 ---- tan({expr}) Float tangent of {expr} tanh({expr}) Float hyperbolic tangent of {expr} tempname() String name for a temporary file + test_garbagecollect_now() none free memory right now for testing + test_null_channel() Channel null value for testing + test_null_dict() Dict null value for testing + test_null_job() Job null value for testing + test_null_list() List null value for testing + test_null_partial() Funcref null value for testing + test_null_string() String null value for testing timer_start({time}, {callback} [, {options}]) Number create a timer timer_stop({timer}) none stop a timer *************** *** 3702,3712 **** collection will also be done when exiting Vim, if it wasn't done before. This is useful when checking for memory leaks. ! garbagecollect_for_testing() *garbagecollect_for_testing()* ! Like garbagecollect(), but executed right away. This must ! only be called directly to avoid any structure to exist ! internally, and |v:testing| must have been set before calling ! any function. get({list}, {idx} [, {default}]) *get()* Get item {idx} from |List| {list}. When this item is not --- 3758,3767 ---- collection will also be done when exiting Vim, if it wasn't done before. This is useful when checking for memory leaks. ! The garbage collection is not done immediately but only when ! it's safe to perform. This is when waiting for the user to ! type a character. To force garbage collection immediately use ! |test_garbagecollect_now()|. get({list}, {idx} [, {default}]) *get()* Get item {idx} from |List| {list}. When this item is not *************** *** 7040,7056 **** located by Vim. Refer to |tags-file-format| for the format of the tags file generated by the different ctags tools. - tempname() *tempname()* *temp-file-name* - The result is a String, which is the name of a file that - doesn't exist. It can be used for a temporary file. The name - is different for at least 26 consecutive calls. Example: > - :let tmpfile = tempname() - :exe "redir > " . tmpfile - < For Unix, the file will be in a private directory |tempfile|. - For MS-Windows forward slashes are used when the 'shellslash' - option is set or when 'shellcmdflag' starts with '-'. - - tan({expr}) *tan()* Return the tangent of {expr}, measured in radians, as a |Float| in the range [-inf, inf]. --- 7170,7175 ---- *************** *** 7075,7080 **** --- 7194,7237 ---- {only available when compiled with the |+float| feature} + tempname() *tempname()* *temp-file-name* + The result is a String, which is the name of a file that + doesn't exist. It can be used for a temporary file. The name + is different for at least 26 consecutive calls. Example: > + :let tmpfile = tempname() + :exe "redir > " . tmpfile + < For Unix, the file will be in a private directory |tempfile|. + For MS-Windows forward slashes are used when the 'shellslash' + option is set or when 'shellcmdflag' starts with '-'. + + + test_garbagecollect_now() *test_garbagecollect_now()* + Like garbagecollect(), but executed right away. This must + only be called directly to avoid any structure to exist + internally, and |v:testing| must have been set before calling + any function. + + test_null_channel() *test_null_channel()* + Return a Channel that is null. Only useful for testing. + {only available when compiled with the +channel feature} + + test_null_dict() *test_null_dict()* + Return a Dict that is null. Only useful for testing. + + test_null_job() *test_null_job()* + Return a Job that is null. Only useful for testing. + {only available when compiled with the +job feature} + + test_null_list() *test_null_list()* + Return a List that is null. Only useful for testing. + + test_null_partial() *test_null_partial()* + Return a Partial that is null. Only useful for testing. + + test_null_string() *test_null_string()* + Return a String that is null. Only useful for testing. + + *timer_start()* timer_start({time}, {callback} [, {options}]) Create a timer and return the timer ID. *** ../vim-7.4.1837/src/version.c 2016-05-24 16:07:35.035276986 +0200 --- src/version.c 2016-05-24 16:30:09.703258352 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1838, /**/ -- A consultant is a person who takes your money and annoys your employees while tirelessly searching for the best way to extend the consulting contract. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///