patch 9.1.0844: if_python: no way to pass local vars to python
Problem: if_python: no way to pass local vars to python
Solution: Add locals argument to py3eval(), pyeval() and pyxeval()
(Ben Jackson)
fixes: #8573
closes: #10594
Signed-off-by: Ben Jackson <puremourning@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/if_py_both.h b/src/if_py_both.h
index 5ba443b..5603ac7 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -328,7 +328,7 @@
#define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1))
typedef void (*rangeinitializer)(void *);
-typedef void (*runner)(const char *, void *
+typedef void (*runner)(const char *, dict_T *, void *
#ifdef PY_CAN_RECURSE
, PyGILState_STATE *
#endif
@@ -6032,7 +6032,7 @@
}
static void
-run_cmd(const char *cmd, void *arg UNUSED
+run_cmd(const char *cmd, dict_T* locals UNUSED, void *arg UNUSED
#ifdef PY_CAN_RECURSE
, PyGILState_STATE *pygilstate UNUSED
#endif
@@ -6057,7 +6057,7 @@
static int code_hdr_len = 30;
static void
-run_do(const char *cmd, void *arg UNUSED
+run_do(const char *cmd, dict_T* locals UNUSED, void *arg UNUSED
#ifdef PY_CAN_RECURSE
, PyGILState_STATE *pygilstate
#endif
@@ -6180,7 +6180,7 @@
}
static void
-run_eval(const char *cmd, void *arg
+run_eval(const char *cmd, dict_T *locals, void *arg
#ifdef PY_CAN_RECURSE
, PyGILState_STATE *pygilstate UNUSED
#endif
@@ -6188,8 +6188,9 @@
{
PyObject *run_ret;
typval_T *rettv = (typval_T*)arg;
+ PyObject *pylocals = locals ? NEW_DICTIONARY(locals) : globals;
- run_ret = PyRun_String((char *)cmd, Py_eval_input, globals, globals);
+ run_ret = PyRun_String((char *)cmd, Py_eval_input, globals, pylocals);
if (run_ret == NULL)
{
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))