Mercurial > vim
comparison src/if_py_both.h @ 4851:96e154e825a7 v7.3.1172
updated for version 7.3.1172
Problem: Python 2: loading modules doesn't work well.
Solution: Fix the code. Add more tests. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 12 Jun 2013 14:20:36 +0200 |
parents | 70b1178dec79 |
children | 52850ef928f8 |
comparison
equal
deleted
inserted
replaced
4850:6c1f3a6714bd | 4851:96e154e825a7 |
---|---|
938 {"chdir", (PyCFunction)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, | 938 {"chdir", (PyCFunction)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, |
939 {"fchdir", (PyCFunction)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, | 939 {"fchdir", (PyCFunction)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, |
940 {"foreach_rtp", VimForeachRTP, METH_VARARGS, "Call given callable for each path in &rtp"}, | 940 {"foreach_rtp", VimForeachRTP, METH_VARARGS, "Call given callable for each path in &rtp"}, |
941 #if PY_MAJOR_VERSION < 3 | 941 #if PY_MAJOR_VERSION < 3 |
942 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"}, | 942 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"}, |
943 {"load_module", LoaderLoadModule, METH_VARARGS, "Internal use only, tries importing the given module from &rtp by temporary mocking sys.path (to an rtp-based one) and unsetting sys.meta_path and sys.path_hooks"}, | |
944 #endif | 943 #endif |
945 {"path_hook", VimPathHook, METH_VARARGS, "Hook function to install in sys.path_hooks"}, | 944 {"path_hook", VimPathHook, METH_VARARGS, "Hook function to install in sys.path_hooks"}, |
946 {"_get_paths", (PyCFunction)Vim_GetPaths, METH_NOARGS, "Get &rtp-based additions to sys.path"}, | 945 {"_get_paths", (PyCFunction)Vim_GetPaths, METH_NOARGS, "Get &rtp-based additions to sys.path"}, |
947 { NULL, NULL, 0, NULL} | 946 { NULL, NULL, 0, NULL} |
948 }; | 947 }; |
5193 typedef struct | 5192 typedef struct |
5194 { | 5193 { |
5195 PyObject_HEAD | 5194 PyObject_HEAD |
5196 } FinderObject; | 5195 } FinderObject; |
5197 static PyTypeObject FinderType; | 5196 static PyTypeObject FinderType; |
5197 #else | |
5198 typedef struct | |
5199 { | |
5200 PyObject_HEAD | |
5201 PyObject *module; | |
5202 } LoaderObject; | |
5203 static PyTypeObject LoaderType; | |
5198 #endif | 5204 #endif |
5199 | 5205 |
5200 static void | 5206 static void |
5201 init_structs(void) | 5207 init_structs(void) |
5202 { | 5208 { |
5442 PYTYPE_READY(FunctionType); | 5448 PYTYPE_READY(FunctionType); |
5443 PYTYPE_READY(OptionsType); | 5449 PYTYPE_READY(OptionsType); |
5444 PYTYPE_READY(OutputType); | 5450 PYTYPE_READY(OutputType); |
5445 #if PY_MAJOR_VERSION >= 3 | 5451 #if PY_MAJOR_VERSION >= 3 |
5446 PYTYPE_READY(FinderType); | 5452 PYTYPE_READY(FinderType); |
5453 #else | |
5454 PYTYPE_READY(LoaderType); | |
5447 #endif | 5455 #endif |
5448 return 0; | 5456 return 0; |
5449 } | 5457 } |
5450 | 5458 |
5451 static int | 5459 static int |
5568 {"List", (PyObject *)&ListType}, | 5576 {"List", (PyObject *)&ListType}, |
5569 {"Function", (PyObject *)&FunctionType}, | 5577 {"Function", (PyObject *)&FunctionType}, |
5570 {"Options", (PyObject *)&OptionsType}, | 5578 {"Options", (PyObject *)&OptionsType}, |
5571 #if PY_MAJOR_VERSION >= 3 | 5579 #if PY_MAJOR_VERSION >= 3 |
5572 {"Finder", (PyObject *)&FinderType}, | 5580 {"Finder", (PyObject *)&FinderType}, |
5581 #else | |
5582 {"Loader", (PyObject *)&LoaderType}, | |
5573 #endif | 5583 #endif |
5574 }; | 5584 }; |
5575 | 5585 |
5576 typedef int (*object_adder)(PyObject *, const char *, PyObject *); | 5586 typedef int (*object_adder)(PyObject *, const char *, PyObject *); |
5577 typedef PyObject *(*attr_getter)(PyObject *, const char *); | 5587 typedef PyObject *(*attr_getter)(PyObject *, const char *); |
5664 #if PY_MAJOR_VERSION >= 3 | 5674 #if PY_MAJOR_VERSION >= 3 |
5665 ADD_OBJECT(m, "_PathFinder", path_finder); | 5675 ADD_OBJECT(m, "_PathFinder", path_finder); |
5666 ADD_CHECKED_OBJECT(m, "_find_module", | 5676 ADD_CHECKED_OBJECT(m, "_find_module", |
5667 (py_find_module = PyObject_GetAttrString(path_finder, | 5677 (py_find_module = PyObject_GetAttrString(path_finder, |
5668 "find_module"))); | 5678 "find_module"))); |
5679 #else | |
5680 ADD_OBJECT(m, "_find_module", py_find_module); | |
5681 ADD_OBJECT(m, "_load_module", py_load_module); | |
5669 #endif | 5682 #endif |
5670 | 5683 |
5671 return 0; | 5684 return 0; |
5672 } | 5685 } |