annotate src/if_python.c @ 3518:7bafe52b6245 v7.3.520

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