]> granicus.if.org Git - vim/commitdiff
patch 8.2.5117: crash when calling a Lua callback from a :def function v8.2.5117
authorBram Moolenaar <Bram@vim.org>
Fri, 17 Jun 2022 18:23:34 +0000 (19:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 17 Jun 2022 18:23:34 +0000 (19:23 +0100)
Problem:    Crash when calling a Lua callback from a :def function. (Bohdan
            Makohin)
Solution:   Handle FC_CFUNC in call_user_func_check(). (closes #10587)

src/testdir/test_lua.vim
src/userfunc.c
src/version.c

index e45da6afc75420f64d2d8281a02895876fa61391..7fcd13d7dafad16266e1b33e6c33db5103b845ff 100644 (file)
@@ -664,6 +664,17 @@ func Test_lua_blob()
         \ '[string "vim chunk"]:1: string expected, got table')
 endfunc
 
+def Vim9Test(Callback: func())
+  Callback()
+enddef
+
+func Test_call_lua_func_from_vim9_func()
+  " this only tests that Vim doesn't crash
+  lua << EOF
+vim.fn.Vim9Test(function () print('Hello') end)
+EOF
+endfunc
+
 func Test_lua_funcref()
   function I(x)
     return a:x
index cc477fed331fbf45843269203d792558fb076e28..9b960b7752f3edfe3713c288a8c08bf5414a1bfe 100644 (file)
@@ -3021,6 +3021,15 @@ call_user_func_check(
 {
     int error;
 
+#ifdef FEAT_LUA
+    if (fp->uf_flags & FC_CFUNC)
+    {
+       cfunc_T cb = fp->uf_cb;
+
+       return (*cb)(argcount, argvars, rettv, fp->uf_cb_state);
+    }
+#endif
+
     if (fp->uf_flags & FC_RANGE && funcexe->fe_doesrange != NULL)
        *funcexe->fe_doesrange = TRUE;
     error = check_user_func_argcount(fp, argcount);
@@ -3584,14 +3593,6 @@ call_func(
 
            if (fp != NULL && (fp->uf_flags & FC_DELETED))
                error = FCERR_DELETED;
-#ifdef FEAT_LUA
-           else if (fp != NULL && (fp->uf_flags & FC_CFUNC))
-           {
-               cfunc_T cb = fp->uf_cb;
-
-               error = (*cb)(argcount, argvars, rettv, fp->uf_cb_state);
-           }
-#endif
            else if (fp != NULL)
            {
                if (funcexe->fe_argv_func != NULL)
index c842e19ddef26bd279c4d731eb16a20f6ae9f774..1b6fd289333df6818034ca12df7b074fb42c38be 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5117,
 /**/
     5116,
 /**/