|
Karsten Hopp |
eabdb9 |
To: vim_dev@googlegroups.com
|
|
Karsten Hopp |
eabdb9 |
Subject: Patch 7.3.1174
|
|
Karsten Hopp |
eabdb9 |
Fcc: outbox
|
|
Karsten Hopp |
eabdb9 |
From: Bram Moolenaar <Bram@moolenaar.net>
|
|
Karsten Hopp |
eabdb9 |
Mime-Version: 1.0
|
|
Karsten Hopp |
eabdb9 |
Content-Type: text/plain; charset=UTF-8
|
|
Karsten Hopp |
eabdb9 |
Content-Transfer-Encoding: 8bit
|
|
Karsten Hopp |
eabdb9 |
------------
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
Patch 7.3.1174
|
|
Karsten Hopp |
eabdb9 |
Problem: Python 2 and 3 use different ways to load modules.
|
|
Karsten Hopp |
eabdb9 |
Solution: Use the same method. (ZyX)
|
|
Karsten Hopp |
eabdb9 |
Files: runtime/doc/if_pyth.txt, src/if_py_both.h, src/if_python3.c,
|
|
Karsten Hopp |
eabdb9 |
src/if_python.c
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
*** ../vim-7.3.1173/runtime/doc/if_pyth.txt 2013-06-12 14:20:15.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
--- runtime/doc/if_pyth.txt 2013-06-12 14:33:12.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 315,321 ****
|
|
Karsten Hopp |
eabdb9 |
{rtp}/python2 (or python3) and {rtp}/pythonx (for both python versions) for
|
|
Karsten Hopp |
eabdb9 |
each {rtp} found in 'runtimepath'.
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
! Implementation for python 2 is similar to the following, but written in C: >
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
from imp import find_module, load_module
|
|
Karsten Hopp |
eabdb9 |
import vim
|
|
Karsten Hopp |
eabdb9 |
--- 315,321 ----
|
|
Karsten Hopp |
eabdb9 |
{rtp}/python2 (or python3) and {rtp}/pythonx (for both python versions) for
|
|
Karsten Hopp |
eabdb9 |
each {rtp} found in 'runtimepath'.
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
! Implementation is similar to the following, but written in C: >
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
from imp import find_module, load_module
|
|
Karsten Hopp |
eabdb9 |
import vim
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 344,359 ****
|
|
Karsten Hopp |
eabdb9 |
# matter for python which object has find_module function attached to as
|
|
Karsten Hopp |
eabdb9 |
# an attribute.
|
|
Karsten Hopp |
eabdb9 |
class VimPathFinder(object):
|
|
Karsten Hopp |
eabdb9 |
def find_module(cls, fullname, path=None):
|
|
Karsten Hopp |
eabdb9 |
try:
|
|
Karsten Hopp |
eabdb9 |
return VimModuleLoader(_find_module(fullname, fullname, path or vim._get_paths()))
|
|
Karsten Hopp |
eabdb9 |
except ImportError:
|
|
Karsten Hopp |
eabdb9 |
return None
|
|
Karsten Hopp |
eabdb9 |
- find_module = classmethod(find_module)
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
def load_module(cls, fullname, path=None):
|
|
Karsten Hopp |
eabdb9 |
return _find_module(fullname, fullname, path or vim._get_paths())
|
|
Karsten Hopp |
eabdb9 |
- load_module = classmethod(load_module)
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
def hook(path):
|
|
Karsten Hopp |
eabdb9 |
if path == vim.VIM_SPECIAL_PATH:
|
|
Karsten Hopp |
eabdb9 |
--- 344,359 ----
|
|
Karsten Hopp |
eabdb9 |
# matter for python which object has find_module function attached to as
|
|
Karsten Hopp |
eabdb9 |
# an attribute.
|
|
Karsten Hopp |
eabdb9 |
class VimPathFinder(object):
|
|
Karsten Hopp |
eabdb9 |
+ @classmethod
|
|
Karsten Hopp |
eabdb9 |
def find_module(cls, fullname, path=None):
|
|
Karsten Hopp |
eabdb9 |
try:
|
|
Karsten Hopp |
eabdb9 |
return VimModuleLoader(_find_module(fullname, fullname, path or vim._get_paths()))
|
|
Karsten Hopp |
eabdb9 |
except ImportError:
|
|
Karsten Hopp |
eabdb9 |
return None
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
+ @classmethod
|
|
Karsten Hopp |
eabdb9 |
def load_module(cls, fullname, path=None):
|
|
Karsten Hopp |
eabdb9 |
return _find_module(fullname, fullname, path or vim._get_paths())
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
def hook(path):
|
|
Karsten Hopp |
eabdb9 |
if path == vim.VIM_SPECIAL_PATH:
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 363,392 ****
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
sys.path_hooks.append(hook)
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
- Implementation for python 3 is cleaner: code is similar to the following, but,
|
|
Karsten Hopp |
eabdb9 |
- again, written in C: >
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- from importlib.machinery import PathFinder
|
|
Karsten Hopp |
eabdb9 |
- import sys
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- class Finder(PathFinder):
|
|
Karsten Hopp |
eabdb9 |
- @classmethod
|
|
Karsten Hopp |
eabdb9 |
- def find_module(cls, fullname):
|
|
Karsten Hopp |
eabdb9 |
- # see vim._get_paths below
|
|
Karsten Hopp |
eabdb9 |
- new_path = _get_paths()
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- # super().find_module is also a class method
|
|
Karsten Hopp |
eabdb9 |
- # super() is not used because this variant is easier to implement
|
|
Karsten Hopp |
eabdb9 |
- # in C
|
|
Karsten Hopp |
eabdb9 |
- return PathFinder.find_module(fullname, new_path)
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- def path_hook(path):
|
|
Karsten Hopp |
eabdb9 |
- if path == VIM_SPECIAL_PATH:
|
|
Karsten Hopp |
eabdb9 |
- return Finder
|
|
Karsten Hopp |
eabdb9 |
- raise ImportError
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- sys.path_hooks.append(path_hook)
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
vim.VIM_SPECIAL_PATH *python-VIM_SPECIAL_PATH*
|
|
Karsten Hopp |
eabdb9 |
String constant used in conjunction with vim path hook. If path hook
|
|
Karsten Hopp |
eabdb9 |
installed by vim is requested to handle anything but path equal to
|
|
Karsten Hopp |
eabdb9 |
--- 363,368 ----
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 402,409 ****
|
|
Karsten Hopp |
eabdb9 |
You should not be using any of these directly except for vim.path_hook
|
|
Karsten Hopp |
eabdb9 |
in case you need to do something with sys.meta_path. It is not
|
|
Karsten Hopp |
eabdb9 |
guaranteed that any of the objects will exist in the future vim
|
|
Karsten Hopp |
eabdb9 |
! versions. In fact, find_module methods do not exists
|
|
Karsten Hopp |
eabdb9 |
! in python3.
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
vim._get_paths *python-_get_paths*
|
|
Karsten Hopp |
eabdb9 |
Methods returning a list of paths which will be searched for by path
|
|
Karsten Hopp |
eabdb9 |
--- 378,384 ----
|
|
Karsten Hopp |
eabdb9 |
You should not be using any of these directly except for vim.path_hook
|
|
Karsten Hopp |
eabdb9 |
in case you need to do something with sys.meta_path. It is not
|
|
Karsten Hopp |
eabdb9 |
guaranteed that any of the objects will exist in the future vim
|
|
Karsten Hopp |
eabdb9 |
! versions.
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
vim._get_paths *python-_get_paths*
|
|
Karsten Hopp |
eabdb9 |
Methods returning a list of paths which will be searched for by path
|
|
Karsten Hopp |
eabdb9 |
*** ../vim-7.3.1173/src/if_py_both.h 2013-06-12 14:20:15.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
--- src/if_py_both.h 2013-06-12 14:35:42.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 60,65 ****
|
|
Karsten Hopp |
eabdb9 |
--- 60,70 ----
|
|
Karsten Hopp |
eabdb9 |
static PyObject *vim_module;
|
|
Karsten Hopp |
eabdb9 |
static PyObject *vim_special_path_object;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *py_find_module;
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *py_load_module;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *VimError;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
/*
|
|
Karsten Hopp |
eabdb9 |
* obtain a lock on the Vim data structures
|
|
Karsten Hopp |
eabdb9 |
*/
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 393,400 ****
|
|
Karsten Hopp |
eabdb9 |
return 0;
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
! static PyObject *VimError;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
/* Check to see whether a Vim error has been reported, or a keyboard
|
|
Karsten Hopp |
eabdb9 |
* interrupt has been detected.
|
|
Karsten Hopp |
eabdb9 |
--- 398,431 ----
|
|
Karsten Hopp |
eabdb9 |
return 0;
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
+ typedef struct
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ PyObject_HEAD
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *module;
|
|
Karsten Hopp |
eabdb9 |
+ } LoaderObject;
|
|
Karsten Hopp |
eabdb9 |
+ static PyTypeObject LoaderType;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ static void
|
|
Karsten Hopp |
eabdb9 |
+ LoaderDestructor(LoaderObject *self)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(self->module);
|
|
Karsten Hopp |
eabdb9 |
+ DESTRUCTOR_FINISH(self);
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *
|
|
Karsten Hopp |
eabdb9 |
+ LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *r = self->module;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
! Py_INCREF(r);
|
|
Karsten Hopp |
eabdb9 |
! return r;
|
|
Karsten Hopp |
eabdb9 |
! }
|
|
Karsten Hopp |
eabdb9 |
!
|
|
Karsten Hopp |
eabdb9 |
! static struct PyMethodDef LoaderMethods[] = {
|
|
Karsten Hopp |
eabdb9 |
! /* name, function, calling, doc */
|
|
Karsten Hopp |
eabdb9 |
! {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""},
|
|
Karsten Hopp |
eabdb9 |
! { NULL, NULL, 0, NULL}
|
|
Karsten Hopp |
eabdb9 |
! };
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
/* Check to see whether a Vim error has been reported, or a keyboard
|
|
Karsten Hopp |
eabdb9 |
* interrupt has been detected.
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 925,930 ****
|
|
Karsten Hopp |
eabdb9 |
--- 956,1105 ----
|
|
Karsten Hopp |
eabdb9 |
return r;
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *
|
|
Karsten Hopp |
eabdb9 |
+ call_load_module(char *name, int len, PyObject *find_module_result)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *fd, *pathname, *description;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!PyTuple_Check(find_module_result)
|
|
Karsten Hopp |
eabdb9 |
+ || PyTuple_GET_SIZE(find_module_result) != 3)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ PyErr_SetString(PyExc_TypeError,
|
|
Karsten Hopp |
eabdb9 |
+ _("expected 3-tuple as imp.find_module() result"));
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(fd = PyTuple_GET_ITEM(find_module_result, 0))
|
|
Karsten Hopp |
eabdb9 |
+ || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
|
|
Karsten Hopp |
eabdb9 |
+ || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ PyErr_SetString(PyExc_RuntimeError,
|
|
Karsten Hopp |
eabdb9 |
+ _("internal error: imp.find_module returned tuple with NULL"));
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ return PyObject_CallFunction(py_load_module,
|
|
Karsten Hopp |
eabdb9 |
+ "s#OOO", name, len, fd, pathname, description);
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *
|
|
Karsten Hopp |
eabdb9 |
+ find_module(char *fullname, char *tail, PyObject *new_path)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *find_module_result;
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *module;
|
|
Karsten Hopp |
eabdb9 |
+ char *dot;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if ((dot = (char *) vim_strchr((char_u *) tail, '.')))
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ /*
|
|
Karsten Hopp |
eabdb9 |
+ * There is a dot in the name: call find_module recursively without the
|
|
Karsten Hopp |
eabdb9 |
+ * first component
|
|
Karsten Hopp |
eabdb9 |
+ */
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *newest_path;
|
|
Karsten Hopp |
eabdb9 |
+ int partlen = (int) (dot - 1 - tail);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(find_module_result = PyObject_CallFunction(py_find_module,
|
|
Karsten Hopp |
eabdb9 |
+ "s#O", tail, partlen, new_path)))
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(module = call_load_module(
|
|
Karsten Hopp |
eabdb9 |
+ fullname,
|
|
Karsten Hopp |
eabdb9 |
+ ((int) (tail - fullname)) + partlen,
|
|
Karsten Hopp |
eabdb9 |
+ find_module_result)))
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(module);
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(module);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ module = find_module(fullname, dot + 1, newest_path);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(newest_path);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ return module;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+ else
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ if (!(find_module_result = PyObject_CallFunction(py_find_module,
|
|
Karsten Hopp |
eabdb9 |
+ "sO", tail, new_path)))
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(module = call_load_module(
|
|
Karsten Hopp |
eabdb9 |
+ fullname,
|
|
Karsten Hopp |
eabdb9 |
+ STRLEN(fullname),
|
|
Karsten Hopp |
eabdb9 |
+ find_module_result)))
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ return module;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *
|
|
Karsten Hopp |
eabdb9 |
+ FinderFindModule(PyObject *self, PyObject *args)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ char *fullname;
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *module;
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *new_path;
|
|
Karsten Hopp |
eabdb9 |
+ LoaderObject *loader;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!PyArg_ParseTuple(args, "s", &fullname))
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(new_path = Vim_GetPaths(self)))
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ module = find_module(fullname, fullname, new_path);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(new_path);
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!module)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_INCREF(Py_None);
|
|
Karsten Hopp |
eabdb9 |
+ return Py_None;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (!(loader = PyObject_NEW(LoaderObject, &LoaderType)))
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_DECREF(module);
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ loader->module = module;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ return (PyObject *) loader;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject *
|
|
Karsten Hopp |
eabdb9 |
+ VimPathHook(PyObject *self UNUSED, PyObject *args)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ char *path;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ if (PyArg_ParseTuple(args, "s", &path)
|
|
Karsten Hopp |
eabdb9 |
+ && STRCMP(path, vim_special_path) == 0)
|
|
Karsten Hopp |
eabdb9 |
+ {
|
|
Karsten Hopp |
eabdb9 |
+ Py_INCREF(vim_module);
|
|
Karsten Hopp |
eabdb9 |
+ return vim_module;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
+ PyErr_Clear();
|
|
Karsten Hopp |
eabdb9 |
+ PyErr_SetNone(PyExc_ImportError);
|
|
Karsten Hopp |
eabdb9 |
+ return NULL;
|
|
Karsten Hopp |
eabdb9 |
+ }
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
/*
|
|
Karsten Hopp |
eabdb9 |
* Vim module - Definitions
|
|
Karsten Hopp |
eabdb9 |
*/
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 938,946 ****
|
|
Karsten Hopp |
eabdb9 |
{"chdir", (PyCFunction)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
|
|
Karsten Hopp |
eabdb9 |
{"fchdir", (PyCFunction)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
|
|
Karsten Hopp |
eabdb9 |
{"foreach_rtp", VimForeachRTP, METH_VARARGS, "Call given callable for each path in &rtp"},
|
|
Karsten Hopp |
eabdb9 |
- #if PY_MAJOR_VERSION < 3
|
|
Karsten Hopp |
eabdb9 |
{"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"},
|
|
Karsten Hopp |
eabdb9 |
- #endif
|
|
Karsten Hopp |
eabdb9 |
{"path_hook", VimPathHook, METH_VARARGS, "Hook function to install in sys.path_hooks"},
|
|
Karsten Hopp |
eabdb9 |
{"_get_paths", (PyCFunction)Vim_GetPaths, METH_NOARGS, "Get &rtp-based additions to sys.path"},
|
|
Karsten Hopp |
eabdb9 |
{ NULL, NULL, 0, NULL}
|
|
Karsten Hopp |
eabdb9 |
--- 1113,1119 ----
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 5188,5208 ****
|
|
Karsten Hopp |
eabdb9 |
} CurrentObject;
|
|
Karsten Hopp |
eabdb9 |
static PyTypeObject CurrentType;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
- #if PY_MAJOR_VERSION >= 3
|
|
Karsten Hopp |
eabdb9 |
- typedef struct
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyObject_HEAD
|
|
Karsten Hopp |
eabdb9 |
- } FinderObject;
|
|
Karsten Hopp |
eabdb9 |
- static PyTypeObject FinderType;
|
|
Karsten Hopp |
eabdb9 |
- #else
|
|
Karsten Hopp |
eabdb9 |
- typedef struct
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyObject_HEAD
|
|
Karsten Hopp |
eabdb9 |
- PyObject *module;
|
|
Karsten Hopp |
eabdb9 |
- } LoaderObject;
|
|
Karsten Hopp |
eabdb9 |
- static PyTypeObject LoaderType;
|
|
Karsten Hopp |
eabdb9 |
- #endif
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
static void
|
|
Karsten Hopp |
eabdb9 |
init_structs(void)
|
|
Karsten Hopp |
eabdb9 |
{
|
|
Karsten Hopp |
eabdb9 |
--- 5361,5366 ----
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 5418,5423 ****
|
|
Karsten Hopp |
eabdb9 |
--- 5576,5589 ----
|
|
Karsten Hopp |
eabdb9 |
OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
|
|
Karsten Hopp |
eabdb9 |
OptionsType.tp_clear = (inquiry)OptionsClear;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
+ vim_memset(&LoaderType, 0, sizeof(LoaderType));
|
|
Karsten Hopp |
eabdb9 |
+ LoaderType.tp_name = "vim.Loader";
|
|
Karsten Hopp |
eabdb9 |
+ LoaderType.tp_basicsize = sizeof(LoaderObject);
|
|
Karsten Hopp |
eabdb9 |
+ LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
|
|
Karsten Hopp |
eabdb9 |
+ LoaderType.tp_doc = "vim message object";
|
|
Karsten Hopp |
eabdb9 |
+ LoaderType.tp_methods = LoaderMethods;
|
|
Karsten Hopp |
eabdb9 |
+ LoaderType.tp_dealloc = (destructor)LoaderDestructor;
|
|
Karsten Hopp |
eabdb9 |
+
|
|
Karsten Hopp |
eabdb9 |
#if PY_MAJOR_VERSION >= 3
|
|
Karsten Hopp |
eabdb9 |
vim_memset(&vimmodule, 0, sizeof(vimmodule));
|
|
Karsten Hopp |
eabdb9 |
vimmodule.m_name = "vim";
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 5448,5458 ****
|
|
Karsten Hopp |
eabdb9 |
PYTYPE_READY(FunctionType);
|
|
Karsten Hopp |
eabdb9 |
PYTYPE_READY(OptionsType);
|
|
Karsten Hopp |
eabdb9 |
PYTYPE_READY(OutputType);
|
|
Karsten Hopp |
eabdb9 |
- #if PY_MAJOR_VERSION >= 3
|
|
Karsten Hopp |
eabdb9 |
- PYTYPE_READY(FinderType);
|
|
Karsten Hopp |
eabdb9 |
- #else
|
|
Karsten Hopp |
eabdb9 |
PYTYPE_READY(LoaderType);
|
|
Karsten Hopp |
eabdb9 |
- #endif
|
|
Karsten Hopp |
eabdb9 |
return 0;
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
--- 5614,5620 ----
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 5576,5586 ****
|
|
Karsten Hopp |
eabdb9 |
{"List", (PyObject *)&ListType},
|
|
Karsten Hopp |
eabdb9 |
{"Function", (PyObject *)&FunctionType},
|
|
Karsten Hopp |
eabdb9 |
{"Options", (PyObject *)&OptionsType},
|
|
Karsten Hopp |
eabdb9 |
! #if PY_MAJOR_VERSION >= 3
|
|
Karsten Hopp |
eabdb9 |
! {"Finder", (PyObject *)&FinderType},
|
|
Karsten Hopp |
eabdb9 |
! #else
|
|
Karsten Hopp |
eabdb9 |
! {"Loader", (PyObject *)&LoaderType},
|
|
Karsten Hopp |
eabdb9 |
! #endif
|
|
Karsten Hopp |
eabdb9 |
};
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
typedef int (*object_adder)(PyObject *, const char *, PyObject *);
|
|
Karsten Hopp |
eabdb9 |
--- 5738,5744 ----
|
|
Karsten Hopp |
eabdb9 |
{"List", (PyObject *)&ListType},
|
|
Karsten Hopp |
eabdb9 |
{"Function", (PyObject *)&FunctionType},
|
|
Karsten Hopp |
eabdb9 |
{"Options", (PyObject *)&OptionsType},
|
|
Karsten Hopp |
eabdb9 |
! {"_Loader", (PyObject *)&LoaderType},
|
|
Karsten Hopp |
eabdb9 |
};
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
typedef int (*object_adder)(PyObject *, const char *, PyObject *);
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 5604,5609 ****
|
|
Karsten Hopp |
eabdb9 |
--- 5762,5768 ----
|
|
Karsten Hopp |
eabdb9 |
int i;
|
|
Karsten Hopp |
eabdb9 |
PyObject *other_module;
|
|
Karsten Hopp |
eabdb9 |
PyObject *attr;
|
|
Karsten Hopp |
eabdb9 |
+ PyObject *imp;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
for (i = 0; i < (int)(sizeof(numeric_constants)
|
|
Karsten Hopp |
eabdb9 |
/ sizeof(struct numeric_constant));
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 5671,5685 ****
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
ADD_OBJECT(m, "VIM_SPECIAL_PATH", vim_special_path_object);
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
! #if PY_MAJOR_VERSION >= 3
|
|
Karsten Hopp |
eabdb9 |
! ADD_OBJECT(m, "_PathFinder", path_finder);
|
|
Karsten Hopp |
eabdb9 |
! ADD_CHECKED_OBJECT(m, "_find_module",
|
|
Karsten Hopp |
eabdb9 |
! (py_find_module = PyObject_GetAttrString(path_finder,
|
|
Karsten Hopp |
eabdb9 |
! "find_module")));
|
|
Karsten Hopp |
eabdb9 |
! #else
|
|
Karsten Hopp |
eabdb9 |
ADD_OBJECT(m, "_find_module", py_find_module);
|
|
Karsten Hopp |
eabdb9 |
ADD_OBJECT(m, "_load_module", py_load_module);
|
|
Karsten Hopp |
eabdb9 |
- #endif
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
return 0;
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
--- 5830,5855 ----
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
ADD_OBJECT(m, "VIM_SPECIAL_PATH", vim_special_path_object);
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
! if (!(imp = PyImport_ImportModule("imp")))
|
|
Karsten Hopp |
eabdb9 |
! return -1;
|
|
Karsten Hopp |
eabdb9 |
!
|
|
Karsten Hopp |
eabdb9 |
! if (!(py_find_module = PyObject_GetAttrString(imp, "find_module")))
|
|
Karsten Hopp |
eabdb9 |
! {
|
|
Karsten Hopp |
eabdb9 |
! Py_DECREF(imp);
|
|
Karsten Hopp |
eabdb9 |
! return -1;
|
|
Karsten Hopp |
eabdb9 |
! }
|
|
Karsten Hopp |
eabdb9 |
!
|
|
Karsten Hopp |
eabdb9 |
! if (!(py_load_module = PyObject_GetAttrString(imp, "load_module")))
|
|
Karsten Hopp |
eabdb9 |
! {
|
|
Karsten Hopp |
eabdb9 |
! Py_DECREF(py_find_module);
|
|
Karsten Hopp |
eabdb9 |
! Py_DECREF(imp);
|
|
Karsten Hopp |
eabdb9 |
! return -1;
|
|
Karsten Hopp |
eabdb9 |
! }
|
|
Karsten Hopp |
eabdb9 |
!
|
|
Karsten Hopp |
eabdb9 |
! Py_DECREF(imp);
|
|
Karsten Hopp |
eabdb9 |
!
|
|
Karsten Hopp |
eabdb9 |
ADD_OBJECT(m, "_find_module", py_find_module);
|
|
Karsten Hopp |
eabdb9 |
ADD_OBJECT(m, "_load_module", py_load_module);
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
return 0;
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
*** ../vim-7.3.1173/src/if_python3.c 2013-06-10 21:27:18.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
--- src/if_python3.c 2013-06-12 14:36:00.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 175,180 ****
|
|
Karsten Hopp |
eabdb9 |
--- 175,181 ----
|
|
Karsten Hopp |
eabdb9 |
# define PyObject_HasAttrString py3_PyObject_HasAttrString
|
|
Karsten Hopp |
eabdb9 |
# define PyObject_SetAttrString py3_PyObject_SetAttrString
|
|
Karsten Hopp |
eabdb9 |
# define PyObject_CallFunctionObjArgs py3_PyObject_CallFunctionObjArgs
|
|
Karsten Hopp |
eabdb9 |
+ # define _PyObject_CallFunction_SizeT py3__PyObject_CallFunction_SizeT
|
|
Karsten Hopp |
eabdb9 |
# define PyObject_Call py3_PyObject_Call
|
|
Karsten Hopp |
eabdb9 |
# define PyEval_GetLocals py3_PyEval_GetLocals
|
|
Karsten Hopp |
eabdb9 |
# define PyEval_GetGlobals py3_PyEval_GetGlobals
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 296,301 ****
|
|
Karsten Hopp |
eabdb9 |
--- 297,303 ----
|
|
Karsten Hopp |
eabdb9 |
static int (*py3_PyObject_HasAttrString)(PyObject *, const char *);
|
|
Karsten Hopp |
eabdb9 |
static PyObject* (*py3_PyObject_SetAttrString)(PyObject *, const char *, PyObject *);
|
|
Karsten Hopp |
eabdb9 |
static PyObject* (*py3_PyObject_CallFunctionObjArgs)(PyObject *, ...);
|
|
Karsten Hopp |
eabdb9 |
+ static PyObject* (*py3__PyObject_CallFunction_SizeT)(PyObject *, char *, ...);
|
|
Karsten Hopp |
eabdb9 |
static PyObject* (*py3_PyObject_Call)(PyObject *, PyObject *, PyObject *);
|
|
Karsten Hopp |
eabdb9 |
static PyObject* (*py3_PyEval_GetGlobals)();
|
|
Karsten Hopp |
eabdb9 |
static PyObject* (*py3_PyEval_GetLocals)();
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 458,463 ****
|
|
Karsten Hopp |
eabdb9 |
--- 460,466 ----
|
|
Karsten Hopp |
eabdb9 |
{"PyObject_HasAttrString", (PYTHON_PROC*)&py3_PyObject_HasAttrString},
|
|
Karsten Hopp |
eabdb9 |
{"PyObject_SetAttrString", (PYTHON_PROC*)&py3_PyObject_SetAttrString},
|
|
Karsten Hopp |
eabdb9 |
{"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&py3_PyObject_CallFunctionObjArgs},
|
|
Karsten Hopp |
eabdb9 |
+ {"_PyObject_CallFunction_SizeT", (PYTHON_PROC*)&py3__PyObject_CallFunction_SizeT},
|
|
Karsten Hopp |
eabdb9 |
{"PyObject_Call", (PYTHON_PROC*)&py3_PyObject_Call},
|
|
Karsten Hopp |
eabdb9 |
{"PyEval_GetGlobals", (PYTHON_PROC*)&py3_PyEval_GetGlobals},
|
|
Karsten Hopp |
eabdb9 |
{"PyEval_GetLocals", (PYTHON_PROC*)&py3_PyEval_GetLocals},
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 740,748 ****
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
static struct PyModuleDef vimmodule;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *path_finder;
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *py_find_module = NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
#define PY_CAN_RECURSE
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
/*
|
|
Karsten Hopp |
eabdb9 |
--- 743,748 ----
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 1603,1672 ****
|
|
Karsten Hopp |
eabdb9 |
#endif
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- VimPathHook(PyObject *self UNUSED, PyObject *args)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- char *path;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (PyArg_ParseTuple(args, "s", &path)
|
|
Karsten Hopp |
eabdb9 |
- && STRCMP(path, vim_special_path) == 0)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_INCREF(&FinderType);
|
|
Karsten Hopp |
eabdb9 |
- return (PyObject *) &FinderType;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- PyErr_Clear();
|
|
Karsten Hopp |
eabdb9 |
- PyErr_SetNone(PyExc_ImportError);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- FinderFindModule(PyObject *cls UNUSED, PyObject *fullname)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyObject *new_path;
|
|
Karsten Hopp |
eabdb9 |
- PyObject *r;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(new_path = Vim_GetPaths(NULL)))
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- /* call find_module of the super() class */
|
|
Karsten Hopp |
eabdb9 |
- r = PyObject_CallFunctionObjArgs(py_find_module, fullname, new_path, NULL);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(new_path);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- return r;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static struct PyMethodDef FinderMethods[] = {
|
|
Karsten Hopp |
eabdb9 |
- {"find_module", FinderFindModule, METH_CLASS|METH_O, ""},
|
|
Karsten Hopp |
eabdb9 |
- {NULL, NULL, 0, NULL}
|
|
Karsten Hopp |
eabdb9 |
- };
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
Py3Init_vim(void)
|
|
Karsten Hopp |
eabdb9 |
{
|
|
Karsten Hopp |
eabdb9 |
/* The special value is removed from sys.path in Python3_Init(). */
|
|
Karsten Hopp |
eabdb9 |
static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL};
|
|
Karsten Hopp |
eabdb9 |
- PyObject *importlib_machinery;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(importlib_machinery = PyImport_ImportModule("importlib.machinery")))
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(path_finder = PyObject_GetAttrString(importlib_machinery,
|
|
Karsten Hopp |
eabdb9 |
- "PathFinder")))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(importlib_machinery);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(importlib_machinery);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- vim_memset(&FinderType, 0, sizeof(FinderObject));
|
|
Karsten Hopp |
eabdb9 |
- FinderType.tp_name = "vim.Finder";
|
|
Karsten Hopp |
eabdb9 |
- FinderType.tp_basicsize = sizeof(FinderObject);
|
|
Karsten Hopp |
eabdb9 |
- FinderType.tp_base = (PyTypeObject *) path_finder;
|
|
Karsten Hopp |
eabdb9 |
- FinderType.tp_flags = Py_TPFLAGS_DEFAULT;
|
|
Karsten Hopp |
eabdb9 |
- FinderType.tp_doc = "Vim finder class, for use with path hook";
|
|
Karsten Hopp |
eabdb9 |
- FinderType.tp_methods = FinderMethods;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
if (init_types())
|
|
Karsten Hopp |
eabdb9 |
return NULL;
|
|
Karsten Hopp |
eabdb9 |
--- 1603,1612 ----
|
|
Karsten Hopp |
eabdb9 |
*** ../vim-7.3.1173/src/if_python.c 2013-06-12 14:20:15.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
--- src/if_python.c 2013-06-12 14:35:49.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 752,763 ****
|
|
Karsten Hopp |
eabdb9 |
static PyObject *ListGetattr(PyObject *, char *);
|
|
Karsten Hopp |
eabdb9 |
static PyObject *FunctionGetattr(PyObject *, char *);
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *FinderFindModule(PyObject *, PyObject *);
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *VimPathHook(PyObject *, PyObject *);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *py_find_module;
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *py_load_module;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
#ifndef Py_VISIT
|
|
Karsten Hopp |
eabdb9 |
# define Py_VISIT(obj) visit(obj, arg)
|
|
Karsten Hopp |
eabdb9 |
#endif
|
|
Karsten Hopp |
eabdb9 |
--- 752,757 ----
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 1382,1585 ****
|
|
Karsten Hopp |
eabdb9 |
}
|
|
Karsten Hopp |
eabdb9 |
#endif
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
- static void
|
|
Karsten Hopp |
eabdb9 |
- LoaderDestructor(LoaderObject *self)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(self->module);
|
|
Karsten Hopp |
eabdb9 |
- DESTRUCTOR_FINISH(self);
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyObject *r = self->module;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_INCREF(r);
|
|
Karsten Hopp |
eabdb9 |
- return r;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static struct PyMethodDef LoaderMethods[] = {
|
|
Karsten Hopp |
eabdb9 |
- /* name, function, calling, doc */
|
|
Karsten Hopp |
eabdb9 |
- {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""},
|
|
Karsten Hopp |
eabdb9 |
- { NULL, NULL, 0, NULL}
|
|
Karsten Hopp |
eabdb9 |
- };
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- call_load_module(char *name, int len, PyObject *find_module_result)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyObject *fd, *pathname, *description;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!PyTuple_Check(find_module_result)
|
|
Karsten Hopp |
eabdb9 |
- || PyTuple_GET_SIZE(find_module_result) != 3)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyErr_SetString(PyExc_TypeError,
|
|
Karsten Hopp |
eabdb9 |
- _("expected 3-tuple as imp.find_module() result"));
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(fd = PyTuple_GET_ITEM(find_module_result, 0))
|
|
Karsten Hopp |
eabdb9 |
- || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
|
|
Karsten Hopp |
eabdb9 |
- || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyErr_SetString(PyExc_RuntimeError,
|
|
Karsten Hopp |
eabdb9 |
- _("internal error: imp.find_module returned tuple with NULL"));
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- return PyObject_CallFunction(py_load_module,
|
|
Karsten Hopp |
eabdb9 |
- "s#OOO", name, len, fd, pathname, description);
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- find_module(char *fullname, char *tail, PyObject *new_path)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- PyObject *find_module_result;
|
|
Karsten Hopp |
eabdb9 |
- PyObject *module;
|
|
Karsten Hopp |
eabdb9 |
- char *dot;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if ((dot = (char *) vim_strchr((char_u *) tail, '.')))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- /*
|
|
Karsten Hopp |
eabdb9 |
- * There is a dot in the name: call find_module recursively without the
|
|
Karsten Hopp |
eabdb9 |
- * first component
|
|
Karsten Hopp |
eabdb9 |
- */
|
|
Karsten Hopp |
eabdb9 |
- PyObject *newest_path;
|
|
Karsten Hopp |
eabdb9 |
- int partlen = (int) (dot - 1 - tail);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(find_module_result = PyObject_CallFunction(py_find_module,
|
|
Karsten Hopp |
eabdb9 |
- "s#O", tail, partlen, new_path)))
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(module = call_load_module(
|
|
Karsten Hopp |
eabdb9 |
- fullname,
|
|
Karsten Hopp |
eabdb9 |
- ((int) (tail - fullname)) + partlen,
|
|
Karsten Hopp |
eabdb9 |
- find_module_result)))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(module);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(module);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- module = find_module(fullname, dot + 1, newest_path);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(newest_path);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- return module;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
- else
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- if (!(find_module_result = PyObject_CallFunction(py_find_module,
|
|
Karsten Hopp |
eabdb9 |
- "sO", tail, new_path)))
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(module = call_load_module(
|
|
Karsten Hopp |
eabdb9 |
- fullname,
|
|
Karsten Hopp |
eabdb9 |
- STRLEN(fullname),
|
|
Karsten Hopp |
eabdb9 |
- find_module_result)))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(find_module_result);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- return module;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- FinderFindModule(PyObject *self, PyObject *args)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- char *fullname;
|
|
Karsten Hopp |
eabdb9 |
- PyObject *module;
|
|
Karsten Hopp |
eabdb9 |
- PyObject *new_path;
|
|
Karsten Hopp |
eabdb9 |
- LoaderObject *loader;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!PyArg_ParseTuple(args, "s", &fullname))
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(new_path = Vim_GetPaths(self)))
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- module = find_module(fullname, fullname, new_path);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(new_path);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!module)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_INCREF(Py_None);
|
|
Karsten Hopp |
eabdb9 |
- return Py_None;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(loader = PyObject_NEW(LoaderObject, &LoaderType)))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(module);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- loader->module = module;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- return (PyObject *) loader;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- static PyObject *
|
|
Karsten Hopp |
eabdb9 |
- VimPathHook(PyObject *self UNUSED, PyObject *args)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- char *path;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (PyArg_ParseTuple(args, "s", &path)
|
|
Karsten Hopp |
eabdb9 |
- && STRCMP(path, vim_special_path) == 0)
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_INCREF(vim_module);
|
|
Karsten Hopp |
eabdb9 |
- return vim_module;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- PyErr_Clear();
|
|
Karsten Hopp |
eabdb9 |
- PyErr_SetNone(PyExc_ImportError);
|
|
Karsten Hopp |
eabdb9 |
- return NULL;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
static int
|
|
Karsten Hopp |
eabdb9 |
PythonMod_Init(void)
|
|
Karsten Hopp |
eabdb9 |
{
|
|
Karsten Hopp |
eabdb9 |
/* The special value is removed from sys.path in Python_Init(). */
|
|
Karsten Hopp |
eabdb9 |
static char *(argv[2]) = {"/must>not&exist/foo", NULL};
|
|
Karsten Hopp |
eabdb9 |
- PyObject *imp;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(imp = PyImport_ImportModule("imp")))
|
|
Karsten Hopp |
eabdb9 |
- return -1;
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(py_find_module = PyObject_GetAttrString(imp, "find_module")))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(imp);
|
|
Karsten Hopp |
eabdb9 |
- return -1;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- if (!(py_load_module = PyObject_GetAttrString(imp, "load_module")))
|
|
Karsten Hopp |
eabdb9 |
- {
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(py_find_module);
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(imp);
|
|
Karsten Hopp |
eabdb9 |
- return -1;
|
|
Karsten Hopp |
eabdb9 |
- }
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- Py_DECREF(imp);
|
|
Karsten Hopp |
eabdb9 |
-
|
|
Karsten Hopp |
eabdb9 |
- vim_memset(&LoaderType, 0, sizeof(LoaderType));
|
|
Karsten Hopp |
eabdb9 |
- LoaderType.tp_name = "vim.Loader";
|
|
Karsten Hopp |
eabdb9 |
- LoaderType.tp_basicsize = sizeof(LoaderObject);
|
|
Karsten Hopp |
eabdb9 |
- LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
|
|
Karsten Hopp |
eabdb9 |
- LoaderType.tp_doc = "vim message object";
|
|
Karsten Hopp |
eabdb9 |
- LoaderType.tp_methods = LoaderMethods;
|
|
Karsten Hopp |
eabdb9 |
- LoaderType.tp_dealloc = (destructor)LoaderDestructor;
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
if (init_types())
|
|
Karsten Hopp |
eabdb9 |
return -1;
|
|
Karsten Hopp |
eabdb9 |
--- 1376,1386 ----
|
|
Karsten Hopp |
eabdb9 |
*** ../vim-7.3.1173/src/version.c 2013-06-12 14:26:20.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
--- src/version.c 2013-06-12 14:35:25.000000000 +0200
|
|
Karsten Hopp |
eabdb9 |
***************
|
|
Karsten Hopp |
eabdb9 |
*** 730,731 ****
|
|
Karsten Hopp |
eabdb9 |
--- 730,733 ----
|
|
Karsten Hopp |
eabdb9 |
{ /* Add new patch number below this line */
|
|
Karsten Hopp |
eabdb9 |
+ /**/
|
|
Karsten Hopp |
eabdb9 |
+ 1174,
|
|
Karsten Hopp |
eabdb9 |
/**/
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
--
|
|
Karsten Hopp |
eabdb9 |
"Hit any key to continue" is very confusing when you have two keyboards.
|
|
Karsten Hopp |
eabdb9 |
|
|
Karsten Hopp |
eabdb9 |
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
|
|
Karsten Hopp |
eabdb9 |
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
|
|
Karsten Hopp |
eabdb9 |
\\\ an exciting new programming language -- http://www.Zimbu.org ///
|
|
Karsten Hopp |
eabdb9 |
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|