annotate src/if_python.c @ 3751:b7eea2409507 v7.3.634

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