annotate src/if_python.c @ 2904:c249d9aa60f7 v7.3.225

updated for version 7.3.225 Problem: Using "\n" in a substitute inside ":s" does not result in a line break. Solution: Change behavior inside vim_regexec_nl(). Add tests. (Motoya Kurotsu)
author Bram Moolenaar <bram@vim.org>
date Sun, 19 Jun 2011 04:32:15 +0200
parents fe9c7da98b5e
children e4f3fa1a474e
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 {
2554
7abef60aca22 Add a configure check for RTLD_GLOBAL. (James Vega, Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents: 2528
diff changeset
371 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
372 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
373 }
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
374 #endif
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
375
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 if (hinstPython)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 return OK;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
378 hinstPython = load_dll(libname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 if (!hinstPython)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 if (verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 EMSG2(_(e_loadlib), libname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 for (i = 0; python_funcname_table[i].ptr; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 {
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
388 if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 python_funcname_table[i].name)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 {
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
391 close_dll(hinstPython);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 hinstPython = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 if (verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 EMSG2(_(e_loadfunc), python_funcname_table[i].name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 }
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 * If python is enabled (there is installed python on Windows system) return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 * TRUE, else FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 int
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
406 python_enabled(int verbose)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 return python_runtime_link_init(DYNAMIC_PYTHON_DLL, verbose) == OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
411 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
412 * Load the standard Python exceptions - don't import the symbols from the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 * DLL, as this can cause errors (importing data symbols is not reliable).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 static void
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
416 get_exceptions(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 PyObject *exmod = PyImport_ImportModule("exceptions");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 PyObject *exdict = PyModule_GetDict(exmod);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 Py_XINCREF(imp_PyExc_AttributeError);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 Py_XINCREF(imp_PyExc_IndexError);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 Py_XINCREF(imp_PyExc_KeyboardInterrupt);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 Py_XINCREF(imp_PyExc_TypeError);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 Py_XINCREF(imp_PyExc_ValueError);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 Py_XDECREF(exmod);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 #endif /* DYNAMIC_PYTHON */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
434 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
435 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
436 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
437
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
438 static PyTypeObject RangeType;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
439
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
440 /*
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 * 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
442 */
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 #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
444
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
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 /******************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 * Internal function prototypes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
450 static PyInt RangeStart;
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
451 static PyInt RangeEnd;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 static void PythonIO_Flush(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 static int PythonIO_Init(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 static int PythonMod_Init(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 /* Utility functions for the vim/python interface
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 * ----------------------------------------------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
461 static int SetBufferLineList(buf_T *, PyInt, PyInt, PyObject *, PyInt *);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
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 * 1. Python interpreter main program.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 static int initialised = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 typedef PyObject PyThreadState;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
472 #endif
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
473
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
474 #ifdef PY_CAN_RECURSE
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
475 static PyGILState_STATE pygilstate = PyGILState_UNLOCKED;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
476 #else
36
125e80798a85 updated for version 7.0021
vimboss
parents: 20
diff changeset
477 static PyThreadState *saved_python_thread = NULL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
478 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 * Suspend a thread of the Python interpreter, other threads are allowed to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 * run.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 */
36
125e80798a85 updated for version 7.0021
vimboss
parents: 20
diff changeset
484 static void
125e80798a85 updated for version 7.0021
vimboss
parents: 20
diff changeset
485 Python_SaveThread(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
487 #ifdef PY_CAN_RECURSE
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
488 PyGILState_Release(pygilstate);
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
489 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 saved_python_thread = PyEval_SaveThread();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
491 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 }
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 * Restore a thread of the Python interpreter, waits for other threads to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 * block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 */
36
125e80798a85 updated for version 7.0021
vimboss
parents: 20
diff changeset
498 static void
125e80798a85 updated for version 7.0021
vimboss
parents: 20
diff changeset
499 Python_RestoreThread(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
501 #ifdef PY_CAN_RECURSE
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
502 pygilstate = PyGILState_Ensure();
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
503 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 PyEval_RestoreThread(saved_python_thread);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 saved_python_thread = NULL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
506 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 python_end()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 {
557
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
512 static int recurse = 0;
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
513
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
514 /* If a crash occurs while doing this, don't try again. */
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
515 if (recurse != 0)
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
516 return;
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
517
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
518 ++recurse;
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
519
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 #ifdef DYNAMIC_PYTHON
242
a711f7a6852d updated for version 7.0067
vimboss
parents: 135
diff changeset
521 if (hinstPython && Py_IsInitialized())
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
522 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 671
diff changeset
523 Python_RestoreThread(); /* enter python */
8cd729851562 updated for version 7.0g
vimboss
parents: 671
diff changeset
524 Py_Finalize();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
525 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 end_dynamic_python();
242
a711f7a6852d updated for version 7.0067
vimboss
parents: 135
diff changeset
527 #else
a711f7a6852d updated for version 7.0067
vimboss
parents: 135
diff changeset
528 if (Py_IsInitialized())
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
529 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 671
diff changeset
530 Python_RestoreThread(); /* enter python */
8cd729851562 updated for version 7.0g
vimboss
parents: 671
diff changeset
531 Py_Finalize();
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
532 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 #endif
557
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
534
862863033fdd updated for version 7.0158
vimboss
parents: 502
diff changeset
535 --recurse;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537
2384
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
538 #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
539 int
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
540 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
541 {
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
542 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
543 }
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
544 #endif
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
545
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 Python_Init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 if (!initialised)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 #ifdef DYNAMIC_PYTHON
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 if (!python_enabled(TRUE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 goto fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
559 #ifdef PYTHON_HOME
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
560 Py_SetPythonHome(PYTHON_HOME);
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
561 #endif
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
562
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
563 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
564
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 #if !defined(MACOS) || defined(MACOS_X_UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 Py_Initialize();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 PyMac_Initialize();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 /* initialise threads */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 PyEval_InitThreads();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 #ifdef DYNAMIC_PYTHON
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 get_exceptions();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 if (PythonIO_Init())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 goto fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 if (PythonMod_Init())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 goto fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
1748
06317850ad3a updated for version 7.2-045
vimboss
parents: 1681
diff changeset
583 /* Remove the element from sys.path that was added because of our
06317850ad3a updated for version 7.2-045
vimboss
parents: 1681
diff changeset
584 * argv[0] value in PythonMod_Init(). Previously we used an empty
06317850ad3a updated for version 7.2-045
vimboss
parents: 1681
diff changeset
585 * 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
586 * the current directory in sys.path. */
06317850ad3a updated for version 7.2-045
vimboss
parents: 1681
diff changeset
587 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
588
36
125e80798a85 updated for version 7.0021
vimboss
parents: 20
diff changeset
589 /* the first python thread is vim's, release the lock */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 Python_SaveThread();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 initialised = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 fail:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 /* We call PythonIO_Flush() here to print any Python errors.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 * This is OK, as it is possible to call this function even
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 * if PythonIO_Init() has not completed successfully (it will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 * not do anything in this case).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 PythonIO_Flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 }
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 * External interface
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 DoPythonCommand(exarg_T *eap, const char *cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 {
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
613 #ifndef PY_CAN_RECURSE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 static int recursive = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 #if defined(MACOS) && !defined(MACOS_X_UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 GrafPtr oldPort;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 char *saved_locale;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 #ifndef PY_CAN_RECURSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 if (recursive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 EMSG(_("E659: Cannot invoke Python recursively"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 ++recursive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 #if defined(MACOS) && !defined(MACOS_X_UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 GetPort(&oldPort);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 /* Check if the Python library is available */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 if (Python_Init())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 RangeStart = eap->line1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 RangeEnd = eap->line2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 Python_Release_Vim(); /* leave vim */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 /* Python only works properly when the LC_NUMERIC locale is "C". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 saved_locale = setlocale(LC_NUMERIC, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 saved_locale = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 /* Need to make a copy, value may change when setting new locale. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 saved_locale = (char *)vim_strsave((char_u *)saved_locale);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 (void)setlocale(LC_NUMERIC, "C");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 Python_RestoreThread(); /* enter python */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 PyRun_SimpleString((char *)(cmd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 Python_SaveThread(); /* leave python */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 if (saved_locale != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 (void)setlocale(LC_NUMERIC, saved_locale);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 vim_free(saved_locale);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 Python_Lock_Vim(); /* enter vim */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 PythonIO_Flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 #if defined(MACOS) && !defined(MACOS_X_UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 SetPort(oldPort);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 theend:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 #ifndef PY_CAN_RECURSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 --recursive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 return; /* keeps lint happy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 }
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 * ":python"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 ex_python(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 char_u *script;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 script = script_get(eap, eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 if (script == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 DoPythonCommand(eap, (char *)eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 DoPythonCommand(eap, (char *)script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 vim_free(script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 #define BUFFER_SIZE 1024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 * ":pyfile"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 ex_pyfile(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 static char buffer[BUFFER_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 const char *file = (char *)eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 /* Have to do it like this. PyRun_SimpleFile requires you to pass a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 * stdio file pointer, but Vim and the Python DLL are compiled with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 * different options under Windows, meaning that stdio pointers aren't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 * compatible between the two. Yuk.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 * Put the string "execfile('file')" into buffer. But, we need to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 * escape any backslashes or single quotes in the file name, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 * Python won't mangle the file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 strcpy(buffer, "execfile('");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 p = buffer + 10; /* size of "execfile('" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 while (*file && p < buffer + (BUFFER_SIZE - 3))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 if (*file == '\\' || *file == '\'')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 *p++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 *p++ = *file++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 /* If we didn't finish the file name, we hit a buffer overflow */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 if (*file != '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 /* Put in the terminating "')" and a null */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 *p++ = '\'';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 *p++ = ')';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 *p++ = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 /* Execute the file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 DoPythonCommand(eap, buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 }
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 * 2. Python output stream: writes output via [e]msg().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 /* Implementation functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 OutputGetattr(PyObject *self, char *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 if (strcmp(name, "softspace") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 return PyInt_FromLong(((OutputObject *)(self))->softspace);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 return Py_FindMethod(OutputMethods, self, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 OutputSetattr(PyObject *self, char *name, PyObject *val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 if (val == NULL) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 if (strcmp(name, "softspace") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 if (!PyInt_Check(val)) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 ((OutputObject *)(self))->softspace = PyInt_AsLong(val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 }
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 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 PythonIO_Init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 /* Fixups... */
2735
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
793 PyType_Ready(&OutputType);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794
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
795 return PythonIO_Init_io();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 }
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 * 3. Implementation of the Vim module for Python
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 /* Window type - Implementation functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 * --------------------------------------
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 #define WindowType_Check(obj) ((obj)->ob_type == &WindowType)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 static void WindowDestructor(PyObject *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 static PyObject *WindowGetattr(PyObject *, char *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 /* Buffer type - Implementation functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 * --------------------------------------
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 #define BufferType_Check(obj) ((obj)->ob_type == &BufferType)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 static void BufferDestructor(PyObject *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 static PyObject *BufferGetattr(PyObject *, char *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 static PyObject *BufferRepr(PyObject *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
821 static PyInt BufferLength(PyObject *);
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
822 static PyObject *BufferItem(PyObject *, PyInt);
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
823 static PyObject *BufferSlice(PyObject *, PyInt, PyInt);
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
824 static PyInt BufferAssItem(PyObject *, PyInt, PyObject *);
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
825 static PyInt BufferAssSlice(PyObject *, PyInt, PyInt, PyObject *);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 /* Line range type - Implementation functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 * --------------------------------------
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 #define RangeType_Check(obj) ((obj)->ob_type == &RangeType)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
833 static PyInt RangeAssItem(PyObject *, PyInt, PyObject *);
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
834 static PyInt RangeAssSlice(PyObject *, PyInt, PyInt, PyObject *);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 /* Current objects type - Implementation functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 * -----------------------------------------------
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 static PyObject *CurrentGetattr(PyObject *, char *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 static int CurrentSetattr(PyObject *, char *, PyObject *);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 static PySequenceMethods BufferAsSeq = {
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
844 (PyInquiry) BufferLength, /* sq_length, len(x) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 (binaryfunc) 0, /* BufferConcat, */ /* sq_concat, x+y */
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
846 (PyIntArgFunc) 0, /* BufferRepeat, */ /* sq_repeat, x*n */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
847 (PyIntArgFunc) BufferItem, /* sq_item, x[i] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
848 (PyIntIntArgFunc) BufferSlice, /* sq_slice, x[i:j] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
849 (PyIntObjArgProc) BufferAssItem, /* sq_ass_item, x[i]=v */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
850 (PyIntIntObjArgProc) BufferAssSlice, /* sq_ass_slice, x[i:j]=v */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 static PyTypeObject BufferType = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 PyObject_HEAD_INIT(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 "buffer",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 sizeof(BufferObject),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 (destructor) BufferDestructor, /* tp_dealloc, refcount==0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 (printfunc) 0, /* tp_print, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 (getattrfunc) BufferGetattr, /* tp_getattr, x.attr */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 (setattrfunc) 0, /* tp_setattr, x.attr=v */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 (cmpfunc) 0, /* tp_compare, x>y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 (reprfunc) BufferRepr, /* tp_repr, `x`, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 0, /* as number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 &BufferAsSeq, /* as sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 0, /* as mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 (hashfunc) 0, /* tp_hash, dict(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 (ternaryfunc) 0, /* tp_call, x() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 (reprfunc) 0, /* tp_str, str(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 /* Buffer object - Implementation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 BufferNew(buf_T *buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 /* We need to handle deletion of buffers underneath us.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
883 * If we add a "b_python_ref" field to the buf_T structure,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 * then we can get at it in buf_freeall() in vim. We then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 * need to create only ONE Python object per buffer - if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 * we try to create a second, just INCREF the existing one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 * and return it. The (single) Python object referring to
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
888 * the buffer is stored in "b_python_ref".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 * Question: what to do on a buf_freeall(). We'll probably
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 * have to either delete the Python object (DECREF it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 * zero - a bad idea, as it leaves dangling refs!) or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 * set the buf_T * value to an invalid value (-1?), which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 * means we need checks in all access functions... Bah.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 BufferObject *self;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
898 if (buf->b_python_ref != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
900 self = buf->b_python_ref;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 Py_INCREF(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 self = PyObject_NEW(BufferObject, &BufferType);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 if (self == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 self->buf = buf;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
909 buf->b_python_ref = self;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 return (PyObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 BufferDestructor(PyObject *self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 BufferObject *this = (BufferObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 if (this->buf && this->buf != INVALID_BUFFER_VALUE)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
921 this->buf->b_python_ref = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922
986
8fd2e00c44ae updated for version 7.0-112
vimboss
parents: 856
diff changeset
923 Py_DECREF(self);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 BufferGetattr(PyObject *self, char *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 BufferObject *this = (BufferObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 if (CheckBuffer(this))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 if (strcmp(name, "name") == 0)
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
935 return Py_BuildValue("s", this->buf->b_ffname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 else if (strcmp(name, "number") == 0)
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
937 return Py_BuildValue(Py_ssize_t_fmt, this->buf->b_fnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 else if (strcmp(name,"__members__") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 return Py_BuildValue("[ss]", "name", "number");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 return Py_FindMethod(BufferMethods, self, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 BufferRepr(PyObject *self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 242
diff changeset
947 static char repr[100];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 BufferObject *this = (BufferObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 if (this->buf == INVALID_BUFFER_VALUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 {
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
952 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 return PyString_FromString(repr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 char *name = (char *)this->buf->b_fname;
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
958 PyInt len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 name = "";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 len = strlen(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 if (len > 35)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 name = name + (35 - len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 242
diff changeset
967 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 return PyString_FromString(repr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 }
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
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
975 static PyInt
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 BufferLength(PyObject *self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 if (CheckBuffer((BufferObject *)(self)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 return -1; /* ??? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 return (((BufferObject *)(self))->buf->b_ml.ml_line_count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 static PyObject *
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
986 BufferItem(PyObject *self, PyInt n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 return RBItem((BufferObject *)(self), n, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 static PyObject *
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
993 BufferSlice(PyObject *self, PyInt lo, PyInt hi)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 return RBSlice((BufferObject *)(self), lo, hi, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 (int)((BufferObject *)(self))->buf->b_ml.ml_line_count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
999 static PyInt
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1000 BufferAssItem(PyObject *self, PyInt n, PyObject *val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 {
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1002 return RBAsItem((BufferObject *)(self), n, val, 1,
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1003 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1007 static PyInt
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1008 BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2737
diff changeset
1010 return RBAsSlice((BufferObject *)(self), lo, hi, val, 1,
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1011 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 static PySequenceMethods RangeAsSeq = {
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1016 (PyInquiry) RangeLength, /* sq_length, len(x) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 (binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1018 (PyIntArgFunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1019 (PyIntArgFunc) RangeItem, /* sq_item, x[i] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1020 (PyIntIntArgFunc) RangeSlice, /* sq_slice, x[i:j] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1021 (PyIntObjArgProc) RangeAssItem, /* sq_ass_item, x[i]=v */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1022 (PyIntIntObjArgProc) RangeAssSlice, /* sq_ass_slice, x[i:j]=v */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 /* Line range object - Implementation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 RangeDestructor(PyObject *self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 Py_DECREF(((RangeObject *)(self))->buf);
986
8fd2e00c44ae updated for version 7.0-112
vimboss
parents: 856
diff changeset
1032 Py_DECREF(self);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 RangeGetattr(PyObject *self, char *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 if (strcmp(name, "start") == 0)
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1039 return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->start - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 else if (strcmp(name, "end") == 0)
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1041 return Py_BuildValue(Py_ssize_t_fmt, ((RangeObject *)(self))->end - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 return Py_FindMethod(RangeMethods, self, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 }
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
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1048 static PyInt
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1049 RangeAssItem(PyObject *self, PyInt n, PyObject *val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 {
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1051 return RBAsItem(((RangeObject *)(self))->buf, n, val,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 ((RangeObject *)(self))->start,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 ((RangeObject *)(self))->end,
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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1057 static PyInt
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1058 RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2737
diff changeset
1060 return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 ((RangeObject *)(self))->start,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 ((RangeObject *)(self))->end,
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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 /* Buffer list object - Definitions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 PyObject_HEAD
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1072 } BufListObject;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 static PySequenceMethods BufListAsSeq = {
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1075 (PyInquiry) BufListLength, /* sq_length, len(x) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 (binaryfunc) 0, /* sq_concat, x+y */
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1077 (PyIntArgFunc) 0, /* sq_repeat, x*n */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1078 (PyIntArgFunc) BufListItem, /* sq_item, x[i] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1079 (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1080 (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1081 (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 static PyTypeObject BufListType = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 PyObject_HEAD_INIT(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 "buffer list",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 sizeof(BufListObject),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 (destructor) 0, /* tp_dealloc, refcount==0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 (printfunc) 0, /* tp_print, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 (getattrfunc) 0, /* tp_getattr, x.attr */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 (setattrfunc) 0, /* tp_setattr, x.attr=v */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 (cmpfunc) 0, /* tp_compare, x>y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 (reprfunc) 0, /* tp_repr, `x`, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 0, /* as number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 &BufListAsSeq, /* as sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 0, /* as mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 (hashfunc) 0, /* tp_hash, dict(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 (ternaryfunc) 0, /* tp_call, x() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 (reprfunc) 0, /* tp_str, str(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 /* Window object - Definitions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 static struct PyMethodDef WindowMethods[] = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 /* name, function, calling, documentation */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 { NULL, NULL, 0, NULL }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 static PyTypeObject WindowType = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 PyObject_HEAD_INIT(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 "window",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 sizeof(WindowObject),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 (destructor) WindowDestructor, /* tp_dealloc, refcount==0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 (printfunc) 0, /* tp_print, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 (getattrfunc) WindowGetattr, /* tp_getattr, x.attr */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 (setattrfunc) WindowSetattr, /* tp_setattr, x.attr=v */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 (cmpfunc) 0, /* tp_compare, x>y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 (reprfunc) WindowRepr, /* tp_repr, `x`, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 0, /* as number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 0, /* as sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 0, /* as mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 (hashfunc) 0, /* tp_hash, dict(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 (ternaryfunc) 0, /* tp_call, x() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 (reprfunc) 0, /* tp_str, str(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 /* Window object - Implementation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 WindowNew(win_T *win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 /* We need to handle deletion of windows underneath us.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1145 * If we add a "w_python_ref" field to the win_T structure,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 * then we can get at it in win_free() in vim. We then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 * need to create only ONE Python object per window - if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 * we try to create a second, just INCREF the existing one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 * and return it. The (single) Python object referring to
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1150 * the window is stored in "w_python_ref".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 * On a win_free() we set the Python object's win_T* field
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 * to an invalid value. We trap all uses of a window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 * object, and reject them if the win_T* field is invalid.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 WindowObject *self;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1158 if (win->w_python_ref)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1160 self = win->w_python_ref;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 Py_INCREF(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 self = PyObject_NEW(WindowObject, &WindowType);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 if (self == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 self->win = win;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1169 win->w_python_ref = self;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 return (PyObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 WindowDestructor(PyObject *self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 WindowObject *this = (WindowObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 if (this->win && this->win != INVALID_WINDOW_VALUE)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1181 this->win->w_python_ref = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182
986
8fd2e00c44ae updated for version 7.0-112
vimboss
parents: 856
diff changeset
1183 Py_DECREF(self);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 WindowGetattr(PyObject *self, char *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 WindowObject *this = (WindowObject *)(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 if (CheckWindow(this))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 if (strcmp(name, "buffer") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 return (PyObject *)BufferNew(this->win->w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 else if (strcmp(name, "cursor") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 pos_T *pos = &this->win->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 else if (strcmp(name, "height") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 return Py_BuildValue("l", (long)(this->win->w_height));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 #ifdef FEAT_VERTSPLIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 else if (strcmp(name, "width") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 return Py_BuildValue("l", (long)(W_WIDTH(this->win)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 else if (strcmp(name,"__members__") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 return Py_BuildValue("[sss]", "buffer", "cursor", "height");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 return Py_FindMethod(WindowMethods, self, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 /* Window list object - Definitions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 PyObject_HEAD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 WinListObject;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 static PySequenceMethods WinListAsSeq = {
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1224 (PyInquiry) WinListLength, /* sq_length, len(x) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 (binaryfunc) 0, /* sq_concat, x+y */
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1226 (PyIntArgFunc) 0, /* sq_repeat, x*n */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1227 (PyIntArgFunc) WinListItem, /* sq_item, x[i] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1228 (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1229 (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1230 (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 static PyTypeObject WinListType = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 PyObject_HEAD_INIT(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 "window list",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 sizeof(WinListObject),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 (destructor) 0, /* tp_dealloc, refcount==0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 (printfunc) 0, /* tp_print, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 (getattrfunc) 0, /* tp_getattr, x.attr */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 (setattrfunc) 0, /* tp_setattr, x.attr=v */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 (cmpfunc) 0, /* tp_compare, x>y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 (reprfunc) 0, /* tp_repr, `x`, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 0, /* as number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 &WinListAsSeq, /* as sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 0, /* as mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 (hashfunc) 0, /* tp_hash, dict(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 (ternaryfunc) 0, /* tp_call, x() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 (reprfunc) 0, /* tp_str, str(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 /* Current items object - Definitions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 PyObject_HEAD
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1262 } CurrentObject;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 static PyTypeObject CurrentType = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 PyObject_HEAD_INIT(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 "current data",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 sizeof(CurrentObject),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 (destructor) 0, /* tp_dealloc, refcount==0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 (printfunc) 0, /* tp_print, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 (getattrfunc) CurrentGetattr, /* tp_getattr, x.attr */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 (setattrfunc) CurrentSetattr, /* tp_setattr, x.attr=v */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 (cmpfunc) 0, /* tp_compare, x>y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 (reprfunc) 0, /* tp_repr, `x`, print x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 0, /* as number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 0, /* as sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 0, /* as mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 (hashfunc) 0, /* tp_hash, dict(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 (ternaryfunc) 0, /* tp_call, x() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 (reprfunc) 0, /* tp_str, str(x) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 /* Current items object - Implementation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 static PyObject *
1887
fc89a4f98a8b updated for version 7.2-184
vimboss
parents: 1786
diff changeset
1290 CurrentGetattr(PyObject *self UNUSED, char *name)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 if (strcmp(name, "buffer") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 return (PyObject *)BufferNew(curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 else if (strcmp(name, "window") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 return (PyObject *)WindowNew(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 else if (strcmp(name, "line") == 0)
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1297 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 else if (strcmp(name, "range") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 return RangeNew(curbuf, RangeStart, RangeEnd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 else if (strcmp(name,"__members__") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 return Py_BuildValue("[ssss]", "buffer", "window", "line", "range");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 PyErr_SetString(PyExc_AttributeError, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 }
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 static int
1887
fc89a4f98a8b updated for version 7.2-184
vimboss
parents: 1786
diff changeset
1310 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *value)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 if (strcmp(name, "line") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 {
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1314 if (SetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum, value, NULL) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 PyErr_SetString(PyExc_AttributeError, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 }
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 /* External interface
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 python_buffer_free(buf_T *buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1332 if (buf->b_python_ref != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1334 BufferObject *bp = buf->b_python_ref;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 bp->buf = INVALID_BUFFER_VALUE;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1336 buf->b_python_ref = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 }
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 #if defined(FEAT_WINDOWS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 python_window_free(win_T *win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1344 if (win->w_python_ref != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1346 WindowObject *wp = win->w_python_ref;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 wp->win = INVALID_WINDOW_VALUE;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 456
diff changeset
1348 win->w_python_ref = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 static BufListObject TheBufferList =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 PyObject_HEAD_INIT(&BufListType)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 static WinListObject TheWindowList =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 PyObject_HEAD_INIT(&WinListType)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 static CurrentObject TheCurrent =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 PyObject_HEAD_INIT(&CurrentType)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 PythonMod_Init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 PyObject *mod;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 PyObject *dict;
1748
06317850ad3a updated for version 7.2-045
vimboss
parents: 1681
diff changeset
1373 /* The special value is removed from sys.path in Python_Init(). */
06317850ad3a updated for version 7.2-045
vimboss
parents: 1681
diff changeset
1374 static char *(argv[2]) = {"/must>not&exist/foo", NULL};
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 /* Fixups... */
2735
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
1377 PyType_Ready(&BufferType);
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
1378 PyType_Ready(&RangeType);
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
1379 PyType_Ready(&WindowType);
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
1380 PyType_Ready(&BufListType);
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
1381 PyType_Ready(&WinListType);
322a5c8d392b updated for version 7.3.144
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
1382 PyType_Ready(&CurrentType);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 /* Set sys.argv[] to avoid a crash in warn(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 PySys_SetArgv(1, argv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386
1607
4f1130893a1c updated for version 7.1-320
vimboss
parents: 1594
diff changeset
1387 mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL, PYTHON_API_VERSION);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 dict = PyModule_GetDict(mod);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 VimError = Py_BuildValue("s", "vim.error");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 PyDict_SetItemString(dict, "error", VimError);
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 36
diff changeset
1393 PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferList);
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 36
diff changeset
1394 PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent);
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 36
diff changeset
1395 PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 if (PyErr_Occurred())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 }
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 * 4. Utility functions for handling the interface between Vim and Python.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 /* Convert a Vim line into a Python string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 * All internal newlines are replaced by null characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 * On errors, the Python exception data is set, and NULL is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 static PyObject *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 LineToString(const char *str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 PyObject *result;
1594
23aeaff96141 updated for version 7.1-307
vimboss
parents: 1083
diff changeset
1416 PyInt len = strlen(str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 /* Allocate an Python string object, with uninitialised contents. We
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 * must do it this way, so that we can modify the string in place
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 * later. See the Python source, Objects/stringobject.c for details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 result = PyString_FromStringAndSize(NULL, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 if (result == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 p = PyString_AsString(result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 while (*str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 if (*str == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 *p = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 *p = *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 ++str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 return result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 }
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 /* Don't generate a prototype for the next function, it generates an error on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 * newer Python versions. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */ && !defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 Py_GetProgramName(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 return "vim";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 #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
1454
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 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
1456 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
1457 {
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 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
1459 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
1460 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
1461 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
1462 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
1463
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1464 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
1465 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
1466 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
1467 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
1468 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
1469 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
1470 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
1471 }