changeset 29196:e391590249a1 v8.2.5117

patch 8.2.5117: crash when calling a Lua callback from a :def function Commit: https://github.com/vim/vim/commit/7d149f899d423b7bf2b90d7b11ebe3e560c462b9 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 17 19:23:34 2022 +0100 patch 8.2.5117: crash when calling a Lua callback from a :def function Problem: Crash when calling a Lua callback from a :def function. (Bohdan Makohin) Solution: Handle FC_CFUNC in call_user_func_check(). (closes #10587)
author Bram Moolenaar <Bram@vim.org>
date Fri, 17 Jun 2022 20:30:03 +0200
parents ee8ebed77cee
children d2d4cfebc668
files src/testdir/test_lua.vim src/userfunc.c src/version.c
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_lua.vim
+++ b/src/testdir/test_lua.vim
@@ -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
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -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)
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    5117,
+/**/
     5116,
 /**/
     5115,