Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 22 | #include <limits.h> |
| 23 | |
| 24 | /* Python.h defines _POSIX_THREADS itself (if needed) */ |
| 25 | #ifdef _POSIX_THREADS |
| 26 | # undef _POSIX_THREADS |
| 27 | #endif |
| 28 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 29 | #if defined(_WIN32) && defined(HAVE_FCNTL_H) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | # undef HAVE_FCNTL_H |
| 31 | #endif |
| 32 | |
| 33 | #ifdef _DEBUG |
| 34 | # undef _DEBUG |
| 35 | #endif |
| 36 | |
| 37 | #ifdef HAVE_STDARG_H |
| 38 | # undef HAVE_STDARG_H /* Python's config.h defines it as well. */ |
| 39 | #endif |
Bram Moolenaar | be2c9ae | 2009-11-11 14:06:59 +0000 | [diff] [blame] | 40 | #ifdef _POSIX_C_SOURCE |
| 41 | # undef _POSIX_C_SOURCE /* pyconfig.h defines it as well. */ |
| 42 | #endif |
| 43 | #ifdef _XOPEN_SOURCE |
| 44 | # undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ |
| 45 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | |
| 47 | #include <Python.h> |
| 48 | #if defined(MACOS) && !defined(MACOS_X_UNIX) |
| 49 | # include "macglue.h" |
| 50 | # include <CodeFragments.h> |
| 51 | #endif |
| 52 | #undef main /* Defined in python.h - aargh */ |
| 53 | #undef HAVE_FCNTL_H /* Clash with os_win32.h */ |
| 54 | |
Bram Moolenaar | e8cdcef | 2012-09-12 20:21:43 +0200 | [diff] [blame] | 55 | #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 |
| 56 | # define PY_SSIZE_T_CLEAN |
| 57 | #endif |
| 58 | |
Bram Moolenaar | 170bf1a | 2010-07-24 23:51:45 +0200 | [diff] [blame] | 59 | static void init_structs(void); |
| 60 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 61 | #define PyBytes_FromString PyString_FromString |
Bram Moolenaar | 335e0b6 | 2013-04-24 13:47:45 +0200 | [diff] [blame] | 62 | #define PyBytes_Check PyString_Check |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 63 | |
Bram Moolenaar | 19e6094 | 2011-06-19 00:27:51 +0200 | [diff] [blame] | 64 | /* No-op conversion functions, use with care! */ |
| 65 | #define PyString_AsBytes(obj) (obj) |
| 66 | #define PyString_FreeBytes(obj) |
| 67 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | #if !defined(FEAT_PYTHON) && defined(PROTO) |
| 69 | /* Use this to be able to generate prototypes without python being used. */ |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 70 | # define PyObject Py_ssize_t |
| 71 | # define PyThreadState Py_ssize_t |
| 72 | # define PyTypeObject Py_ssize_t |
| 73 | struct PyMethodDef { Py_ssize_t a; }; |
| 74 | # define PySequenceMethods Py_ssize_t |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 77 | #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
| 78 | # define PY_USE_CAPSULE |
| 79 | #endif |
| 80 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 81 | #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 |
| 82 | # define PyInt Py_ssize_t |
| 83 | # define PyInquiry lenfunc |
| 84 | # define PyIntArgFunc ssizeargfunc |
| 85 | # define PyIntIntArgFunc ssizessizeargfunc |
| 86 | # define PyIntObjArgProc ssizeobjargproc |
| 87 | # define PyIntIntObjArgProc ssizessizeobjargproc |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 88 | # define Py_ssize_t_fmt "n" |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 89 | #else |
| 90 | # define PyInt int |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 91 | # define lenfunc inquiry |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 92 | # define PyInquiry inquiry |
| 93 | # define PyIntArgFunc intargfunc |
| 94 | # define PyIntIntArgFunc intintargfunc |
| 95 | # define PyIntObjArgProc intobjargproc |
| 96 | # define PyIntIntObjArgProc intintobjargproc |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 97 | # define Py_ssize_t_fmt "i" |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 98 | #endif |
| 99 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 100 | /* Parser flags */ |
| 101 | #define single_input 256 |
| 102 | #define file_input 257 |
| 103 | #define eval_input 258 |
| 104 | |
| 105 | #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 |
| 106 | /* Python 2.3: can invoke ":python" recursively. */ |
| 107 | # define PY_CAN_RECURSE |
| 108 | #endif |
| 109 | |
Bram Moolenaar | b61f95c | 2010-08-09 22:06:13 +0200 | [diff] [blame] | 110 | # if defined(DYNAMIC_PYTHON) || defined(PROTO) |
| 111 | # ifndef DYNAMIC_PYTHON |
| 112 | # define HINSTANCE long_u /* for generating prototypes */ |
| 113 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 114 | |
Bram Moolenaar | b61f95c | 2010-08-09 22:06:13 +0200 | [diff] [blame] | 115 | # ifndef WIN3264 |
| 116 | # include <dlfcn.h> |
| 117 | # define FARPROC void* |
| 118 | # define HINSTANCE void* |
Bram Moolenaar | 644d37b | 2010-11-16 19:26:02 +0100 | [diff] [blame] | 119 | # if defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL) |
Bram Moolenaar | b61f95c | 2010-08-09 22:06:13 +0200 | [diff] [blame] | 120 | # define load_dll(n) dlopen((n), RTLD_LAZY) |
| 121 | # else |
| 122 | # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) |
| 123 | # endif |
| 124 | # define close_dll dlclose |
| 125 | # define symbol_from_dll dlsym |
| 126 | # else |
Bram Moolenaar | ebbcb82 | 2010-10-23 14:02:54 +0200 | [diff] [blame] | 127 | # define load_dll vimLoadLib |
Bram Moolenaar | b61f95c | 2010-08-09 22:06:13 +0200 | [diff] [blame] | 128 | # define close_dll FreeLibrary |
| 129 | # define symbol_from_dll GetProcAddress |
| 130 | # endif |
Bram Moolenaar | bd5e15f | 2010-07-17 21:19:38 +0200 | [diff] [blame] | 131 | |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 132 | /* This makes if_python.c compile without warnings against Python 2.5 |
| 133 | * on Win32 and Win64. */ |
Bram Moolenaar | b61f95c | 2010-08-09 22:06:13 +0200 | [diff] [blame] | 134 | # undef PyRun_SimpleString |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 135 | # undef PyRun_String |
Bram Moolenaar | b61f95c | 2010-08-09 22:06:13 +0200 | [diff] [blame] | 136 | # undef PyArg_Parse |
| 137 | # undef PyArg_ParseTuple |
| 138 | # undef Py_BuildValue |
| 139 | # undef Py_InitModule4 |
| 140 | # undef Py_InitModule4_64 |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 141 | # undef PyObject_CallMethod |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 142 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | /* |
| 144 | * Wrapper defines |
| 145 | */ |
| 146 | # define PyArg_Parse dll_PyArg_Parse |
| 147 | # define PyArg_ParseTuple dll_PyArg_ParseTuple |
Bram Moolenaar | 19e6094 | 2011-06-19 00:27:51 +0200 | [diff] [blame] | 148 | # define PyMem_Free dll_PyMem_Free |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 149 | # define PyMem_Malloc dll_PyMem_Malloc |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 150 | # define PyDict_SetItemString dll_PyDict_SetItemString |
| 151 | # define PyErr_BadArgument dll_PyErr_BadArgument |
| 152 | # define PyErr_Clear dll_PyErr_Clear |
Bram Moolenaar | 4d36987 | 2013-02-20 16:09:43 +0100 | [diff] [blame] | 153 | # define PyErr_PrintEx dll_PyErr_PrintEx |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 154 | # define PyErr_NoMemory dll_PyErr_NoMemory |
| 155 | # define PyErr_Occurred dll_PyErr_Occurred |
| 156 | # define PyErr_SetNone dll_PyErr_SetNone |
| 157 | # define PyErr_SetString dll_PyErr_SetString |
| 158 | # define PyEval_InitThreads dll_PyEval_InitThreads |
| 159 | # define PyEval_RestoreThread dll_PyEval_RestoreThread |
| 160 | # define PyEval_SaveThread dll_PyEval_SaveThread |
| 161 | # ifdef PY_CAN_RECURSE |
| 162 | # define PyGILState_Ensure dll_PyGILState_Ensure |
| 163 | # define PyGILState_Release dll_PyGILState_Release |
| 164 | # endif |
| 165 | # define PyInt_AsLong dll_PyInt_AsLong |
| 166 | # define PyInt_FromLong dll_PyInt_FromLong |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 167 | # define PyLong_AsLong dll_PyLong_AsLong |
| 168 | # define PyLong_FromLong dll_PyLong_FromLong |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 169 | # define PyBool_Type (*dll_PyBool_Type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | # define PyInt_Type (*dll_PyInt_Type) |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 171 | # define PyLong_Type (*dll_PyLong_Type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | # define PyList_GetItem dll_PyList_GetItem |
Bram Moolenaar | 0ac9379 | 2006-01-21 22:16:51 +0000 | [diff] [blame] | 173 | # define PyList_Append dll_PyList_Append |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 174 | # define PyList_New dll_PyList_New |
| 175 | # define PyList_SetItem dll_PyList_SetItem |
| 176 | # define PyList_Size dll_PyList_Size |
| 177 | # define PyList_Type (*dll_PyList_Type) |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 178 | # define PySequence_Check dll_PySequence_Check |
| 179 | # define PySequence_Size dll_PySequence_Size |
| 180 | # define PySequence_GetItem dll_PySequence_GetItem |
| 181 | # define PyTuple_Size dll_PyTuple_Size |
| 182 | # define PyTuple_GetItem dll_PyTuple_GetItem |
| 183 | # define PyTuple_Type (*dll_PyTuple_Type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | # define PyImport_ImportModule dll_PyImport_ImportModule |
Bram Moolenaar | 0ac9379 | 2006-01-21 22:16:51 +0000 | [diff] [blame] | 185 | # define PyDict_New dll_PyDict_New |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 186 | # define PyDict_GetItemString dll_PyDict_GetItemString |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 187 | # define PyDict_Next dll_PyDict_Next |
| 188 | # ifdef PyMapping_Items |
| 189 | # define PY_NO_MAPPING_ITEMS |
| 190 | # else |
| 191 | # define PyMapping_Items dll_PyMapping_Items |
| 192 | # endif |
| 193 | # define PyObject_CallMethod dll_PyObject_CallMethod |
| 194 | # define PyMapping_Check dll_PyMapping_Check |
| 195 | # define PyIter_Next dll_PyIter_Next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 196 | # define PyModule_GetDict dll_PyModule_GetDict |
| 197 | # define PyRun_SimpleString dll_PyRun_SimpleString |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 198 | # define PyRun_String dll_PyRun_String |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 199 | # define PyString_AsString dll_PyString_AsString |
Bram Moolenaar | cdab905 | 2012-09-05 19:03:56 +0200 | [diff] [blame] | 200 | # define PyString_AsStringAndSize dll_PyString_AsStringAndSize |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 201 | # define PyString_FromString dll_PyString_FromString |
| 202 | # define PyString_FromStringAndSize dll_PyString_FromStringAndSize |
| 203 | # define PyString_Size dll_PyString_Size |
| 204 | # define PyString_Type (*dll_PyString_Type) |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 205 | # define PyUnicode_Type (*dll_PyUnicode_Type) |
Bram Moolenaar | cc3e85f | 2012-06-29 19:14:52 +0200 | [diff] [blame] | 206 | # undef PyUnicode_AsEncodedString |
| 207 | # define PyUnicode_AsEncodedString py_PyUnicode_AsEncodedString |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 208 | # define PyFloat_AsDouble dll_PyFloat_AsDouble |
| 209 | # define PyFloat_FromDouble dll_PyFloat_FromDouble |
| 210 | # define PyFloat_Type (*dll_PyFloat_Type) |
| 211 | # define PyImport_AddModule (*dll_PyImport_AddModule) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 212 | # define PySys_SetObject dll_PySys_SetObject |
| 213 | # define PySys_SetArgv dll_PySys_SetArgv |
| 214 | # define PyType_Type (*dll_PyType_Type) |
Bram Moolenaar | 30fec7b | 2011-03-26 18:32:05 +0100 | [diff] [blame] | 215 | # define PyType_Ready (*dll_PyType_Ready) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 216 | # define Py_BuildValue dll_Py_BuildValue |
| 217 | # define Py_FindMethod dll_Py_FindMethod |
| 218 | # define Py_InitModule4 dll_Py_InitModule4 |
Bram Moolenaar | 644d37b | 2010-11-16 19:26:02 +0100 | [diff] [blame] | 219 | # define Py_SetPythonHome dll_Py_SetPythonHome |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 220 | # define Py_Initialize dll_Py_Initialize |
Bram Moolenaar | 0e21a3f | 2005-04-17 20:28:32 +0000 | [diff] [blame] | 221 | # define Py_Finalize dll_Py_Finalize |
| 222 | # define Py_IsInitialized dll_Py_IsInitialized |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 223 | # define _PyObject_New dll__PyObject_New |
Bram Moolenaar | e721122 | 2012-06-30 13:21:08 +0200 | [diff] [blame] | 224 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
| 225 | # define _PyObject_NextNotImplemented (*dll__PyObject_NextNotImplemented) |
| 226 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 227 | # define _Py_NoneStruct (*dll__Py_NoneStruct) |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 228 | # define _Py_ZeroStruct (*dll__Py_ZeroStruct) |
| 229 | # define _Py_TrueStruct (*dll__Py_TrueStruct) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 230 | # define PyObject_Init dll__PyObject_Init |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 231 | # define PyObject_GetIter dll_PyObject_GetIter |
Bram Moolenaar | 03db85b | 2013-05-15 14:51:35 +0200 | [diff] [blame] | 232 | # define PyObject_IsTrue dll_PyObject_IsTrue |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 233 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
| 234 | # define PyType_IsSubtype dll_PyType_IsSubtype |
| 235 | # endif |
| 236 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 |
| 237 | # define PyObject_Malloc dll_PyObject_Malloc |
| 238 | # define PyObject_Free dll_PyObject_Free |
| 239 | # endif |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 240 | # ifdef PY_USE_CAPSULE |
| 241 | # define PyCapsule_New dll_PyCapsule_New |
| 242 | # define PyCapsule_GetPointer dll_PyCapsule_GetPointer |
| 243 | # else |
| 244 | # define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr |
| 245 | # define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr |
| 246 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 247 | |
| 248 | /* |
| 249 | * Pointers for dynamic link |
| 250 | */ |
| 251 | static int(*dll_PyArg_Parse)(PyObject *, char *, ...); |
| 252 | static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...); |
Bram Moolenaar | 19e6094 | 2011-06-19 00:27:51 +0200 | [diff] [blame] | 253 | static int(*dll_PyMem_Free)(void *); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 254 | static void* (*dll_PyMem_Malloc)(size_t); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 255 | static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); |
| 256 | static int(*dll_PyErr_BadArgument)(void); |
| 257 | static void(*dll_PyErr_Clear)(void); |
Bram Moolenaar | 4d36987 | 2013-02-20 16:09:43 +0100 | [diff] [blame] | 258 | static void(*dll_PyErr_PrintEx)(int); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 259 | static PyObject*(*dll_PyErr_NoMemory)(void); |
| 260 | static PyObject*(*dll_PyErr_Occurred)(void); |
| 261 | static void(*dll_PyErr_SetNone)(PyObject *); |
| 262 | static void(*dll_PyErr_SetString)(PyObject *, const char *); |
| 263 | static void(*dll_PyEval_InitThreads)(void); |
| 264 | static void(*dll_PyEval_RestoreThread)(PyThreadState *); |
| 265 | static PyThreadState*(*dll_PyEval_SaveThread)(void); |
| 266 | # ifdef PY_CAN_RECURSE |
| 267 | static PyGILState_STATE (*dll_PyGILState_Ensure)(void); |
| 268 | static void (*dll_PyGILState_Release)(PyGILState_STATE); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 269 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 270 | static long(*dll_PyInt_AsLong)(PyObject *); |
| 271 | static PyObject*(*dll_PyInt_FromLong)(long); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 272 | static long(*dll_PyLong_AsLong)(PyObject *); |
| 273 | static PyObject*(*dll_PyLong_FromLong)(long); |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 274 | static PyTypeObject* dll_PyBool_Type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 275 | static PyTypeObject* dll_PyInt_Type; |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 276 | static PyTypeObject* dll_PyLong_Type; |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 277 | static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt); |
Bram Moolenaar | 0ac9379 | 2006-01-21 22:16:51 +0000 | [diff] [blame] | 278 | static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *); |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 279 | static PyObject*(*dll_PyList_New)(PyInt size); |
| 280 | static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *); |
| 281 | static PyInt(*dll_PyList_Size)(PyObject *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 282 | static PyTypeObject* dll_PyList_Type; |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 283 | static int (*dll_PySequence_Check)(PyObject *); |
| 284 | static PyInt(*dll_PySequence_Size)(PyObject *); |
| 285 | static PyObject*(*dll_PySequence_GetItem)(PyObject *, PyInt); |
| 286 | static PyInt(*dll_PyTuple_Size)(PyObject *); |
| 287 | static PyObject*(*dll_PyTuple_GetItem)(PyObject *, PyInt); |
| 288 | static PyTypeObject* dll_PyTuple_Type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 289 | static PyObject*(*dll_PyImport_ImportModule)(const char *); |
Bram Moolenaar | 0ac9379 | 2006-01-21 22:16:51 +0000 | [diff] [blame] | 290 | static PyObject*(*dll_PyDict_New)(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 291 | static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 292 | static int (*dll_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **); |
| 293 | # ifndef PY_NO_MAPPING_ITEMS |
| 294 | static PyObject* (*dll_PyMapping_Items)(PyObject *); |
| 295 | # endif |
| 296 | static PyObject* (*dll_PyObject_CallMethod)(PyObject *, char *, PyObject *); |
| 297 | static int (*dll_PyMapping_Check)(PyObject *); |
| 298 | static PyObject* (*dll_PyIter_Next)(PyObject *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 299 | static PyObject*(*dll_PyModule_GetDict)(PyObject *); |
| 300 | static int(*dll_PyRun_SimpleString)(char *); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 301 | static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 302 | static char*(*dll_PyString_AsString)(PyObject *); |
Bram Moolenaar | cdab905 | 2012-09-05 19:03:56 +0200 | [diff] [blame] | 303 | static int(*dll_PyString_AsStringAndSize)(PyObject *, char **, int *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 304 | static PyObject*(*dll_PyString_FromString)(const char *); |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 305 | static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt); |
| 306 | static PyInt(*dll_PyString_Size)(PyObject *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 307 | static PyTypeObject* dll_PyString_Type; |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 308 | static PyTypeObject* dll_PyUnicode_Type; |
Bram Moolenaar | cc3e85f | 2012-06-29 19:14:52 +0200 | [diff] [blame] | 309 | static PyObject *(*py_PyUnicode_AsEncodedString)(PyObject *, char *, char *); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 310 | static double(*dll_PyFloat_AsDouble)(PyObject *); |
| 311 | static PyObject*(*dll_PyFloat_FromDouble)(double); |
| 312 | static PyTypeObject* dll_PyFloat_Type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 313 | static int(*dll_PySys_SetObject)(char *, PyObject *); |
| 314 | static int(*dll_PySys_SetArgv)(int, char **); |
| 315 | static PyTypeObject* dll_PyType_Type; |
Bram Moolenaar | 30fec7b | 2011-03-26 18:32:05 +0100 | [diff] [blame] | 316 | static int (*dll_PyType_Ready)(PyTypeObject *type); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 317 | static PyObject*(*dll_Py_BuildValue)(char *, ...); |
| 318 | static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *); |
| 319 | static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 320 | static PyObject*(*dll_PyImport_AddModule)(char *); |
Bram Moolenaar | 644d37b | 2010-11-16 19:26:02 +0100 | [diff] [blame] | 321 | static void(*dll_Py_SetPythonHome)(char *home); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 322 | static void(*dll_Py_Initialize)(void); |
Bram Moolenaar | 0e21a3f | 2005-04-17 20:28:32 +0000 | [diff] [blame] | 323 | static void(*dll_Py_Finalize)(void); |
| 324 | static int(*dll_Py_IsInitialized)(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 325 | static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *); |
| 326 | static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 327 | static PyObject* (*dll_PyObject_GetIter)(PyObject *); |
Bram Moolenaar | 03db85b | 2013-05-15 14:51:35 +0200 | [diff] [blame] | 328 | static int (*dll_PyObject_IsTrue)(PyObject *); |
Bram Moolenaar | e721122 | 2012-06-30 13:21:08 +0200 | [diff] [blame] | 329 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 330 | static iternextfunc dll__PyObject_NextNotImplemented; |
Bram Moolenaar | e721122 | 2012-06-30 13:21:08 +0200 | [diff] [blame] | 331 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 332 | static PyObject* dll__Py_NoneStruct; |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 333 | static PyObject* _Py_ZeroStruct; |
| 334 | static PyObject* dll__Py_TrueStruct; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 335 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
| 336 | static int (*dll_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); |
| 337 | # endif |
| 338 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 |
| 339 | static void* (*dll_PyObject_Malloc)(size_t); |
| 340 | static void (*dll_PyObject_Free)(void*); |
| 341 | # endif |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 342 | # ifdef PY_USE_CAPSULE |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 343 | static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor); |
| 344 | static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *); |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 345 | # else |
Bram Moolenaar | 221d687 | 2012-06-30 13:34:34 +0200 | [diff] [blame] | 346 | static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *)); |
| 347 | static void* (*dll_PyCObject_AsVoidPtr)(PyObject *); |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 348 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 349 | |
| 350 | static HINSTANCE hinstPython = 0; /* Instance of python.dll */ |
| 351 | |
| 352 | /* Imported exception objects */ |
| 353 | static PyObject *imp_PyExc_AttributeError; |
| 354 | static PyObject *imp_PyExc_IndexError; |
Bram Moolenaar | af6abb9 | 2013-04-24 13:04:26 +0200 | [diff] [blame] | 355 | static PyObject *imp_PyExc_KeyError; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 356 | static PyObject *imp_PyExc_KeyboardInterrupt; |
| 357 | static PyObject *imp_PyExc_TypeError; |
| 358 | static PyObject *imp_PyExc_ValueError; |
| 359 | |
| 360 | # define PyExc_AttributeError imp_PyExc_AttributeError |
| 361 | # define PyExc_IndexError imp_PyExc_IndexError |
Bram Moolenaar | af6abb9 | 2013-04-24 13:04:26 +0200 | [diff] [blame] | 362 | # define PyExc_KeyError imp_PyExc_KeyError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 363 | # define PyExc_KeyboardInterrupt imp_PyExc_KeyboardInterrupt |
| 364 | # define PyExc_TypeError imp_PyExc_TypeError |
| 365 | # define PyExc_ValueError imp_PyExc_ValueError |
| 366 | |
| 367 | /* |
| 368 | * Table of name to function pointer of python. |
| 369 | */ |
| 370 | # define PYTHON_PROC FARPROC |
| 371 | static struct |
| 372 | { |
| 373 | char *name; |
| 374 | PYTHON_PROC *ptr; |
| 375 | } python_funcname_table[] = |
| 376 | { |
Bram Moolenaar | e8cdcef | 2012-09-12 20:21:43 +0200 | [diff] [blame] | 377 | #ifndef PY_SSIZE_T_CLEAN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 378 | {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse}, |
| 379 | {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple}, |
Bram Moolenaar | e8cdcef | 2012-09-12 20:21:43 +0200 | [diff] [blame] | 380 | {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue}, |
| 381 | #else |
| 382 | {"_PyArg_Parse_SizeT", (PYTHON_PROC*)&dll_PyArg_Parse}, |
| 383 | {"_PyArg_ParseTuple_SizeT", (PYTHON_PROC*)&dll_PyArg_ParseTuple}, |
| 384 | {"_Py_BuildValue_SizeT", (PYTHON_PROC*)&dll_Py_BuildValue}, |
| 385 | #endif |
Bram Moolenaar | 19e6094 | 2011-06-19 00:27:51 +0200 | [diff] [blame] | 386 | {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 387 | {"PyMem_Malloc", (PYTHON_PROC*)&dll_PyMem_Malloc}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 388 | {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString}, |
| 389 | {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument}, |
| 390 | {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear}, |
Bram Moolenaar | 4d36987 | 2013-02-20 16:09:43 +0100 | [diff] [blame] | 391 | {"PyErr_PrintEx", (PYTHON_PROC*)&dll_PyErr_PrintEx}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 392 | {"PyErr_NoMemory", (PYTHON_PROC*)&dll_PyErr_NoMemory}, |
| 393 | {"PyErr_Occurred", (PYTHON_PROC*)&dll_PyErr_Occurred}, |
| 394 | {"PyErr_SetNone", (PYTHON_PROC*)&dll_PyErr_SetNone}, |
| 395 | {"PyErr_SetString", (PYTHON_PROC*)&dll_PyErr_SetString}, |
| 396 | {"PyEval_InitThreads", (PYTHON_PROC*)&dll_PyEval_InitThreads}, |
| 397 | {"PyEval_RestoreThread", (PYTHON_PROC*)&dll_PyEval_RestoreThread}, |
| 398 | {"PyEval_SaveThread", (PYTHON_PROC*)&dll_PyEval_SaveThread}, |
| 399 | # ifdef PY_CAN_RECURSE |
| 400 | {"PyGILState_Ensure", (PYTHON_PROC*)&dll_PyGILState_Ensure}, |
| 401 | {"PyGILState_Release", (PYTHON_PROC*)&dll_PyGILState_Release}, |
| 402 | # endif |
| 403 | {"PyInt_AsLong", (PYTHON_PROC*)&dll_PyInt_AsLong}, |
| 404 | {"PyInt_FromLong", (PYTHON_PROC*)&dll_PyInt_FromLong}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 405 | {"PyLong_AsLong", (PYTHON_PROC*)&dll_PyLong_AsLong}, |
| 406 | {"PyLong_FromLong", (PYTHON_PROC*)&dll_PyLong_FromLong}, |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 407 | {"PyBool_Type", (PYTHON_PROC*)&dll_PyBool_Type}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 408 | {"PyInt_Type", (PYTHON_PROC*)&dll_PyInt_Type}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 409 | {"PyLong_Type", (PYTHON_PROC*)&dll_PyLong_Type}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 410 | {"PyList_GetItem", (PYTHON_PROC*)&dll_PyList_GetItem}, |
Bram Moolenaar | 0ac9379 | 2006-01-21 22:16:51 +0000 | [diff] [blame] | 411 | {"PyList_Append", (PYTHON_PROC*)&dll_PyList_Append}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 412 | {"PyList_New", (PYTHON_PROC*)&dll_PyList_New}, |
| 413 | {"PyList_SetItem", (PYTHON_PROC*)&dll_PyList_SetItem}, |
| 414 | {"PyList_Size", (PYTHON_PROC*)&dll_PyList_Size}, |
| 415 | {"PyList_Type", (PYTHON_PROC*)&dll_PyList_Type}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 416 | {"PySequence_GetItem", (PYTHON_PROC*)&dll_PySequence_GetItem}, |
| 417 | {"PySequence_Size", (PYTHON_PROC*)&dll_PySequence_Size}, |
| 418 | {"PySequence_Check", (PYTHON_PROC*)&dll_PySequence_Check}, |
| 419 | {"PyTuple_GetItem", (PYTHON_PROC*)&dll_PyTuple_GetItem}, |
| 420 | {"PyTuple_Size", (PYTHON_PROC*)&dll_PyTuple_Size}, |
| 421 | {"PyTuple_Type", (PYTHON_PROC*)&dll_PyTuple_Type}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 422 | {"PyImport_ImportModule", (PYTHON_PROC*)&dll_PyImport_ImportModule}, |
| 423 | {"PyDict_GetItemString", (PYTHON_PROC*)&dll_PyDict_GetItemString}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 424 | {"PyDict_Next", (PYTHON_PROC*)&dll_PyDict_Next}, |
Bram Moolenaar | 0ac9379 | 2006-01-21 22:16:51 +0000 | [diff] [blame] | 425 | {"PyDict_New", (PYTHON_PROC*)&dll_PyDict_New}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 426 | # ifndef PY_NO_MAPPING_ITEMS |
| 427 | {"PyMapping_Items", (PYTHON_PROC*)&dll_PyMapping_Items}, |
| 428 | # endif |
| 429 | {"PyObject_CallMethod", (PYTHON_PROC*)&dll_PyObject_CallMethod}, |
| 430 | {"PyMapping_Check", (PYTHON_PROC*)&dll_PyMapping_Check}, |
| 431 | {"PyIter_Next", (PYTHON_PROC*)&dll_PyIter_Next}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 432 | {"PyModule_GetDict", (PYTHON_PROC*)&dll_PyModule_GetDict}, |
| 433 | {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 434 | {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 435 | {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString}, |
Bram Moolenaar | cdab905 | 2012-09-05 19:03:56 +0200 | [diff] [blame] | 436 | {"PyString_AsStringAndSize", (PYTHON_PROC*)&dll_PyString_AsStringAndSize}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 437 | {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString}, |
| 438 | {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize}, |
| 439 | {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size}, |
| 440 | {"PyString_Type", (PYTHON_PROC*)&dll_PyString_Type}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 441 | {"PyUnicode_Type", (PYTHON_PROC*)&dll_PyUnicode_Type}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 442 | {"PyFloat_Type", (PYTHON_PROC*)&dll_PyFloat_Type}, |
| 443 | {"PyFloat_AsDouble", (PYTHON_PROC*)&dll_PyFloat_AsDouble}, |
| 444 | {"PyFloat_FromDouble", (PYTHON_PROC*)&dll_PyFloat_FromDouble}, |
| 445 | {"PyImport_AddModule", (PYTHON_PROC*)&dll_PyImport_AddModule}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 446 | {"PySys_SetObject", (PYTHON_PROC*)&dll_PySys_SetObject}, |
| 447 | {"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv}, |
| 448 | {"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type}, |
Bram Moolenaar | 30fec7b | 2011-03-26 18:32:05 +0100 | [diff] [blame] | 449 | {"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 450 | {"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod}, |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 451 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 \ |
| 452 | && SIZEOF_SIZE_T != SIZEOF_INT |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 453 | {"Py_InitModule4_64", (PYTHON_PROC*)&dll_Py_InitModule4}, |
| 454 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 455 | {"Py_InitModule4", (PYTHON_PROC*)&dll_Py_InitModule4}, |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 456 | # endif |
Bram Moolenaar | 644d37b | 2010-11-16 19:26:02 +0100 | [diff] [blame] | 457 | {"Py_SetPythonHome", (PYTHON_PROC*)&dll_Py_SetPythonHome}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 458 | {"Py_Initialize", (PYTHON_PROC*)&dll_Py_Initialize}, |
Bram Moolenaar | 0e21a3f | 2005-04-17 20:28:32 +0000 | [diff] [blame] | 459 | {"Py_Finalize", (PYTHON_PROC*)&dll_Py_Finalize}, |
| 460 | {"Py_IsInitialized", (PYTHON_PROC*)&dll_Py_IsInitialized}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 461 | {"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New}, |
| 462 | {"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init}, |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 463 | {"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter}, |
Bram Moolenaar | 03db85b | 2013-05-15 14:51:35 +0200 | [diff] [blame] | 464 | {"PyObject_IsTrue", (PYTHON_PROC*)&dll_PyObject_IsTrue}, |
Bram Moolenaar | e721122 | 2012-06-30 13:21:08 +0200 | [diff] [blame] | 465 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 466 | {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented}, |
Bram Moolenaar | e721122 | 2012-06-30 13:21:08 +0200 | [diff] [blame] | 467 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 468 | {"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct}, |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 469 | {"_Py_ZeroStruct", (PYTHON_PROC*)&dll__Py_ZeroStruct}, |
| 470 | {"_Py_TrueStruct", (PYTHON_PROC*)&dll__Py_TrueStruct}, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 471 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 |
| 472 | {"PyType_IsSubtype", (PYTHON_PROC*)&dll_PyType_IsSubtype}, |
| 473 | # endif |
| 474 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02030000 |
| 475 | {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc}, |
| 476 | {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free}, |
| 477 | # endif |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 478 | # ifdef PY_USE_CAPSULE |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 479 | {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New}, |
| 480 | {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer}, |
Bram Moolenaar | 2afa323 | 2012-06-29 16:28:28 +0200 | [diff] [blame] | 481 | # else |
| 482 | {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr}, |
| 483 | {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr}, |
| 484 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 485 | {"", NULL}, |
| 486 | }; |
| 487 | |
| 488 | /* |
| 489 | * Free python.dll |
| 490 | */ |
| 491 | static void |
| 492 | end_dynamic_python(void) |
| 493 | { |
| 494 | if (hinstPython) |
| 495 | { |
Bram Moolenaar | bd5e15f | 2010-07-17 21:19:38 +0200 | [diff] [blame] | 496 | close_dll(hinstPython); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 497 | hinstPython = 0; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * Load library and get all pointers. |
| 503 | * Parameter 'libname' provides name of DLL. |
| 504 | * Return OK or FAIL. |
| 505 | */ |
| 506 | static int |
| 507 | python_runtime_link_init(char *libname, int verbose) |
| 508 | { |
| 509 | int i; |
Bram Moolenaar | cc3e85f | 2012-06-29 19:14:52 +0200 | [diff] [blame] | 510 | void *ucs_as_encoded_string; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 511 | |
Bram Moolenaar | 644d37b | 2010-11-16 19:26:02 +0100 | [diff] [blame] | 512 | #if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) |
Bram Moolenaar | b744b2f | 2010-08-13 16:22:57 +0200 | [diff] [blame] | 513 | /* Can't have Python and Python3 loaded at the same time. |
| 514 | * It cause a crash, because RTLD_GLOBAL is needed for |
| 515 | * standard C extension libraries of one or both python versions. */ |
Bram Moolenaar | 4c3a326 | 2010-07-24 15:42:14 +0200 | [diff] [blame] | 516 | if (python3_loaded()) |
| 517 | { |
Bram Moolenaar | 9dc93ae | 2011-08-28 16:00:19 +0200 | [diff] [blame] | 518 | if (verbose) |
| 519 | EMSG(_("E836: This Vim cannot execute :python after using :py3")); |
Bram Moolenaar | 4c3a326 | 2010-07-24 15:42:14 +0200 | [diff] [blame] | 520 | return FAIL; |
| 521 | } |
| 522 | #endif |
| 523 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 524 | if (hinstPython) |
| 525 | return OK; |
Bram Moolenaar | bd5e15f | 2010-07-17 21:19:38 +0200 | [diff] [blame] | 526 | hinstPython = load_dll(libname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 527 | if (!hinstPython) |
| 528 | { |
| 529 | if (verbose) |
| 530 | EMSG2(_(e_loadlib), libname); |
| 531 | return FAIL; |
| 532 | } |
| 533 | |
| 534 | for (i = 0; python_funcname_table[i].ptr; ++i) |
| 535 | { |
Bram Moolenaar | bd5e15f | 2010-07-17 21:19:38 +0200 | [diff] [blame] | 536 | if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 537 | python_funcname_table[i].name)) == NULL) |
| 538 | { |
Bram Moolenaar | bd5e15f | 2010-07-17 21:19:38 +0200 | [diff] [blame] | 539 | close_dll(hinstPython); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 540 | hinstPython = 0; |
| 541 | if (verbose) |
| 542 | EMSG2(_(e_loadfunc), python_funcname_table[i].name); |
| 543 | return FAIL; |
| 544 | } |
| 545 | } |
Bram Moolenaar | cc3e85f | 2012-06-29 19:14:52 +0200 | [diff] [blame] | 546 | |
| 547 | /* Load unicode functions separately as only the ucs2 or the ucs4 functions |
| 548 | * will be present in the library. */ |
| 549 | ucs_as_encoded_string = symbol_from_dll(hinstPython, |
| 550 | "PyUnicodeUCS2_AsEncodedString"); |
| 551 | if (ucs_as_encoded_string == NULL) |
| 552 | ucs_as_encoded_string = symbol_from_dll(hinstPython, |
| 553 | "PyUnicodeUCS4_AsEncodedString"); |
| 554 | if (ucs_as_encoded_string != NULL) |
| 555 | py_PyUnicode_AsEncodedString = ucs_as_encoded_string; |
| 556 | else |
| 557 | { |
| 558 | close_dll(hinstPython); |
| 559 | hinstPython = 0; |
| 560 | if (verbose) |
| 561 | EMSG2(_(e_loadfunc), "PyUnicode_UCSX_*"); |
| 562 | return FAIL; |
| 563 | } |
| 564 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 565 | return OK; |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | * If python is enabled (there is installed python on Windows system) return |
| 570 | * TRUE, else FALSE. |
| 571 | */ |
| 572 | int |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 573 | python_enabled(int verbose) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 574 | { |
| 575 | return python_runtime_link_init(DYNAMIC_PYTHON_DLL, verbose) == OK; |
| 576 | } |
| 577 | |
Bram Moolenaar | ca8a4df | 2010-07-31 19:54:14 +0200 | [diff] [blame] | 578 | /* |
| 579 | * Load the standard Python exceptions - don't import the symbols from the |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 580 | * DLL, as this can cause errors (importing data symbols is not reliable). |
| 581 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 582 | static void |
Bram Moolenaar | ca8a4df | 2010-07-31 19:54:14 +0200 | [diff] [blame] | 583 | get_exceptions(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 584 | { |
| 585 | PyObject *exmod = PyImport_ImportModule("exceptions"); |
| 586 | PyObject *exdict = PyModule_GetDict(exmod); |
| 587 | imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError"); |
| 588 | imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError"); |
Bram Moolenaar | af6abb9 | 2013-04-24 13:04:26 +0200 | [diff] [blame] | 589 | imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 590 | imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt"); |
| 591 | imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError"); |
| 592 | imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError"); |
| 593 | Py_XINCREF(imp_PyExc_AttributeError); |
| 594 | Py_XINCREF(imp_PyExc_IndexError); |
Bram Moolenaar | af6abb9 | 2013-04-24 13:04:26 +0200 | [diff] [blame] | 595 | Py_XINCREF(imp_PyExc_KeyError); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 596 | Py_XINCREF(imp_PyExc_KeyboardInterrupt); |
| 597 | Py_XINCREF(imp_PyExc_TypeError); |
| 598 | Py_XINCREF(imp_PyExc_ValueError); |
| 599 | Py_XDECREF(exmod); |
| 600 | } |
| 601 | #endif /* DYNAMIC_PYTHON */ |
| 602 | |
Bram Moolenaar | ca8a4df | 2010-07-31 19:54:14 +0200 | [diff] [blame] | 603 | static PyObject *BufferNew (buf_T *); |
| 604 | static PyObject *WindowNew(win_T *); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 605 | static PyObject *DictionaryNew(dict_T *); |
Bram Moolenaar | ca8a4df | 2010-07-31 19:54:14 +0200 | [diff] [blame] | 606 | static PyObject *LineToString(const char *); |
| 607 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 608 | static int initialised = 0; |
| 609 | #define PYINITIALISED initialised |
| 610 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 611 | #define DICTKEY_GET(err) \ |
| 612 | if (!PyString_Check(keyObject)) \ |
| 613 | { \ |
| 614 | PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \ |
| 615 | return err; \ |
| 616 | } \ |
Bram Moolenaar | cdab905 | 2012-09-05 19:03:56 +0200 | [diff] [blame] | 617 | if (PyString_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \ |
| 618 | return err; |
| 619 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 620 | #define DICTKEY_UNREF |
| 621 | #define DICTKEY_DECL |
| 622 | |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 623 | #define DESTRUCTOR_FINISH(self) Py_DECREF(self); |
| 624 | |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 625 | #define WIN_PYTHON_REF(win) win->w_python_ref |
| 626 | #define BUF_PYTHON_REF(buf) buf->b_python_ref |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 627 | #define TAB_PYTHON_REF(tab) tab->tp_python_ref |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 628 | |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 629 | static PyObject *OutputGetattr(PyObject *, char *); |
| 630 | static PyObject *BufferGetattr(PyObject *, char *); |
| 631 | static PyObject *WindowGetattr(PyObject *, char *); |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 632 | static PyObject *TabPageGetattr(PyObject *, char *); |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 633 | static PyObject *RangeGetattr(PyObject *, char *); |
| 634 | static PyObject *DictionaryGetattr(PyObject *, char*); |
| 635 | static PyObject *ListGetattr(PyObject *, char *); |
| 636 | static PyObject *FunctionGetattr(PyObject *, char *); |
| 637 | |
Bram Moolenaar | 170bf1a | 2010-07-24 23:51:45 +0200 | [diff] [blame] | 638 | /* |
| 639 | * Include the code shared with if_python3.c |
| 640 | */ |
| 641 | #include "if_py_both.h" |
| 642 | |
| 643 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 644 | /****************************************************** |
| 645 | * Internal function prototypes. |
| 646 | */ |
| 647 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 648 | static PyObject *globals; |
| 649 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 650 | static void PythonIO_Flush(void); |
| 651 | static int PythonIO_Init(void); |
| 652 | static int PythonMod_Init(void); |
| 653 | |
| 654 | /* Utility functions for the vim/python interface |
| 655 | * ---------------------------------------------- |
| 656 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 657 | |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 658 | static int SetBufferLineList(buf_T *, PyInt, PyInt, PyObject *, PyInt *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 659 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 660 | |
| 661 | /****************************************************** |
| 662 | * 1. Python interpreter main program. |
| 663 | */ |
| 664 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 665 | #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ |
| 666 | typedef PyObject PyThreadState; |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 667 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 668 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 669 | #ifdef PY_CAN_RECURSE |
| 670 | static PyGILState_STATE pygilstate = PyGILState_UNLOCKED; |
| 671 | #else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 672 | static PyThreadState *saved_python_thread = NULL; |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 673 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * Suspend a thread of the Python interpreter, other threads are allowed to |
| 677 | * run. |
| 678 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 679 | static void |
| 680 | Python_SaveThread(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 681 | { |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 682 | #ifdef PY_CAN_RECURSE |
| 683 | PyGILState_Release(pygilstate); |
| 684 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 685 | saved_python_thread = PyEval_SaveThread(); |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 686 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /* |
| 690 | * Restore a thread of the Python interpreter, waits for other threads to |
| 691 | * block. |
| 692 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 693 | static void |
| 694 | Python_RestoreThread(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 695 | { |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 696 | #ifdef PY_CAN_RECURSE |
| 697 | pygilstate = PyGILState_Ensure(); |
| 698 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 699 | PyEval_RestoreThread(saved_python_thread); |
| 700 | saved_python_thread = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 701 | #endif |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 702 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 703 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 704 | void |
| 705 | python_end() |
| 706 | { |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 707 | static int recurse = 0; |
| 708 | |
| 709 | /* If a crash occurs while doing this, don't try again. */ |
| 710 | if (recurse != 0) |
| 711 | return; |
| 712 | |
| 713 | ++recurse; |
| 714 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 715 | #ifdef DYNAMIC_PYTHON |
Bram Moolenaar | 0e21a3f | 2005-04-17 20:28:32 +0000 | [diff] [blame] | 716 | if (hinstPython && Py_IsInitialized()) |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 717 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 718 | Python_RestoreThread(); /* enter python */ |
| 719 | Py_Finalize(); |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 720 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 721 | end_dynamic_python(); |
Bram Moolenaar | 0e21a3f | 2005-04-17 20:28:32 +0000 | [diff] [blame] | 722 | #else |
| 723 | if (Py_IsInitialized()) |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 724 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 725 | Python_RestoreThread(); /* enter python */ |
| 726 | Py_Finalize(); |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 727 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 728 | #endif |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 729 | |
| 730 | --recurse; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Bram Moolenaar | 4c3a326 | 2010-07-24 15:42:14 +0200 | [diff] [blame] | 733 | #if (defined(DYNAMIC_PYTHON) && defined(FEAT_PYTHON3)) || defined(PROTO) |
| 734 | int |
| 735 | python_loaded() |
| 736 | { |
| 737 | return (hinstPython != 0); |
| 738 | } |
| 739 | #endif |
| 740 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 741 | static int |
| 742 | Python_Init(void) |
| 743 | { |
| 744 | if (!initialised) |
| 745 | { |
| 746 | #ifdef DYNAMIC_PYTHON |
| 747 | if (!python_enabled(TRUE)) |
| 748 | { |
| 749 | EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); |
| 750 | goto fail; |
| 751 | } |
| 752 | #endif |
| 753 | |
Bram Moolenaar | 644d37b | 2010-11-16 19:26:02 +0100 | [diff] [blame] | 754 | #ifdef PYTHON_HOME |
| 755 | Py_SetPythonHome(PYTHON_HOME); |
| 756 | #endif |
| 757 | |
Bram Moolenaar | 170bf1a | 2010-07-24 23:51:45 +0200 | [diff] [blame] | 758 | init_structs(); |
| 759 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 760 | #if !defined(MACOS) || defined(MACOS_X_UNIX) |
| 761 | Py_Initialize(); |
| 762 | #else |
| 763 | PyMac_Initialize(); |
| 764 | #endif |
Bram Moolenaar | 0236625 | 2013-01-30 11:44:39 +0100 | [diff] [blame] | 765 | /* Initialise threads, and below save the state using |
Bram Moolenaar | 76d711c | 2013-02-13 14:17:08 +0100 | [diff] [blame] | 766 | * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread |
Bram Moolenaar | 0236625 | 2013-01-30 11:44:39 +0100 | [diff] [blame] | 767 | * specific state (such as the system trace hook), will be lost |
| 768 | * between invocations of Python code. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 769 | PyEval_InitThreads(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 770 | #ifdef DYNAMIC_PYTHON |
| 771 | get_exceptions(); |
| 772 | #endif |
| 773 | |
| 774 | if (PythonIO_Init()) |
| 775 | goto fail; |
| 776 | |
| 777 | if (PythonMod_Init()) |
| 778 | goto fail; |
| 779 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 780 | globals = PyModule_GetDict(PyImport_AddModule("__main__")); |
| 781 | |
Bram Moolenaar | 9774ecc | 2008-11-20 10:04:53 +0000 | [diff] [blame] | 782 | /* Remove the element from sys.path that was added because of our |
| 783 | * argv[0] value in PythonMod_Init(). Previously we used an empty |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 784 | * string, but depending on the OS we then get an empty entry or |
Bram Moolenaar | 9774ecc | 2008-11-20 10:04:53 +0000 | [diff] [blame] | 785 | * the current directory in sys.path. */ |
| 786 | PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); |
| 787 | |
Bram Moolenaar | 76d711c | 2013-02-13 14:17:08 +0100 | [diff] [blame] | 788 | /* lock is created and acquired in PyEval_InitThreads() and thread |
| 789 | * state is created in Py_Initialize() |
| 790 | * there _PyGILState_NoteThreadState() also sets gilcounter to 1 |
| 791 | * (python must have threads enabled!) |
| 792 | * so the following does both: unlock GIL and save thread state in TLS |
| 793 | * without deleting thread state |
| 794 | */ |
Bram Moolenaar | 03db85b | 2013-05-15 14:51:35 +0200 | [diff] [blame] | 795 | #ifndef PY_CAN_RECURSE |
| 796 | saved_python_thread = |
| 797 | #endif |
| 798 | PyEval_SaveThread(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 799 | |
| 800 | initialised = 1; |
| 801 | } |
| 802 | |
| 803 | return 0; |
| 804 | |
| 805 | fail: |
| 806 | /* We call PythonIO_Flush() here to print any Python errors. |
| 807 | * This is OK, as it is possible to call this function even |
| 808 | * if PythonIO_Init() has not completed successfully (it will |
| 809 | * not do anything in this case). |
| 810 | */ |
| 811 | PythonIO_Flush(); |
| 812 | return -1; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * External interface |
| 817 | */ |
| 818 | static void |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 819 | DoPythonCommand(exarg_T *eap, const char *cmd, typval_T *rettv) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 820 | { |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 821 | #ifndef PY_CAN_RECURSE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 822 | static int recursive = 0; |
| 823 | #endif |
| 824 | #if defined(MACOS) && !defined(MACOS_X_UNIX) |
| 825 | GrafPtr oldPort; |
| 826 | #endif |
| 827 | #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
| 828 | char *saved_locale; |
| 829 | #endif |
| 830 | |
| 831 | #ifndef PY_CAN_RECURSE |
| 832 | if (recursive) |
| 833 | { |
| 834 | EMSG(_("E659: Cannot invoke Python recursively")); |
| 835 | return; |
| 836 | } |
| 837 | ++recursive; |
| 838 | #endif |
| 839 | |
| 840 | #if defined(MACOS) && !defined(MACOS_X_UNIX) |
| 841 | GetPort(&oldPort); |
| 842 | /* Check if the Python library is available */ |
| 843 | if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress) |
| 844 | goto theend; |
| 845 | #endif |
| 846 | if (Python_Init()) |
| 847 | goto theend; |
| 848 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 849 | if (rettv == NULL) |
| 850 | { |
| 851 | RangeStart = eap->line1; |
| 852 | RangeEnd = eap->line2; |
| 853 | } |
| 854 | else |
| 855 | { |
| 856 | RangeStart = (PyInt) curwin->w_cursor.lnum; |
| 857 | RangeEnd = RangeStart; |
| 858 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 859 | Python_Release_Vim(); /* leave vim */ |
| 860 | |
| 861 | #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
| 862 | /* Python only works properly when the LC_NUMERIC locale is "C". */ |
| 863 | saved_locale = setlocale(LC_NUMERIC, NULL); |
| 864 | if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) |
| 865 | saved_locale = NULL; |
| 866 | else |
| 867 | { |
| 868 | /* Need to make a copy, value may change when setting new locale. */ |
| 869 | saved_locale = (char *)vim_strsave((char_u *)saved_locale); |
| 870 | (void)setlocale(LC_NUMERIC, "C"); |
| 871 | } |
| 872 | #endif |
| 873 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 874 | Python_RestoreThread(); /* enter python */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 875 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 876 | if (rettv == NULL) |
| 877 | PyRun_SimpleString((char *)(cmd)); |
| 878 | else |
| 879 | { |
| 880 | PyObject *r; |
| 881 | |
| 882 | r = PyRun_String((char *)(cmd), Py_eval_input, globals, globals); |
| 883 | if (r == NULL) |
Bram Moolenaar | 4d36987 | 2013-02-20 16:09:43 +0100 | [diff] [blame] | 884 | { |
| 885 | if (PyErr_Occurred() && !msg_silent) |
| 886 | PyErr_PrintEx(0); |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 887 | EMSG(_("E858: Eval did not return a valid python object")); |
Bram Moolenaar | 4d36987 | 2013-02-20 16:09:43 +0100 | [diff] [blame] | 888 | } |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 889 | else |
| 890 | { |
| 891 | if (ConvertFromPyObject(r, rettv) == -1) |
| 892 | EMSG(_("E859: Failed to convert returned python object to vim value")); |
| 893 | Py_DECREF(r); |
| 894 | } |
| 895 | PyErr_Clear(); |
| 896 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 897 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 898 | Python_SaveThread(); /* leave python */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 899 | |
| 900 | #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
| 901 | if (saved_locale != NULL) |
| 902 | { |
| 903 | (void)setlocale(LC_NUMERIC, saved_locale); |
| 904 | vim_free(saved_locale); |
| 905 | } |
| 906 | #endif |
| 907 | |
| 908 | Python_Lock_Vim(); /* enter vim */ |
| 909 | PythonIO_Flush(); |
| 910 | #if defined(MACOS) && !defined(MACOS_X_UNIX) |
| 911 | SetPort(oldPort); |
| 912 | #endif |
| 913 | |
| 914 | theend: |
| 915 | #ifndef PY_CAN_RECURSE |
| 916 | --recursive; |
| 917 | #endif |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 918 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | /* |
| 922 | * ":python" |
| 923 | */ |
| 924 | void |
| 925 | ex_python(exarg_T *eap) |
| 926 | { |
| 927 | char_u *script; |
| 928 | |
| 929 | script = script_get(eap, eap->arg); |
| 930 | if (!eap->skip) |
| 931 | { |
| 932 | if (script == NULL) |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 933 | DoPythonCommand(eap, (char *)eap->arg, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 934 | else |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 935 | DoPythonCommand(eap, (char *)script, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 936 | } |
| 937 | vim_free(script); |
| 938 | } |
| 939 | |
| 940 | #define BUFFER_SIZE 1024 |
| 941 | |
| 942 | /* |
| 943 | * ":pyfile" |
| 944 | */ |
| 945 | void |
| 946 | ex_pyfile(exarg_T *eap) |
| 947 | { |
| 948 | static char buffer[BUFFER_SIZE]; |
| 949 | const char *file = (char *)eap->arg; |
| 950 | char *p; |
| 951 | |
| 952 | /* Have to do it like this. PyRun_SimpleFile requires you to pass a |
| 953 | * stdio file pointer, but Vim and the Python DLL are compiled with |
| 954 | * different options under Windows, meaning that stdio pointers aren't |
| 955 | * compatible between the two. Yuk. |
| 956 | * |
| 957 | * Put the string "execfile('file')" into buffer. But, we need to |
| 958 | * escape any backslashes or single quotes in the file name, so that |
| 959 | * Python won't mangle the file name. |
| 960 | */ |
| 961 | strcpy(buffer, "execfile('"); |
| 962 | p = buffer + 10; /* size of "execfile('" */ |
| 963 | |
| 964 | while (*file && p < buffer + (BUFFER_SIZE - 3)) |
| 965 | { |
| 966 | if (*file == '\\' || *file == '\'') |
| 967 | *p++ = '\\'; |
| 968 | *p++ = *file++; |
| 969 | } |
| 970 | |
| 971 | /* If we didn't finish the file name, we hit a buffer overflow */ |
| 972 | if (*file != '\0') |
| 973 | return; |
| 974 | |
| 975 | /* Put in the terminating "')" and a null */ |
| 976 | *p++ = '\''; |
| 977 | *p++ = ')'; |
| 978 | *p++ = '\0'; |
| 979 | |
| 980 | /* Execute the file */ |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 981 | DoPythonCommand(eap, buffer, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /****************************************************** |
| 985 | * 2. Python output stream: writes output via [e]msg(). |
| 986 | */ |
| 987 | |
| 988 | /* Implementation functions |
| 989 | */ |
| 990 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 991 | static PyObject * |
| 992 | OutputGetattr(PyObject *self, char *name) |
| 993 | { |
| 994 | if (strcmp(name, "softspace") == 0) |
| 995 | return PyInt_FromLong(((OutputObject *)(self))->softspace); |
| 996 | |
| 997 | return Py_FindMethod(OutputMethods, self, name); |
| 998 | } |
| 999 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1000 | /***************/ |
| 1001 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1002 | static int |
| 1003 | PythonIO_Init(void) |
| 1004 | { |
| 1005 | /* Fixups... */ |
Bram Moolenaar | 21377c8 | 2011-03-26 13:56:48 +0100 | [diff] [blame] | 1006 | PyType_Ready(&OutputType); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1007 | |
Bram Moolenaar | 170bf1a | 2010-07-24 23:51:45 +0200 | [diff] [blame] | 1008 | return PythonIO_Init_io(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /****************************************************** |
| 1012 | * 3. Implementation of the Vim module for Python |
| 1013 | */ |
| 1014 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1015 | static PyObject *ConvertToPyObject(typval_T *); |
| 1016 | static int ConvertFromPyObject(PyObject *, typval_T *); |
| 1017 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1018 | /* Window type - Implementation functions |
| 1019 | * -------------------------------------- |
| 1020 | */ |
| 1021 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1022 | #define WindowType_Check(obj) ((obj)->ob_type == &WindowType) |
| 1023 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1024 | /* Buffer type - Implementation functions |
| 1025 | * -------------------------------------- |
| 1026 | */ |
| 1027 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1028 | #define BufferType_Check(obj) ((obj)->ob_type == &BufferType) |
| 1029 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1030 | static PyInt BufferAssItem(PyObject *, PyInt, PyObject *); |
| 1031 | static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1032 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1033 | /* Line range type - Implementation functions |
| 1034 | * -------------------------------------- |
| 1035 | */ |
| 1036 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1037 | #define RangeType_Check(obj) ((obj)->ob_type == &RangeType) |
| 1038 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1039 | static PyInt RangeAssItem(PyObject *, PyInt, PyObject *); |
| 1040 | static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1041 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1042 | /* Current objects type - Implementation functions |
| 1043 | * ----------------------------------------------- |
| 1044 | */ |
| 1045 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1046 | static PySequenceMethods BufferAsSeq = { |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1047 | (PyInquiry) BufferLength, /* sq_length, len(x) */ |
Bram Moolenaar | 77fceb8 | 2012-09-05 18:54:48 +0200 | [diff] [blame] | 1048 | (binaryfunc) 0, /* BufferConcat, sq_concat, x+y */ |
| 1049 | (PyIntArgFunc) 0, /* BufferRepeat, sq_repeat, x*n */ |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1050 | (PyIntArgFunc) BufferItem, /* sq_item, x[i] */ |
| 1051 | (PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */ |
| 1052 | (PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */ |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1053 | (PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */ |
| 1054 | (objobjproc) 0, |
| 1055 | #if PY_MAJOR_VERSION >= 2 |
| 1056 | (binaryfunc) 0, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1057 | 0, |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1058 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1059 | }; |
| 1060 | |
| 1061 | /* Buffer object - Implementation |
| 1062 | */ |
| 1063 | |
| 1064 | static PyObject * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1065 | BufferGetattr(PyObject *self, char *name) |
| 1066 | { |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1067 | PyObject *r; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1068 | |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1069 | if (CheckBuffer((BufferObject *)(self))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1070 | return NULL; |
| 1071 | |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1072 | r = BufferAttr((BufferObject *)(self), name); |
| 1073 | if (r || PyErr_Occurred()) |
| 1074 | return r; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1075 | else |
| 1076 | return Py_FindMethod(BufferMethods, self, name); |
| 1077 | } |
| 1078 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1079 | /******************/ |
| 1080 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1081 | static PyInt |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1082 | BufferAssItem(PyObject *self, PyInt n, PyObject *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1083 | { |
Bram Moolenaar | 8f1723d | 2013-05-12 20:36:14 +0200 | [diff] [blame] | 1084 | return RBAsItem((BufferObject *)(self), n, val, 1, -1, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1087 | static PyInt |
| 1088 | BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1089 | { |
Bram Moolenaar | 8f1723d | 2013-05-12 20:36:14 +0200 | [diff] [blame] | 1090 | return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, -1, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1093 | static PySequenceMethods RangeAsSeq = { |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1094 | (PyInquiry) RangeLength, /* sq_length, len(x) */ |
| 1095 | (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */ |
| 1096 | (PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */ |
| 1097 | (PyIntArgFunc) RangeItem, /* sq_item, x[i] */ |
| 1098 | (PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */ |
| 1099 | (PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */ |
| 1100 | (PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */ |
| 1101 | (objobjproc) 0, |
| 1102 | #if PY_MAJOR_VERSION >= 2 |
| 1103 | (binaryfunc) 0, |
| 1104 | 0, |
| 1105 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1106 | }; |
| 1107 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1108 | /* Line range object - Implementation |
| 1109 | */ |
| 1110 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1111 | static PyObject * |
| 1112 | RangeGetattr(PyObject *self, char *name) |
| 1113 | { |
| 1114 | if (strcmp(name, "start") == 0) |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 1115 | return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->start - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1116 | else if (strcmp(name, "end") == 0) |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 1117 | return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->end - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1118 | else |
| 1119 | return Py_FindMethod(RangeMethods, self, name); |
| 1120 | } |
| 1121 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1122 | /****************/ |
| 1123 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1124 | static PyInt |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1125 | RangeAssItem(PyObject *self, PyInt n, PyObject *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1126 | { |
Bram Moolenaar | ca8a4df | 2010-07-31 19:54:14 +0200 | [diff] [blame] | 1127 | return RBAsItem(((RangeObject *)(self))->buf, n, val, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1128 | ((RangeObject *)(self))->start, |
| 1129 | ((RangeObject *)(self))->end, |
| 1130 | &((RangeObject *)(self))->end); |
| 1131 | } |
| 1132 | |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1133 | static PyInt |
| 1134 | RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1135 | { |
Bram Moolenaar | 19e6094 | 2011-06-19 00:27:51 +0200 | [diff] [blame] | 1136 | return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1137 | ((RangeObject *)(self))->start, |
| 1138 | ((RangeObject *)(self))->end, |
| 1139 | &((RangeObject *)(self))->end); |
| 1140 | } |
| 1141 | |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1142 | /* TabPage object - Implementation |
| 1143 | */ |
| 1144 | |
| 1145 | static PyObject * |
| 1146 | TabPageGetattr(PyObject *self, char *name) |
| 1147 | { |
| 1148 | PyObject *r; |
| 1149 | |
| 1150 | if (CheckTabPage((TabPageObject *)(self))) |
| 1151 | return NULL; |
| 1152 | |
| 1153 | r = TabPageAttr((TabPageObject *)(self), name); |
| 1154 | if (r || PyErr_Occurred()) |
| 1155 | return r; |
| 1156 | else |
| 1157 | return Py_FindMethod(TabPageMethods, self, name); |
| 1158 | } |
| 1159 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1160 | /* Window object - Implementation |
| 1161 | */ |
| 1162 | |
| 1163 | static PyObject * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1164 | WindowGetattr(PyObject *self, char *name) |
| 1165 | { |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1166 | PyObject *r; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1167 | |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1168 | if (CheckWindow((WindowObject *)(self))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1169 | return NULL; |
| 1170 | |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1171 | r = WindowAttr((WindowObject *)(self), name); |
| 1172 | if (r || PyErr_Occurred()) |
| 1173 | return r; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1174 | else |
| 1175 | return Py_FindMethod(WindowMethods, self, name); |
| 1176 | } |
| 1177 | |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1178 | /* Tab page list object - Definitions |
| 1179 | */ |
| 1180 | |
| 1181 | static PySequenceMethods TabListAsSeq = { |
| 1182 | (PyInquiry) TabListLength, /* sq_length, len(x) */ |
| 1183 | (binaryfunc) 0, /* sq_concat, x+y */ |
| 1184 | (PyIntArgFunc) 0, /* sq_repeat, x*n */ |
| 1185 | (PyIntArgFunc) TabListItem, /* sq_item, x[i] */ |
| 1186 | (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ |
| 1187 | (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ |
| 1188 | (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ |
| 1189 | (objobjproc) 0, |
| 1190 | #if PY_MAJOR_VERSION >= 2 |
| 1191 | (binaryfunc) 0, |
| 1192 | 0, |
| 1193 | #endif |
| 1194 | }; |
| 1195 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1196 | /* Window list object - Definitions |
| 1197 | */ |
| 1198 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1199 | static PySequenceMethods WinListAsSeq = { |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1200 | (PyInquiry) WinListLength, /* sq_length, len(x) */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1201 | (binaryfunc) 0, /* sq_concat, x+y */ |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1202 | (PyIntArgFunc) 0, /* sq_repeat, x*n */ |
| 1203 | (PyIntArgFunc) WinListItem, /* sq_item, x[i] */ |
| 1204 | (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */ |
| 1205 | (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */ |
Bram Moolenaar | 4d1da49 | 2013-04-24 13:39:15 +0200 | [diff] [blame] | 1206 | (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */ |
| 1207 | (objobjproc) 0, |
| 1208 | #if PY_MAJOR_VERSION >= 2 |
| 1209 | (binaryfunc) 0, |
| 1210 | 0, |
| 1211 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1212 | }; |
| 1213 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1214 | /* External interface |
| 1215 | */ |
| 1216 | |
| 1217 | void |
| 1218 | python_buffer_free(buf_T *buf) |
| 1219 | { |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 1220 | if (BUF_PYTHON_REF(buf) != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1221 | { |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 1222 | BufferObject *bp = BUF_PYTHON_REF(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1223 | bp->buf = INVALID_BUFFER_VALUE; |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 1224 | BUF_PYTHON_REF(buf) = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 1229 | void |
| 1230 | python_window_free(win_T *win) |
| 1231 | { |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 1232 | if (WIN_PYTHON_REF(win) != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1233 | { |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 1234 | WindowObject *wp = WIN_PYTHON_REF(win); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1235 | wp->win = INVALID_WINDOW_VALUE; |
Bram Moolenaar | 971db46 | 2013-05-12 18:44:48 +0200 | [diff] [blame] | 1236 | WIN_PYTHON_REF(win) = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1237 | } |
| 1238 | } |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1239 | |
| 1240 | void |
| 1241 | python_tabpage_free(tabpage_T *tab) |
| 1242 | { |
| 1243 | if (TAB_PYTHON_REF(tab) != NULL) |
| 1244 | { |
| 1245 | TabPageObject *tp = TAB_PYTHON_REF(tab); |
| 1246 | tp->tab = INVALID_TABPAGE_VALUE; |
| 1247 | TAB_PYTHON_REF(tab) = NULL; |
| 1248 | } |
| 1249 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | #endif |
| 1251 | |
Bram Moolenaar | dfa38d4 | 2013-05-15 13:38:47 +0200 | [diff] [blame] | 1252 | static BufMapObject TheBufferMap = |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1253 | { |
Bram Moolenaar | dfa38d4 | 2013-05-15 13:38:47 +0200 | [diff] [blame] | 1254 | PyObject_HEAD_INIT(&BufMapType) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1255 | }; |
| 1256 | |
| 1257 | static WinListObject TheWindowList = |
| 1258 | { |
| 1259 | PyObject_HEAD_INIT(&WinListType) |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1260 | NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1261 | }; |
| 1262 | |
| 1263 | static CurrentObject TheCurrent = |
| 1264 | { |
| 1265 | PyObject_HEAD_INIT(&CurrentType) |
| 1266 | }; |
| 1267 | |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1268 | static TabListObject TheTabPageList = |
| 1269 | { |
| 1270 | PyObject_HEAD_INIT(&TabListType) |
| 1271 | }; |
| 1272 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1273 | static int |
| 1274 | PythonMod_Init(void) |
| 1275 | { |
| 1276 | PyObject *mod; |
| 1277 | PyObject *dict; |
Bram Moolenaar | 230bb3f | 2013-04-24 14:07:45 +0200 | [diff] [blame] | 1278 | PyObject *tmp; |
Bram Moolenaar | 9774ecc | 2008-11-20 10:04:53 +0000 | [diff] [blame] | 1279 | /* The special value is removed from sys.path in Python_Init(). */ |
| 1280 | static char *(argv[2]) = {"/must>not&exist/foo", NULL}; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1281 | |
| 1282 | /* Fixups... */ |
Bram Moolenaar | b6c589a | 2013-05-15 14:39:52 +0200 | [diff] [blame] | 1283 | PyType_Ready(&IterType); |
Bram Moolenaar | 21377c8 | 2011-03-26 13:56:48 +0100 | [diff] [blame] | 1284 | PyType_Ready(&BufferType); |
| 1285 | PyType_Ready(&RangeType); |
| 1286 | PyType_Ready(&WindowType); |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1287 | PyType_Ready(&TabPageType); |
Bram Moolenaar | dfa38d4 | 2013-05-15 13:38:47 +0200 | [diff] [blame] | 1288 | PyType_Ready(&BufMapType); |
Bram Moolenaar | 21377c8 | 2011-03-26 13:56:48 +0100 | [diff] [blame] | 1289 | PyType_Ready(&WinListType); |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1290 | PyType_Ready(&TabListType); |
Bram Moolenaar | 21377c8 | 2011-03-26 13:56:48 +0100 | [diff] [blame] | 1291 | PyType_Ready(&CurrentType); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 1292 | PyType_Ready(&OptionsType); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1293 | |
| 1294 | /* Set sys.argv[] to avoid a crash in warn(). */ |
| 1295 | PySys_SetArgv(1, argv); |
| 1296 | |
Bram Moolenaar | e7cb9cf | 2008-06-20 14:32:41 +0000 | [diff] [blame] | 1297 | mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL, PYTHON_API_VERSION); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1298 | dict = PyModule_GetDict(mod); |
| 1299 | |
| 1300 | VimError = Py_BuildValue("s", "vim.error"); |
| 1301 | |
| 1302 | PyDict_SetItemString(dict, "error", VimError); |
Bram Moolenaar | dfa38d4 | 2013-05-15 13:38:47 +0200 | [diff] [blame] | 1303 | PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferMap); |
Bram Moolenaar | 7df2d66 | 2005-01-25 22:18:08 +0000 | [diff] [blame] | 1304 | PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent); |
| 1305 | PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList); |
Bram Moolenaar | 5e538ec | 2013-05-15 15:12:29 +0200 | [diff] [blame^] | 1306 | PyDict_SetItemString(dict, "tabpages", (PyObject *)(void *)&TheTabPageList); |
Bram Moolenaar | 230bb3f | 2013-04-24 14:07:45 +0200 | [diff] [blame] | 1307 | tmp = DictionaryNew(&globvardict); |
| 1308 | PyDict_SetItemString(dict, "vars", tmp); |
| 1309 | Py_DECREF(tmp); |
| 1310 | tmp = DictionaryNew(&vimvardict); |
| 1311 | PyDict_SetItemString(dict, "vvars", tmp); |
| 1312 | Py_DECREF(tmp); |
Bram Moolenaar | 84e0f6c | 2013-05-06 03:52:55 +0200 | [diff] [blame] | 1313 | tmp = OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL); |
| 1314 | PyDict_SetItemString(dict, "options", tmp); |
| 1315 | Py_DECREF(tmp); |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 1316 | PyDict_SetItemString(dict, "VAR_LOCKED", PyInt_FromLong(VAR_LOCKED)); |
| 1317 | PyDict_SetItemString(dict, "VAR_FIXED", PyInt_FromLong(VAR_FIXED)); |
| 1318 | PyDict_SetItemString(dict, "VAR_SCOPE", PyInt_FromLong(VAR_SCOPE)); |
| 1319 | PyDict_SetItemString(dict, "VAR_DEF_SCOPE", PyInt_FromLong(VAR_DEF_SCOPE)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1320 | |
| 1321 | if (PyErr_Occurred()) |
| 1322 | return -1; |
| 1323 | |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | /************************************************************************* |
| 1328 | * 4. Utility functions for handling the interface between Vim and Python. |
| 1329 | */ |
| 1330 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1331 | /* Convert a Vim line into a Python string. |
| 1332 | * All internal newlines are replaced by null characters. |
| 1333 | * |
| 1334 | * On errors, the Python exception data is set, and NULL is returned. |
| 1335 | */ |
| 1336 | static PyObject * |
| 1337 | LineToString(const char *str) |
| 1338 | { |
| 1339 | PyObject *result; |
Bram Moolenaar | 2c45e94 | 2008-06-04 11:35:26 +0000 | [diff] [blame] | 1340 | PyInt len = strlen(str); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1341 | char *p; |
| 1342 | |
| 1343 | /* Allocate an Python string object, with uninitialised contents. We |
| 1344 | * must do it this way, so that we can modify the string in place |
| 1345 | * later. See the Python source, Objects/stringobject.c for details. |
| 1346 | */ |
| 1347 | result = PyString_FromStringAndSize(NULL, len); |
| 1348 | if (result == NULL) |
| 1349 | return NULL; |
| 1350 | |
| 1351 | p = PyString_AsString(result); |
| 1352 | |
| 1353 | while (*str) |
| 1354 | { |
| 1355 | if (*str == '\n') |
| 1356 | *p = '\0'; |
| 1357 | else |
| 1358 | *p = *str; |
| 1359 | |
| 1360 | ++p; |
| 1361 | ++str; |
| 1362 | } |
| 1363 | |
| 1364 | return result; |
| 1365 | } |
| 1366 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1367 | static PyObject * |
| 1368 | DictionaryGetattr(PyObject *self, char *name) |
| 1369 | { |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 1370 | DictionaryObject *this = ((DictionaryObject *) (self)); |
| 1371 | |
| 1372 | if (strcmp(name, "locked") == 0) |
| 1373 | return PyInt_FromLong(this->dict->dv_lock); |
| 1374 | else if (strcmp(name, "scope") == 0) |
| 1375 | return PyInt_FromLong(this->dict->dv_scope); |
| 1376 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1377 | return Py_FindMethod(DictionaryMethods, self, name); |
| 1378 | } |
| 1379 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1380 | static PySequenceMethods ListAsSeq = { |
| 1381 | (PyInquiry) ListLength, |
| 1382 | (binaryfunc) 0, |
| 1383 | (PyIntArgFunc) 0, |
| 1384 | (PyIntArgFunc) ListItem, |
| 1385 | (PyIntIntArgFunc) ListSlice, |
| 1386 | (PyIntObjArgProc) ListAssItem, |
| 1387 | (PyIntIntObjArgProc) ListAssSlice, |
| 1388 | (objobjproc) 0, |
| 1389 | #if PY_MAJOR_VERSION >= 2 |
| 1390 | (binaryfunc) ListConcatInPlace, |
| 1391 | 0, |
| 1392 | #endif |
| 1393 | }; |
| 1394 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1395 | static PyObject * |
| 1396 | ListGetattr(PyObject *self, char *name) |
| 1397 | { |
Bram Moolenaar | 66b7985 | 2012-09-21 14:00:35 +0200 | [diff] [blame] | 1398 | if (strcmp(name, "locked") == 0) |
| 1399 | return PyInt_FromLong(((ListObject *)(self))->list->lv_lock); |
| 1400 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1401 | return Py_FindMethod(ListMethods, self, name); |
| 1402 | } |
| 1403 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1404 | static PyObject * |
| 1405 | FunctionGetattr(PyObject *self, char *name) |
| 1406 | { |
| 1407 | FunctionObject *this = (FunctionObject *)(self); |
| 1408 | |
| 1409 | if (strcmp(name, "name") == 0) |
| 1410 | return PyString_FromString((char *)(this->name)); |
| 1411 | else |
| 1412 | return Py_FindMethod(FunctionMethods, self, name); |
| 1413 | } |
| 1414 | |
| 1415 | void |
| 1416 | do_pyeval (char_u *str, typval_T *rettv) |
| 1417 | { |
| 1418 | DoPythonCommand(NULL, (char *) str, rettv); |
| 1419 | switch(rettv->v_type) |
| 1420 | { |
| 1421 | case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; |
| 1422 | case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; |
| 1423 | case VAR_FUNC: func_ref(rettv->vval.v_string); break; |
Bram Moolenaar | 77fceb8 | 2012-09-05 18:54:48 +0200 | [diff] [blame] | 1424 | case VAR_UNKNOWN: |
| 1425 | rettv->v_type = VAR_NUMBER; |
| 1426 | rettv->vval.v_number = 0; |
| 1427 | break; |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1428 | } |
| 1429 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1430 | |
| 1431 | /* Don't generate a prototype for the next function, it generates an error on |
| 1432 | * newer Python versions. */ |
| 1433 | #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO) |
| 1434 | |
| 1435 | char * |
| 1436 | Py_GetProgramName(void) |
| 1437 | { |
| 1438 | return "vim"; |
| 1439 | } |
| 1440 | #endif /* Python 1.4 */ |
Bram Moolenaar | 170bf1a | 2010-07-24 23:51:45 +0200 | [diff] [blame] | 1441 | |
Bram Moolenaar | db91395 | 2012-06-29 12:54:53 +0200 | [diff] [blame] | 1442 | void |
| 1443 | set_ref_in_python (int copyID) |
| 1444 | { |
| 1445 | set_ref_in_py(copyID); |
| 1446 | } |