Mercurial > vim
annotate src/if_python.c @ 11103:3335c3c75611 v8.0.0439
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
commit https://github.com/vim/vim/commit/69a92fb5aecdf2f9d5f6947790b18991b22d0e4c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 9 15:58:30 2017 +0100
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Problem: Using ":%argdel" while the argument list is already empty gives an
error. (Pavol Juhas)
Solution: Don't give an error. (closes #1546)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 09 Mar 2017 16:00:05 +0100 |
parents | 7598ce51bf2a |
children | 3b53bb2a0e39 |
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 | |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
24 /* uncomment this if used with the debug version of python. |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
25 * Checked on 2.7.4. */ |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
26 /* #define Py_DEBUG */ |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
27 /* Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
28 */ |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
29 /* uncomment this if used with the debug version of python, but without its |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
30 * allocator */ |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
31 /* #define Py_DEBUG_NO_PYMALLOC */ |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
32 |
7 | 33 /* Python.h defines _POSIX_THREADS itself (if needed) */ |
34 #ifdef _POSIX_THREADS | |
35 # undef _POSIX_THREADS | |
36 #endif | |
37 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2100
diff
changeset
|
38 #if defined(_WIN32) && defined(HAVE_FCNTL_H) |
7 | 39 # undef HAVE_FCNTL_H |
40 #endif | |
41 | |
42 #ifdef _DEBUG | |
43 # undef _DEBUG | |
44 #endif | |
45 | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
46 #ifdef HAVE_STRFTIME |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
47 # undef HAVE_STRFTIME |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
48 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
49 #ifdef HAVE_STRING_H |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
50 # undef HAVE_STRING_H |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
51 #endif |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
52 #ifdef HAVE_PUTENV |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
53 # undef HAVE_PUTENV |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
8041
diff
changeset
|
54 #endif |
7 | 55 #ifdef HAVE_STDARG_H |
56 # undef HAVE_STDARG_H /* Python's config.h defines it as well. */ | |
57 #endif | |
1991 | 58 #ifdef _POSIX_C_SOURCE |
59 # undef _POSIX_C_SOURCE /* pyconfig.h defines it as well. */ | |
60 #endif | |
61 #ifdef _XOPEN_SOURCE | |
62 # undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ | |
63 #endif | |
7 | 64 |
4823
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
65 #define PY_SSIZE_T_CLEAN |
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
66 |
7 | 67 #include <Python.h> |
4823
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
68 |
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
69 #if !defined(PY_VERSION_HEX) || PY_VERSION_HEX < 0x02050000 |
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
70 # undef PY_SSIZE_T_CLEAN |
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
71 #endif |
46077370bc60
updated for version 7.3.1158
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
72 |
7 | 73 #if defined(MACOS) && !defined(MACOS_X_UNIX) |
74 # include "macglue.h" | |
75 # include <CodeFragments.h> | |
76 #endif | |
77 #undef main /* Defined in python.h - aargh */ | |
78 #undef HAVE_FCNTL_H /* Clash with os_win32.h */ | |
79 | |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4855
diff
changeset
|
80 #define PyBytes_FromString PyString_FromString |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4855
diff
changeset
|
81 #define PyBytes_Check PyString_Check |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4855
diff
changeset
|
82 #define PyBytes_AsStringAndSize PyString_AsStringAndSize |
2894 | 83 |
7 | 84 #if !defined(FEAT_PYTHON) && defined(PROTO) |
85 /* Use this to be able to generate prototypes without python being used. */ | |
1607 | 86 # define PyObject Py_ssize_t |
87 # define PyThreadState Py_ssize_t | |
88 # define PyTypeObject Py_ssize_t | |
89 struct PyMethodDef { Py_ssize_t a; }; | |
90 # define PySequenceMethods Py_ssize_t | |
7 | 91 #endif |
92 | |
3638 | 93 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
94 # define PY_USE_CAPSULE | |
95 #endif | |
96 | |
1594 | 97 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 |
98 # define PyInt Py_ssize_t | |
99 # define PyInquiry lenfunc | |
100 # define PyIntArgFunc ssizeargfunc | |
101 # define PyIntIntArgFunc ssizessizeargfunc | |
102 # define PyIntObjArgProc ssizeobjargproc | |
103 # define PyIntIntObjArgProc ssizessizeobjargproc | |
1607 | 104 # define Py_ssize_t_fmt "n" |
1594 | 105 #else |
106 # define PyInt int | |
4319 | 107 # define lenfunc inquiry |
1594 | 108 # define PyInquiry inquiry |
109 # define PyIntArgFunc intargfunc | |
110 # define PyIntIntArgFunc intintargfunc | |
111 # define PyIntObjArgProc intobjargproc | |
112 # define PyIntIntObjArgProc intintobjargproc | |
1607 | 113 # define Py_ssize_t_fmt "i" |
1594 | 114 #endif |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
115 #define Py_bytes_fmt "s" |
1594 | 116 |
7 | 117 /* Parser flags */ |
118 #define single_input 256 | |
119 #define file_input 257 | |
120 #define eval_input 258 | |
121 | |
122 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 | |
123 /* Python 2.3: can invoke ":python" recursively. */ | |
124 # define PY_CAN_RECURSE | |
125 #endif | |
126 | |
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
|
127 # 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
|
128 # 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
|
129 # 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
|
130 # endif |
7 | 131 |
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 # 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
|
133 # 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
|
134 # 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
|
135 # define HINSTANCE void* |
2641 | 136 # 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
|
137 # 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
|
138 # 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
|
139 # 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
|
140 # 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
|
141 # 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
|
142 # 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
|
143 # else |
2612 | 144 # 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
|
145 # 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
|
146 # 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
|
147 # endif |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
148 |
1607 | 149 /* This makes if_python.c compile without warnings against Python 2.5 |
150 * 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
|
151 # undef PyRun_SimpleString |
3618 | 152 # 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
|
153 # 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
|
154 # 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
|
155 # 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
|
156 # 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
|
157 # undef Py_InitModule4_64 |
3618 | 158 # undef PyObject_CallMethod |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
159 # undef PyObject_CallFunction |
1607 | 160 |
7 | 161 /* |
162 * Wrapper defines | |
163 */ | |
164 # define PyArg_Parse dll_PyArg_Parse | |
165 # define PyArg_ParseTuple dll_PyArg_ParseTuple | |
2894 | 166 # define PyMem_Free dll_PyMem_Free |
3618 | 167 # define PyMem_Malloc dll_PyMem_Malloc |
7 | 168 # define PyDict_SetItemString dll_PyDict_SetItemString |
169 # define PyErr_BadArgument dll_PyErr_BadArgument | |
4409 | 170 # define PyErr_NewException dll_PyErr_NewException |
7 | 171 # define PyErr_Clear dll_PyErr_Clear |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
172 # define PyErr_Format dll_PyErr_Format |
4145 | 173 # define PyErr_PrintEx dll_PyErr_PrintEx |
7 | 174 # define PyErr_NoMemory dll_PyErr_NoMemory |
175 # define PyErr_Occurred dll_PyErr_Occurred | |
176 # define PyErr_SetNone dll_PyErr_SetNone | |
177 # define PyErr_SetString dll_PyErr_SetString | |
4403 | 178 # define PyErr_SetObject dll_PyErr_SetObject |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
179 # define PyErr_ExceptionMatches dll_PyErr_ExceptionMatches |
7 | 180 # define PyEval_InitThreads dll_PyEval_InitThreads |
181 # define PyEval_RestoreThread dll_PyEval_RestoreThread | |
182 # define PyEval_SaveThread dll_PyEval_SaveThread | |
183 # ifdef PY_CAN_RECURSE | |
184 # define PyGILState_Ensure dll_PyGILState_Ensure | |
185 # define PyGILState_Release dll_PyGILState_Release | |
186 # endif | |
187 # define PyInt_AsLong dll_PyInt_AsLong | |
188 # define PyInt_FromLong dll_PyInt_FromLong | |
3618 | 189 # define PyLong_AsLong dll_PyLong_AsLong |
190 # define PyLong_FromLong dll_PyLong_FromLong | |
3828 | 191 # define PyBool_Type (*dll_PyBool_Type) |
7 | 192 # define PyInt_Type (*dll_PyInt_Type) |
3618 | 193 # define PyLong_Type (*dll_PyLong_Type) |
7 | 194 # define PyList_GetItem dll_PyList_GetItem |
637 | 195 # define PyList_Append dll_PyList_Append |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
196 # define PyList_Insert dll_PyList_Insert |
7 | 197 # define PyList_New dll_PyList_New |
198 # define PyList_SetItem dll_PyList_SetItem | |
199 # define PyList_Size dll_PyList_Size | |
200 # define PyList_Type (*dll_PyList_Type) | |
3618 | 201 # define PySequence_Check dll_PySequence_Check |
202 # define PySequence_Size dll_PySequence_Size | |
203 # define PySequence_GetItem dll_PySequence_GetItem | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
204 # define PySequence_Fast dll_PySequence_Fast |
3618 | 205 # define PyTuple_Size dll_PyTuple_Size |
206 # define PyTuple_GetItem dll_PyTuple_GetItem | |
207 # define PyTuple_Type (*dll_PyTuple_Type) | |
5608 | 208 # define PySlice_GetIndicesEx dll_PySlice_GetIndicesEx |
7 | 209 # define PyImport_ImportModule dll_PyImport_ImportModule |
637 | 210 # define PyDict_New dll_PyDict_New |
7 | 211 # define PyDict_GetItemString dll_PyDict_GetItemString |
3618 | 212 # define PyDict_Next dll_PyDict_Next |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
213 # define PyDict_Type (*dll_PyDict_Type) |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
214 # ifdef PyMapping_Keys |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
215 # define PY_NO_MAPPING_KEYS |
3618 | 216 # else |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
217 # define PyMapping_Keys dll_PyMapping_Keys |
3618 | 218 # endif |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
219 # define PyObject_GetItem dll_PyObject_GetItem |
3618 | 220 # define PyObject_CallMethod dll_PyObject_CallMethod |
221 # define PyMapping_Check dll_PyMapping_Check | |
222 # define PyIter_Next dll_PyIter_Next | |
7 | 223 # define PyModule_GetDict dll_PyModule_GetDict |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4823
diff
changeset
|
224 # define PyModule_AddObject dll_PyModule_AddObject |
7 | 225 # define PyRun_SimpleString dll_PyRun_SimpleString |
3618 | 226 # define PyRun_String dll_PyRun_String |
4435 | 227 # define PyObject_GetAttrString dll_PyObject_GetAttrString |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
228 # define PyObject_HasAttrString dll_PyObject_HasAttrString |
4435 | 229 # define PyObject_SetAttrString dll_PyObject_SetAttrString |
230 # define PyObject_CallFunctionObjArgs dll_PyObject_CallFunctionObjArgs | |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
231 # define PyObject_CallFunction dll_PyObject_CallFunction |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4645
diff
changeset
|
232 # define PyObject_Call dll_PyObject_Call |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
233 # define PyObject_Repr dll_PyObject_Repr |
7 | 234 # define PyString_AsString dll_PyString_AsString |
3798 | 235 # define PyString_AsStringAndSize dll_PyString_AsStringAndSize |
7 | 236 # define PyString_FromString dll_PyString_FromString |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
237 # define PyString_FromFormat dll_PyString_FromFormat |
7 | 238 # define PyString_FromStringAndSize dll_PyString_FromStringAndSize |
239 # define PyString_Size dll_PyString_Size | |
240 # define PyString_Type (*dll_PyString_Type) | |
3618 | 241 # define PyUnicode_Type (*dll_PyUnicode_Type) |
3642 | 242 # undef PyUnicode_AsEncodedString |
243 # define PyUnicode_AsEncodedString py_PyUnicode_AsEncodedString | |
3618 | 244 # define PyFloat_AsDouble dll_PyFloat_AsDouble |
245 # define PyFloat_FromDouble dll_PyFloat_FromDouble | |
246 # define PyFloat_Type (*dll_PyFloat_Type) | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
247 # define PyNumber_Check dll_PyNumber_Check |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
248 # define PyNumber_Long dll_PyNumber_Long |
3618 | 249 # define PyImport_AddModule (*dll_PyImport_AddModule) |
7 | 250 # define PySys_SetObject dll_PySys_SetObject |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
251 # define PySys_GetObject dll_PySys_GetObject |
7 | 252 # define PySys_SetArgv dll_PySys_SetArgv |
253 # define PyType_Type (*dll_PyType_Type) | |
5608 | 254 # define PySlice_Type (*dll_PySlice_Type) |
2737 | 255 # define PyType_Ready (*dll_PyType_Ready) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
256 # define PyType_GenericAlloc dll_PyType_GenericAlloc |
7 | 257 # define Py_BuildValue dll_Py_BuildValue |
258 # define Py_FindMethod dll_Py_FindMethod | |
259 # define Py_InitModule4 dll_Py_InitModule4 | |
2641 | 260 # define Py_SetPythonHome dll_Py_SetPythonHome |
7 | 261 # define Py_Initialize dll_Py_Initialize |
242 | 262 # define Py_Finalize dll_Py_Finalize |
263 # define Py_IsInitialized dll_Py_IsInitialized | |
7 | 264 # define _PyObject_New dll__PyObject_New |
4500 | 265 # define _PyObject_GC_New dll__PyObject_GC_New |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
266 # ifdef PyObject_GC_Del |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
267 # define Py_underscore_GC |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
268 # define _PyObject_GC_Del dll__PyObject_GC_Del |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
269 # define _PyObject_GC_UnTrack dll__PyObject_GC_UnTrack |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
270 # else |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
271 # define PyObject_GC_Del dll_PyObject_GC_Del |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
272 # define PyObject_GC_UnTrack dll_PyObject_GC_UnTrack |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
273 # endif |
3646 | 274 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
275 # define _PyObject_NextNotImplemented (*dll__PyObject_NextNotImplemented) | |
276 # endif | |
7 | 277 # define _Py_NoneStruct (*dll__Py_NoneStruct) |
3828 | 278 # define _Py_ZeroStruct (*dll__Py_ZeroStruct) |
279 # define _Py_TrueStruct (*dll__Py_TrueStruct) | |
7 | 280 # define PyObject_Init dll__PyObject_Init |
3618 | 281 # define PyObject_GetIter dll_PyObject_GetIter |
4399 | 282 # define PyObject_IsTrue dll_PyObject_IsTrue |
7 | 283 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
284 # define PyType_IsSubtype dll_PyType_IsSubtype | |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
285 # ifdef Py_DEBUG |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
286 # define _Py_NegativeRefcount dll__Py_NegativeRefcount |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
287 # define _Py_RefTotal (*dll__Py_RefTotal) |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
288 # define _Py_Dealloc dll__Py_Dealloc |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
289 # endif |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
290 # endif |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
291 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
292 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
293 # define _PyObject_DebugMalloc dll__PyObject_DebugMalloc |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
294 # define _PyObject_DebugFree dll__PyObject_DebugFree |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
295 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
296 # define PyObject_Malloc dll_PyObject_Malloc |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
297 # define PyObject_Free dll_PyObject_Free |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
298 # endif |
7 | 299 # endif |
3638 | 300 # ifdef PY_USE_CAPSULE |
301 # define PyCapsule_New dll_PyCapsule_New | |
302 # define PyCapsule_GetPointer dll_PyCapsule_GetPointer | |
303 # else | |
304 # define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr | |
305 # define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr | |
306 # endif | |
6083 | 307 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
308 # define Py_NoSiteFlag (*dll_Py_NoSiteFlag) | |
309 # endif | |
7 | 310 |
311 /* | |
312 * Pointers for dynamic link | |
313 */ | |
314 static int(*dll_PyArg_Parse)(PyObject *, char *, ...); | |
315 static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...); | |
2894 | 316 static int(*dll_PyMem_Free)(void *); |
3618 | 317 static void* (*dll_PyMem_Malloc)(size_t); |
7 | 318 static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); |
319 static int(*dll_PyErr_BadArgument)(void); | |
4409 | 320 static PyObject *(*dll_PyErr_NewException)(char *, PyObject *, PyObject *); |
7 | 321 static void(*dll_PyErr_Clear)(void); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
322 static PyObject*(*dll_PyErr_Format)(PyObject *, const char *, ...); |
4145 | 323 static void(*dll_PyErr_PrintEx)(int); |
7 | 324 static PyObject*(*dll_PyErr_NoMemory)(void); |
325 static PyObject*(*dll_PyErr_Occurred)(void); | |
326 static void(*dll_PyErr_SetNone)(PyObject *); | |
327 static void(*dll_PyErr_SetString)(PyObject *, const char *); | |
4403 | 328 static void(*dll_PyErr_SetObject)(PyObject *, PyObject *); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
329 static int(*dll_PyErr_ExceptionMatches)(PyObject *); |
7 | 330 static void(*dll_PyEval_InitThreads)(void); |
331 static void(*dll_PyEval_RestoreThread)(PyThreadState *); | |
332 static PyThreadState*(*dll_PyEval_SaveThread)(void); | |
333 # ifdef PY_CAN_RECURSE | |
334 static PyGILState_STATE (*dll_PyGILState_Ensure)(void); | |
335 static void (*dll_PyGILState_Release)(PyGILState_STATE); | |
3618 | 336 # endif |
7 | 337 static long(*dll_PyInt_AsLong)(PyObject *); |
338 static PyObject*(*dll_PyInt_FromLong)(long); | |
3618 | 339 static long(*dll_PyLong_AsLong)(PyObject *); |
340 static PyObject*(*dll_PyLong_FromLong)(long); | |
3828 | 341 static PyTypeObject* dll_PyBool_Type; |
7 | 342 static PyTypeObject* dll_PyInt_Type; |
3618 | 343 static PyTypeObject* dll_PyLong_Type; |
1594 | 344 static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
345 static int(*dll_PyList_Append)(PyObject *, PyObject *); |
4986
048c69ebe8ee
updated for version 7.3.1238
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
346 static int(*dll_PyList_Insert)(PyObject *, PyInt, PyObject *); |
1594 | 347 static PyObject*(*dll_PyList_New)(PyInt size); |
348 static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *); | |
349 static PyInt(*dll_PyList_Size)(PyObject *); | |
7 | 350 static PyTypeObject* dll_PyList_Type; |
3618 | 351 static int (*dll_PySequence_Check)(PyObject *); |
352 static PyInt(*dll_PySequence_Size)(PyObject *); | |
353 static PyObject*(*dll_PySequence_GetItem)(PyObject *, PyInt); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
354 static PyObject*(*dll_PySequence_Fast)(PyObject *, const char *); |
3618 | 355 static PyInt(*dll_PyTuple_Size)(PyObject *); |
356 static PyObject*(*dll_PyTuple_GetItem)(PyObject *, PyInt); | |
357 static PyTypeObject* dll_PyTuple_Type; | |
5612 | 358 static int (*dll_PySlice_GetIndicesEx)(PySliceObject *r, PyInt length, |
5608 | 359 PyInt *start, PyInt *stop, PyInt *step, |
360 PyInt *slicelen); | |
7 | 361 static PyObject*(*dll_PyImport_ImportModule)(const char *); |
637 | 362 static PyObject*(*dll_PyDict_New)(void); |
7 | 363 static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *); |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
364 static int (*dll_PyDict_Next)(PyObject *, PyInt *, PyObject **, PyObject **); |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
365 static PyTypeObject* dll_PyDict_Type; |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
366 # ifndef PY_NO_MAPPING_KEYS |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
367 static PyObject* (*dll_PyMapping_Keys)(PyObject *); |
3618 | 368 # endif |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
369 static PyObject* (*dll_PyObject_GetItem)(PyObject *, PyObject *); |
3618 | 370 static PyObject* (*dll_PyObject_CallMethod)(PyObject *, char *, PyObject *); |
371 static int (*dll_PyMapping_Check)(PyObject *); | |
372 static PyObject* (*dll_PyIter_Next)(PyObject *); | |
7 | 373 static PyObject*(*dll_PyModule_GetDict)(PyObject *); |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4823
diff
changeset
|
374 static int(*dll_PyModule_AddObject)(PyObject *, const char *, PyObject *); |
7 | 375 static int(*dll_PyRun_SimpleString)(char *); |
3618 | 376 static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *); |
4435 | 377 static PyObject* (*dll_PyObject_GetAttrString)(PyObject *, const char *); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
378 static int (*dll_PyObject_HasAttrString)(PyObject *, const char *); |
5419 | 379 static int (*dll_PyObject_SetAttrString)(PyObject *, const char *, PyObject *); |
4435 | 380 static PyObject* (*dll_PyObject_CallFunctionObjArgs)(PyObject *, ...); |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
381 static PyObject* (*dll_PyObject_CallFunction)(PyObject *, char *, ...); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4645
diff
changeset
|
382 static PyObject* (*dll_PyObject_Call)(PyObject *, PyObject *, PyObject *); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
383 static PyObject* (*dll_PyObject_Repr)(PyObject *); |
7 | 384 static char*(*dll_PyString_AsString)(PyObject *); |
4986
048c69ebe8ee
updated for version 7.3.1238
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
385 static int(*dll_PyString_AsStringAndSize)(PyObject *, char **, PyInt *); |
7 | 386 static PyObject*(*dll_PyString_FromString)(const char *); |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
387 static PyObject*(*dll_PyString_FromFormat)(const char *, ...); |
1594 | 388 static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt); |
389 static PyInt(*dll_PyString_Size)(PyObject *); | |
7 | 390 static PyTypeObject* dll_PyString_Type; |
3618 | 391 static PyTypeObject* dll_PyUnicode_Type; |
3642 | 392 static PyObject *(*py_PyUnicode_AsEncodedString)(PyObject *, char *, char *); |
3618 | 393 static double(*dll_PyFloat_AsDouble)(PyObject *); |
394 static PyObject*(*dll_PyFloat_FromDouble)(double); | |
395 static PyTypeObject* dll_PyFloat_Type; | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
396 static int(*dll_PyNumber_Check)(PyObject *); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
397 static PyObject*(*dll_PyNumber_Long)(PyObject *); |
7 | 398 static int(*dll_PySys_SetObject)(char *, PyObject *); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
399 static PyObject *(*dll_PySys_GetObject)(char *); |
7 | 400 static int(*dll_PySys_SetArgv)(int, char **); |
401 static PyTypeObject* dll_PyType_Type; | |
5608 | 402 static PyTypeObject* dll_PySlice_Type; |
2737 | 403 static int (*dll_PyType_Ready)(PyTypeObject *type); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
404 static PyObject* (*dll_PyType_GenericAlloc)(PyTypeObject *type, PyInt nitems); |
7 | 405 static PyObject*(*dll_Py_BuildValue)(char *, ...); |
406 static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *); | |
407 static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int); | |
3618 | 408 static PyObject*(*dll_PyImport_AddModule)(char *); |
2641 | 409 static void(*dll_Py_SetPythonHome)(char *home); |
7 | 410 static void(*dll_Py_Initialize)(void); |
242 | 411 static void(*dll_Py_Finalize)(void); |
412 static int(*dll_Py_IsInitialized)(void); | |
7 | 413 static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *); |
4500 | 414 static PyObject*(*dll__PyObject_GC_New)(PyTypeObject *); |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
415 # ifdef Py_underscore_GC |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
416 static void(*dll__PyObject_GC_Del)(void *); |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
417 static void(*dll__PyObject_GC_UnTrack)(void *); |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
418 # else |
4500 | 419 static void(*dll_PyObject_GC_Del)(void *); |
420 static void(*dll_PyObject_GC_UnTrack)(void *); | |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
421 # endif |
7 | 422 static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *); |
3618 | 423 static PyObject* (*dll_PyObject_GetIter)(PyObject *); |
4399 | 424 static int (*dll_PyObject_IsTrue)(PyObject *); |
3646 | 425 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
3618 | 426 static iternextfunc dll__PyObject_NextNotImplemented; |
3646 | 427 # endif |
7 | 428 static PyObject* dll__Py_NoneStruct; |
3828 | 429 static PyObject* _Py_ZeroStruct; |
430 static PyObject* dll__Py_TrueStruct; | |
7 | 431 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
432 static int (*dll_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); | |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
433 # ifdef Py_DEBUG |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
434 static void (*dll__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op); |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
435 static PyInt* dll__Py_RefTotal; |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
436 static void (*dll__Py_Dealloc)(PyObject *obj); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
437 # endif |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
438 # endif |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
439 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
440 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
441 static void (*dll__PyObject_DebugFree)(void*); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
442 static void* (*dll__PyObject_DebugMalloc)(size_t); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
443 # else |
7 | 444 static void* (*dll_PyObject_Malloc)(size_t); |
445 static void (*dll_PyObject_Free)(void*); | |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
446 # endif |
7 | 447 # endif |
3638 | 448 # ifdef PY_USE_CAPSULE |
3618 | 449 static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor); |
450 static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *); | |
3638 | 451 # else |
3648 | 452 static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *)); |
453 static void* (*dll_PyCObject_AsVoidPtr)(PyObject *); | |
3638 | 454 # endif |
6083 | 455 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
456 static int* dll_Py_NoSiteFlag; | |
457 # endif | |
7 | 458 |
459 static HINSTANCE hinstPython = 0; /* Instance of python.dll */ | |
460 | |
461 /* Imported exception objects */ | |
462 static PyObject *imp_PyExc_AttributeError; | |
463 static PyObject *imp_PyExc_IndexError; | |
4315 | 464 static PyObject *imp_PyExc_KeyError; |
7 | 465 static PyObject *imp_PyExc_KeyboardInterrupt; |
466 static PyObject *imp_PyExc_TypeError; | |
467 static PyObject *imp_PyExc_ValueError; | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4986
diff
changeset
|
468 static PyObject *imp_PyExc_SystemExit; |
4405 | 469 static PyObject *imp_PyExc_RuntimeError; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
470 static PyObject *imp_PyExc_ImportError; |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
471 static PyObject *imp_PyExc_OverflowError; |
7 | 472 |
473 # define PyExc_AttributeError imp_PyExc_AttributeError | |
474 # define PyExc_IndexError imp_PyExc_IndexError | |
4315 | 475 # define PyExc_KeyError imp_PyExc_KeyError |
7 | 476 # define PyExc_KeyboardInterrupt imp_PyExc_KeyboardInterrupt |
477 # define PyExc_TypeError imp_PyExc_TypeError | |
478 # define PyExc_ValueError imp_PyExc_ValueError | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4986
diff
changeset
|
479 # define PyExc_SystemExit imp_PyExc_SystemExit |
4405 | 480 # define PyExc_RuntimeError imp_PyExc_RuntimeError |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
481 # define PyExc_ImportError imp_PyExc_ImportError |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
482 # define PyExc_OverflowError imp_PyExc_OverflowError |
7 | 483 |
484 /* | |
485 * Table of name to function pointer of python. | |
486 */ | |
487 # define PYTHON_PROC FARPROC | |
488 static struct | |
489 { | |
490 char *name; | |
491 PYTHON_PROC *ptr; | |
492 } python_funcname_table[] = | |
493 { | |
3806 | 494 #ifndef PY_SSIZE_T_CLEAN |
7 | 495 {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse}, |
496 {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple}, | |
3806 | 497 {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue}, |
498 #else | |
499 {"_PyArg_Parse_SizeT", (PYTHON_PROC*)&dll_PyArg_Parse}, | |
500 {"_PyArg_ParseTuple_SizeT", (PYTHON_PROC*)&dll_PyArg_ParseTuple}, | |
501 {"_Py_BuildValue_SizeT", (PYTHON_PROC*)&dll_Py_BuildValue}, | |
502 #endif | |
2894 | 503 {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free}, |
3618 | 504 {"PyMem_Malloc", (PYTHON_PROC*)&dll_PyMem_Malloc}, |
7 | 505 {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString}, |
506 {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument}, | |
4409 | 507 {"PyErr_NewException", (PYTHON_PROC*)&dll_PyErr_NewException}, |
7 | 508 {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear}, |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
509 {"PyErr_Format", (PYTHON_PROC*)&dll_PyErr_Format}, |
4145 | 510 {"PyErr_PrintEx", (PYTHON_PROC*)&dll_PyErr_PrintEx}, |
7 | 511 {"PyErr_NoMemory", (PYTHON_PROC*)&dll_PyErr_NoMemory}, |
512 {"PyErr_Occurred", (PYTHON_PROC*)&dll_PyErr_Occurred}, | |
513 {"PyErr_SetNone", (PYTHON_PROC*)&dll_PyErr_SetNone}, | |
514 {"PyErr_SetString", (PYTHON_PROC*)&dll_PyErr_SetString}, | |
4403 | 515 {"PyErr_SetObject", (PYTHON_PROC*)&dll_PyErr_SetObject}, |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
516 {"PyErr_ExceptionMatches", (PYTHON_PROC*)&dll_PyErr_ExceptionMatches}, |
7 | 517 {"PyEval_InitThreads", (PYTHON_PROC*)&dll_PyEval_InitThreads}, |
518 {"PyEval_RestoreThread", (PYTHON_PROC*)&dll_PyEval_RestoreThread}, | |
519 {"PyEval_SaveThread", (PYTHON_PROC*)&dll_PyEval_SaveThread}, | |
520 # ifdef PY_CAN_RECURSE | |
521 {"PyGILState_Ensure", (PYTHON_PROC*)&dll_PyGILState_Ensure}, | |
522 {"PyGILState_Release", (PYTHON_PROC*)&dll_PyGILState_Release}, | |
523 # endif | |
524 {"PyInt_AsLong", (PYTHON_PROC*)&dll_PyInt_AsLong}, | |
525 {"PyInt_FromLong", (PYTHON_PROC*)&dll_PyInt_FromLong}, | |
3618 | 526 {"PyLong_AsLong", (PYTHON_PROC*)&dll_PyLong_AsLong}, |
527 {"PyLong_FromLong", (PYTHON_PROC*)&dll_PyLong_FromLong}, | |
3828 | 528 {"PyBool_Type", (PYTHON_PROC*)&dll_PyBool_Type}, |
7 | 529 {"PyInt_Type", (PYTHON_PROC*)&dll_PyInt_Type}, |
3618 | 530 {"PyLong_Type", (PYTHON_PROC*)&dll_PyLong_Type}, |
7 | 531 {"PyList_GetItem", (PYTHON_PROC*)&dll_PyList_GetItem}, |
637 | 532 {"PyList_Append", (PYTHON_PROC*)&dll_PyList_Append}, |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
533 {"PyList_Insert", (PYTHON_PROC*)&dll_PyList_Insert}, |
7 | 534 {"PyList_New", (PYTHON_PROC*)&dll_PyList_New}, |
535 {"PyList_SetItem", (PYTHON_PROC*)&dll_PyList_SetItem}, | |
536 {"PyList_Size", (PYTHON_PROC*)&dll_PyList_Size}, | |
537 {"PyList_Type", (PYTHON_PROC*)&dll_PyList_Type}, | |
3618 | 538 {"PySequence_Size", (PYTHON_PROC*)&dll_PySequence_Size}, |
539 {"PySequence_Check", (PYTHON_PROC*)&dll_PySequence_Check}, | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
540 {"PySequence_GetItem", (PYTHON_PROC*)&dll_PySequence_GetItem}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
541 {"PySequence_Fast", (PYTHON_PROC*)&dll_PySequence_Fast}, |
3618 | 542 {"PyTuple_GetItem", (PYTHON_PROC*)&dll_PyTuple_GetItem}, |
543 {"PyTuple_Size", (PYTHON_PROC*)&dll_PyTuple_Size}, | |
544 {"PyTuple_Type", (PYTHON_PROC*)&dll_PyTuple_Type}, | |
5608 | 545 {"PySlice_GetIndicesEx", (PYTHON_PROC*)&dll_PySlice_GetIndicesEx}, |
7 | 546 {"PyImport_ImportModule", (PYTHON_PROC*)&dll_PyImport_ImportModule}, |
547 {"PyDict_GetItemString", (PYTHON_PROC*)&dll_PyDict_GetItemString}, | |
3618 | 548 {"PyDict_Next", (PYTHON_PROC*)&dll_PyDict_Next}, |
637 | 549 {"PyDict_New", (PYTHON_PROC*)&dll_PyDict_New}, |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
550 {"PyDict_Type", (PYTHON_PROC*)&dll_PyDict_Type}, |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
551 # ifndef PY_NO_MAPPING_KEYS |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
552 {"PyMapping_Keys", (PYTHON_PROC*)&dll_PyMapping_Keys}, |
3618 | 553 # endif |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
554 {"PyObject_GetItem", (PYTHON_PROC*)&dll_PyObject_GetItem}, |
3618 | 555 {"PyObject_CallMethod", (PYTHON_PROC*)&dll_PyObject_CallMethod}, |
556 {"PyMapping_Check", (PYTHON_PROC*)&dll_PyMapping_Check}, | |
557 {"PyIter_Next", (PYTHON_PROC*)&dll_PyIter_Next}, | |
7 | 558 {"PyModule_GetDict", (PYTHON_PROC*)&dll_PyModule_GetDict}, |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4823
diff
changeset
|
559 {"PyModule_AddObject", (PYTHON_PROC*)&dll_PyModule_AddObject}, |
7 | 560 {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString}, |
3618 | 561 {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String}, |
4435 | 562 {"PyObject_GetAttrString", (PYTHON_PROC*)&dll_PyObject_GetAttrString}, |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
563 {"PyObject_HasAttrString", (PYTHON_PROC*)&dll_PyObject_HasAttrString}, |
4435 | 564 {"PyObject_SetAttrString", (PYTHON_PROC*)&dll_PyObject_SetAttrString}, |
565 {"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&dll_PyObject_CallFunctionObjArgs}, | |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
566 {"PyObject_CallFunction", (PYTHON_PROC*)&dll_PyObject_CallFunction}, |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4645
diff
changeset
|
567 {"PyObject_Call", (PYTHON_PROC*)&dll_PyObject_Call}, |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
568 {"PyObject_Repr", (PYTHON_PROC*)&dll_PyObject_Repr}, |
7 | 569 {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString}, |
3798 | 570 {"PyString_AsStringAndSize", (PYTHON_PROC*)&dll_PyString_AsStringAndSize}, |
7 | 571 {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString}, |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
572 {"PyString_FromFormat", (PYTHON_PROC*)&dll_PyString_FromFormat}, |
7 | 573 {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize}, |
574 {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size}, | |
575 {"PyString_Type", (PYTHON_PROC*)&dll_PyString_Type}, | |
3618 | 576 {"PyUnicode_Type", (PYTHON_PROC*)&dll_PyUnicode_Type}, |
577 {"PyFloat_Type", (PYTHON_PROC*)&dll_PyFloat_Type}, | |
578 {"PyFloat_AsDouble", (PYTHON_PROC*)&dll_PyFloat_AsDouble}, | |
579 {"PyFloat_FromDouble", (PYTHON_PROC*)&dll_PyFloat_FromDouble}, | |
580 {"PyImport_AddModule", (PYTHON_PROC*)&dll_PyImport_AddModule}, | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
581 {"PyNumber_Check", (PYTHON_PROC*)&dll_PyNumber_Check}, |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
582 {"PyNumber_Long", (PYTHON_PROC*)&dll_PyNumber_Long}, |
7 | 583 {"PySys_SetObject", (PYTHON_PROC*)&dll_PySys_SetObject}, |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
584 {"PySys_GetObject", (PYTHON_PROC*)&dll_PySys_GetObject}, |
7 | 585 {"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv}, |
586 {"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type}, | |
5608 | 587 {"PySlice_Type", (PYTHON_PROC*)&dll_PySlice_Type}, |
2737 | 588 {"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready}, |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
589 {"PyType_GenericAlloc", (PYTHON_PROC*)&dll_PyType_GenericAlloc}, |
7 | 590 {"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod}, |
2641 | 591 {"Py_SetPythonHome", (PYTHON_PROC*)&dll_Py_SetPythonHome}, |
7 | 592 {"Py_Initialize", (PYTHON_PROC*)&dll_Py_Initialize}, |
242 | 593 {"Py_Finalize", (PYTHON_PROC*)&dll_Py_Finalize}, |
594 {"Py_IsInitialized", (PYTHON_PROC*)&dll_Py_IsInitialized}, | |
7 | 595 {"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New}, |
4500 | 596 {"_PyObject_GC_New", (PYTHON_PROC*)&dll__PyObject_GC_New}, |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
597 # ifdef Py_underscore_GC |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
598 {"_PyObject_GC_Del", (PYTHON_PROC*)&dll__PyObject_GC_Del}, |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
599 {"_PyObject_GC_UnTrack", (PYTHON_PROC*)&dll__PyObject_GC_UnTrack}, |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
600 # else |
4500 | 601 {"PyObject_GC_Del", (PYTHON_PROC*)&dll_PyObject_GC_Del}, |
602 {"PyObject_GC_UnTrack", (PYTHON_PROC*)&dll_PyObject_GC_UnTrack}, | |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
603 # endif |
7 | 604 {"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init}, |
3618 | 605 {"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter}, |
4399 | 606 {"PyObject_IsTrue", (PYTHON_PROC*)&dll_PyObject_IsTrue}, |
3646 | 607 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
3618 | 608 {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented}, |
3646 | 609 # endif |
7 | 610 {"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct}, |
3828 | 611 {"_Py_ZeroStruct", (PYTHON_PROC*)&dll__Py_ZeroStruct}, |
612 {"_Py_TrueStruct", (PYTHON_PROC*)&dll__Py_TrueStruct}, | |
7 | 613 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
614 # ifdef Py_DEBUG |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
615 {"_Py_NegativeRefcount", (PYTHON_PROC*)&dll__Py_NegativeRefcount}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
616 {"_Py_RefTotal", (PYTHON_PROC*)&dll__Py_RefTotal}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
617 {"_Py_Dealloc", (PYTHON_PROC*)&dll__Py_Dealloc}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
618 # endif |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
619 {"PyType_IsSubtype", (PYTHON_PROC*)&dll_PyType_IsSubtype}, |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
620 # endif |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
621 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
622 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
623 {"_PyObject_DebugFree", (PYTHON_PROC*)&dll__PyObject_DebugFree}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
624 {"_PyObject_DebugMalloc", (PYTHON_PROC*)&dll__PyObject_DebugMalloc}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
625 # else |
7 | 626 {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc}, |
627 {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free}, | |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
628 # endif |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
629 # endif |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
630 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 \ |
5684 | 631 && SIZEOF_SIZE_T != VIM_SIZEOF_INT |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
632 # ifdef Py_DEBUG |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
633 {"Py_InitModule4TraceRefs_64", (PYTHON_PROC*)&dll_Py_InitModule4}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
634 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
635 {"Py_InitModule4_64", (PYTHON_PROC*)&dll_Py_InitModule4}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
636 # endif |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
637 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
638 # ifdef Py_DEBUG |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
639 {"Py_InitModule4TraceRefs", (PYTHON_PROC*)&dll_Py_InitModule4}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
640 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
641 {"Py_InitModule4", (PYTHON_PROC*)&dll_Py_InitModule4}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
642 # endif |
7 | 643 # endif |
3638 | 644 # ifdef PY_USE_CAPSULE |
3618 | 645 {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New}, |
646 {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer}, | |
3638 | 647 # else |
648 {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr}, | |
649 {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr}, | |
650 # endif | |
6083 | 651 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
652 {"Py_NoSiteFlag", (PYTHON_PROC*)&dll_Py_NoSiteFlag}, | |
653 # endif | |
7 | 654 {"", NULL}, |
655 }; | |
656 | |
657 /* | |
658 * Free python.dll | |
659 */ | |
660 static void | |
661 end_dynamic_python(void) | |
662 { | |
663 if (hinstPython) | |
664 { | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
665 close_dll(hinstPython); |
7 | 666 hinstPython = 0; |
667 } | |
668 } | |
669 | |
670 /* | |
671 * Load library and get all pointers. | |
672 * Parameter 'libname' provides name of DLL. | |
673 * Return OK or FAIL. | |
674 */ | |
675 static int | |
676 python_runtime_link_init(char *libname, int verbose) | |
677 { | |
678 int i; | |
3642 | 679 void *ucs_as_encoded_string; |
7 | 680 |
2641 | 681 #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
|
682 /* 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
|
683 * 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
|
684 * 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
|
685 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
|
686 { |
3032 | 687 if (verbose) |
688 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
|
689 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
|
690 } |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
691 #endif |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
692 |
7 | 693 if (hinstPython) |
694 return OK; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
695 hinstPython = load_dll(libname); |
7 | 696 if (!hinstPython) |
697 { | |
698 if (verbose) | |
699 EMSG2(_(e_loadlib), libname); | |
700 return FAIL; | |
701 } | |
702 | |
703 for (i = 0; python_funcname_table[i].ptr; ++i) | |
704 { | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
705 if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython, |
7 | 706 python_funcname_table[i].name)) == NULL) |
707 { | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
708 close_dll(hinstPython); |
7 | 709 hinstPython = 0; |
710 if (verbose) | |
711 EMSG2(_(e_loadfunc), python_funcname_table[i].name); | |
712 return FAIL; | |
713 } | |
714 } | |
3642 | 715 |
716 /* Load unicode functions separately as only the ucs2 or the ucs4 functions | |
717 * will be present in the library. */ | |
718 ucs_as_encoded_string = symbol_from_dll(hinstPython, | |
719 "PyUnicodeUCS2_AsEncodedString"); | |
720 if (ucs_as_encoded_string == NULL) | |
721 ucs_as_encoded_string = symbol_from_dll(hinstPython, | |
722 "PyUnicodeUCS4_AsEncodedString"); | |
723 if (ucs_as_encoded_string != NULL) | |
724 py_PyUnicode_AsEncodedString = ucs_as_encoded_string; | |
725 else | |
726 { | |
727 close_dll(hinstPython); | |
728 hinstPython = 0; | |
729 if (verbose) | |
730 EMSG2(_(e_loadfunc), "PyUnicode_UCSX_*"); | |
731 return FAIL; | |
732 } | |
733 | |
7 | 734 return OK; |
735 } | |
736 | |
737 /* | |
738 * If python is enabled (there is installed python on Windows system) return | |
739 * TRUE, else FALSE. | |
740 */ | |
741 int | |
1607 | 742 python_enabled(int verbose) |
7 | 743 { |
7528
53163e4d9e4f
commit https://github.com/vim/vim/commit/25e4fcde767084d1a79e0926bc301c92987c0cce
Christian Brabandt <cb@256bit.org>
parents:
7416
diff
changeset
|
744 return python_runtime_link_init((char *)p_pydll, verbose) == OK; |
7 | 745 } |
746 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
747 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
748 * Load the standard Python exceptions - don't import the symbols from the |
7 | 749 * DLL, as this can cause errors (importing data symbols is not reliable). |
750 */ | |
751 static void | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
752 get_exceptions(void) |
7 | 753 { |
754 PyObject *exmod = PyImport_ImportModule("exceptions"); | |
755 PyObject *exdict = PyModule_GetDict(exmod); | |
756 imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError"); | |
757 imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError"); | |
4315 | 758 imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError"); |
7 | 759 imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt"); |
760 imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError"); | |
761 imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError"); | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4986
diff
changeset
|
762 imp_PyExc_SystemExit = PyDict_GetItemString(exdict, "SystemExit"); |
4405 | 763 imp_PyExc_RuntimeError = PyDict_GetItemString(exdict, "RuntimeError"); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
764 imp_PyExc_ImportError = PyDict_GetItemString(exdict, "ImportError"); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
765 imp_PyExc_OverflowError = PyDict_GetItemString(exdict, "OverflowError"); |
7 | 766 Py_XINCREF(imp_PyExc_AttributeError); |
767 Py_XINCREF(imp_PyExc_IndexError); | |
4315 | 768 Py_XINCREF(imp_PyExc_KeyError); |
7 | 769 Py_XINCREF(imp_PyExc_KeyboardInterrupt); |
770 Py_XINCREF(imp_PyExc_TypeError); | |
771 Py_XINCREF(imp_PyExc_ValueError); | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4986
diff
changeset
|
772 Py_XINCREF(imp_PyExc_SystemExit); |
4405 | 773 Py_XINCREF(imp_PyExc_RuntimeError); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
774 Py_XINCREF(imp_PyExc_ImportError); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
775 Py_XINCREF(imp_PyExc_OverflowError); |
7 | 776 Py_XDECREF(exmod); |
777 } | |
778 #endif /* DYNAMIC_PYTHON */ | |
779 | |
3618 | 780 static int initialised = 0; |
781 #define PYINITIALISED initialised | |
782 | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
783 #define DESTRUCTOR_FINISH(self) self->ob_type->tp_free((PyObject*)self); |
4319 | 784 |
4377 | 785 #define WIN_PYTHON_REF(win) win->w_python_ref |
786 #define BUF_PYTHON_REF(buf) buf->b_python_ref | |
4401 | 787 #define TAB_PYTHON_REF(tab) tab->tp_python_ref |
4377 | 788 |
4319 | 789 static PyObject *OutputGetattr(PyObject *, char *); |
790 static PyObject *BufferGetattr(PyObject *, char *); | |
791 static PyObject *WindowGetattr(PyObject *, char *); | |
4401 | 792 static PyObject *TabPageGetattr(PyObject *, char *); |
4319 | 793 static PyObject *RangeGetattr(PyObject *, char *); |
794 static PyObject *DictionaryGetattr(PyObject *, char*); | |
795 static PyObject *ListGetattr(PyObject *, char *); | |
796 static PyObject *FunctionGetattr(PyObject *, char *); | |
797 | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
798 #ifndef Py_VISIT |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
799 # define Py_VISIT(obj) visit(obj, arg) |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
800 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
801 #ifndef Py_CLEAR |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
802 # define Py_CLEAR(obj) \ |
4591
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
803 { \ |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
804 Py_XDECREF(obj); \ |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
805 obj = NULL; \ |
1e8952a5a726
updated for version 7.3.1043
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
806 } |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
807 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
808 |
4645
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
809 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
810 static void * |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
811 py_memsave(void *p, size_t len) |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
812 { |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
813 void *r; |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
814 |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
815 if (!(r = PyMem_Malloc(len))) |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
816 return NULL; |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
817 mch_memmove(r, p, len); |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
818 return r; |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
819 } |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
820 |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
821 # define PY_STRSAVE(s) ((char_u *) py_memsave(s, STRLEN(s) + 1)) |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
822 #endif |
c316a30a8892
updated for version 7.3.1070
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
823 |
5768 | 824 typedef PySliceObject PySliceObject_T; |
825 | |
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
|
826 /* |
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
|
827 * 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
|
828 */ |
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
|
829 #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
|
830 |
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
|
831 |
7 | 832 /****************************************************** |
833 * Internal function prototypes. | |
834 */ | |
835 | |
836 static int PythonMod_Init(void); | |
837 | |
838 | |
839 /****************************************************** | |
840 * 1. Python interpreter main program. | |
841 */ | |
842 | |
843 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ | |
844 typedef PyObject PyThreadState; | |
323 | 845 #endif |
846 | |
4415 | 847 #ifndef PY_CAN_RECURSE |
36 | 848 static PyThreadState *saved_python_thread = NULL; |
7 | 849 |
850 /* | |
851 * Suspend a thread of the Python interpreter, other threads are allowed to | |
852 * run. | |
853 */ | |
36 | 854 static void |
855 Python_SaveThread(void) | |
7 | 856 { |
857 saved_python_thread = PyEval_SaveThread(); | |
858 } | |
859 | |
860 /* | |
861 * Restore a thread of the Python interpreter, waits for other threads to | |
862 * block. | |
863 */ | |
36 | 864 static void |
865 Python_RestoreThread(void) | |
7 | 866 { |
867 PyEval_RestoreThread(saved_python_thread); | |
868 saved_python_thread = NULL; | |
4415 | 869 } |
323 | 870 #endif |
7 | 871 |
872 void | |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
873 python_end(void) |
7 | 874 { |
557 | 875 static int recurse = 0; |
876 | |
877 /* If a crash occurs while doing this, don't try again. */ | |
878 if (recurse != 0) | |
879 return; | |
880 | |
881 ++recurse; | |
882 | |
7 | 883 #ifdef DYNAMIC_PYTHON |
242 | 884 if (hinstPython && Py_IsInitialized()) |
323 | 885 { |
4415 | 886 # ifdef PY_CAN_RECURSE |
887 PyGILState_Ensure(); | |
888 # else | |
856 | 889 Python_RestoreThread(); /* enter python */ |
4415 | 890 # endif |
856 | 891 Py_Finalize(); |
323 | 892 } |
7 | 893 end_dynamic_python(); |
242 | 894 #else |
895 if (Py_IsInitialized()) | |
323 | 896 { |
4415 | 897 # ifdef PY_CAN_RECURSE |
898 PyGILState_Ensure(); | |
899 # else | |
856 | 900 Python_RestoreThread(); /* enter python */ |
4415 | 901 # endif |
856 | 902 Py_Finalize(); |
323 | 903 } |
7 | 904 #endif |
557 | 905 |
906 --recurse; | |
7 | 907 } |
908 | |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
909 #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
|
910 int |
7823
bcef391c101c
commit https://github.com/vim/vim/commit/68c2f638e65d914dc6e84eb7ce2624f08af525c0
Christian Brabandt <cb@256bit.org>
parents:
7528
diff
changeset
|
911 python_loaded(void) |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
912 { |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
913 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
|
914 } |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
915 #endif |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
916 |
7 | 917 static int |
918 Python_Init(void) | |
919 { | |
920 if (!initialised) | |
921 { | |
6083 | 922 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
923 PyObject *site; | |
924 #endif | |
925 | |
7 | 926 #ifdef DYNAMIC_PYTHON |
927 if (!python_enabled(TRUE)) | |
928 { | |
929 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); | |
930 goto fail; | |
931 } | |
932 #endif | |
933 | |
2641 | 934 #ifdef PYTHON_HOME |
7416
cd69647bb839
commit https://github.com/vim/vim/commit/1000565c3a2439c9a7c9759284814dbf3b8bc20d
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
935 # ifdef DYNAMIC_PYTHON |
cd69647bb839
commit https://github.com/vim/vim/commit/1000565c3a2439c9a7c9759284814dbf3b8bc20d
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
936 if (mch_getenv((char_u *)"PYTHONHOME") == NULL) |
cd69647bb839
commit https://github.com/vim/vim/commit/1000565c3a2439c9a7c9759284814dbf3b8bc20d
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
937 # endif |
cd69647bb839
commit https://github.com/vim/vim/commit/1000565c3a2439c9a7c9759284814dbf3b8bc20d
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
938 Py_SetPythonHome(PYTHON_HOME); |
2641 | 939 #endif |
940 | |
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
|
941 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
|
942 |
6083 | 943 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
944 /* Disable implicit 'import site', because it may cause Vim to exit | |
945 * when it can't be found. */ | |
946 Py_NoSiteFlag++; | |
947 #endif | |
948 | |
7 | 949 #if !defined(MACOS) || defined(MACOS_X_UNIX) |
950 Py_Initialize(); | |
951 #else | |
952 PyMac_Initialize(); | |
953 #endif | |
6083 | 954 |
955 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 | |
956 /* 'import site' explicitly. */ | |
957 site = PyImport_ImportModule("site"); | |
958 if (site == NULL) | |
959 { | |
960 EMSG(_("E887: Sorry, this command is disabled, the Python's site module could not be loaded.")); | |
961 goto fail; | |
962 } | |
963 Py_DECREF(site); | |
964 #endif | |
965 | |
4063 | 966 /* Initialise threads, and below save the state using |
4109 | 967 * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread |
4063 | 968 * specific state (such as the system trace hook), will be lost |
969 * between invocations of Python code. */ | |
7 | 970 PyEval_InitThreads(); |
971 #ifdef DYNAMIC_PYTHON | |
972 get_exceptions(); | |
973 #endif | |
974 | |
4494 | 975 if (PythonIO_Init_io()) |
7 | 976 goto fail; |
977 | |
978 if (PythonMod_Init()) | |
979 goto fail; | |
980 | |
3618 | 981 globals = PyModule_GetDict(PyImport_AddModule("__main__")); |
982 | |
1748 | 983 /* Remove the element from sys.path that was added because of our |
984 * argv[0] value in PythonMod_Init(). Previously we used an empty | |
4352 | 985 * string, but depending on the OS we then get an empty entry or |
1748 | 986 * the current directory in sys.path. */ |
987 PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); | |
988 | |
4109 | 989 /* lock is created and acquired in PyEval_InitThreads() and thread |
990 * state is created in Py_Initialize() | |
991 * there _PyGILState_NoteThreadState() also sets gilcounter to 1 | |
992 * (python must have threads enabled!) | |
993 * so the following does both: unlock GIL and save thread state in TLS | |
994 * without deleting thread state | |
995 */ | |
4399 | 996 #ifndef PY_CAN_RECURSE |
997 saved_python_thread = | |
998 #endif | |
999 PyEval_SaveThread(); | |
7 | 1000 |
1001 initialised = 1; | |
1002 } | |
1003 | |
1004 return 0; | |
1005 | |
1006 fail: | |
1007 /* We call PythonIO_Flush() here to print any Python errors. | |
1008 * This is OK, as it is possible to call this function even | |
4494 | 1009 * if PythonIO_Init_io() has not completed successfully (it will |
7 | 1010 * not do anything in this case). |
1011 */ | |
1012 PythonIO_Flush(); | |
1013 return -1; | |
1014 } | |
1015 | |
1016 /* | |
1017 * External interface | |
1018 */ | |
1019 static void | |
4486 | 1020 DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg) |
7 | 1021 { |
323 | 1022 #ifndef PY_CAN_RECURSE |
7 | 1023 static int recursive = 0; |
1024 #endif | |
1025 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
1026 GrafPtr oldPort; | |
1027 #endif | |
1028 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
1029 char *saved_locale; | |
1030 #endif | |
4415 | 1031 #ifdef PY_CAN_RECURSE |
1032 PyGILState_STATE pygilstate; | |
1033 #endif | |
7 | 1034 |
1035 #ifndef PY_CAN_RECURSE | |
1036 if (recursive) | |
1037 { | |
1038 EMSG(_("E659: Cannot invoke Python recursively")); | |
1039 return; | |
1040 } | |
1041 ++recursive; | |
1042 #endif | |
1043 | |
1044 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
1045 GetPort(&oldPort); | |
1046 /* Check if the Python library is available */ | |
1047 if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress) | |
1048 goto theend; | |
1049 #endif | |
1050 if (Python_Init()) | |
1051 goto theend; | |
1052 | |
4486 | 1053 init_range(arg); |
1054 | |
7 | 1055 Python_Release_Vim(); /* leave vim */ |
1056 | |
1057 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
1058 /* Python only works properly when the LC_NUMERIC locale is "C". */ | |
1059 saved_locale = setlocale(LC_NUMERIC, NULL); | |
1060 if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) | |
1061 saved_locale = NULL; | |
1062 else | |
1063 { | |
1064 /* Need to make a copy, value may change when setting new locale. */ | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1065 saved_locale = (char *) PY_STRSAVE(saved_locale); |
7 | 1066 (void)setlocale(LC_NUMERIC, "C"); |
1067 } | |
1068 #endif | |
1069 | |
4415 | 1070 #ifdef PY_CAN_RECURSE |
1071 pygilstate = PyGILState_Ensure(); | |
1072 #else | |
7 | 1073 Python_RestoreThread(); /* enter python */ |
4415 | 1074 #endif |
7 | 1075 |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1076 run((char *) cmd, arg |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1077 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1078 , &pygilstate |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1079 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1080 ); |
7 | 1081 |
4415 | 1082 #ifdef PY_CAN_RECURSE |
1083 PyGILState_Release(pygilstate); | |
1084 #else | |
7 | 1085 Python_SaveThread(); /* leave python */ |
4415 | 1086 #endif |
7 | 1087 |
1088 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
1089 if (saved_locale != NULL) | |
1090 { | |
1091 (void)setlocale(LC_NUMERIC, saved_locale); | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1092 PyMem_Free(saved_locale); |
7 | 1093 } |
1094 #endif | |
1095 | |
1096 Python_Lock_Vim(); /* enter vim */ | |
1097 PythonIO_Flush(); | |
1098 #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
1099 SetPort(oldPort); | |
1100 #endif | |
1101 | |
1102 theend: | |
1103 #ifndef PY_CAN_RECURSE | |
1104 --recursive; | |
1105 #endif | |
3618 | 1106 return; |
7 | 1107 } |
1108 | |
1109 /* | |
1110 * ":python" | |
1111 */ | |
1112 void | |
1113 ex_python(exarg_T *eap) | |
1114 { | |
1115 char_u *script; | |
1116 | |
10722
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1117 if (p_pyx == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1118 p_pyx = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1119 |
7 | 1120 script = script_get(eap, eap->arg); |
1121 if (!eap->skip) | |
1122 { | |
4486 | 1123 DoPyCommand(script == NULL ? (char *) eap->arg : (char *) script, |
1124 (rangeinitializer) init_range_cmd, | |
1125 (runner) run_cmd, | |
1126 (void *) eap); | |
7 | 1127 } |
1128 vim_free(script); | |
1129 } | |
1130 | |
1131 #define BUFFER_SIZE 1024 | |
1132 | |
1133 /* | |
1134 * ":pyfile" | |
1135 */ | |
1136 void | |
1137 ex_pyfile(exarg_T *eap) | |
1138 { | |
1139 static char buffer[BUFFER_SIZE]; | |
1140 const char *file = (char *)eap->arg; | |
1141 char *p; | |
1142 | |
10722
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1143 if (p_pyx == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1144 p_pyx = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1145 |
7 | 1146 /* Have to do it like this. PyRun_SimpleFile requires you to pass a |
1147 * stdio file pointer, but Vim and the Python DLL are compiled with | |
1148 * different options under Windows, meaning that stdio pointers aren't | |
1149 * compatible between the two. Yuk. | |
1150 * | |
1151 * Put the string "execfile('file')" into buffer. But, we need to | |
1152 * escape any backslashes or single quotes in the file name, so that | |
1153 * Python won't mangle the file name. | |
1154 */ | |
1155 strcpy(buffer, "execfile('"); | |
1156 p = buffer + 10; /* size of "execfile('" */ | |
1157 | |
1158 while (*file && p < buffer + (BUFFER_SIZE - 3)) | |
1159 { | |
1160 if (*file == '\\' || *file == '\'') | |
1161 *p++ = '\\'; | |
1162 *p++ = *file++; | |
1163 } | |
1164 | |
1165 /* If we didn't finish the file name, we hit a buffer overflow */ | |
1166 if (*file != '\0') | |
1167 return; | |
1168 | |
1169 /* Put in the terminating "')" and a null */ | |
1170 *p++ = '\''; | |
1171 *p++ = ')'; | |
1172 *p++ = '\0'; | |
1173 | |
1174 /* Execute the file */ | |
4486 | 1175 DoPyCommand(buffer, |
1176 (rangeinitializer) init_range_cmd, | |
1177 (runner) run_cmd, | |
1178 (void *) eap); | |
7 | 1179 } |
1180 | |
4435 | 1181 void |
1182 ex_pydo(exarg_T *eap) | |
1183 { | |
10722
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1184 if (p_pyx == 0) |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1185 p_pyx = 2; |
7598ce51bf2a
patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
1186 |
4486 | 1187 DoPyCommand((char *)eap->arg, |
1188 (rangeinitializer) init_range_cmd, | |
1189 (runner)run_do, | |
1190 (void *)eap); | |
4435 | 1191 } |
1192 | |
7 | 1193 /****************************************************** |
1194 * 2. Python output stream: writes output via [e]msg(). | |
1195 */ | |
1196 | |
1197 /* Implementation functions | |
1198 */ | |
1199 | |
1200 static PyObject * | |
1201 OutputGetattr(PyObject *self, char *name) | |
1202 { | |
1203 if (strcmp(name, "softspace") == 0) | |
1204 return PyInt_FromLong(((OutputObject *)(self))->softspace); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1205 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1206 return ObjectDir(NULL, OutputAttrs); |
8967
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8889
diff
changeset
|
1207 else if (strcmp(name, "errors") == 0) |
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8889
diff
changeset
|
1208 return PyString_FromString("strict"); |
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8889
diff
changeset
|
1209 else if (strcmp(name, "encoding") == 0) |
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8889
diff
changeset
|
1210 return PyString_FromString(ENC_OPT); |
7 | 1211 return Py_FindMethod(OutputMethods, self, name); |
1212 } | |
1213 | |
1214 /****************************************************** | |
1215 * 3. Implementation of the Vim module for Python | |
1216 */ | |
1217 | |
1218 /* Window type - Implementation functions | |
1219 * -------------------------------------- | |
1220 */ | |
1221 | |
1222 #define WindowType_Check(obj) ((obj)->ob_type == &WindowType) | |
1223 | |
1224 /* Buffer type - Implementation functions | |
1225 * -------------------------------------- | |
1226 */ | |
1227 | |
1228 #define BufferType_Check(obj) ((obj)->ob_type == &BufferType) | |
1229 | |
1594 | 1230 static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); |
1231 static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); | |
7 | 1232 |
1233 /* Line range type - Implementation functions | |
1234 * -------------------------------------- | |
1235 */ | |
1236 | |
1237 #define RangeType_Check(obj) ((obj)->ob_type == &RangeType) | |
1238 | |
1594 | 1239 static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); |
1240 static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); | |
7 | 1241 |
1242 /* Current objects type - Implementation functions | |
1243 * ----------------------------------------------- | |
1244 */ | |
1245 | |
1246 static PySequenceMethods BufferAsSeq = { | |
1594 | 1247 (PyInquiry) BufferLength, /* sq_length, len(x) */ |
3796 | 1248 (binaryfunc) 0, /* BufferConcat, sq_concat, x+y */ |
1249 (PyIntArgFunc) 0, /* BufferRepeat, sq_repeat, x*n */ | |
1594 | 1250 (PyIntArgFunc) BufferItem, /* sq_item, x[i] */ |
1251 (PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */ | |
1252 (PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */ | |
4319 | 1253 (PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */ |
1254 (objobjproc) 0, | |
1255 (binaryfunc) 0, | |
7 | 1256 0, |
1257 }; | |
1258 | |
1259 /* Buffer object - Implementation | |
1260 */ | |
1261 | |
1262 static PyObject * | |
1263 BufferGetattr(PyObject *self, char *name) | |
1264 { | |
4319 | 1265 PyObject *r; |
7 | 1266 |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1267 if ((r = BufferAttrValid((BufferObject *)(self), name))) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1268 return r; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1269 |
4319 | 1270 if (CheckBuffer((BufferObject *)(self))) |
7 | 1271 return NULL; |
1272 | |
4319 | 1273 r = BufferAttr((BufferObject *)(self), name); |
1274 if (r || PyErr_Occurred()) | |
1275 return r; | |
7 | 1276 else |
1277 return Py_FindMethod(BufferMethods, self, name); | |
1278 } | |
1279 | |
1280 /******************/ | |
1281 | |
1594 | 1282 static PyInt |
1283 BufferAssItem(PyObject *self, PyInt n, PyObject *val) | |
7 | 1284 { |
4387 | 1285 return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL); |
7 | 1286 } |
1287 | |
1594 | 1288 static PyInt |
1289 BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
7 | 1290 { |
4387 | 1291 return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, -1, NULL); |
7 | 1292 } |
1293 | |
1294 static PySequenceMethods RangeAsSeq = { | |
4319 | 1295 (PyInquiry) RangeLength, /* sq_length, len(x) */ |
1296 (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */ | |
1297 (PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */ | |
1298 (PyIntArgFunc) RangeItem, /* sq_item, x[i] */ | |
1299 (PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */ | |
1300 (PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */ | |
1301 (PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */ | |
1302 (objobjproc) 0, | |
1303 #if PY_MAJOR_VERSION >= 2 | |
1304 (binaryfunc) 0, | |
1305 0, | |
1306 #endif | |
7 | 1307 }; |
1308 | |
1309 /* Line range object - Implementation | |
1310 */ | |
1311 | |
1312 static PyObject * | |
1313 RangeGetattr(PyObject *self, char *name) | |
1314 { | |
1315 if (strcmp(name, "start") == 0) | |
1607 | 1316 return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->start - 1); |
7 | 1317 else if (strcmp(name, "end") == 0) |
1607 | 1318 return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->end - 1); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1319 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1320 return ObjectDir(NULL, RangeAttrs); |
7 | 1321 else |
1322 return Py_FindMethod(RangeMethods, self, name); | |
1323 } | |
1324 | |
1325 /****************/ | |
1326 | |
1594 | 1327 static PyInt |
1328 RangeAssItem(PyObject *self, PyInt n, PyObject *val) | |
7 | 1329 { |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1330 return RBAsItem(((RangeObject *)(self))->buf, n, val, |
7 | 1331 ((RangeObject *)(self))->start, |
1332 ((RangeObject *)(self))->end, | |
1333 &((RangeObject *)(self))->end); | |
1334 } | |
1335 | |
1594 | 1336 static PyInt |
1337 RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
7 | 1338 { |
2894 | 1339 return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val, |
7 | 1340 ((RangeObject *)(self))->start, |
1341 ((RangeObject *)(self))->end, | |
1342 &((RangeObject *)(self))->end); | |
1343 } | |
1344 | |
4401 | 1345 /* TabPage object - Implementation |
1346 */ | |
1347 | |
1348 static PyObject * | |
1349 TabPageGetattr(PyObject *self, char *name) | |
1350 { | |
1351 PyObject *r; | |
1352 | |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1353 if ((r = TabPageAttrValid((TabPageObject *)(self), name))) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1354 return r; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1355 |
4401 | 1356 if (CheckTabPage((TabPageObject *)(self))) |
1357 return NULL; | |
1358 | |
1359 r = TabPageAttr((TabPageObject *)(self), name); | |
1360 if (r || PyErr_Occurred()) | |
1361 return r; | |
1362 else | |
1363 return Py_FindMethod(TabPageMethods, self, name); | |
1364 } | |
1365 | |
7 | 1366 /* Window object - Implementation |
1367 */ | |
1368 | |
1369 static PyObject * | |
1370 WindowGetattr(PyObject *self, char *name) | |
1371 { | |
4319 | 1372 PyObject *r; |
7 | 1373 |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1374 if ((r = WindowAttrValid((WindowObject *)(self), name))) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1375 return r; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4591
diff
changeset
|
1376 |
4319 | 1377 if (CheckWindow((WindowObject *)(self))) |
7 | 1378 return NULL; |
1379 | |
4319 | 1380 r = WindowAttr((WindowObject *)(self), name); |
1381 if (r || PyErr_Occurred()) | |
1382 return r; | |
7 | 1383 else |
1384 return Py_FindMethod(WindowMethods, self, name); | |
1385 } | |
1386 | |
4401 | 1387 /* Tab page list object - Definitions |
1388 */ | |
1389 | |
1390 static PySequenceMethods TabListAsSeq = { | |
1391 (PyInquiry) TabListLength, /* sq_length, len(x) */ | |
1392 (binaryfunc) 0, /* sq_concat, x+y */ | |
1393 (PyIntArgFunc) 0, /* sq_repeat, x*n */ | |
1394 (PyIntArgFunc) TabListItem, /* sq_item, x[i] */ | |
1395 (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ | |
1396 (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ | |
1397 (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ | |
1398 (objobjproc) 0, | |
1399 #if PY_MAJOR_VERSION >= 2 | |
1400 (binaryfunc) 0, | |
1401 0, | |
1402 #endif | |
1403 }; | |
1404 | |
7 | 1405 /* Window list object - Definitions |
1406 */ | |
1407 | |
1408 static PySequenceMethods WinListAsSeq = { | |
1594 | 1409 (PyInquiry) WinListLength, /* sq_length, len(x) */ |
7 | 1410 (binaryfunc) 0, /* sq_concat, x+y */ |
1594 | 1411 (PyIntArgFunc) 0, /* sq_repeat, x*n */ |
1412 (PyIntArgFunc) WinListItem, /* sq_item, x[i] */ | |
1413 (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ | |
1414 (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ | |
4319 | 1415 (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ |
1416 (objobjproc) 0, | |
1417 #if PY_MAJOR_VERSION >= 2 | |
1418 (binaryfunc) 0, | |
7 | 1419 0, |
4319 | 1420 #endif |
7 | 1421 }; |
1422 | |
1423 /* External interface | |
1424 */ | |
1425 | |
1426 void | |
1427 python_buffer_free(buf_T *buf) | |
1428 { | |
4377 | 1429 if (BUF_PYTHON_REF(buf) != NULL) |
7 | 1430 { |
4377 | 1431 BufferObject *bp = BUF_PYTHON_REF(buf); |
7 | 1432 bp->buf = INVALID_BUFFER_VALUE; |
4377 | 1433 BUF_PYTHON_REF(buf) = NULL; |
7 | 1434 } |
1435 } | |
1436 | |
1437 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
1438 void | |
1439 python_window_free(win_T *win) | |
1440 { | |
4377 | 1441 if (WIN_PYTHON_REF(win) != NULL) |
7 | 1442 { |
4377 | 1443 WindowObject *wp = WIN_PYTHON_REF(win); |
7 | 1444 wp->win = INVALID_WINDOW_VALUE; |
4377 | 1445 WIN_PYTHON_REF(win) = NULL; |
7 | 1446 } |
1447 } | |
4401 | 1448 |
1449 void | |
1450 python_tabpage_free(tabpage_T *tab) | |
1451 { | |
1452 if (TAB_PYTHON_REF(tab) != NULL) | |
1453 { | |
1454 TabPageObject *tp = TAB_PYTHON_REF(tab); | |
1455 tp->tab = INVALID_TABPAGE_VALUE; | |
1456 TAB_PYTHON_REF(tab) = NULL; | |
1457 } | |
1458 } | |
7 | 1459 #endif |
1460 | |
4494 | 1461 static int |
7 | 1462 PythonMod_Init(void) |
1463 { | |
1748 | 1464 /* The special value is removed from sys.path in Python_Init(). */ |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
1465 static char *(argv[2]) = {"/must>not&exist/foo", NULL}; |
7 | 1466 |
4494 | 1467 if (init_types()) |
1468 return -1; | |
7 | 1469 |
1470 /* Set sys.argv[] to avoid a crash in warn(). */ | |
1471 PySys_SetArgv(1, argv); | |
1472 | |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1473 vim_module = Py_InitModule4("vim", VimMethods, (char *)NULL, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1474 (PyObject *)NULL, PYTHON_API_VERSION); |
7 | 1475 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1476 if (populate_module(vim_module)) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1477 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1478 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1479 if (init_sys_path()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1480 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1481 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1482 return 0; |
7 | 1483 } |
1484 | |
1485 /************************************************************************* | |
1486 * 4. Utility functions for handling the interface between Vim and Python. | |
1487 */ | |
1488 | |
1489 /* Convert a Vim line into a Python string. | |
1490 * All internal newlines are replaced by null characters. | |
1491 * | |
1492 * On errors, the Python exception data is set, and NULL is returned. | |
1493 */ | |
1494 static PyObject * | |
1495 LineToString(const char *str) | |
1496 { | |
1497 PyObject *result; | |
1594 | 1498 PyInt len = strlen(str); |
7 | 1499 char *p; |
1500 | |
1501 /* Allocate an Python string object, with uninitialised contents. We | |
1502 * must do it this way, so that we can modify the string in place | |
1503 * later. See the Python source, Objects/stringobject.c for details. | |
1504 */ | |
1505 result = PyString_FromStringAndSize(NULL, len); | |
1506 if (result == NULL) | |
1507 return NULL; | |
1508 | |
1509 p = PyString_AsString(result); | |
1510 | |
1511 while (*str) | |
1512 { | |
1513 if (*str == '\n') | |
1514 *p = '\0'; | |
1515 else | |
1516 *p = *str; | |
1517 | |
1518 ++p; | |
1519 ++str; | |
1520 } | |
1521 | |
1522 return result; | |
1523 } | |
1524 | |
3618 | 1525 static PyObject * |
1526 DictionaryGetattr(PyObject *self, char *name) | |
1527 { | |
3828 | 1528 DictionaryObject *this = ((DictionaryObject *) (self)); |
1529 | |
1530 if (strcmp(name, "locked") == 0) | |
1531 return PyInt_FromLong(this->dict->dv_lock); | |
1532 else if (strcmp(name, "scope") == 0) | |
1533 return PyInt_FromLong(this->dict->dv_scope); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1534 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1535 return ObjectDir(NULL, DictionaryAttrs); |
3828 | 1536 |
3618 | 1537 return Py_FindMethod(DictionaryMethods, self, name); |
1538 } | |
1539 | |
1540 static PyObject * | |
1541 ListGetattr(PyObject *self, char *name) | |
1542 { | |
3828 | 1543 if (strcmp(name, "locked") == 0) |
1544 return PyInt_FromLong(((ListObject *)(self))->list->lv_lock); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1545 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1546 return ObjectDir(NULL, ListAttrs); |
3828 | 1547 |
3618 | 1548 return Py_FindMethod(ListMethods, self, name); |
1549 } | |
1550 | |
1551 static PyObject * | |
1552 FunctionGetattr(PyObject *self, char *name) | |
1553 { | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
1554 PyObject *r; |
3618 | 1555 |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
1556 r = FunctionAttr((FunctionObject *)(self), name); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
1557 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
1558 if (r || PyErr_Occurred()) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
1559 return r; |
3618 | 1560 else |
1561 return Py_FindMethod(FunctionMethods, self, name); | |
1562 } | |
1563 | |
1564 void | |
1565 do_pyeval (char_u *str, typval_T *rettv) | |
1566 { | |
4486 | 1567 DoPyCommand((char *) str, |
1568 (rangeinitializer) init_range_eval, | |
1569 (runner) run_eval, | |
1570 (void *) rettv); | |
3618 | 1571 switch(rettv->v_type) |
1572 { | |
1573 case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; | |
1574 case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; | |
1575 case VAR_FUNC: func_ref(rettv->vval.v_string); break; | |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
1576 case VAR_PARTIAL: ++rettv->vval.v_partial->pt_refcount; break; |
3796 | 1577 case VAR_UNKNOWN: |
1578 rettv->v_type = VAR_NUMBER; | |
1579 rettv->vval.v_number = 0; | |
1580 break; | |
7949
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1581 case VAR_NUMBER: |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1582 case VAR_STRING: |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1583 case VAR_FLOAT: |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1584 case VAR_SPECIAL: |
7969
0de25de30ba3
commit https://github.com/vim/vim/commit/eba6d8c66c3511a5e1bfe6ffa30c8bea47d129ad
Christian Brabandt <cb@256bit.org>
parents:
7953
diff
changeset
|
1585 case VAR_JOB: |
8041
c6443e78cf2d
commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents:
7969
diff
changeset
|
1586 case VAR_CHANNEL: |
7949
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7823
diff
changeset
|
1587 break; |
3618 | 1588 } |
1589 } | |
7 | 1590 |
1591 /* Don't generate a prototype for the next function, it generates an error on | |
1592 * newer Python versions. */ | |
1593 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO) | |
1594 | |
1595 char * | |
1596 Py_GetProgramName(void) | |
1597 { | |
1598 return "vim"; | |
1599 } | |
1600 #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
|
1601 |
6565 | 1602 int |
3618 | 1603 set_ref_in_python (int copyID) |
1604 { | |
6565 | 1605 return set_ref_in_py(copyID); |
3618 | 1606 } |