home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.1174 < prev    next >
Encoding:
Internet Message Format  |  2013-06-11  |  22.4 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1174
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.1174
  11. Problem:    Python 2 and 3 use different ways to load modules.
  12. Solution:   Use the same method. (ZyX)
  13. Files:        runtime/doc/if_pyth.txt, src/if_py_both.h, src/if_python3.c,
  14.         src/if_python.c
  15.  
  16.  
  17. *** ../vim-7.3.1173/runtime/doc/if_pyth.txt    2013-06-12 14:20:15.000000000 +0200
  18. --- runtime/doc/if_pyth.txt    2013-06-12 14:33:12.000000000 +0200
  19. ***************
  20. *** 315,321 ****
  21.   {rtp}/python2 (or python3) and {rtp}/pythonx (for both python versions) for 
  22.   each {rtp} found in 'runtimepath'.
  23.   
  24. ! Implementation for python 2 is similar to the following, but written in C: >
  25.   
  26.       from imp import find_module, load_module
  27.       import vim
  28. --- 315,321 ----
  29.   {rtp}/python2 (or python3) and {rtp}/pythonx (for both python versions) for 
  30.   each {rtp} found in 'runtimepath'.
  31.   
  32. ! Implementation is similar to the following, but written in C: >
  33.   
  34.       from imp import find_module, load_module
  35.       import vim
  36. ***************
  37. *** 344,359 ****
  38.       # matter for python which object has find_module function attached to as 
  39.       # an attribute.
  40.       class VimPathFinder(object):
  41.           def find_module(cls, fullname, path=None):
  42.               try:
  43.                   return VimModuleLoader(_find_module(fullname, fullname, path or vim._get_paths()))
  44.               except ImportError:
  45.                   return None
  46. -         find_module = classmethod(find_module)
  47.   
  48.           def load_module(cls, fullname, path=None):
  49.               return _find_module(fullname, fullname, path or vim._get_paths())
  50. -         load_module = classmethod(load_module)
  51.   
  52.       def hook(path):
  53.           if path == vim.VIM_SPECIAL_PATH:
  54. --- 344,359 ----
  55.       # matter for python which object has find_module function attached to as 
  56.       # an attribute.
  57.       class VimPathFinder(object):
  58. +         @classmethod
  59.           def find_module(cls, fullname, path=None):
  60.               try:
  61.                   return VimModuleLoader(_find_module(fullname, fullname, path or vim._get_paths()))
  62.               except ImportError:
  63.                   return None
  64.   
  65. +         @classmethod
  66.           def load_module(cls, fullname, path=None):
  67.               return _find_module(fullname, fullname, path or vim._get_paths())
  68.   
  69.       def hook(path):
  70.           if path == vim.VIM_SPECIAL_PATH:
  71. ***************
  72. *** 363,392 ****
  73.   
  74.       sys.path_hooks.append(hook)
  75.   
  76. - Implementation for python 3 is cleaner: code is similar to the following, but, 
  77. - again, written in C: >
  78. -     from importlib.machinery import PathFinder
  79. -     import sys
  80. -     class Finder(PathFinder):
  81. -         @classmethod
  82. -         def find_module(cls, fullname):
  83. -             # see vim._get_paths below
  84. -             new_path = _get_paths()
  85. -             # super().find_module is also a class method
  86. -             # super() is not used because this variant is easier to implement 
  87. -             # in C
  88. -             return PathFinder.find_module(fullname, new_path)
  89. -     def path_hook(path):
  90. -         if path == VIM_SPECIAL_PATH:
  91. -             return Finder
  92. -         raise ImportError
  93. -     sys.path_hooks.append(path_hook)
  94.   vim.VIM_SPECIAL_PATH                    *python-VIM_SPECIAL_PATH*
  95.       String constant used in conjunction with vim path hook. If path hook 
  96.       installed by vim is requested to handle anything but path equal to 
  97. --- 363,368 ----
  98. ***************
  99. *** 402,409 ****
  100.       You should not be using any of these directly except for vim.path_hook 
  101.       in case you need to do something with sys.meta_path. It is not 
  102.       guaranteed that any of the objects will exist in the future vim 
  103. !     versions. In fact, find_module methods do not exists 
  104. !     in python3.
  105.   
  106.   vim._get_paths                        *python-_get_paths*
  107.       Methods returning a list of paths which will be searched for by path 
  108. --- 378,384 ----
  109.       You should not be using any of these directly except for vim.path_hook 
  110.       in case you need to do something with sys.meta_path. It is not 
  111.       guaranteed that any of the objects will exist in the future vim 
  112. !     versions.
  113.   
  114.   vim._get_paths                        *python-_get_paths*
  115.       Methods returning a list of paths which will be searched for by path 
  116. *** ../vim-7.3.1173/src/if_py_both.h    2013-06-12 14:20:15.000000000 +0200
  117. --- src/if_py_both.h    2013-06-12 14:35:42.000000000 +0200
  118. ***************
  119. *** 60,65 ****
  120. --- 60,70 ----
  121.   static PyObject *vim_module;
  122.   static PyObject *vim_special_path_object;
  123.   
  124. + static PyObject *py_find_module;
  125. + static PyObject *py_load_module;
  126. + static PyObject *VimError;
  127.   /*
  128.    * obtain a lock on the Vim data structures
  129.    */
  130. ***************
  131. *** 393,400 ****
  132.       return 0;
  133.   }
  134.   
  135.   
  136. ! static PyObject *VimError;
  137.   
  138.   /* Check to see whether a Vim error has been reported, or a keyboard
  139.    * interrupt has been detected.
  140. --- 398,431 ----
  141.       return 0;
  142.   }
  143.   
  144. + typedef struct
  145. + {
  146. +     PyObject_HEAD
  147. +     PyObject    *module;
  148. + } LoaderObject;
  149. + static PyTypeObject LoaderType;
  150. +     static void
  151. + LoaderDestructor(LoaderObject *self)
  152. + {
  153. +     Py_DECREF(self->module);
  154. +     DESTRUCTOR_FINISH(self);
  155. + }
  156. +     static PyObject *
  157. + LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
  158. + {
  159. +     PyObject    *r = self->module;
  160.   
  161. !     Py_INCREF(r);
  162. !     return r;
  163. ! }
  164. ! static struct PyMethodDef LoaderMethods[] = {
  165. !     /* name,        function,                calling,    doc */
  166. !     {"load_module", (PyCFunction)LoaderLoadModule,    METH_VARARGS,    ""},
  167. !     { NULL,        NULL,                0,        NULL}
  168. ! };
  169.   
  170.   /* Check to see whether a Vim error has been reported, or a keyboard
  171.    * interrupt has been detected.
  172. ***************
  173. *** 925,930 ****
  174. --- 956,1105 ----
  175.       return r;
  176.   }
  177.   
  178. +     static PyObject *
  179. + call_load_module(char *name, int len, PyObject *find_module_result)
  180. + {
  181. +     PyObject    *fd, *pathname, *description;
  182. +     if (!PyTuple_Check(find_module_result)
  183. +         || PyTuple_GET_SIZE(find_module_result) != 3)
  184. +     {
  185. +     PyErr_SetString(PyExc_TypeError,
  186. +         _("expected 3-tuple as imp.find_module() result"));
  187. +     return NULL;
  188. +     }
  189. +     if (!(fd = PyTuple_GET_ITEM(find_module_result, 0))
  190. +         || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
  191. +         || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
  192. +     {
  193. +     PyErr_SetString(PyExc_RuntimeError,
  194. +         _("internal error: imp.find_module returned tuple with NULL"));
  195. +     return NULL;
  196. +     }
  197. +     return PyObject_CallFunction(py_load_module,
  198. +         "s#OOO", name, len, fd, pathname, description);
  199. + }
  200. +     static PyObject *
  201. + find_module(char *fullname, char *tail, PyObject *new_path)
  202. + {
  203. +     PyObject    *find_module_result;
  204. +     PyObject    *module;
  205. +     char    *dot;
  206. +     if ((dot = (char *) vim_strchr((char_u *) tail, '.')))
  207. +     {
  208. +     /*
  209. +      * There is a dot in the name: call find_module recursively without the 
  210. +      * first component
  211. +      */
  212. +     PyObject    *newest_path;
  213. +     int        partlen = (int) (dot - 1 - tail);
  214. +     if (!(find_module_result = PyObject_CallFunction(py_find_module,
  215. +             "s#O", tail, partlen, new_path)))
  216. +         return NULL;
  217. +     if (!(module = call_load_module(
  218. +             fullname,
  219. +             ((int) (tail - fullname)) + partlen,
  220. +             find_module_result)))
  221. +     {
  222. +         Py_DECREF(find_module_result);
  223. +         return NULL;
  224. +     }
  225. +     Py_DECREF(find_module_result);
  226. +     if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
  227. +     {
  228. +         Py_DECREF(module);
  229. +         return NULL;
  230. +     }
  231. +     Py_DECREF(module);
  232. +     module = find_module(fullname, dot + 1, newest_path);
  233. +     Py_DECREF(newest_path);
  234. +     return module;
  235. +     }
  236. +     else
  237. +     {
  238. +     if (!(find_module_result = PyObject_CallFunction(py_find_module,
  239. +             "sO", tail, new_path)))
  240. +         return NULL;
  241. +     if (!(module = call_load_module(
  242. +             fullname,
  243. +             STRLEN(fullname),
  244. +             find_module_result)))
  245. +     {
  246. +         Py_DECREF(find_module_result);
  247. +         return NULL;
  248. +     }
  249. +     Py_DECREF(find_module_result);
  250. +     return module;
  251. +     }
  252. + }
  253. +     static PyObject *
  254. + FinderFindModule(PyObject *self, PyObject *args)
  255. + {
  256. +     char    *fullname;
  257. +     PyObject    *module;
  258. +     PyObject    *new_path;
  259. +     LoaderObject    *loader;
  260. +     if (!PyArg_ParseTuple(args, "s", &fullname))
  261. +     return NULL;
  262. +     if (!(new_path = Vim_GetPaths(self)))
  263. +     return NULL;
  264. +     module = find_module(fullname, fullname, new_path);
  265. +     Py_DECREF(new_path);
  266. +     if (!module)
  267. +     {
  268. +     Py_INCREF(Py_None);
  269. +     return Py_None;
  270. +     }
  271. +     if (!(loader = PyObject_NEW(LoaderObject, &LoaderType)))
  272. +     {
  273. +     Py_DECREF(module);
  274. +     return NULL;
  275. +     }
  276. +     loader->module = module;
  277. +     return (PyObject *) loader;
  278. + }
  279. +     static PyObject *
  280. + VimPathHook(PyObject *self UNUSED, PyObject *args)
  281. + {
  282. +     char    *path;
  283. +     if (PyArg_ParseTuple(args, "s", &path)
  284. +         && STRCMP(path, vim_special_path) == 0)
  285. +     {
  286. +     Py_INCREF(vim_module);
  287. +     return vim_module;
  288. +     }
  289. +     PyErr_Clear();
  290. +     PyErr_SetNone(PyExc_ImportError);
  291. +     return NULL;
  292. + }
  293.   /*
  294.    * Vim module - Definitions
  295.    */
  296. ***************
  297. *** 938,946 ****
  298.       {"chdir",        (PyCFunction)VimChdir,    METH_VARARGS|METH_KEYWORDS,    "Change directory"},
  299.       {"fchdir",        (PyCFunction)VimFchdir,    METH_VARARGS|METH_KEYWORDS,    "Change directory"},
  300.       {"foreach_rtp", VimForeachRTP,        METH_VARARGS,            "Call given callable for each path in &rtp"},
  301. - #if PY_MAJOR_VERSION < 3
  302.       {"find_module", FinderFindModule,        METH_VARARGS,            "Internal use only, returns loader object for any input it receives"},
  303. - #endif
  304.       {"path_hook",   VimPathHook,        METH_VARARGS,            "Hook function to install in sys.path_hooks"},
  305.       {"_get_paths",  (PyCFunction)Vim_GetPaths,    METH_NOARGS,            "Get &rtp-based additions to sys.path"},
  306.       { NULL,        NULL,            0,                NULL}
  307. --- 1113,1119 ----
  308. ***************
  309. *** 5188,5208 ****
  310.   } CurrentObject;
  311.   static PyTypeObject CurrentType;
  312.   
  313. - #if PY_MAJOR_VERSION >= 3
  314. - typedef struct
  315. - {
  316. -     PyObject_HEAD
  317. - } FinderObject;
  318. - static PyTypeObject FinderType;
  319. - #else
  320. - typedef struct
  321. - {
  322. -     PyObject_HEAD
  323. -     PyObject    *module;
  324. - } LoaderObject;
  325. - static PyTypeObject LoaderType;
  326. - #endif
  327.       static void
  328.   init_structs(void)
  329.   {
  330. --- 5361,5366 ----
  331. ***************
  332. *** 5418,5423 ****
  333. --- 5576,5589 ----
  334.       OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
  335.       OptionsType.tp_clear = (inquiry)OptionsClear;
  336.   
  337. +     vim_memset(&LoaderType, 0, sizeof(LoaderType));
  338. +     LoaderType.tp_name = "vim.Loader";
  339. +     LoaderType.tp_basicsize = sizeof(LoaderObject);
  340. +     LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
  341. +     LoaderType.tp_doc = "vim message object";
  342. +     LoaderType.tp_methods = LoaderMethods;
  343. +     LoaderType.tp_dealloc = (destructor)LoaderDestructor;
  344.   #if PY_MAJOR_VERSION >= 3
  345.       vim_memset(&vimmodule, 0, sizeof(vimmodule));
  346.       vimmodule.m_name = "vim";
  347. ***************
  348. *** 5448,5458 ****
  349.       PYTYPE_READY(FunctionType);
  350.       PYTYPE_READY(OptionsType);
  351.       PYTYPE_READY(OutputType);
  352. - #if PY_MAJOR_VERSION >= 3
  353. -     PYTYPE_READY(FinderType);
  354. - #else
  355.       PYTYPE_READY(LoaderType);
  356. - #endif
  357.       return 0;
  358.   }
  359.   
  360. --- 5614,5620 ----
  361. ***************
  362. *** 5576,5586 ****
  363.       {"List",       (PyObject *)&ListType},
  364.       {"Function",   (PyObject *)&FunctionType},
  365.       {"Options",    (PyObject *)&OptionsType},
  366. ! #if PY_MAJOR_VERSION >= 3
  367. !     {"Finder",     (PyObject *)&FinderType},
  368. ! #else
  369. !     {"Loader",     (PyObject *)&LoaderType},
  370. ! #endif
  371.   };
  372.   
  373.   typedef int (*object_adder)(PyObject *, const char *, PyObject *);
  374. --- 5738,5744 ----
  375.       {"List",       (PyObject *)&ListType},
  376.       {"Function",   (PyObject *)&FunctionType},
  377.       {"Options",    (PyObject *)&OptionsType},
  378. !     {"_Loader",    (PyObject *)&LoaderType},
  379.   };
  380.   
  381.   typedef int (*object_adder)(PyObject *, const char *, PyObject *);
  382. ***************
  383. *** 5604,5609 ****
  384. --- 5762,5768 ----
  385.       int        i;
  386.       PyObject    *other_module;
  387.       PyObject    *attr;
  388. +     PyObject    *imp;
  389.   
  390.       for (i = 0; i < (int)(sizeof(numeric_constants)
  391.                          / sizeof(struct numeric_constant));
  392. ***************
  393. *** 5671,5685 ****
  394.   
  395.       ADD_OBJECT(m, "VIM_SPECIAL_PATH", vim_special_path_object);
  396.   
  397. ! #if PY_MAJOR_VERSION >= 3
  398. !     ADD_OBJECT(m, "_PathFinder", path_finder);
  399. !     ADD_CHECKED_OBJECT(m, "_find_module",
  400. !         (py_find_module = PyObject_GetAttrString(path_finder,
  401. !                              "find_module")));
  402. ! #else
  403.       ADD_OBJECT(m, "_find_module", py_find_module);
  404.       ADD_OBJECT(m, "_load_module", py_load_module);
  405. - #endif
  406.   
  407.       return 0;
  408.   }
  409. --- 5830,5855 ----
  410.   
  411.       ADD_OBJECT(m, "VIM_SPECIAL_PATH", vim_special_path_object);
  412.   
  413. !     if (!(imp = PyImport_ImportModule("imp")))
  414. !     return -1;
  415. !     if (!(py_find_module = PyObject_GetAttrString(imp, "find_module")))
  416. !     {
  417. !     Py_DECREF(imp);
  418. !     return -1;
  419. !     }
  420. !     if (!(py_load_module = PyObject_GetAttrString(imp, "load_module")))
  421. !     {
  422. !     Py_DECREF(py_find_module);
  423. !     Py_DECREF(imp);
  424. !     return -1;
  425. !     }
  426. !     Py_DECREF(imp);
  427.       ADD_OBJECT(m, "_find_module", py_find_module);
  428.       ADD_OBJECT(m, "_load_module", py_load_module);
  429.   
  430.       return 0;
  431.   }
  432. *** ../vim-7.3.1173/src/if_python3.c    2013-06-10 21:27:18.000000000 +0200
  433. --- src/if_python3.c    2013-06-12 14:36:00.000000000 +0200
  434. ***************
  435. *** 175,180 ****
  436. --- 175,181 ----
  437.   # define PyObject_HasAttrString py3_PyObject_HasAttrString
  438.   # define PyObject_SetAttrString py3_PyObject_SetAttrString
  439.   # define PyObject_CallFunctionObjArgs py3_PyObject_CallFunctionObjArgs
  440. + # define _PyObject_CallFunction_SizeT py3__PyObject_CallFunction_SizeT
  441.   # define PyObject_Call py3_PyObject_Call
  442.   # define PyEval_GetLocals py3_PyEval_GetLocals
  443.   # define PyEval_GetGlobals py3_PyEval_GetGlobals
  444. ***************
  445. *** 296,301 ****
  446. --- 297,303 ----
  447.   static int (*py3_PyObject_HasAttrString)(PyObject *, const char *);
  448.   static PyObject* (*py3_PyObject_SetAttrString)(PyObject *, const char *, PyObject *);
  449.   static PyObject* (*py3_PyObject_CallFunctionObjArgs)(PyObject *, ...);
  450. + static PyObject* (*py3__PyObject_CallFunction_SizeT)(PyObject *, char *, ...);
  451.   static PyObject* (*py3_PyObject_Call)(PyObject *, PyObject *, PyObject *);
  452.   static PyObject* (*py3_PyEval_GetGlobals)();
  453.   static PyObject* (*py3_PyEval_GetLocals)();
  454. ***************
  455. *** 458,463 ****
  456. --- 460,466 ----
  457.       {"PyObject_HasAttrString", (PYTHON_PROC*)&py3_PyObject_HasAttrString},
  458.       {"PyObject_SetAttrString", (PYTHON_PROC*)&py3_PyObject_SetAttrString},
  459.       {"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&py3_PyObject_CallFunctionObjArgs},
  460. +     {"_PyObject_CallFunction_SizeT", (PYTHON_PROC*)&py3__PyObject_CallFunction_SizeT},
  461.       {"PyObject_Call", (PYTHON_PROC*)&py3_PyObject_Call},
  462.       {"PyEval_GetGlobals", (PYTHON_PROC*)&py3_PyEval_GetGlobals},
  463.       {"PyEval_GetLocals", (PYTHON_PROC*)&py3_PyEval_GetLocals},
  464. ***************
  465. *** 740,748 ****
  466.   
  467.   static struct PyModuleDef vimmodule;
  468.   
  469. - static PyObject *path_finder;
  470. - static PyObject *py_find_module = NULL;
  471.   #define PY_CAN_RECURSE
  472.   
  473.   /*
  474. --- 743,748 ----
  475. ***************
  476. *** 1603,1672 ****
  477.   #endif
  478.   
  479.       static PyObject *
  480. - VimPathHook(PyObject *self UNUSED, PyObject *args)
  481. - {
  482. -     char    *path;
  483. -     if (PyArg_ParseTuple(args, "s", &path)
  484. -         && STRCMP(path, vim_special_path) == 0)
  485. -     {
  486. -     Py_INCREF(&FinderType);
  487. -     return (PyObject *) &FinderType;
  488. -     }
  489. -     PyErr_Clear();
  490. -     PyErr_SetNone(PyExc_ImportError);
  491. -     return NULL;
  492. - }
  493. -     static PyObject *
  494. - FinderFindModule(PyObject *cls UNUSED, PyObject *fullname)
  495. - {
  496. -     PyObject    *new_path;
  497. -     PyObject    *r;
  498. -     if (!(new_path = Vim_GetPaths(NULL)))
  499. -     return NULL;
  500. -     /* call find_module of the super() class */
  501. -     r = PyObject_CallFunctionObjArgs(py_find_module, fullname, new_path, NULL);
  502. -     Py_DECREF(new_path);
  503. -     return r;
  504. - }
  505. - static struct PyMethodDef FinderMethods[] = {
  506. -     {"find_module",    FinderFindModule,    METH_CLASS|METH_O,    ""},
  507. -     {NULL,        NULL,            0,            NULL}
  508. - };
  509. -     static PyObject *
  510.   Py3Init_vim(void)
  511.   {
  512.       /* The special value is removed from sys.path in Python3_Init(). */
  513.       static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL};
  514. -     PyObject    *importlib_machinery;
  515. -     if (!(importlib_machinery = PyImport_ImportModule("importlib.machinery")))
  516. -     return NULL;
  517. -     if (!(path_finder = PyObject_GetAttrString(importlib_machinery,
  518. -                            "PathFinder")))
  519. -     {
  520. -     Py_DECREF(importlib_machinery);
  521. -     return NULL;
  522. -     }
  523. -     Py_DECREF(importlib_machinery);
  524. -     vim_memset(&FinderType, 0, sizeof(FinderObject));
  525. -     FinderType.tp_name = "vim.Finder";
  526. -     FinderType.tp_basicsize = sizeof(FinderObject);
  527. -     FinderType.tp_base = (PyTypeObject *) path_finder;
  528. -     FinderType.tp_flags = Py_TPFLAGS_DEFAULT;
  529. -     FinderType.tp_doc = "Vim finder class, for use with path hook";
  530. -     FinderType.tp_methods = FinderMethods;
  531.   
  532.       if (init_types())
  533.       return NULL;
  534. --- 1603,1612 ----
  535. *** ../vim-7.3.1173/src/if_python.c    2013-06-12 14:20:15.000000000 +0200
  536. --- src/if_python.c    2013-06-12 14:35:49.000000000 +0200
  537. ***************
  538. *** 752,763 ****
  539.   static PyObject *ListGetattr(PyObject *, char *);
  540.   static PyObject *FunctionGetattr(PyObject *, char *);
  541.   
  542. - static PyObject *FinderFindModule(PyObject *, PyObject *);
  543. - static PyObject *VimPathHook(PyObject *, PyObject *);
  544. - static PyObject *py_find_module;
  545. - static PyObject *py_load_module;
  546.   #ifndef Py_VISIT
  547.   # define Py_VISIT(obj) visit(obj, arg)
  548.   #endif
  549. --- 752,757 ----
  550. ***************
  551. *** 1382,1585 ****
  552.   }
  553.   #endif
  554.   
  555. -     static void
  556. - LoaderDestructor(LoaderObject *self)
  557. - {
  558. -     Py_DECREF(self->module);
  559. -     DESTRUCTOR_FINISH(self);
  560. - }
  561. -     static PyObject *
  562. - LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
  563. - {
  564. -     PyObject    *r = self->module;
  565. -     Py_INCREF(r);
  566. -     return r;
  567. - }
  568. - static struct PyMethodDef LoaderMethods[] = {
  569. -     /* name,        function,                calling,    doc */
  570. -     {"load_module", (PyCFunction)LoaderLoadModule,    METH_VARARGS,    ""},
  571. -     { NULL,        NULL,                0,        NULL}
  572. - };
  573. -     static PyObject *
  574. - call_load_module(char *name, int len, PyObject *find_module_result)
  575. - {
  576. -     PyObject    *fd, *pathname, *description;
  577. -     if (!PyTuple_Check(find_module_result)
  578. -         || PyTuple_GET_SIZE(find_module_result) != 3)
  579. -     {
  580. -     PyErr_SetString(PyExc_TypeError,
  581. -         _("expected 3-tuple as imp.find_module() result"));
  582. -     return NULL;
  583. -     }
  584. -     if (!(fd = PyTuple_GET_ITEM(find_module_result, 0))
  585. -         || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
  586. -         || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
  587. -     {
  588. -     PyErr_SetString(PyExc_RuntimeError,
  589. -         _("internal error: imp.find_module returned tuple with NULL"));
  590. -     return NULL;
  591. -     }
  592. -     return PyObject_CallFunction(py_load_module,
  593. -         "s#OOO", name, len, fd, pathname, description);
  594. - }
  595. -     static PyObject *
  596. - find_module(char *fullname, char *tail, PyObject *new_path)
  597. - {
  598. -     PyObject    *find_module_result;
  599. -     PyObject    *module;
  600. -     char    *dot;
  601. -     if ((dot = (char *) vim_strchr((char_u *) tail, '.')))
  602. -     {
  603. -     /*
  604. -      * There is a dot in the name: call find_module recursively without the 
  605. -      * first component
  606. -      */
  607. -     PyObject    *newest_path;
  608. -     int        partlen = (int) (dot - 1 - tail);
  609. -     if (!(find_module_result = PyObject_CallFunction(py_find_module,
  610. -             "s#O", tail, partlen, new_path)))
  611. -         return NULL;
  612. -     if (!(module = call_load_module(
  613. -             fullname,
  614. -             ((int) (tail - fullname)) + partlen,
  615. -             find_module_result)))
  616. -     {
  617. -         Py_DECREF(find_module_result);
  618. -         return NULL;
  619. -     }
  620. -     Py_DECREF(find_module_result);
  621. -     if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
  622. -     {
  623. -         Py_DECREF(module);
  624. -         return NULL;
  625. -     }
  626. -     Py_DECREF(module);
  627. -     module = find_module(fullname, dot + 1, newest_path);
  628. -     Py_DECREF(newest_path);
  629. -     return module;
  630. -     }
  631. -     else
  632. -     {
  633. -     if (!(find_module_result = PyObject_CallFunction(py_find_module,
  634. -             "sO", tail, new_path)))
  635. -         return NULL;
  636. -     if (!(module = call_load_module(
  637. -             fullname,
  638. -             STRLEN(fullname),
  639. -             find_module_result)))
  640. -     {
  641. -         Py_DECREF(find_module_result);
  642. -         return NULL;
  643. -     }
  644. -     Py_DECREF(find_module_result);
  645. -     return module;
  646. -     }
  647. - }
  648. -     static PyObject *
  649. - FinderFindModule(PyObject *self, PyObject *args)
  650. - {
  651. -     char    *fullname;
  652. -     PyObject    *module;
  653. -     PyObject    *new_path;
  654. -     LoaderObject    *loader;
  655. -     if (!PyArg_ParseTuple(args, "s", &fullname))
  656. -     return NULL;
  657. -     if (!(new_path = Vim_GetPaths(self)))
  658. -     return NULL;
  659. -     module = find_module(fullname, fullname, new_path);
  660. -     Py_DECREF(new_path);
  661. -     if (!module)
  662. -     {
  663. -     Py_INCREF(Py_None);
  664. -     return Py_None;
  665. -     }
  666. -     if (!(loader = PyObject_NEW(LoaderObject, &LoaderType)))
  667. -     {
  668. -     Py_DECREF(module);
  669. -     return NULL;
  670. -     }
  671. -     loader->module = module;
  672. -     return (PyObject *) loader;
  673. - }
  674. -     static PyObject *
  675. - VimPathHook(PyObject *self UNUSED, PyObject *args)
  676. - {
  677. -     char    *path;
  678. -     if (PyArg_ParseTuple(args, "s", &path)
  679. -         && STRCMP(path, vim_special_path) == 0)
  680. -     {
  681. -     Py_INCREF(vim_module);
  682. -     return vim_module;
  683. -     }
  684. -     PyErr_Clear();
  685. -     PyErr_SetNone(PyExc_ImportError);
  686. -     return NULL;
  687. - }
  688.       static int
  689.   PythonMod_Init(void)
  690.   {
  691.       /* The special value is removed from sys.path in Python_Init(). */
  692.       static char    *(argv[2]) = {"/must>not&exist/foo", NULL};
  693. -     PyObject    *imp;
  694. -     if (!(imp = PyImport_ImportModule("imp")))
  695. -     return -1;
  696. -     if (!(py_find_module = PyObject_GetAttrString(imp, "find_module")))
  697. -     {
  698. -     Py_DECREF(imp);
  699. -     return -1;
  700. -     }
  701. -     if (!(py_load_module = PyObject_GetAttrString(imp, "load_module")))
  702. -     {
  703. -     Py_DECREF(py_find_module);
  704. -     Py_DECREF(imp);
  705. -     return -1;
  706. -     }
  707. -     Py_DECREF(imp);
  708. -     vim_memset(&LoaderType, 0, sizeof(LoaderType));
  709. -     LoaderType.tp_name = "vim.Loader";
  710. -     LoaderType.tp_basicsize = sizeof(LoaderObject);
  711. -     LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
  712. -     LoaderType.tp_doc = "vim message object";
  713. -     LoaderType.tp_methods = LoaderMethods;
  714. -     LoaderType.tp_dealloc = (destructor)LoaderDestructor;
  715.   
  716.       if (init_types())
  717.       return -1;
  718. --- 1376,1386 ----
  719. *** ../vim-7.3.1173/src/version.c    2013-06-12 14:26:20.000000000 +0200
  720. --- src/version.c    2013-06-12 14:35:25.000000000 +0200
  721. ***************
  722. *** 730,731 ****
  723. --- 730,733 ----
  724.   {   /* Add new patch number below this line */
  725. + /**/
  726. +     1174,
  727.   /**/
  728.  
  729. -- 
  730. "Hit any key to continue" is very confusing when you have two keyboards.
  731.  
  732.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  733. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  734. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  735.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  736.