annotate src/if_python.c @ 3931:b23f583e132e v7.3.721

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