comparison src/evalfunc.c @ 16078:d13aa9c5a1d1 v8.1.1044

patch 8.1.1044: no way to check the reference count of objects commit https://github.com/vim/vim/commit/c3e92c161d6394d126a334011526c02e8c3f655f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 23 14:23:07 2019 +0100 patch 8.1.1044: no way to check the reference count of objects Problem: No way to check the reference count of objects. Solution: Add test_refcount(). (Ozaki Kiichi, closes https://github.com/vim/vim/issues/4124)
author Bram Moolenaar <Bram@vim.org>
date Sat, 23 Mar 2019 14:30:05 +0100
parents c435843c7535
children 518f44125207
comparison
equal deleted inserted replaced
16077:e5e2a222cb79 16078:d13aa9c5a1d1
426 static void f_test_alloc_fail(typval_T *argvars, typval_T *rettv); 426 static void f_test_alloc_fail(typval_T *argvars, typval_T *rettv);
427 static void f_test_autochdir(typval_T *argvars, typval_T *rettv); 427 static void f_test_autochdir(typval_T *argvars, typval_T *rettv);
428 static void f_test_feedinput(typval_T *argvars, typval_T *rettv); 428 static void f_test_feedinput(typval_T *argvars, typval_T *rettv);
429 static void f_test_option_not_set(typval_T *argvars, typval_T *rettv); 429 static void f_test_option_not_set(typval_T *argvars, typval_T *rettv);
430 static void f_test_override(typval_T *argvars, typval_T *rettv); 430 static void f_test_override(typval_T *argvars, typval_T *rettv);
431 static void f_test_refcount(typval_T *argvars, typval_T *rettv);
431 static void f_test_garbagecollect_now(typval_T *argvars, typval_T *rettv); 432 static void f_test_garbagecollect_now(typval_T *argvars, typval_T *rettv);
432 static void f_test_ignore_error(typval_T *argvars, typval_T *rettv); 433 static void f_test_ignore_error(typval_T *argvars, typval_T *rettv);
433 static void f_test_null_blob(typval_T *argvars, typval_T *rettv); 434 static void f_test_null_blob(typval_T *argvars, typval_T *rettv);
434 #ifdef FEAT_JOB_CHANNEL 435 #ifdef FEAT_JOB_CHANNEL
435 static void f_test_null_channel(typval_T *argvars, typval_T *rettv); 436 static void f_test_null_channel(typval_T *argvars, typval_T *rettv);
950 {"test_alloc_fail", 3, 3, f_test_alloc_fail}, 951 {"test_alloc_fail", 3, 3, f_test_alloc_fail},
951 {"test_autochdir", 0, 0, f_test_autochdir}, 952 {"test_autochdir", 0, 0, f_test_autochdir},
952 {"test_feedinput", 1, 1, f_test_feedinput}, 953 {"test_feedinput", 1, 1, f_test_feedinput},
953 {"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now}, 954 {"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now},
954 {"test_ignore_error", 1, 1, f_test_ignore_error}, 955 {"test_ignore_error", 1, 1, f_test_ignore_error},
955 {"test_null_blob", 0, 0, f_test_null_blob}, 956 {"test_null_blob", 0, 0, f_test_null_blob},
956 #ifdef FEAT_JOB_CHANNEL 957 #ifdef FEAT_JOB_CHANNEL
957 {"test_null_channel", 0, 0, f_test_null_channel}, 958 {"test_null_channel", 0, 0, f_test_null_channel},
958 #endif 959 #endif
959 {"test_null_dict", 0, 0, f_test_null_dict}, 960 {"test_null_dict", 0, 0, f_test_null_dict},
960 #ifdef FEAT_JOB_CHANNEL 961 #ifdef FEAT_JOB_CHANNEL
962 #endif 963 #endif
963 {"test_null_list", 0, 0, f_test_null_list}, 964 {"test_null_list", 0, 0, f_test_null_list},
964 {"test_null_partial", 0, 0, f_test_null_partial}, 965 {"test_null_partial", 0, 0, f_test_null_partial},
965 {"test_null_string", 0, 0, f_test_null_string}, 966 {"test_null_string", 0, 0, f_test_null_string},
966 {"test_option_not_set", 1, 1, f_test_option_not_set}, 967 {"test_option_not_set", 1, 1, f_test_option_not_set},
967 {"test_override", 2, 2, f_test_override}, 968 {"test_override", 2, 2, f_test_override},
969 {"test_refcount", 1, 1, f_test_refcount},
968 #ifdef FEAT_GUI 970 #ifdef FEAT_GUI
969 {"test_scrollbar", 3, 3, f_test_scrollbar}, 971 {"test_scrollbar", 3, 3, f_test_scrollbar},
970 #endif 972 #endif
971 {"test_settime", 1, 1, f_test_settime}, 973 {"test_settime", 1, 1, f_test_settime},
972 #ifdef FEAT_TIMERS 974 #ifdef FEAT_TIMERS
13845 semsg(_(e_invarg2), name); 13847 semsg(_(e_invarg2), name);
13846 } 13848 }
13847 } 13849 }
13848 13850
13849 /* 13851 /*
13852 * "test_refcount({expr})" function
13853 */
13854 static void
13855 f_test_refcount(typval_T *argvars, typval_T *rettv)
13856 {
13857 int retval = -1;
13858
13859 switch (argvars[0].v_type)
13860 {
13861 case VAR_UNKNOWN:
13862 case VAR_NUMBER:
13863 case VAR_FLOAT:
13864 case VAR_SPECIAL:
13865 case VAR_STRING:
13866 break;
13867 case VAR_JOB:
13868 #ifdef FEAT_JOB_CHANNEL
13869 if (argvars[0].vval.v_job != NULL)
13870 retval = argvars[0].vval.v_job->jv_refcount - 1;
13871 #endif
13872 break;
13873 case VAR_CHANNEL:
13874 #ifdef FEAT_JOB_CHANNEL
13875 if (argvars[0].vval.v_channel != NULL)
13876 retval = argvars[0].vval.v_channel->ch_refcount - 1;
13877 #endif
13878 break;
13879 case VAR_FUNC:
13880 if (argvars[0].vval.v_string != NULL)
13881 {
13882 ufunc_T *fp;
13883
13884 fp = find_func(argvars[0].vval.v_string);
13885 if (fp != NULL)
13886 retval = fp->uf_refcount;
13887 }
13888 break;
13889 case VAR_PARTIAL:
13890 if (argvars[0].vval.v_partial != NULL)
13891 retval = argvars[0].vval.v_partial->pt_refcount - 1;
13892 break;
13893 case VAR_BLOB:
13894 if (argvars[0].vval.v_blob != NULL)
13895 retval = argvars[0].vval.v_blob->bv_refcount - 1;
13896 break;
13897 case VAR_LIST:
13898 if (argvars[0].vval.v_list != NULL)
13899 retval = argvars[0].vval.v_list->lv_refcount - 1;
13900 break;
13901 case VAR_DICT:
13902 if (argvars[0].vval.v_dict != NULL)
13903 retval = argvars[0].vval.v_dict->dv_refcount - 1;
13904 break;
13905 }
13906
13907 rettv->v_type = VAR_NUMBER;
13908 rettv->vval.v_number = retval;
13909
13910 }
13911
13912 /*
13850 * "test_garbagecollect_now()" function 13913 * "test_garbagecollect_now()" function
13851 */ 13914 */
13852 static void 13915 static void
13853 f_test_garbagecollect_now(typval_T *argvars UNUSED, typval_T *rettv UNUSED) 13916 f_test_garbagecollect_now(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
13854 { 13917 {