To: vim_dev@googlegroups.com Subject: Patch 8.2.4063 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4063 Problem: Vim9: exported function in autoload script not found. (Yegappan Lakshmanan) Solution: Use the autoload prefix to search for the function. Files: src/userfunc.c, src/testdir/test_vim9_import.vim *** ../vim-8.2.4062/src/userfunc.c 2022-01-10 18:50:48.419345326 +0000 --- src/userfunc.c 2022-01-11 15:15:12.045039834 +0000 *************** *** 1871,1879 **** static ufunc_T * find_func_with_sid(char_u *name, int sid) { ! hashitem_T *hi; ! char_u buffer[200]; buffer[0] = K_SPECIAL; buffer[1] = KS_EXTRA; buffer[2] = (int)KE_SNR; --- 1871,1883 ---- static ufunc_T * find_func_with_sid(char_u *name, int sid) { ! hashitem_T *hi; ! char_u buffer[200]; ! ! if (!SCRIPT_ID_VALID(sid)) ! return NULL; // not in a script + // A script-local function is stored as "99_name". buffer[0] = K_SPECIAL; buffer[1] = KS_EXTRA; buffer[2] = (int)KE_SNR; *************** *** 1882,1887 **** --- 1886,1931 ---- hi = hash_find(&func_hashtab, buffer); if (!HASHITEM_EMPTY(hi)) return HI2UF(hi); + return NULL; + } + + /* + * Find a function "name" in script "sid" prefixing the autoload prefix. + */ + static ufunc_T * + find_func_with_prefix(char_u *name, int sid) + { + hashitem_T *hi; + char_u buffer[200]; + scriptitem_T *si; + + if (vim_strchr(name, AUTOLOAD_CHAR) != 0) + return NULL; // already has the prefix + if (!SCRIPT_ID_VALID(sid)) + return NULL; // not in a script + si = SCRIPT_ITEM(sid); + if (si->sn_autoload_prefix != NULL) + { + size_t len = STRLEN(si->sn_autoload_prefix) + STRLEN(name) + 1; + char_u *auto_name; + + // An exported function in an autoload script is stored as + // "dir#path#name". + if (len < sizeof(buffer)) + auto_name = buffer; + else + auto_name = alloc(len); + if (auto_name != NULL) + { + vim_snprintf((char *)auto_name, len, "%s%s", + si->sn_autoload_prefix, name); + hi = hash_find(&func_hashtab, auto_name); + if (auto_name != buffer) + vim_free(auto_name); + if (!HASHITEM_EMPTY(hi)) + return HI2UF(hi); + } + } return NULL; } *************** *** 1917,1923 **** if (!HASHITEM_EMPTY(hi)) return HI2UF(hi); ! return NULL; } /* --- 1961,1969 ---- if (!HASHITEM_EMPTY(hi)) return HI2UF(hi); ! // Find autoload function if this is an autoload script. ! return find_func_with_prefix(name[0] == 's' && name[1] == ':' ! ? name + 2 : name, current_sctx.sc_sid); } /* *** ../vim-8.2.4062/src/testdir/test_vim9_import.vim 2022-01-11 11:58:14.920745981 +0000 --- src/testdir/test_vim9_import.vim 2022-01-11 14:48:28.613685047 +0000 *************** *** 1146,1153 **** return 'test' enddef ! export func GetSome() ! return 'some' endfunc export var name = 'name' --- 1146,1153 ---- return 'test' enddef ! export func GetMore() ! return Gettest() .. 'more' endfunc export var name = 'name' *************** *** 1163,1169 **** assert_equal('test', prefixed.Gettest()) assert_equal('yes', g:prefixed_loaded) ! assert_equal('some', prefixed.GetSome()) assert_equal('name', prefixed.name) assert_equal('final', prefixed.fname) assert_equal('const', prefixed.cname) --- 1163,1169 ---- assert_equal('test', prefixed.Gettest()) assert_equal('yes', g:prefixed_loaded) ! assert_equal('testmore', prefixed.GetMore()) assert_equal('name', prefixed.name) assert_equal('final', prefixed.fname) assert_equal('const', prefixed.cname) *************** *** 1173,1179 **** # can also get the items by autoload name lines =<< trim END call assert_equal('test', prefixed#Gettest()) ! call assert_equal('some', prefixed#GetSome()) call assert_equal('name', prefixed#name) call assert_equal('final', prefixed#fname) call assert_equal('const', prefixed#cname) --- 1173,1179 ---- # can also get the items by autoload name lines =<< trim END call assert_equal('test', prefixed#Gettest()) ! call assert_equal('testmore', prefixed#GetMore()) call assert_equal('name', prefixed#name) call assert_equal('final', prefixed#fname) call assert_equal('const', prefixed#cname) *** ../vim-8.2.4062/src/version.c 2022-01-11 13:14:32.978510736 +0000 --- src/version.c 2022-01-11 14:15:42.474890394 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4063, /**/ -- They now pass three KNIGHTS impaled to a tree. With their feet off the ground, with one lance through the lot of them, they are skewered up like a barbecue. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///