diff options
author | Bram Moolenaar <Bram@vim.org> | 2013-06-12 14:41:04 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2013-06-12 14:41:04 +0200 |
commit | 81c40c507c69ab0c3aede3ee14a2ba76c20c4595 (patch) | |
tree | 21bb9f8a713de4a223ab7b581c90207a79cfdb97 /src/if_python3.c | |
parent | 27610ed76c500cf680fdbac000d269e30dcba54c (diff) | |
download | vim-git-81c40c507c69ab0c3aede3ee14a2ba76c20c4595.tar.gz |
updated for version 7.3.1174v7.3.1174
Problem: Python 2 and 3 use different ways to load modules.
Solution: Use the same method. (ZyX)
Diffstat (limited to 'src/if_python3.c')
-rw-r--r-- | src/if_python3.c | 66 |
1 files changed, 3 insertions, 63 deletions
diff --git a/src/if_python3.c b/src/if_python3.c index 5c3c0b0d8..a4f96407a 100644 --- a/src/if_python3.c +++ b/src/if_python3.c @@ -175,6 +175,7 @@ # define PyObject_HasAttrString py3_PyObject_HasAttrString # define PyObject_SetAttrString py3_PyObject_SetAttrString # define PyObject_CallFunctionObjArgs py3_PyObject_CallFunctionObjArgs +# define _PyObject_CallFunction_SizeT py3__PyObject_CallFunction_SizeT # define PyObject_Call py3_PyObject_Call # define PyEval_GetLocals py3_PyEval_GetLocals # define PyEval_GetGlobals py3_PyEval_GetGlobals @@ -296,6 +297,7 @@ static PyObject* (*py3_PyObject_GetAttrString)(PyObject *, const char *); static int (*py3_PyObject_HasAttrString)(PyObject *, const char *); static PyObject* (*py3_PyObject_SetAttrString)(PyObject *, const char *, PyObject *); static PyObject* (*py3_PyObject_CallFunctionObjArgs)(PyObject *, ...); +static PyObject* (*py3__PyObject_CallFunction_SizeT)(PyObject *, char *, ...); static PyObject* (*py3_PyObject_Call)(PyObject *, PyObject *, PyObject *); static PyObject* (*py3_PyEval_GetGlobals)(); static PyObject* (*py3_PyEval_GetLocals)(); @@ -458,6 +460,7 @@ static struct {"PyObject_HasAttrString", (PYTHON_PROC*)&py3_PyObject_HasAttrString}, {"PyObject_SetAttrString", (PYTHON_PROC*)&py3_PyObject_SetAttrString}, {"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&py3_PyObject_CallFunctionObjArgs}, + {"_PyObject_CallFunction_SizeT", (PYTHON_PROC*)&py3__PyObject_CallFunction_SizeT}, {"PyObject_Call", (PYTHON_PROC*)&py3_PyObject_Call}, {"PyEval_GetGlobals", (PYTHON_PROC*)&py3_PyEval_GetGlobals}, {"PyEval_GetLocals", (PYTHON_PROC*)&py3_PyEval_GetLocals}, @@ -740,9 +743,6 @@ static PyObject *VimPathHook(PyObject *, PyObject *); static struct PyModuleDef vimmodule; -static PyObject *path_finder; -static PyObject *py_find_module = NULL; - #define PY_CAN_RECURSE /* @@ -1603,70 +1603,10 @@ python3_tabpage_free(tabpage_T *tab) #endif static PyObject * -VimPathHook(PyObject *self UNUSED, PyObject *args) -{ - char *path; - - if (PyArg_ParseTuple(args, "s", &path) - && STRCMP(path, vim_special_path) == 0) - { - Py_INCREF(&FinderType); - return (PyObject *) &FinderType; - } - - PyErr_Clear(); - PyErr_SetNone(PyExc_ImportError); - return NULL; -} - - static PyObject * -FinderFindModule(PyObject *cls UNUSED, PyObject *fullname) -{ - PyObject *new_path; - PyObject *r; - - if (!(new_path = Vim_GetPaths(NULL))) - return NULL; - - /* call find_module of the super() class */ - r = PyObject_CallFunctionObjArgs(py_find_module, fullname, new_path, NULL); - - Py_DECREF(new_path); - - return r; -} - -static struct PyMethodDef FinderMethods[] = { - {"find_module", FinderFindModule, METH_CLASS|METH_O, ""}, - {NULL, NULL, 0, NULL} -}; - - static PyObject * Py3Init_vim(void) { /* The special value is removed from sys.path in Python3_Init(). */ static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; - PyObject *importlib_machinery; - - if (!(importlib_machinery = PyImport_ImportModule("importlib.machinery"))) - return NULL; - - if (!(path_finder = PyObject_GetAttrString(importlib_machinery, - "PathFinder"))) - { - Py_DECREF(importlib_machinery); - return NULL; - } - - Py_DECREF(importlib_machinery); - - vim_memset(&FinderType, 0, sizeof(FinderObject)); - FinderType.tp_name = "vim.Finder"; - FinderType.tp_basicsize = sizeof(FinderObject); - FinderType.tp_base = (PyTypeObject *) path_finder; - FinderType.tp_flags = Py_TPFLAGS_DEFAULT; - FinderType.tp_doc = "Vim finder class, for use with path hook"; - FinderType.tp_methods = FinderMethods; if (init_types()) return NULL; |