Mercurial > vim
annotate src/if_python.c @ 3638:80ed6aa7b9eb v7.3.579
updated for version 7.3.579
Problem: Can't compile with Python 2.5.
Solution: Use PyCObject when Capsules are not available.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 29 Jun 2012 16:28:28 +0200 |
parents | c052f3b79b99 |
children | 96249a1803e2 |
rev | line source |
---|---|
3618 | 1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * Python extensions by Paul Moore. | |
11 * Changes for Unix by David Leonard. | |
12 * | |
13 * This consists of four parts: | |
14 * 1. Python interpreter main program | |
15 * 2. Python output stream: writes output via [e]msg(). | |
16 * 3. Implementation of the Vim module for Python | |
17 * 4. Utility functions for handling the interface between Vim and Python. | |
18 */ | |
19 | |
20 #include "vim.h" | |
21 | |
22 #include <limits.h> | |
23 | |
24 /* Python.h defines _POSIX_THREADS itself (if needed) */ | |
25 #ifdef _POSIX_THREADS | |
26 # undef _POSIX_THREADS | |
27 #endif | |
28 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2100
diff
changeset
|
29 #if defined(_WIN32) && defined(HAVE_FCNTL_H) |
7 | 30 # undef HAVE_FCNTL_H |
31 #endif | |
32 | |
33 #ifdef _DEBUG | |
34 # undef _DEBUG | |
35 #endif | |
36 | |
37 #ifdef HAVE_STDARG_H | |
38 # undef HAVE_STDARG_H /* Python's config.h defines it as well. */ | |
39 #endif | |
1991 | 40 #ifdef _POSIX_C_SOURCE |
41 # undef _POSIX_C_SOURCE /* pyconfig.h defines it as well. */ | |
42 #endif | |
43 #ifdef _XOPEN_SOURCE | |
44 # undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ | |
45 #endif | |
7 | 46 |
1594 | 47 #define PY_SSIZE_T_CLEAN |
48 | |
7 | 49 #include <Python.h> |
50 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
51 # include "macglue.h" | |
52 # include <CodeFragments.h> | |
53 #endif | |
54 #undef main /* Defined in python.h - aargh */ | |
55 #undef HAVE_FCNTL_H /* Clash with os_win32.h */ | |
56 | |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
57 static void init_structs(void); |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
58 |
3618 | 59 #define PyBytes_FromString PyString_FromString |
60 | |
2894 | 61 /* No-op conversion functions, use with care! */ |
62 #define PyString_AsBytes(obj) (obj) | |
63 #define PyString_FreeBytes(obj) | |
64 | |
7 | 65 #if !defined(FEAT_PYTHON) && defined(PROTO) |
66 /* Use this to be able to generate prototypes without python being used. */ | |
1607 | 67 # define PyObject Py_ssize_t |
68 # define PyThreadState Py_ssize_t | |
69 # define PyTypeObject Py_ssize_t | |
70 struct PyMethodDef { Py_ssize_t a; }; | |
71 # define PySequenceMethods Py_ssize_t | |
7 | 72 #endif |
73 | |
3638 | 74 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
75 # define PY_USE_CAPSULE | |
76 #endif | |
77 | |
1594 | 78 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 |
79 # define PyInt Py_ssize_t | |
80 # define PyInquiry lenfunc | |
81 # define PyIntArgFunc ssizeargfunc | |
82 # define PyIntIntArgFunc ssizessizeargfunc | |
83 # define PyIntObjArgProc ssizeobjargproc | |
84 # define PyIntIntObjArgProc ssizessizeobjargproc | |
1607 | 85 # define Py_ssize_t_fmt "n" |
1594 | 86 #else |
87 # define PyInt int | |
88 # define PyInquiry inquiry | |
89 # define PyIntArgFunc intargfunc | |
90 # define PyIntIntArgFunc intintargfunc | |
91 # define PyIntObjArgProc intobjargproc | |
92 # define PyIntIntObjArgProc intintobjargproc | |
1607 | 93 # define Py_ssize_t_fmt "i" |
1594 | 94 #endif |
95 | |
7 | 96 /* Parser flags */ |
97 #define single_input 256 | |
98 #define file_input 257 | |
99 #define eval_input 258 | |
100 | |
101 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 | |
102 /* Python 2.3: can invoke ":python" recursively. */ | |
103 # define PY_CAN_RECURSE | |
104 #endif | |
105 | |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
106 # if defined(DYNAMIC_PYTHON) || defined(PROTO) |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
107 # ifndef DYNAMIC_PYTHON |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
108 # define HINSTANCE long_u /* for generating prototypes */ |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
109 # endif |
7 | 110 |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
111 # ifndef WIN3264 |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
112 # include <dlfcn.h> |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
113 # define FARPROC void* |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
114 # define HINSTANCE void* |
2641 | 115 # if defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL) |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
116 # define load_dll(n) dlopen((n), RTLD_LAZY) |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
117 # else |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
118 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
119 # endif |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
120 # define close_dll dlclose |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
121 # define symbol_from_dll dlsym |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
122 # else |
2612 | 123 # define load_dll vimLoadLib |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
124 # define close_dll FreeLibrary |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
125 # define symbol_from_dll GetProcAddress |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
126 # endif |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
127 |
1607 | 128 /* This makes if_python.c compile without warnings against Python 2.5 |
129 * on Win32 and Win64. */ | |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
130 # undef PyRun_SimpleString |
3618 | 131 # undef PyRun_String |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
132 # undef PyArg_Parse |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
133 # undef PyArg_ParseTuple |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
134 # undef Py_BuildValue |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
135 # undef Py_InitModule4 |
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
136 # undef Py_InitModule4_64 |
3618 | 137 # undef PyObject_CallMethod |
1607 | 138 |
7 | 139 /* |
140 * Wrapper defines | |
141 */ | |
142 # define PyArg_Parse dll_PyArg_Parse | |
143 # define PyArg_ParseTuple dll_PyArg_ParseTuple | |
2894 | 144 # define PyMem_Free dll_PyMem_Free |
3618 | 145 # define PyMem_Malloc dll_PyMem_Malloc |
7 | 146 # define PyDict_SetItemString dll_PyDict_SetItemString |
147 # define PyErr_BadArgument dll_PyErr_BadArgument | |
148 # define PyErr_Clear dll_PyErr_Clear | |
149 # define PyErr_NoMemory dll_PyErr_NoMemory | |
150 # define PyErr_Occurred dll_PyErr_Occurred | |
151 # define PyErr_SetNone dll_PyErr_SetNone | |
152 # define PyErr_SetString dll_PyErr_SetString | |
153 # define PyEval_InitThreads dll_PyEval_InitThreads | |
154 # define PyEval_RestoreThread dll_PyEval_RestoreThread | |
155 # define PyEval_SaveThread dll_PyEval_SaveThread | |
156 # ifdef PY_CAN_RECURSE | |
157 # define PyGILState_Ensure dll_PyGILState_Ensure | |
158 # define PyGILState_Release dll_PyGILState_Release | |
159 # endif | |
160 # define PyInt_AsLong dll_PyInt_AsLong | |
161 # define PyInt_FromLong dll_PyInt_FromLong | |
3618 | 162 # define PyLong_AsLong dll_PyLong_AsLong |
163 # define PyLong_FromLong dll_PyLong_FromLong | |
7 | 164 # define PyInt_Type (*dll_PyInt_Type) |
3618 | 165 # define PyLong_Type (*dll_PyLong_Type) |
7 | 166 # define PyList_GetItem dll_PyList_GetItem |
637 | 167 # define PyList_Append dll_PyList_Append |
7 | 168 # define PyList_New dll_PyList_New |
169 # define PyList_SetItem dll_PyList_SetItem | |
170 # define PyList_Size dll_PyList_Size | |
171 # define PyList_Type (*dll_PyList_Type) | |
3618 | 172 # define PySequence_Check dll_PySequence_Check |
173 # define PySequence_Size dll_PySequence_Size | |
174 # define PySequence_GetItem dll_PySequence_GetItem | |
175 # define PyTuple_Size dll_PyTuple_Size | |
176 # define PyTuple_GetItem dll_PyTuple_GetItem | |
177 # define PyTuple_Type (*dll_PyTuple_Type) | |
7 | 178 # define PyImport_ImportModule dll_PyImport_ImportModule |
637 | 179 # define PyDict_New dll_PyDict_New |
7 | 180 # define PyDict_GetItemString dll_PyDict_GetItemString |
3618 | 181 # define PyDict_Next dll_PyDict_Next |
182 # ifdef PyMapping_Items | |
183 # define PY_NO_MAPPING_ITEMS | |
184 # else | |
185 # define PyMapping_Items dll_PyMapping_Items | |
186 # endif | |
187 # define PyObject_CallMethod dll_PyObject_CallMethod | |
188 # define PyMapping_Check dll_PyMapping_Check | |
189 # define PyIter_Next dll_PyIter_Next | |
7 | 190 # define PyModule_GetDict dll_PyModule_GetDict |
191 # define PyRun_SimpleString dll_PyRun_SimpleString | |
3618 | 192 # define PyRun_String dll_PyRun_String |
7 | 193 # define PyString_AsString dll_PyString_AsString |
194 # define PyString_FromString dll_PyString_FromString | |
195 # define PyString_FromStringAndSize dll_PyString_FromStringAndSize | |
196 # define PyString_Size dll_PyString_Size | |
197 # define PyString_Type (*dll_PyString_Type) | |
3618 | 198 # define PyUnicode_Type (*dll_PyUnicode_Type) |
199 # define PyUnicodeUCS4_AsEncodedString (*dll_PyUnicodeUCS4_AsEncodedString) | |
200 # define PyFloat_AsDouble dll_PyFloat_AsDouble | |
201 # define PyFloat_FromDouble dll_PyFloat_FromDouble | |
202 # define PyFloat_Type (*dll_PyFloat_Type) | |
203 # define PyImport_AddModule (*dll_PyImport_AddModule) | |
7 | 204 # define PySys_SetObject dll_PySys_SetObject |
205 # define PySys_SetArgv dll_PySys_SetArgv | |
206 # define PyType_Type (*dll_PyType_Type) | |
2737 | 207 # define PyType_Ready (*dll_PyType_Ready) |
7 | 208 # define Py_BuildValue dll_Py_BuildValue |
209 # define Py_FindMethod dll_Py_FindMethod | |
210 # define Py_InitModule4 dll_Py_InitModule4 | |
2641 | 211 # define Py_SetPythonHome dll_Py_SetPythonHome |
7 | 212 # define Py_Initialize dll_Py_Initialize |
242 | 213 # define Py_Finalize dll_Py_Finalize |
214 # define Py_IsInitialized dll_Py_IsInitialized | |
7 | 215 # define _PyObject_New dll__PyObject_New |
3618 | 216 # define _PyObject_NextNotImplemented (*dll__PyObject_NextNotImplemented) |
7 | 217 # define _Py_NoneStruct (*dll__Py_NoneStruct) |
218 # define PyObject_Init dll__PyObject_Init | |
3618 | 219 # define PyObject_GetIter dll_PyObject_GetIter |
7 | 220 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
221 # define PyType_IsSubtype dll_PyType_IsSubtype | |
222 # endif | |
223 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 | |
224 # define PyObject_Malloc dll_PyObject_Malloc | |
225 # define PyObject_Free dll_PyObject_Free | |
226 # endif | |
3638 | 227 # ifdef PY_USE_CAPSULE |
228 # define PyCapsule_New dll_PyCapsule_New | |
229 # define PyCapsule_GetPointer dll_PyCapsule_GetPointer | |
230 # else | |
231 # define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr | |
232 # define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr | |
233 # endif | |
7 | 234 |
235 /* | |
236 * Pointers for dynamic link | |
237 */ | |
238 static int(*dll_PyArg_Parse)(PyObject *, char *, ...); | |
239 static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...); | |
2894 | 240 static int(*dll_PyMem_Free)(void *); |
3618 | 241 static void* (*dll_PyMem_Malloc)(size_t); |
7 | 242 static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); |
243 static int(*dll_PyErr_BadArgument)(void); | |
244 static void(*dll_PyErr_Clear)(void); | |
245 static PyObject*(*dll_PyErr_NoMemory)(void); | |
246 static PyObject*(*dll_PyErr_Occurred)(void); | |
247 static void(*dll_PyErr_SetNone)(PyObject *); | |
248 static void(*dll_PyErr_SetString)(PyObject *, const char *); | |
249 static void(*dll_PyEval_InitThreads)(void); | |
250 static void(*dll_PyEval_RestoreThread)(PyThreadState *); | |
251 static PyThreadState*(*dll_PyEval_SaveThread)(void); | |
252 # ifdef PY_CAN_RECURSE | |
253 static PyGILState_STATE (*dll_PyGILState_Ensure)(void); | |
254 static void (*dll_PyGILState_Release)(PyGILState_STATE); | |
3618 | 255 # endif |
7 | 256 static long(*dll_PyInt_AsLong)(PyObject *); |
257 static PyObject*(*dll_PyInt_FromLong)(long); | |
3618 | 258 static long(*dll_PyLong_AsLong)(PyObject *); |
259 static PyObject*(*dll_PyLong_FromLong)(long); | |
7 | 260 static PyTypeObject* dll_PyInt_Type; |
3618 | 261 static PyTypeObject* dll_PyLong_Type; |
1594 | 262 static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt); |
637 | 263 static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *); |
1594 | 264 static PyObject*(*dll_PyList_New)(PyInt size); |
265 static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *); | |
266 static PyInt(*dll_PyList_Size)(PyObject *); | |
7 | 267 static PyTypeObject* dll_PyList_Type; |
3618 | 268 static int (*dll_PySequence_Check)(PyObject *); |
269 static PyInt(*dll_PySequence_Size)(PyObject *); | |
270 static PyObject*(*dll_PySequence_GetItem)(PyObject *, PyInt); | |
271 static PyInt(*dll_PyTuple_Size)(PyObject *); | |
272 static PyObject*(*dll_PyTuple_GetItem)(PyObject *, PyInt); | |
273 static PyTypeObject* dll_PyTuple_Type; | |
7 | 274 static PyObject*(*dll_PyImport_ImportModule)(const char *); |
637 | 275 static PyObject*(*dll_PyDict_New)(void); |
7 | 276 static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *); |
3618 | 277 static int (*dll_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **); |
278 # ifndef PY_NO_MAPPING_ITEMS | |
279 static PyObject* (*dll_PyMapping_Items)(PyObject *); | |
280 # endif | |
281 static PyObject* (*dll_PyObject_CallMethod)(PyObject *, char *, PyObject *); | |
282 static int (*dll_PyMapping_Check)(PyObject *); | |
283 static PyObject* (*dll_PyIter_Next)(PyObject *); | |
7 | 284 static PyObject*(*dll_PyModule_GetDict)(PyObject *); |
285 static int(*dll_PyRun_SimpleString)(char *); | |
3618 | 286 static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *); |
7 | 287 static char*(*dll_PyString_AsString)(PyObject *); |
288 static PyObject*(*dll_PyString_FromString)(const char *); | |
1594 | 289 static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt); |
290 static PyInt(*dll_PyString_Size)(PyObject *); | |
7 | 291 static PyTypeObject* dll_PyString_Type; |
3618 | 292 static PyTypeObject* dll_PyUnicode_Type; |
293 static PyObject *(*PyUnicodeUCS4_AsEncodedString)(PyObject *, char *, char *); | |
294 static double(*dll_PyFloat_AsDouble)(PyObject *); | |
295 static PyObject*(*dll_PyFloat_FromDouble)(double); | |
296 static PyTypeObject* dll_PyFloat_Type; | |
7 | 297 static int(*dll_PySys_SetObject)(char *, PyObject *); |
298 static int(*dll_PySys_SetArgv)(int, char **); | |
299 static PyTypeObject* dll_PyType_Type; | |
2737 | 300 static int (*dll_PyType_Ready)(PyTypeObject *type); |
7 | 301 static PyObject*(*dll_Py_BuildValue)(char *, ...); |
302 static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *); | |
303 static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int); | |
3618 | 304 static PyObject*(*dll_PyImport_AddModule)(char *); |
2641 | 305 static void(*dll_Py_SetPythonHome)(char *home); |
7 | 306 static void(*dll_Py_Initialize)(void); |
242 | 307 static void(*dll_Py_Finalize)(void); |
308 static int(*dll_Py_IsInitialized)(void); | |
7 | 309 static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *); |
310 static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *); | |
3618 | 311 static PyObject* (*dll_PyObject_GetIter)(PyObject *); |
312 static iternextfunc dll__PyObject_NextNotImplemented; | |
7 | 313 static PyObject* dll__Py_NoneStruct; |
314 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 | |
315 static int (*dll_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); | |
316 # endif | |
317 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 | |
318 static void* (*dll_PyObject_Malloc)(size_t); | |
319 static void (*dll_PyObject_Free)(void*); | |
320 # endif | |
3638 | 321 # ifdef PY_USE_CAPSULE |
3618 | 322 static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor); |
323 static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *); | |
3638 | 324 # else |
325 static PyCObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *)); | |
326 static void* (*dll_PyCObject_AsVoidPtr)(PyCObject *); | |
327 # endif | |
7 | 328 |
329 static HINSTANCE hinstPython = 0; /* Instance of python.dll */ | |
330 | |
331 /* Imported exception objects */ | |
332 static PyObject *imp_PyExc_AttributeError; | |
333 static PyObject *imp_PyExc_IndexError; | |
334 static PyObject *imp_PyExc_KeyboardInterrupt; | |
335 static PyObject *imp_PyExc_TypeError; | |
336 static PyObject *imp_PyExc_ValueError; | |
337 | |
338 # define PyExc_AttributeError imp_PyExc_AttributeError | |
339 # define PyExc_IndexError imp_PyExc_IndexError | |
340 # define PyExc_KeyboardInterrupt imp_PyExc_KeyboardInterrupt | |
341 # define PyExc_TypeError imp_PyExc_TypeError | |
342 # define PyExc_ValueError imp_PyExc_ValueError | |
343 | |
344 /* | |
345 * Table of name to function pointer of python. | |
346 */ | |
347 # define PYTHON_PROC FARPROC | |
348 static struct | |
349 { | |
350 char *name; | |
351 PYTHON_PROC *ptr; | |
352 } python_funcname_table[] = | |
353 { | |
354 {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse}, | |
355 {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple}, | |
2894 | 356 {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free}, |
3618 | 357 {"PyMem_Malloc", (PYTHON_PROC*)&dll_PyMem_Malloc}, |
7 | 358 {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString}, |
359 {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument}, | |
360 {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear}, | |
361 {"PyErr_NoMemory", (PYTHON_PROC*)&dll_PyErr_NoMemory}, | |
362 {"PyErr_Occurred", (PYTHON_PROC*)&dll_PyErr_Occurred}, | |
363 {"PyErr_SetNone", (PYTHON_PROC*)&dll_PyErr_SetNone}, | |
364 {"PyErr_SetString", (PYTHON_PROC*)&dll_PyErr_SetString}, | |
365 {"PyEval_InitThreads", (PYTHON_PROC*)&dll_PyEval_InitThreads}, | |
366 {"PyEval_RestoreThread", (PYTHON_PROC*)&dll_PyEval_RestoreThread}, | |
367 {"PyEval_SaveThread", (PYTHON_PROC*)&dll_PyEval_SaveThread}, | |
368 # ifdef PY_CAN_RECURSE | |
369 {"PyGILState_Ensure", (PYTHON_PROC*)&dll_PyGILState_Ensure}, | |
370 {"PyGILState_Release", (PYTHON_PROC*)&dll_PyGILState_Release}, | |
371 # endif | |
372 {"PyInt_AsLong", (PYTHON_PROC*)&dll_PyInt_AsLong}, | |
373 {"PyInt_FromLong", (PYTHON_PROC*)&dll_PyInt_FromLong}, | |
3618 | 374 {"PyLong_AsLong", (PYTHON_PROC*)&dll_PyLong_AsLong}, |
375 {"PyLong_FromLong", (PYTHON_PROC*)&dll_PyLong_FromLong}, | |
7 | 376 {"PyInt_Type", (PYTHON_PROC*)&dll_PyInt_Type}, |
3618 | 377 {"PyLong_Type", (PYTHON_PROC*)&dll_PyLong_Type}, |
7 | 378 {"PyList_GetItem", (PYTHON_PROC*)&dll_PyList_GetItem}, |
637 | 379 {"PyList_Append", (PYTHON_PROC*)&dll_PyList_Append}, |
7 | 380 {"PyList_New", (PYTHON_PROC*)&dll_PyList_New}, |
381 {"PyList_SetItem", (PYTHON_PROC*)&dll_PyList_SetItem}, | |
382 {"PyList_Size", (PYTHON_PROC*)&dll_PyList_Size}, | |
383 {"PyList_Type", (PYTHON_PROC*)&dll_PyList_Type}, | |
3618 | 384 {"PySequence_GetItem", (PYTHON_PROC*)&dll_PySequence_GetItem}, |
385 {"PySequence_Size", (PYTHON_PROC*)&dll_PySequence_Size}, | |
386 {"PySequence_Check", (PYTHON_PROC*)&dll_PySequence_Check}, | |
387 {"PyTuple_GetItem", (PYTHON_PROC*)&dll_PyTuple_GetItem}, | |
388 {"PyTuple_Size", (PYTHON_PROC*)&dll_PyTuple_Size}, | |
389 {"PyTuple_Type", (PYTHON_PROC*)&dll_PyTuple_Type}, | |
7 | 390 {"PyImport_ImportModule", (PYTHON_PROC*)&dll_PyImport_ImportModule}, |
391 {"PyDict_GetItemString", (PYTHON_PROC*)&dll_PyDict_GetItemString}, | |
3618 | 392 {"PyDict_Next", (PYTHON_PROC*)&dll_PyDict_Next}, |
637 | 393 {"PyDict_New", (PYTHON_PROC*)&dll_PyDict_New}, |
3618 | 394 # ifndef PY_NO_MAPPING_ITEMS |
395 {"PyMapping_Items", (PYTHON_PROC*)&dll_PyMapping_Items}, | |
396 # endif | |
397 {"PyObject_CallMethod", (PYTHON_PROC*)&dll_PyObject_CallMethod}, | |
398 {"PyMapping_Check", (PYTHON_PROC*)&dll_PyMapping_Check}, | |
399 {"PyIter_Next", (PYTHON_PROC*)&dll_PyIter_Next}, | |
7 | 400 {"PyModule_GetDict", (PYTHON_PROC*)&dll_PyModule_GetDict}, |
401 {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString}, | |
3618 | 402 {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String}, |
7 | 403 {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString}, |
404 {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString}, | |
405 {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize}, | |
406 {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size}, | |
407 {"PyString_Type", (PYTHON_PROC*)&dll_PyString_Type}, | |
3618 | 408 {"PyUnicode_Type", (PYTHON_PROC*)&dll_PyUnicode_Type}, |
409 {"PyUnicodeUCS4_AsEncodedString", (PYTHON_PROC*)&dll_PyUnicodeUCS4_AsEncodedString}, | |
410 {"PyFloat_Type", (PYTHON_PROC*)&dll_PyFloat_Type}, | |
411 {"PyFloat_AsDouble", (PYTHON_PROC*)&dll_PyFloat_AsDouble}, | |
412 {"PyFloat_FromDouble", (PYTHON_PROC*)&dll_PyFloat_FromDouble}, | |
413 {"PyImport_AddModule", (PYTHON_PROC*)&dll_PyImport_AddModule}, | |
7 | 414 {"PySys_SetObject", (PYTHON_PROC*)&dll_PySys_SetObject}, |
415 {"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv}, | |
416 {"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type}, | |
2737 | 417 {"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready}, |
7 | 418 {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue}, |
419 {"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod}, | |
3638 | 420 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 \ |
421 && SIZEOF_SIZE_T != SIZEOF_INT | |
1607 | 422 {"Py_InitModule4_64", (PYTHON_PROC*)&dll_Py_InitModule4}, |
423 # else | |
7 | 424 {"Py_InitModule4", (PYTHON_PROC*)&dll_Py_InitModule4}, |
1607 | 425 # endif |
2641 | 426 {"Py_SetPythonHome", (PYTHON_PROC*)&dll_Py_SetPythonHome}, |
7 | 427 {"Py_Initialize", (PYTHON_PROC*)&dll_Py_Initialize}, |
242 | 428 {"Py_Finalize", (PYTHON_PROC*)&dll_Py_Finalize}, |
429 {"Py_IsInitialized", (PYTHON_PROC*)&dll_Py_IsInitialized}, | |
7 | 430 {"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New}, |
431 {"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init}, | |
3618 | 432 {"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter}, |
433 {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented}, | |
7 | 434 {"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct}, |
435 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 | |
436 {"PyType_IsSubtype", (PYTHON_PROC*)&dll_PyType_IsSubtype}, | |
437 # endif | |
438 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 | |
439 {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc}, | |
440 {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free}, | |
441 # endif | |
3638 | 442 # ifdef PY_USE_CAPSULE |
3618 | 443 {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New}, |
444 {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer}, | |
3638 | 445 # else |
446 {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr}, | |
447 {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr}, | |
448 # endif | |
7 | 449 {"", NULL}, |
450 }; | |
451 | |
452 /* | |
453 * Free python.dll | |
454 */ | |
455 static void | |
456 end_dynamic_python(void) | |
457 { | |
458 if (hinstPython) | |
459 { | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
460 close_dll(hinstPython); |
7 | 461 hinstPython = 0; |
462 } | |
463 } | |
464 | |
465 /* | |
466 * Load library and get all pointers. | |
467 * Parameter 'libname' provides name of DLL. | |
468 * Return OK or FAIL. | |
469 */ | |
470 static int | |
471 python_runtime_link_init(char *libname, int verbose) | |
472 { | |
473 int i; | |
474 | |
2641 | 475 #if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) |
2554
7abef60aca22
Add a configure check for RTLD_GLOBAL. (James Vega, Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2528
diff
changeset
|
476 /* Can't have Python and Python3 loaded at the same time. |
7abef60aca22
Add a configure check for RTLD_GLOBAL. (James Vega, Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2528
diff
changeset
|
477 * It cause a crash, because RTLD_GLOBAL is needed for |
7abef60aca22
Add a configure check for RTLD_GLOBAL. (James Vega, Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2528
diff
changeset
|
478 * standard C extension libraries of one or both python versions. */ |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
479 if (python3_loaded()) |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
480 { |
3032 | 481 if (verbose) |
482 EMSG(_("E836: This Vim cannot execute :python after using :py3")); | |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
483 return FAIL; |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
484 } |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
485 #endif |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
486 |
7 | 487 if (hinstPython) |
488 return OK; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
489 hinstPython = load_dll(libname); |
7 | 490 if (!hinstPython) |
491 { | |
492 if (verbose) | |
493 EMSG2(_(e_loadlib), libname); | |
494 return FAIL; | |
495 } | |
496 | |
497 for (i = 0; python_funcname_table[i].ptr; ++i) | |
498 { | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
499 if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython, |
7 | 500 python_funcname_table[i].name)) == NULL) |
501 { | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
502 close_dll(hinstPython); |
7 | 503 hinstPython = 0; |
504 if (verbose) | |
505 EMSG2(_(e_loadfunc), python_funcname_table[i].name); | |
506 return FAIL; | |
507 } | |
508 } | |
509 return OK; | |
510 } | |
511 | |
512 /* | |
513 * If python is enabled (there is installed python on Windows system) return | |
514 * TRUE, else FALSE. | |
515 */ | |
516 int | |
1607 | 517 python_enabled(int verbose) |
7 | 518 { |
519 return python_runtime_link_init(DYNAMIC_PYTHON_DLL, verbose) == OK; | |
520 } | |
521 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
522 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
523 * Load the standard Python exceptions - don't import the symbols from the |
7 | 524 * DLL, as this can cause errors (importing data symbols is not reliable). |
525 */ | |
526 static void | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
527 get_exceptions(void) |
7 | 528 { |
529 PyObject *exmod = PyImport_ImportModule("exceptions"); | |
530 PyObject *exdict = PyModule_GetDict(exmod); | |
531 imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError"); | |
532 imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError"); | |
533 imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt"); | |
534 imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError"); | |
535 imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError"); | |
536 Py_XINCREF(imp_PyExc_AttributeError); | |
537 Py_XINCREF(imp_PyExc_IndexError); | |
538 Py_XINCREF(imp_PyExc_KeyboardInterrupt); | |
539 Py_XINCREF(imp_PyExc_TypeError); | |
540 Py_XINCREF(imp_PyExc_ValueError); | |
541 Py_XDECREF(exmod); | |
542 } | |
543 #endif /* DYNAMIC_PYTHON */ | |
544 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
545 static PyObject *BufferNew (buf_T *); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
546 static PyObject *WindowNew(win_T *); |
3618 | 547 static PyObject *DictionaryNew(dict_T *); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
548 static PyObject *LineToString(const char *); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
549 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
550 static PyTypeObject RangeType; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
551 |
3618 | 552 static int initialised = 0; |
553 #define PYINITIALISED initialised | |
554 | |
555 /* Add conversion from PyInt? */ | |
556 #define DICTKEY_GET(err) \ | |
557 if (!PyString_Check(keyObject)) \ | |
558 { \ | |
559 PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \ | |
560 return err; \ | |
561 } \ | |
562 key = (char_u *) PyString_AsString(keyObject); | |
563 #define DICTKEY_UNREF | |
564 #define DICTKEY_DECL | |
565 | |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
566 /* |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
567 * Include the code shared with if_python3.c |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
568 */ |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
569 #include "if_py_both.h" |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
570 |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
571 |
7 | 572 /****************************************************** |
573 * Internal function prototypes. | |
574 */ | |
575 | |
1607 | 576 static PyInt RangeStart; |
577 static PyInt RangeEnd; | |
7 | 578 |
3618 | 579 static PyObject *globals; |
580 | |
7 | 581 static void PythonIO_Flush(void); |
582 static int PythonIO_Init(void); | |
583 static int PythonMod_Init(void); | |
584 | |
585 /* Utility functions for the vim/python interface | |
586 * ---------------------------------------------- | |
587 */ | |
588 | |
1607 | 589 static int SetBufferLineList(buf_T *, PyInt, PyInt, PyObject *, PyInt *); |
7 | 590 |
591 | |
592 /****************************************************** | |
593 * 1. Python interpreter main program. | |
594 */ | |
595 | |
596 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ | |
597 typedef PyObject PyThreadState; | |
323 | 598 #endif |
599 | |
600 #ifdef PY_CAN_RECURSE | |
601 static PyGILState_STATE pygilstate = PyGILState_UNLOCKED; | |
602 #else | |
36 | 603 static PyThreadState *saved_python_thread = NULL; |
323 | 604 #endif |
7 | 605 |
606 /* | |
607 * Suspend a thread of the Python interpreter, other threads are allowed to | |
608 * run. | |
609 */ | |
36 | 610 static void |
611 Python_SaveThread(void) | |
7 | 612 { |
323 | 613 #ifdef PY_CAN_RECURSE |
614 PyGILState_Release(pygilstate); | |
615 #else | |
7 | 616 saved_python_thread = PyEval_SaveThread(); |
323 | 617 #endif |
7 | 618 } |
619 | |
620 /* | |
621 * Restore a thread of the Python interpreter, waits for other threads to | |
622 * block. | |
623 */ | |
36 | 624 static void |
625 Python_RestoreThread(void) | |
7 | 626 { |
323 | 627 #ifdef PY_CAN_RECURSE |
628 pygilstate = PyGILState_Ensure(); | |
629 #else | |
7 | 630 PyEval_RestoreThread(saved_python_thread); |
631 saved_python_thread = NULL; | |
323 | 632 #endif |
7 | 633 } |
634 | |
635 void | |
636 python_end() | |
637 { | |
557 | 638 static int recurse = 0; |
639 | |
640 /* If a crash occurs while doing this, don't try again. */ | |
641 if (recurse != 0) | |
642 return; | |
643 | |
644 ++recurse; | |
645 | |
7 | 646 #ifdef DYNAMIC_PYTHON |
242 | 647 if (hinstPython && Py_IsInitialized()) |
323 | 648 { |
856 | 649 Python_RestoreThread(); /* enter python */ |
650 Py_Finalize(); | |
323 | 651 } |
7 | 652 end_dynamic_python(); |
242 | 653 #else |
654 if (Py_IsInitialized()) | |
323 | 655 { |
856 | 656 Python_RestoreThread(); /* enter python */ |
657 Py_Finalize(); | |
323 | 658 } |
7 | 659 #endif |
557 | 660 |
661 --recurse; | |
7 | 662 } |
663 | |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
664 #if (defined(DYNAMIC_PYTHON) && defined(FEAT_PYTHON3)) || defined(PROTO) |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
665 int |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
666 python_loaded() |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
667 { |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
668 return (hinstPython != 0); |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
669 } |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
670 #endif |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
671 |
7 | 672 static int |
673 Python_Init(void) | |
674 { | |
675 if (!initialised) | |
676 { | |
677 #ifdef DYNAMIC_PYTHON | |
678 if (!python_enabled(TRUE)) | |
679 { | |
680 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); | |
681 goto fail; | |
682 } | |
683 #endif | |
684 | |
2641 | 685 #ifdef PYTHON_HOME |
686 Py_SetPythonHome(PYTHON_HOME); | |
687 #endif | |
688 | |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
689 init_structs(); |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
690 |
7 | 691 #if !defined(MACOS) || defined(MACOS_X_UNIX) |
692 Py_Initialize(); | |
693 #else | |
694 PyMac_Initialize(); | |
695 #endif | |
696 /* initialise threads */ | |
697 PyEval_InitThreads(); | |
698 | |
699 #ifdef DYNAMIC_PYTHON | |
700 get_exceptions(); | |
701 #endif | |
702 | |
703 if (PythonIO_Init()) | |
704 goto fail; | |
705 | |
706 if (PythonMod_Init()) | |
707 goto fail; | |
708 | |
3618 | 709 globals = PyModule_GetDict(PyImport_AddModule("__main__")); |
710 | |
1748 | 711 /* Remove the element from sys.path that was added because of our |
712 * argv[0] value in PythonMod_Init(). Previously we used an empty | |
713 * string, but dependinding on the OS we then get an empty entry or | |
714 * the current directory in sys.path. */ | |
715 PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); | |
716 | |
36 | 717 /* the first python thread is vim's, release the lock */ |
7 | 718 Python_SaveThread(); |
719 | |
720 initialised = 1; | |
721 } | |
722 | |
723 return 0; | |
724 | |
725 fail: | |
726 /* We call PythonIO_Flush() here to print any Python errors. | |
727 * This is OK, as it is possible to call this function even | |
728 * if PythonIO_Init() has not completed successfully (it will | |
729 * not do anything in this case). | |
730 */ | |
731 PythonIO_Flush(); | |
732 return -1; | |
733 } | |
734 | |
735 /* | |
736 * External interface | |
737 */ | |
738 static void | |
3618 | 739 DoPythonCommand(exarg_T *eap, const char *cmd, typval_T *rettv) |
7 | 740 { |
323 | 741 #ifndef PY_CAN_RECURSE |
7 | 742 static int recursive = 0; |
743 #endif | |
744 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
745 GrafPtr oldPort; | |
746 #endif | |
747 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
748 char *saved_locale; | |
749 #endif | |
750 | |
751 #ifndef PY_CAN_RECURSE | |
752 if (recursive) | |
753 { | |
754 EMSG(_("E659: Cannot invoke Python recursively")); | |
755 return; | |
756 } | |
757 ++recursive; | |
758 #endif | |
759 | |
760 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
761 GetPort(&oldPort); | |
762 /* Check if the Python library is available */ | |
763 if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress) | |
764 goto theend; | |
765 #endif | |
766 if (Python_Init()) | |
767 goto theend; | |
768 | |
3618 | 769 if (rettv == NULL) |
770 { | |
771 RangeStart = eap->line1; | |
772 RangeEnd = eap->line2; | |
773 } | |
774 else | |
775 { | |
776 RangeStart = (PyInt) curwin->w_cursor.lnum; | |
777 RangeEnd = RangeStart; | |
778 } | |
7 | 779 Python_Release_Vim(); /* leave vim */ |
780 | |
781 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
782 /* Python only works properly when the LC_NUMERIC locale is "C". */ | |
783 saved_locale = setlocale(LC_NUMERIC, NULL); | |
784 if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) | |
785 saved_locale = NULL; | |
786 else | |
787 { | |
788 /* Need to make a copy, value may change when setting new locale. */ | |
789 saved_locale = (char *)vim_strsave((char_u *)saved_locale); | |
790 (void)setlocale(LC_NUMERIC, "C"); | |
791 } | |
792 #endif | |
793 | |
794 Python_RestoreThread(); /* enter python */ | |
795 | |
3618 | 796 if (rettv == NULL) |
797 PyRun_SimpleString((char *)(cmd)); | |
798 else | |
799 { | |
800 PyObject *r; | |
801 | |
802 r = PyRun_String((char *)(cmd), Py_eval_input, globals, globals); | |
803 if (r == NULL) | |
804 EMSG(_("E858: Eval did not return a valid python object")); | |
805 else | |
806 { | |
807 if (ConvertFromPyObject(r, rettv) == -1) | |
808 EMSG(_("E859: Failed to convert returned python object to vim value")); | |
809 Py_DECREF(r); | |
810 } | |
811 PyErr_Clear(); | |
812 } | |
7 | 813 |
814 Python_SaveThread(); /* leave python */ | |
815 | |
816 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
817 if (saved_locale != NULL) | |
818 { | |
819 (void)setlocale(LC_NUMERIC, saved_locale); | |
820 vim_free(saved_locale); | |
821 } | |
822 #endif | |
823 | |
824 Python_Lock_Vim(); /* enter vim */ | |
825 PythonIO_Flush(); | |
826 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
827 SetPort(oldPort); | |
828 #endif | |
829 | |
830 theend: | |
831 #ifndef PY_CAN_RECURSE | |
832 --recursive; | |
833 #endif | |
3618 | 834 return; |
7 | 835 } |
836 | |
837 /* | |
838 * ":python" | |
839 */ | |
840 void | |
841 ex_python(exarg_T *eap) | |
842 { | |
843 char_u *script; | |
844 | |
845 script = script_get(eap, eap->arg); | |
846 if (!eap->skip) | |
847 { | |
848 if (script == NULL) | |
3618 | 849 DoPythonCommand(eap, (char *)eap->arg, NULL); |
7 | 850 else |
3618 | 851 DoPythonCommand(eap, (char *)script, NULL); |
7 | 852 } |
853 vim_free(script); | |
854 } | |
855 | |
856 #define BUFFER_SIZE 1024 | |
857 | |
858 /* | |
859 * ":pyfile" | |
860 */ | |
861 void | |
862 ex_pyfile(exarg_T *eap) | |
863 { | |
864 static char buffer[BUFFER_SIZE]; | |
865 const char *file = (char *)eap->arg; | |
866 char *p; | |
867 | |
868 /* Have to do it like this. PyRun_SimpleFile requires you to pass a | |
869 * stdio file pointer, but Vim and the Python DLL are compiled with | |
870 * different options under Windows, meaning that stdio pointers aren't | |
871 * compatible between the two. Yuk. | |
872 * | |
873 * Put the string "execfile('file')" into buffer. But, we need to | |
874 * escape any backslashes or single quotes in the file name, so that | |
875 * Python won't mangle the file name. | |
876 */ | |
877 strcpy(buffer, "execfile('"); | |
878 p = buffer + 10; /* size of "execfile('" */ | |
879 | |
880 while (*file && p < buffer + (BUFFER_SIZE - 3)) | |
881 { | |
882 if (*file == '\\' || *file == '\'') | |
883 *p++ = '\\'; | |
884 *p++ = *file++; | |
885 } | |
886 | |
887 /* If we didn't finish the file name, we hit a buffer overflow */ | |
888 if (*file != '\0') | |
889 return; | |
890 | |
891 /* Put in the terminating "')" and a null */ | |
892 *p++ = '\''; | |
893 *p++ = ')'; | |
894 *p++ = '\0'; | |
895 | |
896 /* Execute the file */ | |
3618 | 897 DoPythonCommand(eap, buffer, NULL); |
7 | 898 } |
899 | |
900 /****************************************************** | |
901 * 2. Python output stream: writes output via [e]msg(). | |
902 */ | |
903 | |
904 /* Implementation functions | |
905 */ | |
906 | |
907 static PyObject * | |
908 OutputGetattr(PyObject *self, char *name) | |
909 { | |
910 if (strcmp(name, "softspace") == 0) | |
911 return PyInt_FromLong(((OutputObject *)(self))->softspace); | |
912 | |
913 return Py_FindMethod(OutputMethods, self, name); | |
914 } | |
915 | |
916 static int | |
917 OutputSetattr(PyObject *self, char *name, PyObject *val) | |
918 { | |
3618 | 919 if (val == NULL) |
920 { | |
7 | 921 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes")); |
922 return -1; | |
923 } | |
924 | |
925 if (strcmp(name, "softspace") == 0) | |
926 { | |
3618 | 927 if (!PyInt_Check(val)) |
928 { | |
7 | 929 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer")); |
930 return -1; | |
931 } | |
932 | |
933 ((OutputObject *)(self))->softspace = PyInt_AsLong(val); | |
934 return 0; | |
935 } | |
936 | |
937 PyErr_SetString(PyExc_AttributeError, _("invalid attribute")); | |
938 return -1; | |
939 } | |
940 | |
941 /***************/ | |
942 | |
943 static int | |
944 PythonIO_Init(void) | |
945 { | |
946 /* Fixups... */ | |
2735 | 947 PyType_Ready(&OutputType); |
7 | 948 |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
949 return PythonIO_Init_io(); |
7 | 950 } |
951 | |
952 /****************************************************** | |
953 * 3. Implementation of the Vim module for Python | |
954 */ | |
955 | |
3618 | 956 static PyObject *ConvertToPyObject(typval_T *); |
957 static int ConvertFromPyObject(PyObject *, typval_T *); | |
958 | |
7 | 959 /* Window type - Implementation functions |
960 * -------------------------------------- | |
961 */ | |
962 | |
963 #define WindowType_Check(obj) ((obj)->ob_type == &WindowType) | |
964 | |
965 static void WindowDestructor(PyObject *); | |
966 static PyObject *WindowGetattr(PyObject *, char *); | |
967 | |
968 /* Buffer type - Implementation functions | |
969 * -------------------------------------- | |
970 */ | |
971 | |
972 #define BufferType_Check(obj) ((obj)->ob_type == &BufferType) | |
973 | |
974 static void BufferDestructor(PyObject *); | |
975 static PyObject *BufferGetattr(PyObject *, char *); | |
976 static PyObject *BufferRepr(PyObject *); | |
977 | |
1594 | 978 static PyInt BufferLength(PyObject *); |
979 static PyObject *BufferItem(PyObject *, PyInt); | |
980 static PyObject *BufferSlice(PyObject *, PyInt, PyInt); | |
981 static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); | |
982 static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); | |
7 | 983 |
984 /* Line range type - Implementation functions | |
985 * -------------------------------------- | |
986 */ | |
987 | |
988 #define RangeType_Check(obj) ((obj)->ob_type == &RangeType) | |
989 | |
1594 | 990 static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); |
991 static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); | |
7 | 992 |
993 /* Current objects type - Implementation functions | |
994 * ----------------------------------------------- | |
995 */ | |
996 | |
997 static PyObject *CurrentGetattr(PyObject *, char *); | |
998 static int CurrentSetattr(PyObject *, char *, PyObject *); | |
999 | |
1000 static PySequenceMethods BufferAsSeq = { | |
1594 | 1001 (PyInquiry) BufferLength, /* sq_length, len(x) */ |
7 | 1002 (binaryfunc) 0, /* BufferConcat, */ /* sq_concat, x+y */ |
1594 | 1003 (PyIntArgFunc) 0, /* BufferRepeat, */ /* sq_repeat, x*n */ |
1004 (PyIntArgFunc) BufferItem, /* sq_item, x[i] */ | |
1005 (PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */ | |
1006 (PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */ | |
1007 (PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */ | |
7 | 1008 }; |
1009 | |
1010 static PyTypeObject BufferType = { | |
1011 PyObject_HEAD_INIT(0) | |
1012 0, | |
1013 "buffer", | |
1014 sizeof(BufferObject), | |
1015 0, | |
1016 | |
1017 (destructor) BufferDestructor, /* tp_dealloc, refcount==0 */ | |
1018 (printfunc) 0, /* tp_print, print x */ | |
1019 (getattrfunc) BufferGetattr, /* tp_getattr, x.attr */ | |
1020 (setattrfunc) 0, /* tp_setattr, x.attr=v */ | |
1021 (cmpfunc) 0, /* tp_compare, x>y */ | |
1022 (reprfunc) BufferRepr, /* tp_repr, `x`, print x */ | |
1023 | |
1024 0, /* as number */ | |
1025 &BufferAsSeq, /* as sequence */ | |
1026 0, /* as mapping */ | |
1027 | |
1028 (hashfunc) 0, /* tp_hash, dict(x) */ | |
1029 (ternaryfunc) 0, /* tp_call, x() */ | |
1030 (reprfunc) 0, /* tp_str, str(x) */ | |
1031 }; | |
1032 | |
1033 /* Buffer object - Implementation | |
1034 */ | |
1035 | |
1036 static PyObject * | |
1037 BufferNew(buf_T *buf) | |
1038 { | |
1039 /* We need to handle deletion of buffers underneath us. | |
502 | 1040 * If we add a "b_python_ref" field to the buf_T structure, |
7 | 1041 * then we can get at it in buf_freeall() in vim. We then |
1042 * need to create only ONE Python object per buffer - if | |
1043 * we try to create a second, just INCREF the existing one | |
1044 * and return it. The (single) Python object referring to | |
502 | 1045 * the buffer is stored in "b_python_ref". |
7 | 1046 * Question: what to do on a buf_freeall(). We'll probably |
1047 * have to either delete the Python object (DECREF it to | |
1048 * zero - a bad idea, as it leaves dangling refs!) or | |
1049 * set the buf_T * value to an invalid value (-1?), which | |
1050 * means we need checks in all access functions... Bah. | |
1051 */ | |
1052 | |
1053 BufferObject *self; | |
1054 | |
502 | 1055 if (buf->b_python_ref != NULL) |
7 | 1056 { |
502 | 1057 self = buf->b_python_ref; |
7 | 1058 Py_INCREF(self); |
1059 } | |
1060 else | |
1061 { | |
1062 self = PyObject_NEW(BufferObject, &BufferType); | |
1063 if (self == NULL) | |
1064 return NULL; | |
1065 self->buf = buf; | |
502 | 1066 buf->b_python_ref = self; |
7 | 1067 } |
1068 | |
1069 return (PyObject *)(self); | |
1070 } | |
1071 | |
1072 static void | |
1073 BufferDestructor(PyObject *self) | |
1074 { | |
1075 BufferObject *this = (BufferObject *)(self); | |
1076 | |
1077 if (this->buf && this->buf != INVALID_BUFFER_VALUE) | |
502 | 1078 this->buf->b_python_ref = NULL; |
7 | 1079 |
986 | 1080 Py_DECREF(self); |
7 | 1081 } |
1082 | |
1083 static PyObject * | |
1084 BufferGetattr(PyObject *self, char *name) | |
1085 { | |
1086 BufferObject *this = (BufferObject *)(self); | |
1087 | |
1088 if (CheckBuffer(this)) | |
1089 return NULL; | |
1090 | |
1091 if (strcmp(name, "name") == 0) | |
1607 | 1092 return Py_BuildValue("s", this->buf->b_ffname); |
7 | 1093 else if (strcmp(name, "number") == 0) |
1607 | 1094 return Py_BuildValue(Py_ssize_t_fmt, this->buf->b_fnum); |
7 | 1095 else if (strcmp(name,"__members__") == 0) |
1096 return Py_BuildValue("[ss]", "name", "number"); | |
1097 else | |
1098 return Py_FindMethod(BufferMethods, self, name); | |
1099 } | |
1100 | |
1101 static PyObject * | |
1102 BufferRepr(PyObject *self) | |
1103 { | |
274 | 1104 static char repr[100]; |
7 | 1105 BufferObject *this = (BufferObject *)(self); |
1106 | |
1107 if (this->buf == INVALID_BUFFER_VALUE) | |
1108 { | |
1607 | 1109 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self)); |
7 | 1110 return PyString_FromString(repr); |
1111 } | |
1112 else | |
1113 { | |
1114 char *name = (char *)this->buf->b_fname; | |
1607 | 1115 PyInt len; |
7 | 1116 |
1117 if (name == NULL) | |
1118 name = ""; | |
1119 len = strlen(name); | |
1120 | |
1121 if (len > 35) | |
1122 name = name + (35 - len); | |
1123 | |
274 | 1124 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name); |
7 | 1125 |
1126 return PyString_FromString(repr); | |
1127 } | |
1128 } | |
1129 | |
1130 /******************/ | |
1131 | |
1594 | 1132 static PyInt |
7 | 1133 BufferLength(PyObject *self) |
1134 { | |
1135 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */ | |
1136 if (CheckBuffer((BufferObject *)(self))) | |
1137 return -1; /* ??? */ | |
1138 | |
1139 return (((BufferObject *)(self))->buf->b_ml.ml_line_count); | |
1140 } | |
1141 | |
1142 static PyObject * | |
1594 | 1143 BufferItem(PyObject *self, PyInt n) |
7 | 1144 { |
1145 return RBItem((BufferObject *)(self), n, 1, | |
1146 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count); | |
1147 } | |
1148 | |
1149 static PyObject * | |
1594 | 1150 BufferSlice(PyObject *self, PyInt lo, PyInt hi) |
7 | 1151 { |
1152 return RBSlice((BufferObject *)(self), lo, hi, 1, | |
1153 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count); | |
1154 } | |
1155 | |
1594 | 1156 static PyInt |
1157 BufferAssItem(PyObject *self, PyInt n, PyObject *val) | |
7 | 1158 { |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1159 return RBAsItem((BufferObject *)(self), n, val, 1, |
1607 | 1160 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, |
7 | 1161 NULL); |
1162 } | |
1163 | |
1594 | 1164 static PyInt |
1165 BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
7 | 1166 { |
2894 | 1167 return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, |
1607 | 1168 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, |
7 | 1169 NULL); |
1170 } | |
1171 | |
1172 static PySequenceMethods RangeAsSeq = { | |
1594 | 1173 (PyInquiry) RangeLength, /* sq_length, len(x) */ |
7 | 1174 (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */ |
1594 | 1175 (PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */ |
1176 (PyIntArgFunc) RangeItem, /* sq_item, x[i] */ | |
1177 (PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */ | |
1178 (PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */ | |
1179 (PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */ | |
7 | 1180 }; |
1181 | |
1182 /* Line range object - Implementation | |
1183 */ | |
1184 | |
1185 static void | |
1186 RangeDestructor(PyObject *self) | |
1187 { | |
1188 Py_DECREF(((RangeObject *)(self))->buf); | |
986 | 1189 Py_DECREF(self); |
7 | 1190 } |
1191 | |
1192 static PyObject * | |
1193 RangeGetattr(PyObject *self, char *name) | |
1194 { | |
1195 if (strcmp(name, "start") == 0) | |
1607 | 1196 return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->start - 1); |
7 | 1197 else if (strcmp(name, "end") == 0) |
1607 | 1198 return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->end - 1); |
7 | 1199 else |
1200 return Py_FindMethod(RangeMethods, self, name); | |
1201 } | |
1202 | |
1203 /****************/ | |
1204 | |
1594 | 1205 static PyInt |
1206 RangeAssItem(PyObject *self, PyInt n, PyObject *val) | |
7 | 1207 { |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1208 return RBAsItem(((RangeObject *)(self))->buf, n, val, |
7 | 1209 ((RangeObject *)(self))->start, |
1210 ((RangeObject *)(self))->end, | |
1211 &((RangeObject *)(self))->end); | |
1212 } | |
1213 | |
1594 | 1214 static PyInt |
1215 RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
7 | 1216 { |
2894 | 1217 return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val, |
7 | 1218 ((RangeObject *)(self))->start, |
1219 ((RangeObject *)(self))->end, | |
1220 &((RangeObject *)(self))->end); | |
1221 } | |
1222 | |
1223 /* Buffer list object - Definitions | |
1224 */ | |
1225 | |
1226 typedef struct | |
1227 { | |
1228 PyObject_HEAD | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1229 } BufListObject; |
7 | 1230 |
1231 static PySequenceMethods BufListAsSeq = { | |
1594 | 1232 (PyInquiry) BufListLength, /* sq_length, len(x) */ |
7 | 1233 (binaryfunc) 0, /* sq_concat, x+y */ |
1594 | 1234 (PyIntArgFunc) 0, /* sq_repeat, x*n */ |
1235 (PyIntArgFunc) BufListItem, /* sq_item, x[i] */ | |
1236 (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ | |
1237 (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ | |
1238 (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ | |
7 | 1239 }; |
1240 | |
1241 static PyTypeObject BufListType = { | |
1242 PyObject_HEAD_INIT(0) | |
1243 0, | |
1244 "buffer list", | |
1245 sizeof(BufListObject), | |
1246 0, | |
1247 | |
1248 (destructor) 0, /* tp_dealloc, refcount==0 */ | |
1249 (printfunc) 0, /* tp_print, print x */ | |
1250 (getattrfunc) 0, /* tp_getattr, x.attr */ | |
1251 (setattrfunc) 0, /* tp_setattr, x.attr=v */ | |
1252 (cmpfunc) 0, /* tp_compare, x>y */ | |
1253 (reprfunc) 0, /* tp_repr, `x`, print x */ | |
1254 | |
1255 0, /* as number */ | |
1256 &BufListAsSeq, /* as sequence */ | |
1257 0, /* as mapping */ | |
1258 | |
1259 (hashfunc) 0, /* tp_hash, dict(x) */ | |
1260 (ternaryfunc) 0, /* tp_call, x() */ | |
1261 (reprfunc) 0, /* tp_str, str(x) */ | |
1262 }; | |
1263 | |
1264 /* Window object - Definitions | |
1265 */ | |
1266 | |
1267 static struct PyMethodDef WindowMethods[] = { | |
1268 /* name, function, calling, documentation */ | |
1269 { NULL, NULL, 0, NULL } | |
1270 }; | |
1271 | |
1272 static PyTypeObject WindowType = { | |
1273 PyObject_HEAD_INIT(0) | |
1274 0, | |
1275 "window", | |
1276 sizeof(WindowObject), | |
1277 0, | |
1278 | |
1279 (destructor) WindowDestructor, /* tp_dealloc, refcount==0 */ | |
1280 (printfunc) 0, /* tp_print, print x */ | |
1281 (getattrfunc) WindowGetattr, /* tp_getattr, x.attr */ | |
1282 (setattrfunc) WindowSetattr, /* tp_setattr, x.attr=v */ | |
1283 (cmpfunc) 0, /* tp_compare, x>y */ | |
1284 (reprfunc) WindowRepr, /* tp_repr, `x`, print x */ | |
1285 | |
1286 0, /* as number */ | |
1287 0, /* as sequence */ | |
1288 0, /* as mapping */ | |
1289 | |
1290 (hashfunc) 0, /* tp_hash, dict(x) */ | |
1291 (ternaryfunc) 0, /* tp_call, x() */ | |
1292 (reprfunc) 0, /* tp_str, str(x) */ | |
1293 }; | |
1294 | |
1295 /* Window object - Implementation | |
1296 */ | |
1297 | |
1298 static PyObject * | |
1299 WindowNew(win_T *win) | |
1300 { | |
1301 /* We need to handle deletion of windows underneath us. | |
502 | 1302 * If we add a "w_python_ref" field to the win_T structure, |
7 | 1303 * then we can get at it in win_free() in vim. We then |
1304 * need to create only ONE Python object per window - if | |
1305 * we try to create a second, just INCREF the existing one | |
1306 * and return it. The (single) Python object referring to | |
502 | 1307 * the window is stored in "w_python_ref". |
7 | 1308 * On a win_free() we set the Python object's win_T* field |
1309 * to an invalid value. We trap all uses of a window | |
1310 * object, and reject them if the win_T* field is invalid. | |
1311 */ | |
1312 | |
1313 WindowObject *self; | |
1314 | |
502 | 1315 if (win->w_python_ref) |
7 | 1316 { |
502 | 1317 self = win->w_python_ref; |
7 | 1318 Py_INCREF(self); |
1319 } | |
1320 else | |
1321 { | |
1322 self = PyObject_NEW(WindowObject, &WindowType); | |
1323 if (self == NULL) | |
1324 return NULL; | |
1325 self->win = win; | |
502 | 1326 win->w_python_ref = self; |
7 | 1327 } |
1328 | |
1329 return (PyObject *)(self); | |
1330 } | |
1331 | |
1332 static void | |
1333 WindowDestructor(PyObject *self) | |
1334 { | |
1335 WindowObject *this = (WindowObject *)(self); | |
1336 | |
1337 if (this->win && this->win != INVALID_WINDOW_VALUE) | |
502 | 1338 this->win->w_python_ref = NULL; |
7 | 1339 |
986 | 1340 Py_DECREF(self); |
7 | 1341 } |
1342 | |
1343 static PyObject * | |
1344 WindowGetattr(PyObject *self, char *name) | |
1345 { | |
1346 WindowObject *this = (WindowObject *)(self); | |
1347 | |
1348 if (CheckWindow(this)) | |
1349 return NULL; | |
1350 | |
1351 if (strcmp(name, "buffer") == 0) | |
1352 return (PyObject *)BufferNew(this->win->w_buffer); | |
1353 else if (strcmp(name, "cursor") == 0) | |
1354 { | |
1355 pos_T *pos = &this->win->w_cursor; | |
1356 | |
1357 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col)); | |
1358 } | |
1359 else if (strcmp(name, "height") == 0) | |
1360 return Py_BuildValue("l", (long)(this->win->w_height)); | |
1361 #ifdef FEAT_VERTSPLIT | |
1362 else if (strcmp(name, "width") == 0) | |
1363 return Py_BuildValue("l", (long)(W_WIDTH(this->win))); | |
1364 #endif | |
1365 else if (strcmp(name,"__members__") == 0) | |
1366 return Py_BuildValue("[sss]", "buffer", "cursor", "height"); | |
1367 else | |
1368 return Py_FindMethod(WindowMethods, self, name); | |
1369 } | |
1370 | |
1371 /* Window list object - Definitions | |
1372 */ | |
1373 | |
1374 typedef struct | |
1375 { | |
1376 PyObject_HEAD | |
1377 } | |
1378 WinListObject; | |
1379 | |
1380 static PySequenceMethods WinListAsSeq = { | |
1594 | 1381 (PyInquiry) WinListLength, /* sq_length, len(x) */ |
7 | 1382 (binaryfunc) 0, /* sq_concat, x+y */ |
1594 | 1383 (PyIntArgFunc) 0, /* sq_repeat, x*n */ |
1384 (PyIntArgFunc) WinListItem, /* sq_item, x[i] */ | |
1385 (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ | |
1386 (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ | |
1387 (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ | |
7 | 1388 }; |
1389 | |
1390 static PyTypeObject WinListType = { | |
1391 PyObject_HEAD_INIT(0) | |
1392 0, | |
1393 "window list", | |
1394 sizeof(WinListObject), | |
1395 0, | |
1396 | |
1397 (destructor) 0, /* tp_dealloc, refcount==0 */ | |
1398 (printfunc) 0, /* tp_print, print x */ | |
1399 (getattrfunc) 0, /* tp_getattr, x.attr */ | |
1400 (setattrfunc) 0, /* tp_setattr, x.attr=v */ | |
1401 (cmpfunc) 0, /* tp_compare, x>y */ | |
1402 (reprfunc) 0, /* tp_repr, `x`, print x */ | |
1403 | |
1404 0, /* as number */ | |
1405 &WinListAsSeq, /* as sequence */ | |
1406 0, /* as mapping */ | |
1407 | |
1408 (hashfunc) 0, /* tp_hash, dict(x) */ | |
1409 (ternaryfunc) 0, /* tp_call, x() */ | |
1410 (reprfunc) 0, /* tp_str, str(x) */ | |
1411 }; | |
1412 | |
1413 /* Current items object - Definitions | |
1414 */ | |
1415 | |
1416 typedef struct | |
1417 { | |
1418 PyObject_HEAD | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1419 } CurrentObject; |
7 | 1420 |
1421 static PyTypeObject CurrentType = { | |
1422 PyObject_HEAD_INIT(0) | |
1423 0, | |
1424 "current data", | |
1425 sizeof(CurrentObject), | |
1426 0, | |
1427 | |
1428 (destructor) 0, /* tp_dealloc, refcount==0 */ | |
1429 (printfunc) 0, /* tp_print, print x */ | |
1430 (getattrfunc) CurrentGetattr, /* tp_getattr, x.attr */ | |
1431 (setattrfunc) CurrentSetattr, /* tp_setattr, x.attr=v */ | |
1432 (cmpfunc) 0, /* tp_compare, x>y */ | |
1433 (reprfunc) 0, /* tp_repr, `x`, print x */ | |
1434 | |
1435 0, /* as number */ | |
1436 0, /* as sequence */ | |
1437 0, /* as mapping */ | |
1438 | |
1439 (hashfunc) 0, /* tp_hash, dict(x) */ | |
1440 (ternaryfunc) 0, /* tp_call, x() */ | |
1441 (reprfunc) 0, /* tp_str, str(x) */ | |
1442 }; | |
1443 | |
1444 /* Current items object - Implementation | |
1445 */ | |
1446 static PyObject * | |
1887 | 1447 CurrentGetattr(PyObject *self UNUSED, char *name) |
7 | 1448 { |
1449 if (strcmp(name, "buffer") == 0) | |
1450 return (PyObject *)BufferNew(curbuf); | |
1451 else if (strcmp(name, "window") == 0) | |
1452 return (PyObject *)WindowNew(curwin); | |
1453 else if (strcmp(name, "line") == 0) | |
1607 | 1454 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum); |
7 | 1455 else if (strcmp(name, "range") == 0) |
1456 return RangeNew(curbuf, RangeStart, RangeEnd); | |
1457 else if (strcmp(name,"__members__") == 0) | |
1458 return Py_BuildValue("[ssss]", "buffer", "window", "line", "range"); | |
1459 else | |
1460 { | |
1461 PyErr_SetString(PyExc_AttributeError, name); | |
1462 return NULL; | |
1463 } | |
1464 } | |
1465 | |
1466 static int | |
1887 | 1467 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *value) |
7 | 1468 { |
1469 if (strcmp(name, "line") == 0) | |
1470 { | |
1607 | 1471 if (SetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum, value, NULL) == FAIL) |
7 | 1472 return -1; |
1473 | |
1474 return 0; | |
1475 } | |
1476 else | |
1477 { | |
1478 PyErr_SetString(PyExc_AttributeError, name); | |
1479 return -1; | |
1480 } | |
1481 } | |
1482 | |
1483 /* External interface | |
1484 */ | |
1485 | |
1486 void | |
1487 python_buffer_free(buf_T *buf) | |
1488 { | |
502 | 1489 if (buf->b_python_ref != NULL) |
7 | 1490 { |
502 | 1491 BufferObject *bp = buf->b_python_ref; |
7 | 1492 bp->buf = INVALID_BUFFER_VALUE; |
502 | 1493 buf->b_python_ref = NULL; |
7 | 1494 } |
1495 } | |
1496 | |
1497 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
1498 void | |
1499 python_window_free(win_T *win) | |
1500 { | |
502 | 1501 if (win->w_python_ref != NULL) |
7 | 1502 { |
502 | 1503 WindowObject *wp = win->w_python_ref; |
7 | 1504 wp->win = INVALID_WINDOW_VALUE; |
502 | 1505 win->w_python_ref = NULL; |
7 | 1506 } |
1507 } | |
1508 #endif | |
1509 | |
1510 static BufListObject TheBufferList = | |
1511 { | |
1512 PyObject_HEAD_INIT(&BufListType) | |
1513 }; | |
1514 | |
1515 static WinListObject TheWindowList = | |
1516 { | |
1517 PyObject_HEAD_INIT(&WinListType) | |
1518 }; | |
1519 | |
1520 static CurrentObject TheCurrent = | |
1521 { | |
1522 PyObject_HEAD_INIT(&CurrentType) | |
1523 }; | |
1524 | |
1525 static int | |
1526 PythonMod_Init(void) | |
1527 { | |
1528 PyObject *mod; | |
1529 PyObject *dict; | |
1748 | 1530 /* The special value is removed from sys.path in Python_Init(). */ |
1531 static char *(argv[2]) = {"/must>not&exist/foo", NULL}; | |
7 | 1532 |
1533 /* Fixups... */ | |
2735 | 1534 PyType_Ready(&BufferType); |
1535 PyType_Ready(&RangeType); | |
1536 PyType_Ready(&WindowType); | |
1537 PyType_Ready(&BufListType); | |
1538 PyType_Ready(&WinListType); | |
1539 PyType_Ready(&CurrentType); | |
7 | 1540 |
1541 /* Set sys.argv[] to avoid a crash in warn(). */ | |
1542 PySys_SetArgv(1, argv); | |
1543 | |
1607 | 1544 mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL, PYTHON_API_VERSION); |
7 | 1545 dict = PyModule_GetDict(mod); |
1546 | |
1547 VimError = Py_BuildValue("s", "vim.error"); | |
1548 | |
1549 PyDict_SetItemString(dict, "error", VimError); | |
135 | 1550 PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferList); |
1551 PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent); | |
1552 PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList); | |
7 | 1553 |
1554 if (PyErr_Occurred()) | |
1555 return -1; | |
1556 | |
1557 return 0; | |
1558 } | |
1559 | |
1560 /************************************************************************* | |
1561 * 4. Utility functions for handling the interface between Vim and Python. | |
1562 */ | |
1563 | |
1564 /* Convert a Vim line into a Python string. | |
1565 * All internal newlines are replaced by null characters. | |
1566 * | |
1567 * On errors, the Python exception data is set, and NULL is returned. | |
1568 */ | |
1569 static PyObject * | |
1570 LineToString(const char *str) | |
1571 { | |
1572 PyObject *result; | |
1594 | 1573 PyInt len = strlen(str); |
7 | 1574 char *p; |
1575 | |
1576 /* Allocate an Python string object, with uninitialised contents. We | |
1577 * must do it this way, so that we can modify the string in place | |
1578 * later. See the Python source, Objects/stringobject.c for details. | |
1579 */ | |
1580 result = PyString_FromStringAndSize(NULL, len); | |
1581 if (result == NULL) | |
1582 return NULL; | |
1583 | |
1584 p = PyString_AsString(result); | |
1585 | |
1586 while (*str) | |
1587 { | |
1588 if (*str == '\n') | |
1589 *p = '\0'; | |
1590 else | |
1591 *p = *str; | |
1592 | |
1593 ++p; | |
1594 ++str; | |
1595 } | |
1596 | |
1597 return result; | |
1598 } | |
1599 | |
3618 | 1600 static void DictionaryDestructor(PyObject *); |
1601 static PyObject *DictionaryGetattr(PyObject *, char*); | |
1602 | |
1603 static PyMappingMethods DictionaryAsMapping = { | |
1604 (PyInquiry) DictionaryLength, | |
1605 (binaryfunc) DictionaryItem, | |
1606 (objobjargproc) DictionaryAssItem, | |
1607 }; | |
1608 | |
1609 static PyTypeObject DictionaryType = { | |
1610 PyObject_HEAD_INIT(0) | |
1611 0, | |
1612 "vimdictionary", | |
1613 sizeof(DictionaryObject), | |
1614 0, | |
1615 | |
1616 (destructor) DictionaryDestructor, | |
1617 (printfunc) 0, | |
1618 (getattrfunc) DictionaryGetattr, | |
1619 (setattrfunc) 0, | |
1620 (cmpfunc) 0, | |
1621 (reprfunc) 0, | |
1622 | |
1623 0, /* as number */ | |
1624 0, /* as sequence */ | |
1625 &DictionaryAsMapping, /* as mapping */ | |
1626 | |
1627 (hashfunc) 0, | |
1628 (ternaryfunc) 0, | |
1629 (reprfunc) 0, | |
1630 }; | |
1631 | |
1632 static void | |
1633 DictionaryDestructor(PyObject *self) | |
1634 { | |
1635 DictionaryObject *this = ((DictionaryObject *) (self)); | |
1636 | |
1637 pyll_remove(&this->ref, &lastdict); | |
1638 dict_unref(this->dict); | |
1639 | |
1640 Py_DECREF(self); | |
1641 } | |
1642 | |
1643 static PyObject * | |
1644 DictionaryGetattr(PyObject *self, char *name) | |
1645 { | |
1646 return Py_FindMethod(DictionaryMethods, self, name); | |
1647 } | |
1648 | |
1649 static void ListDestructor(PyObject *); | |
1650 static PyObject *ListGetattr(PyObject *, char *); | |
1651 | |
1652 static PySequenceMethods ListAsSeq = { | |
1653 (PyInquiry) ListLength, | |
1654 (binaryfunc) 0, | |
1655 (PyIntArgFunc) 0, | |
1656 (PyIntArgFunc) ListItem, | |
1657 (PyIntIntArgFunc) ListSlice, | |
1658 (PyIntObjArgProc) ListAssItem, | |
1659 (PyIntIntObjArgProc) ListAssSlice, | |
1660 (objobjproc) 0, | |
1661 #if PY_MAJOR_VERSION >= 2 | |
1662 (binaryfunc) ListConcatInPlace, | |
1663 0, | |
1664 #endif | |
1665 }; | |
1666 | |
1667 static PyTypeObject ListType = { | |
1668 PyObject_HEAD_INIT(0) | |
1669 0, | |
1670 "vimlist", | |
1671 sizeof(ListObject), | |
1672 0, | |
1673 | |
1674 (destructor) ListDestructor, | |
1675 (printfunc) 0, | |
1676 (getattrfunc) ListGetattr, | |
1677 (setattrfunc) 0, | |
1678 (cmpfunc) 0, | |
1679 (reprfunc) 0, | |
1680 | |
1681 0, /* as number */ | |
1682 &ListAsSeq, /* as sequence */ | |
1683 0, /* as mapping */ | |
1684 | |
1685 (hashfunc) 0, | |
1686 (ternaryfunc) 0, | |
1687 (reprfunc) 0, | |
1688 }; | |
1689 | |
1690 static void | |
1691 ListDestructor(PyObject *self) | |
1692 { | |
1693 ListObject *this = ((ListObject *) (self)); | |
1694 | |
1695 pyll_remove(&this->ref, &lastlist); | |
1696 list_unref(this->list); | |
1697 | |
1698 Py_DECREF(self); | |
1699 } | |
1700 | |
1701 static PyObject * | |
1702 ListGetattr(PyObject *self, char *name) | |
1703 { | |
1704 return Py_FindMethod(ListMethods, self, name); | |
1705 } | |
1706 | |
1707 static void FunctionDestructor(PyObject *); | |
1708 static PyObject *FunctionGetattr(PyObject *, char *); | |
1709 | |
1710 static PyTypeObject FunctionType = { | |
1711 PyObject_HEAD_INIT(0) | |
1712 0, | |
1713 "vimfunction", | |
1714 sizeof(FunctionObject), | |
1715 0, | |
1716 | |
1717 (destructor) FunctionDestructor, | |
1718 (printfunc) 0, | |
1719 (getattrfunc) FunctionGetattr, | |
1720 (setattrfunc) 0, | |
1721 (cmpfunc) 0, | |
1722 (reprfunc) 0, | |
1723 | |
1724 0, /* as number */ | |
1725 0, /* as sequence */ | |
1726 0, /* as mapping */ | |
1727 | |
1728 (hashfunc) 0, | |
1729 (ternaryfunc) FunctionCall, | |
1730 (reprfunc) 0, | |
1731 }; | |
1732 | |
1733 static void | |
1734 FunctionDestructor(PyObject *self) | |
1735 { | |
1736 FunctionObject *this = (FunctionObject *) (self); | |
1737 | |
1738 func_unref(this->name); | |
1739 PyMem_Del(this->name); | |
1740 | |
1741 Py_DECREF(self); | |
1742 } | |
1743 | |
1744 static PyObject * | |
1745 FunctionGetattr(PyObject *self, char *name) | |
1746 { | |
1747 FunctionObject *this = (FunctionObject *)(self); | |
1748 | |
1749 if (strcmp(name, "name") == 0) | |
1750 return PyString_FromString((char *)(this->name)); | |
1751 else | |
1752 return Py_FindMethod(FunctionMethods, self, name); | |
1753 } | |
1754 | |
1755 void | |
1756 do_pyeval (char_u *str, typval_T *rettv) | |
1757 { | |
1758 DoPythonCommand(NULL, (char *) str, rettv); | |
1759 switch(rettv->v_type) | |
1760 { | |
1761 case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; | |
1762 case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; | |
1763 case VAR_FUNC: func_ref(rettv->vval.v_string); break; | |
1764 } | |
1765 } | |
7 | 1766 |
1767 /* Don't generate a prototype for the next function, it generates an error on | |
1768 * newer Python versions. */ | |
1769 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO) | |
1770 | |
1771 char * | |
1772 Py_GetProgramName(void) | |
1773 { | |
1774 return "vim"; | |
1775 } | |
1776 #endif /* Python 1.4 */ | |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1777 |
3618 | 1778 void |
1779 set_ref_in_python (int copyID) | |
1780 { | |
1781 set_ref_in_py(copyID); | |
1782 } | |
1783 | |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1784 static void |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1785 init_structs(void) |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1786 { |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1787 vim_memset(&OutputType, 0, sizeof(OutputType)); |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1788 OutputType.tp_name = "message"; |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1789 OutputType.tp_basicsize = sizeof(OutputObject); |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1790 OutputType.tp_getattr = OutputGetattr; |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1791 OutputType.tp_setattr = OutputSetattr; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1792 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1793 vim_memset(&RangeType, 0, sizeof(RangeType)); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1794 RangeType.tp_name = "range"; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1795 RangeType.tp_basicsize = sizeof(RangeObject); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1796 RangeType.tp_dealloc = RangeDestructor; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1797 RangeType.tp_getattr = RangeGetattr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1798 RangeType.tp_repr = RangeRepr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1799 RangeType.tp_as_sequence = &RangeAsSeq; |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
2384
diff
changeset
|
1800 } |