0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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>
This commit is contained in:
Ben Jackson
2024-11-06 21:50:05 +01:00
committed by Christian Brabandt
parent fd1a838d36
commit ea19e7856b
16 changed files with 291 additions and 30 deletions

View File

@@ -328,7 +328,7 @@ static int Vim_PyRun_SimpleString(const char *str)
#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 @@ init_range_eval(void *rettv UNUSED)
}
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 const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n ";
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 @@ out:
}
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 @@ run_eval(const char *cmd, void *arg
{
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))