1
0
forked from aniani/vim

updated for version 7.3.1174

Problem:    Python 2 and 3 use different ways to load modules.
Solution:   Use the same method. (ZyX)
This commit is contained in:
Bram Moolenaar
2013-06-12 14:41:04 +02:00
parent 27610ed76c
commit 81c40c507c
5 changed files with 213 additions and 325 deletions

View File

@@ -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
/*
@@ -1602,71 +1602,11 @@ 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;