Mercurial > vim
annotate src/if_python3.c @ 4659:80b0081824fa v7.3.1077
updated for version 7.3.1077
Problem: Python: Allocating dict the wrong way, causing a crash.
Solution: Use py_dict_alloc(). Fix some exception problems. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 30 May 2013 22:06:33 +0200 |
parents | 07c534fe9b6c |
children | 542af01979be |
rev | line source |
---|---|
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4: |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2 * |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
4 * |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
8 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
9 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
10 * Python extensions by Paul Moore. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
11 * Changes for Unix by David Leonard. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
12 * |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
13 * This consists of four parts: |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
14 * 1. Python interpreter main program |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
15 * 2. Python output stream: writes output via [e]msg(). |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
16 * 3. Implementation of the Vim module for Python |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
17 * 4. Utility functions for handling the interface between Vim and Python. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
18 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
19 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
20 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
21 * Roland Puntaier 2009/sept/16: |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
22 * Adaptations to support both python3.x and python2.x |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
23 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
24 |
2716 | 25 /* uncomment this if used with the debug version of python */ |
26 /* #define Py_DEBUG */ | |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
27 /* Note: most of time you can add -DPy_DEBUG to CFLAGS in place of uncommenting |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
28 */ |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
29 /* uncomment this if used with the debug version of python, but without its |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
30 * allocator */ |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
31 /* #define Py_DEBUG_NO_PYMALLOC */ |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
32 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
33 #include "vim.h" |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
34 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
35 #include <limits.h> |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
36 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
37 /* Python.h defines _POSIX_THREADS itself (if needed) */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
38 #ifdef _POSIX_THREADS |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
39 # undef _POSIX_THREADS |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
40 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
41 |
2404
eb4718cb2a76
Include old Python changes in Python 3 interface.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
42 #if defined(_WIN32) && defined(HAVE_FCNTL_H) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
43 # undef HAVE_FCNTL_H |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
44 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
45 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
46 #ifdef _DEBUG |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
47 # undef _DEBUG |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
48 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
49 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
50 #ifdef F_BLANK |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
51 # undef F_BLANK |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
52 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
53 |
2340
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
54 #ifdef HAVE_STDARG_H |
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
55 # undef HAVE_STDARG_H /* Python's config.h defines it as well. */ |
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
56 #endif |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
57 #ifdef _POSIX_C_SOURCE /* defined in feature.h */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
58 # undef _POSIX_C_SOURCE |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
59 #endif |
2340
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
60 #ifdef _XOPEN_SOURCE |
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
61 # undef _XOPEN_SOURCE /* pyconfig.h defines it as well. */ |
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
62 #endif |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
63 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
64 #include <Python.h> |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
65 #if defined(MACOS) && !defined(MACOS_X_UNIX) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
66 # include "macglue.h" |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
67 # include <CodeFragments.h> |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
68 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
69 #undef main /* Defined in python.h - aargh */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
70 #undef HAVE_FCNTL_H /* Clash with os_win32.h */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
71 |
3806 | 72 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 |
73 # define PY_SSIZE_T_CLEAN | |
74 #endif | |
75 | |
2955 | 76 /* The "surrogateescape" error handler is new in Python 3.1 */ |
77 #if PY_VERSION_HEX >= 0x030100f0 | |
78 # define CODEC_ERROR_HANDLER "surrogateescape" | |
79 #else | |
80 # define CODEC_ERROR_HANDLER NULL | |
81 #endif | |
82 | |
3638 | 83 /* Python 3 does not support CObjects, always use Capsules */ |
84 #define PY_USE_CAPSULE | |
85 | |
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
|
86 #define PyInt Py_ssize_t |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2404
diff
changeset
|
87 #define PyString_Check(obj) PyUnicode_Check(obj) |
3618 | 88 #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER) |
2894 | 89 #define PyString_FreeBytes(obj) Py_XDECREF(bytes) |
90 #define PyString_AsString(obj) PyBytes_AsString(obj) | |
91 #define PyString_Size(obj) PyBytes_GET_SIZE(bytes) | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2404
diff
changeset
|
92 #define PyString_FromString(repr) PyUnicode_FromString(repr) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
93 #define PyString_FromFormat PyUnicode_FromFormat |
3800 | 94 #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len) |
3826 | 95 #define PyInt_Check(obj) PyLong_Check(obj) |
96 #define PyInt_FromLong(i) PyLong_FromLong(i) | |
97 #define PyInt_AsLong(obj) PyLong_AsLong(obj) | |
4319 | 98 #define Py_ssize_t_fmt "n" |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
99 #define Py_bytes_fmt "y" |
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
|
100 |
2716 | 101 #if defined(DYNAMIC_PYTHON3) || defined(PROTO) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
102 |
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
|
103 # 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
|
104 # 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
|
105 # 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
|
106 # define HINSTANCE void* |
2641 | 107 # 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
|
108 # 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
|
109 # 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
|
110 # 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
|
111 # 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
|
112 # 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
|
113 # 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
|
114 # else |
2612 | 115 # 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
|
116 # 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
|
117 # 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
|
118 # endif |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
119 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
120 * Wrapper defines |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
121 */ |
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
|
122 # undef PyArg_Parse |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
123 # define PyArg_Parse py3_PyArg_Parse |
2528
8bc2e8390c11
When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents:
2447
diff
changeset
|
124 # undef PyArg_ParseTuple |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
125 # define PyArg_ParseTuple py3_PyArg_ParseTuple |
2894 | 126 # define PyMem_Free py3_PyMem_Free |
3618 | 127 # define PyMem_Malloc py3_PyMem_Malloc |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
128 # define PyDict_SetItemString py3_PyDict_SetItemString |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
129 # define PyErr_BadArgument py3_PyErr_BadArgument |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
130 # define PyErr_Clear py3_PyErr_Clear |
4145 | 131 # define PyErr_PrintEx py3_PyErr_PrintEx |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
132 # define PyErr_NoMemory py3_PyErr_NoMemory |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
133 # define PyErr_Occurred py3_PyErr_Occurred |
4417 | 134 # define PyErr_PrintEx py3_PyErr_PrintEx |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
135 # define PyErr_SetNone py3_PyErr_SetNone |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
136 # define PyErr_SetString py3_PyErr_SetString |
4403 | 137 # define PyErr_SetObject py3_PyErr_SetObject |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
138 # define PyEval_InitThreads py3_PyEval_InitThreads |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
139 # define PyEval_RestoreThread py3_PyEval_RestoreThread |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
140 # define PyEval_SaveThread py3_PyEval_SaveThread |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
141 # define PyGILState_Ensure py3_PyGILState_Ensure |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
142 # define PyGILState_Release py3_PyGILState_Release |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
143 # define PyLong_AsLong py3_PyLong_AsLong |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
144 # define PyLong_FromLong py3_PyLong_FromLong |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
145 # define PyList_GetItem py3_PyList_GetItem |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
146 # define PyList_Append py3_PyList_Append |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
147 # define PyList_New py3_PyList_New |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
148 # define PyList_SetItem py3_PyList_SetItem |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
149 # define PyList_Size py3_PyList_Size |
3618 | 150 # define PySequence_Check py3_PySequence_Check |
151 # define PySequence_Size py3_PySequence_Size | |
152 # define PySequence_GetItem py3_PySequence_GetItem | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
153 # define PySequence_Fast py3_PySequence_Fast |
3618 | 154 # define PyTuple_Size py3_PyTuple_Size |
155 # define PyTuple_GetItem py3_PyTuple_GetItem | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
156 # define PySlice_GetIndicesEx py3_PySlice_GetIndicesEx |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
157 # define PyImport_ImportModule py3_PyImport_ImportModule |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
158 # define PyObject_Init py3__PyObject_Init |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
159 # define PyDict_New py3_PyDict_New |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
160 # define PyDict_GetItemString py3_PyDict_GetItemString |
3618 | 161 # define PyDict_Next py3_PyDict_Next |
162 # define PyMapping_Check py3_PyMapping_Check | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
163 # define PyMapping_Keys py3_PyMapping_Keys |
3618 | 164 # define PyIter_Next py3_PyIter_Next |
165 # define PyObject_GetIter py3_PyObject_GetIter | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
166 # define PyObject_GetItem py3_PyObject_GetItem |
4399 | 167 # define PyObject_IsTrue py3_PyObject_IsTrue |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
168 # define PyModule_GetDict py3_PyModule_GetDict |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
169 #undef PyRun_SimpleString |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
170 # define PyRun_SimpleString py3_PyRun_SimpleString |
3618 | 171 #undef PyRun_String |
172 # define PyRun_String py3_PyRun_String | |
4417 | 173 # define PyObject_GetAttrString py3_PyObject_GetAttrString |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
174 # define PyObject_HasAttrString py3_PyObject_HasAttrString |
4417 | 175 # define PyObject_SetAttrString py3_PyObject_SetAttrString |
176 # define PyObject_CallFunctionObjArgs py3_PyObject_CallFunctionObjArgs | |
177 # define PyEval_GetLocals py3_PyEval_GetLocals | |
178 # define PyEval_GetGlobals py3_PyEval_GetGlobals | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
179 # define PySys_SetObject py3_PySys_SetObject |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
180 # define PySys_SetArgv py3_PySys_SetArgv |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
181 # define PyType_Ready py3_PyType_Ready |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
182 #undef Py_BuildValue |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
183 # define Py_BuildValue py3_Py_BuildValue |
2641 | 184 # define Py_SetPythonHome py3_Py_SetPythonHome |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
185 # define Py_Initialize py3_Py_Initialize |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
186 # define Py_Finalize py3_Py_Finalize |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
187 # define Py_IsInitialized py3_Py_IsInitialized |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
188 # define _Py_NoneStruct (*py3__Py_NoneStruct) |
3828 | 189 # define _Py_FalseStruct (*py3__Py_FalseStruct) |
190 # define _Py_TrueStruct (*py3__Py_TrueStruct) | |
3618 | 191 # define _PyObject_NextNotImplemented (*py3__PyObject_NextNotImplemented) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
192 # define PyModule_AddObject py3_PyModule_AddObject |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
193 # define PyImport_AppendInittab py3_PyImport_AppendInittab |
4417 | 194 # define PyImport_AddModule py3_PyImport_AddModule |
3863 | 195 # if PY_VERSION_HEX >= 0x030300f0 |
196 # undef _PyUnicode_AsString | |
3910 | 197 # define _PyUnicode_AsString py3_PyUnicode_AsUTF8 |
3863 | 198 # else |
199 # define _PyUnicode_AsString py3__PyUnicode_AsString | |
200 # endif | |
2894 | 201 # undef PyUnicode_AsEncodedString |
202 # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString | |
203 # undef PyBytes_AsString | |
204 # define PyBytes_AsString py3_PyBytes_AsString | |
3798 | 205 # define PyBytes_AsStringAndSize py3_PyBytes_AsStringAndSize |
3618 | 206 # undef PyBytes_FromString |
207 # define PyBytes_FromString py3_PyBytes_FromString | |
208 # define PyFloat_FromDouble py3_PyFloat_FromDouble | |
209 # define PyFloat_AsDouble py3_PyFloat_AsDouble | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
210 # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr |
3828 | 211 # define PyType_Type (*py3_PyType_Type) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
212 # define PySlice_Type (*py3_PySlice_Type) |
3618 | 213 # define PyFloat_Type (*py3_PyFloat_Type) |
3828 | 214 # define PyBool_Type (*py3_PyBool_Type) |
2894 | 215 # define PyErr_NewException py3_PyErr_NewException |
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
|
216 # ifdef Py_DEBUG |
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
|
217 # define _Py_NegativeRefcount py3__Py_NegativeRefcount |
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
|
218 # define _Py_RefTotal (*py3__Py_RefTotal) |
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
|
219 # define _Py_Dealloc py3__Py_Dealloc |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
220 # define PyModule_Create2TraceRefs py3_PyModule_Create2TraceRefs |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
221 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
222 # define PyModule_Create2 py3_PyModule_Create2 |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
223 # endif |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
224 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
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
|
225 # define _PyObject_DebugMalloc py3__PyObject_DebugMalloc |
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
|
226 # define _PyObject_DebugFree py3__PyObject_DebugFree |
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
|
227 # 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
|
228 # define PyObject_Malloc py3_PyObject_Malloc |
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
|
229 # define PyObject_Free py3_PyObject_Free |
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
|
230 # endif |
4500 | 231 # define _PyObject_GC_New py3__PyObject_GC_New |
232 # define PyObject_GC_Del py3_PyObject_GC_Del | |
233 # define PyObject_GC_UnTrack py3_PyObject_GC_UnTrack | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
234 # define PyType_GenericAlloc py3_PyType_GenericAlloc |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
235 # define PyType_GenericNew py3_PyType_GenericNew |
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
|
236 # undef PyUnicode_FromString |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
237 # define PyUnicode_FromString py3_PyUnicode_FromString |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
238 # ifndef PyUnicode_FromFormat |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
239 # define PyUnicode_FromFormat py3_PyUnicode_FromFormat |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
240 # else |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
241 # define Py_UNICODE_USE_UCS_FUNCTIONS |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
242 # ifdef Py_UNICODE_WIDE |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
243 # define PyUnicodeUCS4_FromFormat py3_PyUnicodeUCS4_FromFormat |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
244 # else |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
245 # define PyUnicodeUCS2_FromFormat py3_PyUnicodeUCS2_FromFormat |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
246 # endif |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
247 # endif |
2894 | 248 # undef PyUnicode_Decode |
249 # define PyUnicode_Decode py3_PyUnicode_Decode | |
3618 | 250 # define PyType_IsSubtype py3_PyType_IsSubtype |
251 # define PyCapsule_New py3_PyCapsule_New | |
252 # define PyCapsule_GetPointer py3_PyCapsule_GetPointer | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
253 |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
254 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
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
|
255 # undef PyObject_NEW |
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
|
256 # define PyObject_NEW(type, typeobj) \ |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
257 ( (type *) PyObject_Init( \ |
2330 | 258 (PyObject *) _PyObject_DebugMalloc( _PyObject_SIZE(typeobj) ), (typeobj)) ) |
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
|
259 # 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
|
260 |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
261 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
262 * Pointers for dynamic link |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
263 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
264 static int (*py3_PySys_SetArgv)(int, wchar_t **); |
2641 | 265 static void (*py3_Py_SetPythonHome)(wchar_t *home); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
266 static void (*py3_Py_Initialize)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
267 static PyObject* (*py3_PyList_New)(Py_ssize_t size); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
268 static PyGILState_STATE (*py3_PyGILState_Ensure)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
269 static void (*py3_PyGILState_Release)(PyGILState_STATE); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
270 static int (*py3_PySys_SetObject)(char *, PyObject *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
271 static PyObject* (*py3_PyList_Append)(PyObject *, PyObject *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
272 static Py_ssize_t (*py3_PyList_Size)(PyObject *); |
3618 | 273 static int (*py3_PySequence_Check)(PyObject *); |
274 static Py_ssize_t (*py3_PySequence_Size)(PyObject *); | |
275 static PyObject* (*py3_PySequence_GetItem)(PyObject *, Py_ssize_t); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
276 static PyObject* (*py3_PySequence_Fast)(PyObject *, const char *); |
3618 | 277 static Py_ssize_t (*py3_PyTuple_Size)(PyObject *); |
278 static PyObject* (*py3_PyTuple_GetItem)(PyObject *, Py_ssize_t); | |
279 static int (*py3_PyMapping_Check)(PyObject *); | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
280 static PyObject* (*py3_PyMapping_Keys)(PyObject *); |
3083 | 281 static int (*py3_PySlice_GetIndicesEx)(PyObject *r, Py_ssize_t length, |
2330 | 282 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
283 static PyObject* (*py3_PyErr_NoMemory)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
284 static void (*py3_Py_Finalize)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
285 static void (*py3_PyErr_SetString)(PyObject *, const char *); |
4403 | 286 static void (*py3_PyErr_SetObject)(PyObject *, PyObject *); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
287 static int (*py3_PyRun_SimpleString)(char *); |
3618 | 288 static PyObject* (*py3_PyRun_String)(char *, int, PyObject *, PyObject *); |
4417 | 289 static PyObject* (*py3_PyObject_GetAttrString)(PyObject *, const char *); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
290 static int (*py3_PyObject_HasAttrString)(PyObject *, const char *); |
4417 | 291 static PyObject* (*py3_PyObject_SetAttrString)(PyObject *, const char *, PyObject *); |
292 static PyObject* (*py3_PyObject_CallFunctionObjArgs)(PyObject *, ...); | |
293 static PyObject* (*py3_PyEval_GetGlobals)(); | |
294 static PyObject* (*py3_PyEval_GetLocals)(); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
295 static PyObject* (*py3_PyList_GetItem)(PyObject *, Py_ssize_t); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
296 static PyObject* (*py3_PyImport_ImportModule)(const char *); |
3618 | 297 static PyObject* (*py3_PyImport_AddModule)(const char *); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
298 static int (*py3_PyErr_BadArgument)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
299 static PyObject* (*py3_PyErr_Occurred)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
300 static PyObject* (*py3_PyModule_GetDict)(PyObject *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
301 static int (*py3_PyList_SetItem)(PyObject *, Py_ssize_t, PyObject *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
302 static PyObject* (*py3_PyDict_GetItemString)(PyObject *, const char *); |
3618 | 303 static int (*py3_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
304 static PyObject* (*py3_PyLong_FromLong)(long); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
305 static PyObject* (*py3_PyDict_New)(void); |
3618 | 306 static PyObject* (*py3_PyIter_Next)(PyObject *); |
307 static PyObject* (*py3_PyObject_GetIter)(PyObject *); | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
308 static PyObject* (*py3_PyObject_GetItem)(PyObject *, PyObject *); |
4399 | 309 static int (*py3_PyObject_IsTrue)(PyObject *); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
310 static PyObject* (*py3_Py_BuildValue)(char *, ...); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
311 static int (*py3_PyType_Ready)(PyTypeObject *type); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
312 static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
313 static PyObject* (*py3_PyUnicode_FromString)(const char *u); |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
314 # ifndef Py_UNICODE_USE_UCS_FUNCTIONS |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
315 static PyObject* (*py3_PyUnicode_FromFormat)(const char *u, ...); |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
316 # else |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
317 # ifdef Py_UNICODE_WIDE |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
318 static PyObject* (*py3_PyUnicodeUCS4_FromFormat)(const char *u, ...); |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
319 # else |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
320 static PyObject* (*py3_PyUnicodeUCS2_FromFormat)(const char *u, ...); |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
321 # endif |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
322 # endif |
2894 | 323 static PyObject* (*py3_PyUnicode_Decode)(const char *u, Py_ssize_t size, |
324 const char *encoding, const char *errors); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
325 static long (*py3_PyLong_AsLong)(PyObject *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
326 static void (*py3_PyErr_SetNone)(PyObject *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
327 static void (*py3_PyEval_InitThreads)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
328 static void(*py3_PyEval_RestoreThread)(PyThreadState *); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
329 static PyThreadState*(*py3_PyEval_SaveThread)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
330 static int (*py3_PyArg_Parse)(PyObject *, char *, ...); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
331 static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...); |
2894 | 332 static int (*py3_PyMem_Free)(void *); |
3618 | 333 static void* (*py3_PyMem_Malloc)(size_t); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
334 static int (*py3_Py_IsInitialized)(void); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
335 static void (*py3_PyErr_Clear)(void); |
4145 | 336 static void (*py3_PyErr_PrintEx)(int); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
337 static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *); |
3618 | 338 static iternextfunc py3__PyObject_NextNotImplemented; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
339 static PyObject* py3__Py_NoneStruct; |
3828 | 340 static PyObject* py3__Py_FalseStruct; |
341 static PyObject* py3__Py_TrueStruct; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
342 static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
343 static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void)); |
3910 | 344 # if PY_VERSION_HEX >= 0x030300f0 |
345 static char* (*py3_PyUnicode_AsUTF8)(PyObject *unicode); | |
346 # else | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
347 static char* (*py3__PyUnicode_AsString)(PyObject *unicode); |
3910 | 348 # endif |
2894 | 349 static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors); |
350 static char* (*py3_PyBytes_AsString)(PyObject *bytes); | |
3798 | 351 static int (*py3_PyBytes_AsStringAndSize)(PyObject *bytes, char **buffer, int *length); |
3618 | 352 static PyObject* (*py3_PyBytes_FromString)(char *str); |
353 static PyObject* (*py3_PyFloat_FromDouble)(double num); | |
354 static double (*py3_PyFloat_AsDouble)(PyObject *); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
355 static PyObject* (*py3_PyObject_GenericGetAttr)(PyObject *obj, PyObject *name); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
356 static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
357 static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds); |
3828 | 358 static PyTypeObject* py3_PyType_Type; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
359 static PyTypeObject* py3_PySlice_Type; |
3618 | 360 static PyTypeObject* py3_PyFloat_Type; |
3828 | 361 static PyTypeObject* py3_PyBool_Type; |
2894 | 362 static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict); |
3618 | 363 static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor); |
364 static void* (*py3_PyCapsule_GetPointer)(PyObject *, char *); | |
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
|
365 # ifdef Py_DEBUG |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
366 static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
367 static Py_ssize_t* py3__Py_RefTotal; |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
368 static void (*py3__Py_Dealloc)(PyObject *obj); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
369 static PyObject* (*py3_PyModule_Create2TraceRefs)(struct PyModuleDef* module, int module_api_version); |
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
|
370 # else |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
371 static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
372 # endif |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
373 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
374 static void (*py3__PyObject_DebugFree)(void*); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
375 static void* (*py3__PyObject_DebugMalloc)(size_t); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
376 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
377 static void (*py3_PyObject_Free)(void*); |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
378 static void* (*py3_PyObject_Malloc)(size_t); |
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
|
379 # endif |
4500 | 380 static PyObject*(*py3__PyObject_GC_New)(PyTypeObject *); |
381 static void(*py3_PyObject_GC_Del)(void *); | |
382 static void(*py3_PyObject_GC_UnTrack)(void *); | |
3618 | 383 static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
384 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
385 static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
386 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
387 /* Imported exception objects */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
388 static PyObject *p3imp_PyExc_AttributeError; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
389 static PyObject *p3imp_PyExc_IndexError; |
4315 | 390 static PyObject *p3imp_PyExc_KeyError; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
391 static PyObject *p3imp_PyExc_KeyboardInterrupt; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
392 static PyObject *p3imp_PyExc_TypeError; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
393 static PyObject *p3imp_PyExc_ValueError; |
4405 | 394 static PyObject *p3imp_PyExc_RuntimeError; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
395 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
396 # define PyExc_AttributeError p3imp_PyExc_AttributeError |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
397 # define PyExc_IndexError p3imp_PyExc_IndexError |
4315 | 398 # define PyExc_KeyError p3imp_PyExc_KeyError |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
399 # define PyExc_KeyboardInterrupt p3imp_PyExc_KeyboardInterrupt |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
400 # define PyExc_TypeError p3imp_PyExc_TypeError |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
401 # define PyExc_ValueError p3imp_PyExc_ValueError |
4405 | 402 # define PyExc_RuntimeError p3imp_PyExc_RuntimeError |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
403 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
404 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
405 * Table of name to function pointer of python. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
406 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
407 # define PYTHON_PROC FARPROC |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
408 static struct |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
409 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
410 char *name; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
411 PYTHON_PROC *ptr; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
412 } py3_funcname_table[] = |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
413 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
414 {"PySys_SetArgv", (PYTHON_PROC*)&py3_PySys_SetArgv}, |
2641 | 415 {"Py_SetPythonHome", (PYTHON_PROC*)&py3_Py_SetPythonHome}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
416 {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize}, |
3910 | 417 # ifndef PY_SSIZE_T_CLEAN |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
418 {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple}, |
3806 | 419 {"Py_BuildValue", (PYTHON_PROC*)&py3_Py_BuildValue}, |
3910 | 420 # else |
3806 | 421 {"_PyArg_ParseTuple_SizeT", (PYTHON_PROC*)&py3_PyArg_ParseTuple}, |
422 {"_Py_BuildValue_SizeT", (PYTHON_PROC*)&py3_Py_BuildValue}, | |
3910 | 423 # endif |
2894 | 424 {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free}, |
3618 | 425 {"PyMem_Malloc", (PYTHON_PROC*)&py3_PyMem_Malloc}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
426 {"PyList_New", (PYTHON_PROC*)&py3_PyList_New}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
427 {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
428 {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
429 {"PySys_SetObject", (PYTHON_PROC*)&py3_PySys_SetObject}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
430 {"PyList_Append", (PYTHON_PROC*)&py3_PyList_Append}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
431 {"PyList_Size", (PYTHON_PROC*)&py3_PyList_Size}, |
3618 | 432 {"PySequence_Check", (PYTHON_PROC*)&py3_PySequence_Check}, |
433 {"PySequence_Size", (PYTHON_PROC*)&py3_PySequence_Size}, | |
434 {"PySequence_GetItem", (PYTHON_PROC*)&py3_PySequence_GetItem}, | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
435 {"PySequence_Fast", (PYTHON_PROC*)&py3_PySequence_Fast}, |
3618 | 436 {"PyTuple_Size", (PYTHON_PROC*)&py3_PyTuple_Size}, |
437 {"PyTuple_GetItem", (PYTHON_PROC*)&py3_PyTuple_GetItem}, | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
438 {"PySlice_GetIndicesEx", (PYTHON_PROC*)&py3_PySlice_GetIndicesEx}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
439 {"PyErr_NoMemory", (PYTHON_PROC*)&py3_PyErr_NoMemory}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
440 {"Py_Finalize", (PYTHON_PROC*)&py3_Py_Finalize}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
441 {"PyErr_SetString", (PYTHON_PROC*)&py3_PyErr_SetString}, |
4403 | 442 {"PyErr_SetObject", (PYTHON_PROC*)&py3_PyErr_SetObject}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
443 {"PyRun_SimpleString", (PYTHON_PROC*)&py3_PyRun_SimpleString}, |
3618 | 444 {"PyRun_String", (PYTHON_PROC*)&py3_PyRun_String}, |
4417 | 445 {"PyObject_GetAttrString", (PYTHON_PROC*)&py3_PyObject_GetAttrString}, |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
446 {"PyObject_HasAttrString", (PYTHON_PROC*)&py3_PyObject_HasAttrString}, |
4417 | 447 {"PyObject_SetAttrString", (PYTHON_PROC*)&py3_PyObject_SetAttrString}, |
448 {"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&py3_PyObject_CallFunctionObjArgs}, | |
449 {"PyEval_GetGlobals", (PYTHON_PROC*)&py3_PyEval_GetGlobals}, | |
450 {"PyEval_GetLocals", (PYTHON_PROC*)&py3_PyEval_GetLocals}, | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
451 {"PyList_GetItem", (PYTHON_PROC*)&py3_PyList_GetItem}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
452 {"PyImport_ImportModule", (PYTHON_PROC*)&py3_PyImport_ImportModule}, |
3618 | 453 {"PyImport_AddModule", (PYTHON_PROC*)&py3_PyImport_AddModule}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
454 {"PyErr_BadArgument", (PYTHON_PROC*)&py3_PyErr_BadArgument}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
455 {"PyErr_Occurred", (PYTHON_PROC*)&py3_PyErr_Occurred}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
456 {"PyModule_GetDict", (PYTHON_PROC*)&py3_PyModule_GetDict}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
457 {"PyList_SetItem", (PYTHON_PROC*)&py3_PyList_SetItem}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
458 {"PyDict_GetItemString", (PYTHON_PROC*)&py3_PyDict_GetItemString}, |
3618 | 459 {"PyDict_Next", (PYTHON_PROC*)&py3_PyDict_Next}, |
460 {"PyMapping_Check", (PYTHON_PROC*)&py3_PyMapping_Check}, | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
461 {"PyMapping_Keys", (PYTHON_PROC*)&py3_PyMapping_Keys}, |
3618 | 462 {"PyIter_Next", (PYTHON_PROC*)&py3_PyIter_Next}, |
463 {"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter}, | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
464 {"PyObject_GetItem", (PYTHON_PROC*)&py3_PyObject_GetItem}, |
4399 | 465 {"PyObject_IsTrue", (PYTHON_PROC*)&py3_PyObject_IsTrue}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
466 {"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
467 {"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
468 {"PyType_Ready", (PYTHON_PROC*)&py3_PyType_Ready}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
469 {"PyDict_SetItemString", (PYTHON_PROC*)&py3_PyDict_SetItemString}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
470 {"PyLong_AsLong", (PYTHON_PROC*)&py3_PyLong_AsLong}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
471 {"PyErr_SetNone", (PYTHON_PROC*)&py3_PyErr_SetNone}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
472 {"PyEval_InitThreads", (PYTHON_PROC*)&py3_PyEval_InitThreads}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
473 {"PyEval_RestoreThread", (PYTHON_PROC*)&py3_PyEval_RestoreThread}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
474 {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
475 {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
476 {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized}, |
3618 | 477 {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&py3__PyObject_NextNotImplemented}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
478 {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct}, |
3828 | 479 {"_Py_FalseStruct", (PYTHON_PROC*)&py3__Py_FalseStruct}, |
480 {"_Py_TrueStruct", (PYTHON_PROC*)&py3__Py_TrueStruct}, | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
481 {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear}, |
4145 | 482 {"PyErr_PrintEx", (PYTHON_PROC*)&py3_PyErr_PrintEx}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
483 {"PyObject_Init", (PYTHON_PROC*)&py3__PyObject_Init}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
484 {"PyModule_AddObject", (PYTHON_PROC*)&py3_PyModule_AddObject}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
485 {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab}, |
3910 | 486 # if PY_VERSION_HEX >= 0x030300f0 |
487 {"PyUnicode_AsUTF8", (PYTHON_PROC*)&py3_PyUnicode_AsUTF8}, | |
488 # else | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
489 {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString}, |
3910 | 490 # endif |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
491 # ifndef Py_UNICODE_USE_UCS_FUNCTIONS |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
492 {"PyUnicode_FromFormat", (PYTHON_PROC*)&py3_PyUnicode_FromFormat}, |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
493 # else |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
494 # ifdef Py_UNICODE_WIDE |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
495 {"PyUnicodeUCS4_FromFormat", (PYTHON_PROC*)&py3_PyUnicodeUCS4_FromFormat}, |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
496 # else |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
497 {"PyUnicodeUCS2_FromFormat", (PYTHON_PROC*)&py3_PyUnicodeUCS2_FromFormat}, |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
498 # endif |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
499 # endif |
2894 | 500 {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString}, |
3798 | 501 {"PyBytes_AsStringAndSize", (PYTHON_PROC*)&py3_PyBytes_AsStringAndSize}, |
3618 | 502 {"PyBytes_FromString", (PYTHON_PROC*)&py3_PyBytes_FromString}, |
503 {"PyFloat_FromDouble", (PYTHON_PROC*)&py3_PyFloat_FromDouble}, | |
504 {"PyFloat_AsDouble", (PYTHON_PROC*)&py3_PyFloat_AsDouble}, | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
505 {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
506 {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
507 {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew}, |
3828 | 508 {"PyType_Type", (PYTHON_PROC*)&py3_PyType_Type}, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
509 {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type}, |
3618 | 510 {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type}, |
3828 | 511 {"PyBool_Type", (PYTHON_PROC*)&py3_PyBool_Type}, |
2894 | 512 {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException}, |
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
|
513 # ifdef Py_DEBUG |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
514 {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
515 {"_Py_RefTotal", (PYTHON_PROC*)&py3__Py_RefTotal}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
516 {"_Py_Dealloc", (PYTHON_PROC*)&py3__Py_Dealloc}, |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
517 {"PyModule_Create2TraceRefs", (PYTHON_PROC*)&py3_PyModule_Create2TraceRefs}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
518 # else |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
519 {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2}, |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
520 # endif |
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
521 # if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
522 {"_PyObject_DebugFree", (PYTHON_PROC*)&py3__PyObject_DebugFree}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
523 {"_PyObject_DebugMalloc", (PYTHON_PROC*)&py3__PyObject_DebugMalloc}, |
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
|
524 # else |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
525 {"PyObject_Malloc", (PYTHON_PROC*)&py3_PyObject_Malloc}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
526 {"PyObject_Free", (PYTHON_PROC*)&py3_PyObject_Free}, |
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
|
527 # endif |
4500 | 528 {"_PyObject_GC_New", (PYTHON_PROC*)&py3__PyObject_GC_New}, |
529 {"PyObject_GC_Del", (PYTHON_PROC*)&py3_PyObject_GC_Del}, | |
530 {"PyObject_GC_UnTrack", (PYTHON_PROC*)&py3_PyObject_GC_UnTrack}, | |
3618 | 531 {"PyType_IsSubtype", (PYTHON_PROC*)&py3_PyType_IsSubtype}, |
532 {"PyCapsule_New", (PYTHON_PROC*)&py3_PyCapsule_New}, | |
533 {"PyCapsule_GetPointer", (PYTHON_PROC*)&py3_PyCapsule_GetPointer}, | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
534 {"", NULL}, |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
535 }; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
536 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
537 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
538 * Free python.dll |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
539 */ |
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
|
540 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
|
541 end_dynamic_python3(void) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
542 { |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
543 if (hinstPy3 != 0) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
544 { |
2330 | 545 close_dll(hinstPy3); |
546 hinstPy3 = 0; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
547 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
548 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
549 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
550 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
551 * Load library and get all pointers. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
552 * Parameter 'libname' provides name of DLL. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
553 * Return OK or FAIL. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
554 */ |
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
|
555 static int |
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
|
556 py3_runtime_link_init(char *libname, int verbose) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
557 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
558 int i; |
2894 | 559 void *ucs_from_string, *ucs_decode, *ucs_as_encoded_string; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
560 |
2641 | 561 # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON) |
2554
7abef60aca22
Add a configure check for RTLD_GLOBAL. (James Vega, Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2528
diff
changeset
|
562 /* 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
|
563 * 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
|
564 * 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
|
565 if (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
|
566 { |
3032 | 567 if (verbose) |
568 EMSG(_("E837: This Vim cannot execute :py3 after using :python")); | |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
569 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
|
570 } |
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
|
571 # endif |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
572 |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
573 if (hinstPy3 != 0) |
2330 | 574 return OK; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
575 hinstPy3 = load_dll(libname); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
576 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
577 if (!hinstPy3) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
578 { |
2330 | 579 if (verbose) |
580 EMSG2(_(e_loadlib), libname); | |
581 return FAIL; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
582 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
583 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
584 for (i = 0; py3_funcname_table[i].ptr; ++i) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
585 { |
2330 | 586 if ((*py3_funcname_table[i].ptr = symbol_from_dll(hinstPy3, |
587 py3_funcname_table[i].name)) == NULL) | |
588 { | |
589 close_dll(hinstPy3); | |
590 hinstPy3 = 0; | |
591 if (verbose) | |
592 EMSG2(_(e_loadfunc), py3_funcname_table[i].name); | |
593 return FAIL; | |
594 } | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
595 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
596 |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2340
diff
changeset
|
597 /* Load unicode functions separately as only the ucs2 or the ucs4 functions |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2340
diff
changeset
|
598 * will be present in the library. */ |
3910 | 599 # if PY_VERSION_HEX >= 0x030300f0 |
3863 | 600 ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicode_FromString"); |
601 ucs_decode = symbol_from_dll(hinstPy3, "PyUnicode_Decode"); | |
602 ucs_as_encoded_string = symbol_from_dll(hinstPy3, | |
603 "PyUnicode_AsEncodedString"); | |
3910 | 604 # else |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
605 ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString"); |
2894 | 606 ucs_decode = symbol_from_dll(hinstPy3, |
607 "PyUnicodeUCS2_Decode"); | |
608 ucs_as_encoded_string = symbol_from_dll(hinstPy3, | |
609 "PyUnicodeUCS2_AsEncodedString"); | |
610 if (!ucs_from_string || !ucs_decode || !ucs_as_encoded_string) | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
611 { |
2330 | 612 ucs_from_string = symbol_from_dll(hinstPy3, |
613 "PyUnicodeUCS4_FromString"); | |
2894 | 614 ucs_decode = symbol_from_dll(hinstPy3, |
615 "PyUnicodeUCS4_Decode"); | |
616 ucs_as_encoded_string = symbol_from_dll(hinstPy3, | |
617 "PyUnicodeUCS4_AsEncodedString"); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
618 } |
3910 | 619 # endif |
2894 | 620 if (ucs_from_string && ucs_decode && ucs_as_encoded_string) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
621 { |
2330 | 622 py3_PyUnicode_FromString = ucs_from_string; |
2894 | 623 py3_PyUnicode_Decode = ucs_decode; |
624 py3_PyUnicode_AsEncodedString = ucs_as_encoded_string; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
625 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
626 else |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
627 { |
2330 | 628 close_dll(hinstPy3); |
629 hinstPy3 = 0; | |
630 if (verbose) | |
631 EMSG2(_(e_loadfunc), "PyUnicode_UCSX_*"); | |
632 return FAIL; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
633 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
634 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
635 return OK; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
636 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
637 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
638 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
639 * If python is enabled (there is installed python on Windows system) return |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
640 * TRUE, else FALSE. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
641 */ |
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
|
642 int |
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
|
643 python3_enabled(int verbose) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
644 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
645 return py3_runtime_link_init(DYNAMIC_PYTHON3_DLL, verbose) == OK; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
646 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
647 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
648 /* Load the standard Python exceptions - don't import the symbols from the |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
649 * DLL, as this can cause errors (importing data symbols is not reliable). |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
650 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
651 static void get_py3_exceptions __ARGS((void)); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
652 |
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
|
653 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
|
654 get_py3_exceptions() |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
655 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
656 PyObject *exmod = PyImport_ImportModule("builtins"); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
657 PyObject *exdict = PyModule_GetDict(exmod); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
658 p3imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError"); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
659 p3imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError"); |
4315 | 660 p3imp_PyExc_KeyError = PyDict_GetItemString(exdict, "KeyError"); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
661 p3imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt"); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
662 p3imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError"); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
663 p3imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError"); |
4405 | 664 p3imp_PyExc_RuntimeError = PyDict_GetItemString(exdict, "RuntimeError"); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
665 Py_XINCREF(p3imp_PyExc_AttributeError); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
666 Py_XINCREF(p3imp_PyExc_IndexError); |
4315 | 667 Py_XINCREF(p3imp_PyExc_KeyError); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
668 Py_XINCREF(p3imp_PyExc_KeyboardInterrupt); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
669 Py_XINCREF(p3imp_PyExc_TypeError); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
670 Py_XINCREF(p3imp_PyExc_ValueError); |
4405 | 671 Py_XINCREF(p3imp_PyExc_RuntimeError); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
672 Py_XDECREF(exmod); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
673 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
674 #endif /* DYNAMIC_PYTHON3 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
675 |
3618 | 676 static int py3initialised = 0; |
677 | |
678 #define PYINITIALISED py3initialised | |
679 | |
4500 | 680 #define DESTRUCTOR_FINISH(self) Py_TYPE(self)->tp_free((PyObject*)self) |
3618 | 681 |
4377 | 682 #define WIN_PYTHON_REF(win) win->w_python3_ref |
683 #define BUF_PYTHON_REF(buf) buf->b_python3_ref | |
4401 | 684 #define TAB_PYTHON_REF(tab) tab->tp_python3_ref |
4377 | 685 |
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
|
686 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
|
687 call_PyObject_Free(void *p) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
688 { |
4585
b9f87487d935
updated for version 7.3.1040
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
689 #if defined(Py_DEBUG) && !defined(Py_DEBUG_NO_PYMALLOC) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
690 _PyObject_DebugFree(p); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
691 #else |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
692 PyObject_Free(p); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
693 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
694 } |
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
|
695 |
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
|
696 static PyObject * |
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
|
697 call_PyType_GenericNew(PyTypeObject *type, PyObject *args, PyObject *kwds) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
698 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
699 return PyType_GenericNew(type,args,kwds); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
700 } |
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
|
701 |
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
|
702 static PyObject * |
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
|
703 call_PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
704 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
705 return PyType_GenericAlloc(type,nitems); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
706 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
707 |
4319 | 708 static PyObject *OutputGetattro(PyObject *, PyObject *); |
709 static int OutputSetattro(PyObject *, PyObject *, PyObject *); | |
710 static PyObject *BufferGetattro(PyObject *, PyObject *); | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
711 static int BufferSetattro(PyObject *, PyObject *, PyObject *); |
4401 | 712 static PyObject *TabPageGetattro(PyObject *, PyObject *); |
4319 | 713 static PyObject *WindowGetattro(PyObject *, PyObject *); |
714 static int WindowSetattro(PyObject *, PyObject *, PyObject *); | |
715 static PyObject *RangeGetattro(PyObject *, PyObject *); | |
716 static PyObject *CurrentGetattro(PyObject *, PyObject *); | |
717 static int CurrentSetattro(PyObject *, PyObject *, PyObject *); | |
718 static PyObject *DictionaryGetattro(PyObject *, PyObject *); | |
719 static int DictionarySetattro(PyObject *, PyObject *, PyObject *); | |
720 static PyObject *ListGetattro(PyObject *, PyObject *); | |
721 static int ListSetattro(PyObject *, PyObject *, PyObject *); | |
722 static PyObject *FunctionGetattro(PyObject *, PyObject *); | |
723 | |
724 static struct PyModuleDef vimmodule; | |
725 | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
726 #define PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
727 |
4319 | 728 /* |
729 * Include the code shared with if_python.c | |
730 */ | |
731 #include "if_py_both.h" | |
732 | |
733 #define GET_ATTR_STRING(name, nameobj) \ | |
734 char *name = ""; \ | |
735 if (PyUnicode_Check(nameobj)) \ | |
736 name = _PyUnicode_AsString(nameobj) | |
737 | |
738 #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0) | |
739 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
740 /****************************************************** |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
741 * Internal function prototypes. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
742 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
743 |
3951 | 744 static PyObject *Py3Init_vim(void); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
745 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
746 /****************************************************** |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
747 * 1. Python interpreter main program. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
748 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
749 |
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
|
750 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
|
751 python3_end() |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
752 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
753 static int recurse = 0; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
754 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
755 /* If a crash occurs while doing this, don't try again. */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
756 if (recurse != 0) |
2330 | 757 return; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
758 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
759 ++recurse; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
760 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
761 #ifdef DYNAMIC_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
762 if (hinstPy3) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
763 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
764 if (Py_IsInitialized()) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
765 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
766 // acquire lock before finalizing |
4415 | 767 PyGILState_Ensure(); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
768 |
2330 | 769 Py_Finalize(); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
770 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
771 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
772 #ifdef DYNAMIC_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
773 end_dynamic_python3(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
774 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
775 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
776 --recurse; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
777 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
778 |
2384
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
779 #if (defined(DYNAMIC_PYTHON) && defined(FEAT_PYTHON)) || 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
|
780 int |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
781 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
|
782 { |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
783 return (hinstPy3 != 0); |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
784 } |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
785 #endif |
aeea25941392
Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents:
2374
diff
changeset
|
786 |
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
|
787 static int |
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
|
788 Python3_Init(void) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
789 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
790 if (!py3initialised) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
791 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
792 #ifdef DYNAMIC_PYTHON3 |
2330 | 793 if (!python3_enabled(TRUE)) |
794 { | |
795 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); | |
796 goto fail; | |
797 } | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
798 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
799 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
800 init_structs(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
801 |
2641 | 802 |
803 #ifdef PYTHON3_HOME | |
804 Py_SetPythonHome(PYTHON3_HOME); | |
805 #endif | |
806 | |
3863 | 807 PyImport_AppendInittab("vim", Py3Init_vim); |
808 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
809 #if !defined(MACOS) || defined(MACOS_X_UNIX) |
2330 | 810 Py_Initialize(); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
811 #else |
2330 | 812 PyMac_Initialize(); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
813 #endif |
4109 | 814 /* Initialise threads, and below save the state using |
815 * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread | |
816 * specific state (such as the system trace hook), will be lost | |
817 * between invocations of Python code. */ | |
2877 | 818 PyEval_InitThreads(); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
819 #ifdef DYNAMIC_PYTHON3 |
2330 | 820 get_py3_exceptions(); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
821 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
822 |
4494 | 823 if (PythonIO_Init_io()) |
2330 | 824 goto fail; |
825 | |
3618 | 826 globals = PyModule_GetDict(PyImport_AddModule("__main__")); |
827 | |
2330 | 828 /* Remove the element from sys.path that was added because of our |
829 * argv[0] value in Py3Init_vim(). Previously we used an empty | |
4352 | 830 * string, but depending on the OS we then get an empty entry or |
2894 | 831 * the current directory in sys.path. |
832 * Only after vim has been imported, the element does exist in | |
833 * sys.path. | |
834 */ | |
835 PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
836 |
4109 | 837 /* lock is created and acquired in PyEval_InitThreads() and thread |
838 * state is created in Py_Initialize() | |
839 * there _PyGILState_NoteThreadState() also sets gilcounter to 1 | |
840 * (python must have threads enabled!) | |
841 * so the following does both: unlock GIL and save thread state in TLS | |
842 * without deleting thread state | |
843 */ | |
844 PyEval_SaveThread(); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
845 |
2330 | 846 py3initialised = 1; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
847 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
848 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
849 return 0; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
850 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
851 fail: |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
852 /* We call PythonIO_Flush() here to print any Python errors. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
853 * This is OK, as it is possible to call this function even |
4494 | 854 * if PythonIO_Init_io() has not completed successfully (it will |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
855 * not do anything in this case). |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
856 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
857 PythonIO_Flush(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
858 return -1; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
859 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
860 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
861 /* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
862 * External interface |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
863 */ |
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
|
864 static void |
4486 | 865 DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
866 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
867 #if defined(MACOS) && !defined(MACOS_X_UNIX) |
2330 | 868 GrafPtr oldPort; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
869 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
870 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
2330 | 871 char *saved_locale; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
872 #endif |
2894 | 873 PyObject *cmdstr; |
874 PyObject *cmdbytes; | |
4415 | 875 PyGILState_STATE pygilstate; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
876 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
877 #if defined(MACOS) && !defined(MACOS_X_UNIX) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
878 GetPort(&oldPort); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
879 /* Check if the Python library is available */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
880 if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress) |
2330 | 881 goto theend; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
882 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
883 if (Python3_Init()) |
2330 | 884 goto theend; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
885 |
4486 | 886 init_range(arg); |
887 | |
2330 | 888 Python_Release_Vim(); /* leave vim */ |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
889 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
890 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
891 /* Python only works properly when the LC_NUMERIC locale is "C". */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
892 saved_locale = setlocale(LC_NUMERIC, NULL); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
893 if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0) |
2330 | 894 saved_locale = NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
895 else |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
896 { |
2330 | 897 /* Need to make a copy, value may change when setting new locale. */ |
898 saved_locale = (char *)vim_strsave((char_u *)saved_locale); | |
899 (void)setlocale(LC_NUMERIC, "C"); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
900 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
901 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
902 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
903 pygilstate = PyGILState_Ensure(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
904 |
2894 | 905 /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause |
906 * SyntaxError (unicode error). */ | |
2955 | 907 cmdstr = PyUnicode_Decode(cmd, strlen(cmd), |
908 (char *)ENC_OPT, CODEC_ERROR_HANDLER); | |
909 cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER); | |
2894 | 910 Py_XDECREF(cmdstr); |
3618 | 911 |
4486 | 912 run(PyBytes_AsString(cmdbytes), arg, &pygilstate); |
2894 | 913 Py_XDECREF(cmdbytes); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
914 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
915 PyGILState_Release(pygilstate); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
916 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
917 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
918 if (saved_locale != NULL) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
919 { |
2330 | 920 (void)setlocale(LC_NUMERIC, saved_locale); |
921 vim_free(saved_locale); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
922 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
923 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
924 |
2330 | 925 Python_Lock_Vim(); /* enter vim */ |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
926 PythonIO_Flush(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
927 #if defined(MACOS) && !defined(MACOS_X_UNIX) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
928 SetPort(oldPort); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
929 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
930 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
931 theend: |
2330 | 932 return; /* keeps lint happy */ |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
933 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
934 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
935 /* |
2350
06feaf4fe36a
Rename some "python3" symbols to "py3", as the command name.
Bram Moolenaar <bram@vim.org>
parents:
2342
diff
changeset
|
936 * ":py3" |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
937 */ |
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
|
938 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
|
939 ex_py3(exarg_T *eap) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
940 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
941 char_u *script; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
942 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
943 script = script_get(eap, eap->arg); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
944 if (!eap->skip) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
945 { |
4486 | 946 DoPyCommand(script == NULL ? (char *) eap->arg : (char *) script, |
947 (rangeinitializer) init_range_cmd, | |
948 (runner) run_cmd, | |
949 (void *) eap); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
950 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
951 vim_free(script); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
952 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
953 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
954 #define BUFFER_SIZE 2048 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
955 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
956 /* |
2340
99c1eba60b2d
Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents:
2330
diff
changeset
|
957 * ":py3file" |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
958 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
959 void |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
960 ex_py3file(exarg_T *eap) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
961 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
962 static char buffer[BUFFER_SIZE]; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
963 const char *file; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
964 char *p; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
965 int i; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
966 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
967 /* Have to do it like this. PyRun_SimpleFile requires you to pass a |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
968 * stdio file pointer, but Vim and the Python DLL are compiled with |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
969 * different options under Windows, meaning that stdio pointers aren't |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
970 * compatible between the two. Yuk. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
971 * |
2894 | 972 * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec')) |
973 * | |
974 * Using bytes so that Python can detect the source encoding as it normally | |
975 * does. The doc does not say "compile" accept bytes, though. | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
976 * |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
977 * We need to escape any backslashes or single quotes in the file name, so that |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
978 * Python won't mangle the file name. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
979 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
980 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
981 strcpy(buffer, "exec(compile(open('"); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
982 p = buffer + 19; /* size of "exec(compile(open('" */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
983 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
984 for (i=0; i<2; ++i) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
985 { |
2330 | 986 file = (char *)eap->arg; |
987 while (*file && p < buffer + (BUFFER_SIZE - 3)) | |
988 { | |
989 if (*file == '\\' || *file == '\'') | |
990 *p++ = '\\'; | |
991 *p++ = *file++; | |
992 } | |
993 /* If we didn't finish the file name, we hit a buffer overflow */ | |
994 if (*file != '\0') | |
995 return; | |
996 if (i==0) | |
997 { | |
2894 | 998 strcpy(p,"','rb').read(),'"); |
999 p += 16; | |
2330 | 1000 } |
1001 else | |
1002 { | |
1003 strcpy(p,"','exec'))"); | |
1004 p += 10; | |
1005 } | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1006 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1007 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1008 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1009 /* Execute the file */ |
4486 | 1010 DoPyCommand(buffer, |
1011 (rangeinitializer) init_range_cmd, | |
1012 (runner) run_cmd, | |
1013 (void *) eap); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1014 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1015 |
4421 | 1016 void |
1017 ex_py3do(exarg_T *eap) | |
4417 | 1018 { |
4486 | 1019 DoPyCommand((char *)eap->arg, |
1020 (rangeinitializer)init_range_cmd, | |
1021 (runner)run_do, | |
1022 (void *)eap); | |
4417 | 1023 } |
1024 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1025 /****************************************************** |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1026 * 2. Python output stream: writes output via [e]msg(). |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1027 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1028 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1029 /* Implementation functions |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1030 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1031 |
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
|
1032 static PyObject * |
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
|
1033 OutputGetattro(PyObject *self, PyObject *nameobj) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1034 { |
3826 | 1035 GET_ATTR_STRING(name, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1036 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1037 if (strcmp(name, "softspace") == 0) |
2330 | 1038 return PyLong_FromLong(((OutputObject *)(self))->softspace); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1039 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1040 return PyObject_GenericGetAttr(self, nameobj); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1041 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1042 |
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
|
1043 static int |
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
|
1044 OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1045 { |
3826 | 1046 GET_ATTR_STRING(name, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1047 |
4488 | 1048 return OutputSetattr((OutputObject *)(self), name, val); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1049 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1050 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1051 /****************************************************** |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1052 * 3. Implementation of the Vim module for Python |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1053 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1054 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1055 /* Window type - Implementation functions |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1056 * -------------------------------------- |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1057 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1058 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1059 #define WindowType_Check(obj) ((obj)->ob_base.ob_type == &WindowType) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1060 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1061 /* Buffer type - Implementation functions |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1062 * -------------------------------------- |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1063 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1064 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1065 #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1066 |
3070 | 1067 static PyObject* BufferSubscript(PyObject *self, PyObject *idx); |
1068 static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1069 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1070 /* Line range type - Implementation functions |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1071 * -------------------------------------- |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1072 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1073 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1074 #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1075 |
3070 | 1076 static PyObject* RangeSubscript(PyObject *self, PyObject *idx); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1077 static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *); |
3070 | 1078 static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1079 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1080 /* Current objects type - Implementation functions |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1081 * ----------------------------------------------- |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1082 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1083 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1084 static PySequenceMethods BufferAsSeq = { |
2330 | 1085 (lenfunc) BufferLength, /* sq_length, len(x) */ |
1086 (binaryfunc) 0, /* sq_concat, x+y */ | |
1087 (ssizeargfunc) 0, /* sq_repeat, x*n */ | |
1088 (ssizeargfunc) BufferItem, /* sq_item, x[i] */ | |
1089 0, /* was_sq_slice, x[i:j] */ | |
2894 | 1090 0, /* sq_ass_item, x[i]=v */ |
2330 | 1091 0, /* sq_ass_slice, x[i:j]=v */ |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1092 0, /* sq_contains */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1093 0, /* sq_inplace_concat */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1094 0, /* sq_inplace_repeat */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1095 }; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1096 |
4319 | 1097 static PyMappingMethods BufferAsMapping = { |
2330 | 1098 /* mp_length */ (lenfunc)BufferLength, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1099 /* mp_subscript */ (binaryfunc)BufferSubscript, |
2894 | 1100 /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1101 }; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1102 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1103 |
4377 | 1104 /* Buffer object |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1105 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1106 |
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
|
1107 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1108 BufferGetattro(PyObject *self, PyObject *nameobj) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1109 { |
4319 | 1110 PyObject *r; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1111 |
3826 | 1112 GET_ATTR_STRING(name, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1113 |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1114 if ((r = BufferAttrValid((BufferObject *)(self), name))) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1115 return r; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1116 |
4319 | 1117 if (CheckBuffer((BufferObject *)(self))) |
2330 | 1118 return NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1119 |
4319 | 1120 r = BufferAttr((BufferObject *)(self), name); |
1121 if (r || PyErr_Occurred()) | |
1122 return r; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1123 else |
2330 | 1124 return PyObject_GenericGetAttr(self, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1125 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1126 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1127 static int |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1128 BufferSetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1129 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1130 GET_ATTR_STRING(name, nameobj); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1131 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1132 return BufferSetattr((BufferObject *)(self), name, val); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1133 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4585
diff
changeset
|
1134 |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1135 /******************/ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1136 |
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
|
1137 static PyObject * |
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
|
1138 BufferSubscript(PyObject *self, PyObject* idx) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1139 { |
3618 | 1140 if (PyLong_Check(idx)) |
1141 { | |
2330 | 1142 long _idx = PyLong_AsLong(idx); |
4488 | 1143 return BufferItem((BufferObject *)(self), _idx); |
3618 | 1144 } else if (PySlice_Check(idx)) |
1145 { | |
2330 | 1146 Py_ssize_t start, stop, step, slicelen; |
1147 | |
4387 | 1148 if (CheckBuffer((BufferObject *) self)) |
1149 return NULL; | |
1150 | |
3074 | 1151 if (PySlice_GetIndicesEx((PyObject *)idx, |
4389 | 1152 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count, |
2330 | 1153 &start, &stop, |
3618 | 1154 &step, &slicelen) < 0) |
1155 { | |
2330 | 1156 return NULL; |
1157 } | |
4488 | 1158 return BufferSlice((BufferObject *)(self), start, stop); |
3618 | 1159 } |
1160 else | |
1161 { | |
4405 | 1162 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
2330 | 1163 return NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1164 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1165 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1166 |
2894 | 1167 static Py_ssize_t |
1168 BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val) | |
1169 { | |
3618 | 1170 if (PyLong_Check(idx)) |
1171 { | |
2894 | 1172 long n = PyLong_AsLong(idx); |
1173 return RBAsItem((BufferObject *)(self), n, val, 1, | |
1174 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
1175 NULL); | |
3618 | 1176 } else if (PySlice_Check(idx)) |
1177 { | |
2894 | 1178 Py_ssize_t start, stop, step, slicelen; |
1179 | |
4387 | 1180 if (CheckBuffer((BufferObject *) self)) |
1181 return -1; | |
1182 | |
3074 | 1183 if (PySlice_GetIndicesEx((PyObject *)idx, |
4389 | 1184 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count, |
2894 | 1185 &start, &stop, |
3618 | 1186 &step, &slicelen) < 0) |
1187 { | |
2894 | 1188 return -1; |
1189 } | |
1190 return RBAsSlice((BufferObject *)(self), start, stop, val, 1, | |
1191 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
1192 NULL); | |
3618 | 1193 } |
1194 else | |
1195 { | |
4405 | 1196 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
2894 | 1197 return -1; |
1198 } | |
1199 } | |
1200 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1201 static PySequenceMethods RangeAsSeq = { |
2330 | 1202 (lenfunc) RangeLength, /* sq_length, len(x) */ |
1203 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ | |
1204 (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */ | |
1205 (ssizeargfunc) RangeItem, /* sq_item, x[i] */ | |
1206 0, /* was_sq_slice, x[i:j] */ | |
1207 (ssizeobjargproc) RangeAsItem, /* sq_as_item, x[i]=v */ | |
1208 0, /* sq_ass_slice, x[i:j]=v */ | |
1209 0, /* sq_contains */ | |
1210 0, /* sq_inplace_concat */ | |
1211 0, /* sq_inplace_repeat */ | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1212 }; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1213 |
4319 | 1214 static PyMappingMethods RangeAsMapping = { |
2330 | 1215 /* mp_length */ (lenfunc)RangeLength, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1216 /* mp_subscript */ (binaryfunc)RangeSubscript, |
3070 | 1217 /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript, |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1218 }; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1219 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1220 /* Line range object - Implementation |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1221 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1222 |
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
|
1223 static PyObject * |
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
|
1224 RangeGetattro(PyObject *self, PyObject *nameobj) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1225 { |
3826 | 1226 GET_ATTR_STRING(name, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1227 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1228 if (strcmp(name, "start") == 0) |
2330 | 1229 return Py_BuildValue("n", ((RangeObject *)(self))->start - 1); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1230 else if (strcmp(name, "end") == 0) |
2330 | 1231 return Py_BuildValue("n", ((RangeObject *)(self))->end - 1); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1232 else |
2330 | 1233 return PyObject_GenericGetAttr(self, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1234 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1235 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1236 /****************/ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1237 |
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
|
1238 static Py_ssize_t |
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
|
1239 RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1240 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1241 return RBAsItem(((RangeObject *)(self))->buf, n, val, |
2330 | 1242 ((RangeObject *)(self))->start, |
1243 ((RangeObject *)(self))->end, | |
1244 &((RangeObject *)(self))->end); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1245 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1246 |
3070 | 1247 static Py_ssize_t |
1248 RangeAsSlice(PyObject *self, Py_ssize_t lo, Py_ssize_t hi, PyObject *val) | |
1249 { | |
1250 return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val, | |
1251 ((RangeObject *)(self))->start, | |
1252 ((RangeObject *)(self))->end, | |
1253 &((RangeObject *)(self))->end); | |
1254 } | |
1255 | |
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
|
1256 static PyObject * |
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
|
1257 RangeSubscript(PyObject *self, PyObject* idx) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1258 { |
3618 | 1259 if (PyLong_Check(idx)) |
1260 { | |
2330 | 1261 long _idx = PyLong_AsLong(idx); |
4488 | 1262 return RangeItem((RangeObject *)(self), _idx); |
3618 | 1263 } else if (PySlice_Check(idx)) |
1264 { | |
2330 | 1265 Py_ssize_t start, stop, step, slicelen; |
1266 | |
3074 | 1267 if (PySlice_GetIndicesEx((PyObject *)idx, |
2330 | 1268 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1, |
1269 &start, &stop, | |
3618 | 1270 &step, &slicelen) < 0) |
1271 { | |
2330 | 1272 return NULL; |
1273 } | |
4488 | 1274 return RangeSlice((RangeObject *)(self), start, stop); |
3618 | 1275 } |
1276 else | |
1277 { | |
4405 | 1278 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
2330 | 1279 return NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1280 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1281 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1282 |
3070 | 1283 static Py_ssize_t |
1284 RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val) | |
1285 { | |
3618 | 1286 if (PyLong_Check(idx)) |
1287 { | |
3070 | 1288 long n = PyLong_AsLong(idx); |
1289 return RangeAsItem(self, n, val); | |
3618 | 1290 } else if (PySlice_Check(idx)) |
1291 { | |
3070 | 1292 Py_ssize_t start, stop, step, slicelen; |
1293 | |
3074 | 1294 if (PySlice_GetIndicesEx((PyObject *)idx, |
3070 | 1295 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1, |
1296 &start, &stop, | |
3618 | 1297 &step, &slicelen) < 0) |
1298 { | |
3070 | 1299 return -1; |
1300 } | |
1301 return RangeAsSlice(self, start, stop, val); | |
3618 | 1302 } |
1303 else | |
1304 { | |
4405 | 1305 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
3070 | 1306 return -1; |
1307 } | |
1308 } | |
1309 | |
4401 | 1310 /* TabPage object - Implementation |
1311 */ | |
1312 | |
1313 static PyObject * | |
1314 TabPageGetattro(PyObject *self, PyObject *nameobj) | |
1315 { | |
1316 PyObject *r; | |
1317 | |
1318 GET_ATTR_STRING(name, nameobj); | |
1319 | |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1320 if ((r = TabPageAttrValid((TabPageObject *)(self), name))) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1321 return r; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1322 |
4401 | 1323 if (CheckTabPage((TabPageObject *)(self))) |
1324 return NULL; | |
1325 | |
1326 r = TabPageAttr((TabPageObject *)(self), name); | |
1327 if (r || PyErr_Occurred()) | |
1328 return r; | |
1329 else | |
1330 return PyObject_GenericGetAttr(self, nameobj); | |
1331 } | |
1332 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1333 /* Window object - Implementation |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1334 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1335 |
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
|
1336 static PyObject * |
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
|
1337 WindowGetattro(PyObject *self, PyObject *nameobj) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1338 { |
4319 | 1339 PyObject *r; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1340 |
3826 | 1341 GET_ATTR_STRING(name, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1342 |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1343 if ((r = WindowAttrValid((WindowObject *)(self), name))) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1344 return r; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
1345 |
4319 | 1346 if (CheckWindow((WindowObject *)(self))) |
2330 | 1347 return NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1348 |
4319 | 1349 r = WindowAttr((WindowObject *)(self), name); |
1350 if (r || PyErr_Occurred()) | |
1351 return r; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1352 else |
2330 | 1353 return PyObject_GenericGetAttr(self, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1354 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1355 |
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
|
1356 static int |
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
|
1357 WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1358 { |
3826 | 1359 GET_ATTR_STRING(name, nameobj); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1360 |
4488 | 1361 return WindowSetattr((WindowObject *)(self), name, val); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1362 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1363 |
4401 | 1364 /* Tab page list object - Definitions |
1365 */ | |
1366 | |
1367 static PySequenceMethods TabListAsSeq = { | |
1368 (lenfunc) TabListLength, /* sq_length, len(x) */ | |
1369 (binaryfunc) 0, /* sq_concat, x+y */ | |
1370 (ssizeargfunc) 0, /* sq_repeat, x*n */ | |
1371 (ssizeargfunc) TabListItem, /* sq_item, x[i] */ | |
1372 0, /* sq_slice, x[i:j] */ | |
1373 (ssizeobjargproc)0, /* sq_as_item, x[i]=v */ | |
1374 0, /* sq_ass_slice, x[i:j]=v */ | |
1375 0, /* sq_contains */ | |
1376 0, /* sq_inplace_concat */ | |
1377 0, /* sq_inplace_repeat */ | |
1378 }; | |
1379 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1380 /* Window list object - Definitions |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1381 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1382 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1383 static PySequenceMethods WinListAsSeq = { |
2330 | 1384 (lenfunc) WinListLength, /* sq_length, len(x) */ |
1385 (binaryfunc) 0, /* sq_concat, x+y */ | |
1386 (ssizeargfunc) 0, /* sq_repeat, x*n */ | |
1387 (ssizeargfunc) WinListItem, /* sq_item, x[i] */ | |
1388 0, /* sq_slice, x[i:j] */ | |
1389 (ssizeobjargproc)0, /* sq_as_item, x[i]=v */ | |
1390 0, /* sq_ass_slice, x[i:j]=v */ | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1391 0, /* sq_contains */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1392 0, /* sq_inplace_concat */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1393 0, /* sq_inplace_repeat */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1394 }; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1395 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1396 /* Current items object - Implementation |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1397 */ |
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
|
1398 static PyObject * |
4319 | 1399 CurrentGetattro(PyObject *self, PyObject *nameobj) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1400 { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1401 PyObject *r; |
3826 | 1402 GET_ATTR_STRING(name, nameobj); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1403 if (!(r = CurrentGetattr(self, name))) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1404 return PyObject_GenericGetAttr(self, nameobj); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
1405 return r; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1406 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1407 |
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
|
1408 static int |
4319 | 1409 CurrentSetattro(PyObject *self, PyObject *nameobj, PyObject *value) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1410 { |
4319 | 1411 GET_ATTR_STRING(name, nameobj); |
1412 return CurrentSetattr(self, name, value); | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1413 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1414 |
3618 | 1415 /* Dictionary object - Definitions |
1416 */ | |
1417 | |
3828 | 1418 static PyObject * |
1419 DictionaryGetattro(PyObject *self, PyObject *nameobj) | |
1420 { | |
1421 DictionaryObject *this = ((DictionaryObject *) (self)); | |
1422 | |
1423 GET_ATTR_STRING(name, nameobj); | |
1424 | |
1425 if (strcmp(name, "locked") == 0) | |
1426 return PyLong_FromLong(this->dict->dv_lock); | |
1427 else if (strcmp(name, "scope") == 0) | |
1428 return PyLong_FromLong(this->dict->dv_scope); | |
1429 | |
1430 return PyObject_GenericGetAttr(self, nameobj); | |
1431 } | |
1432 | |
1433 static int | |
1434 DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val) | |
1435 { | |
1436 GET_ATTR_STRING(name, nameobj); | |
4488 | 1437 return DictionarySetattr((DictionaryObject *)(self), name, val); |
3618 | 1438 } |
1439 | |
1440 /* List object - Definitions | |
1441 */ | |
1442 | |
1443 static PySequenceMethods ListAsSeq = { | |
1444 (lenfunc) ListLength, /* sq_length, len(x) */ | |
1445 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ | |
1446 (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */ | |
1447 (ssizeargfunc) ListItem, /* sq_item, x[i] */ | |
1448 (void *) 0, /* was_sq_slice, x[i:j] */ | |
1449 (ssizeobjargproc) ListAssItem, /* sq_as_item, x[i]=v */ | |
1450 (void *) 0, /* was_sq_ass_slice, x[i:j]=v */ | |
1451 0, /* sq_contains */ | |
1452 (binaryfunc) ListConcatInPlace,/* sq_inplace_concat */ | |
1453 0, /* sq_inplace_repeat */ | |
1454 }; | |
1455 | |
1456 static PyObject *ListSubscript(PyObject *, PyObject *); | |
1457 static Py_ssize_t ListAsSubscript(PyObject *, PyObject *, PyObject *); | |
1458 | |
1459 static PyMappingMethods ListAsMapping = { | |
1460 /* mp_length */ (lenfunc) ListLength, | |
1461 /* mp_subscript */ (binaryfunc) ListSubscript, | |
1462 /* mp_ass_subscript */ (objobjargproc) ListAsSubscript, | |
1463 }; | |
1464 | |
1465 static PyObject * | |
4488 | 1466 ListSubscript(PyObject *self, PyObject* idx) |
3618 | 1467 { |
4488 | 1468 if (PyLong_Check(idx)) |
3618 | 1469 { |
4488 | 1470 long _idx = PyLong_AsLong(idx); |
1471 return ListItem((ListObject *)(self), _idx); | |
3618 | 1472 } |
4488 | 1473 else if (PySlice_Check(idx)) |
3618 | 1474 { |
1475 Py_ssize_t start, stop, step, slicelen; | |
1476 | |
4488 | 1477 if (PySlice_GetIndicesEx(idx, ListLength((ListObject *)(self)), |
1478 &start, &stop, &step, &slicelen) < 0) | |
3618 | 1479 return NULL; |
4488 | 1480 return ListSlice((ListObject *)(self), start, stop); |
3618 | 1481 } |
1482 else | |
1483 { | |
4405 | 1484 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
3618 | 1485 return NULL; |
1486 } | |
1487 } | |
1488 | |
1489 static Py_ssize_t | |
4488 | 1490 ListAsSubscript(PyObject *self, PyObject *idx, PyObject *obj) |
3618 | 1491 { |
4488 | 1492 if (PyLong_Check(idx)) |
3618 | 1493 { |
4488 | 1494 long _idx = PyLong_AsLong(idx); |
1495 return ListAssItem((ListObject *)(self), _idx, obj); | |
3618 | 1496 } |
4488 | 1497 else if (PySlice_Check(idx)) |
3618 | 1498 { |
1499 Py_ssize_t start, stop, step, slicelen; | |
1500 | |
4488 | 1501 if (PySlice_GetIndicesEx(idx, ListLength((ListObject *)(self)), |
1502 &start, &stop, &step, &slicelen) < 0) | |
3618 | 1503 return -1; |
4488 | 1504 return ListAssSlice((ListObject *)(self), start, stop, obj); |
3618 | 1505 } |
1506 else | |
1507 { | |
4405 | 1508 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
3618 | 1509 return -1; |
1510 } | |
1511 } | |
1512 | |
3828 | 1513 static PyObject * |
1514 ListGetattro(PyObject *self, PyObject *nameobj) | |
1515 { | |
1516 GET_ATTR_STRING(name, nameobj); | |
1517 | |
1518 if (strcmp(name, "locked") == 0) | |
1519 return PyLong_FromLong(((ListObject *) (self))->list->lv_lock); | |
1520 | |
1521 return PyObject_GenericGetAttr(self, nameobj); | |
1522 } | |
1523 | |
1524 static int | |
1525 ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val) | |
1526 { | |
1527 GET_ATTR_STRING(name, nameobj); | |
4488 | 1528 return ListSetattr((ListObject *)(self), name, val); |
3618 | 1529 } |
1530 | |
1531 /* Function object - Definitions | |
1532 */ | |
1533 | |
1534 static PyObject * | |
1535 FunctionGetattro(PyObject *self, PyObject *nameobj) | |
1536 { | |
1537 FunctionObject *this = (FunctionObject *)(self); | |
3826 | 1538 |
1539 GET_ATTR_STRING(name, nameobj); | |
3618 | 1540 |
1541 if (strcmp(name, "name") == 0) | |
1542 return PyUnicode_FromString((char *)(this->name)); | |
1543 | |
1544 return PyObject_GenericGetAttr(self, nameobj); | |
1545 } | |
1546 | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1547 /* External interface |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1548 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1549 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1550 void |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1551 python3_buffer_free(buf_T *buf) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1552 { |
4377 | 1553 if (BUF_PYTHON_REF(buf) != NULL) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1554 { |
4377 | 1555 BufferObject *bp = BUF_PYTHON_REF(buf); |
2330 | 1556 bp->buf = INVALID_BUFFER_VALUE; |
4377 | 1557 BUF_PYTHON_REF(buf) = NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1558 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1559 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1560 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1561 #if defined(FEAT_WINDOWS) || defined(PROTO) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1562 void |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1563 python3_window_free(win_T *win) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1564 { |
4377 | 1565 if (WIN_PYTHON_REF(win) != NULL) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1566 { |
4377 | 1567 WindowObject *wp = WIN_PYTHON_REF(win); |
2330 | 1568 wp->win = INVALID_WINDOW_VALUE; |
4377 | 1569 WIN_PYTHON_REF(win) = NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1570 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1571 } |
4401 | 1572 |
1573 void | |
1574 python3_tabpage_free(tabpage_T *tab) | |
1575 { | |
1576 if (TAB_PYTHON_REF(tab) != NULL) | |
1577 { | |
1578 TabPageObject *tp = TAB_PYTHON_REF(tab); | |
1579 tp->tab = INVALID_TABPAGE_VALUE; | |
1580 TAB_PYTHON_REF(tab) = NULL; | |
1581 } | |
1582 } | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1583 #endif |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1584 |
3951 | 1585 static PyObject * |
1586 Py3Init_vim(void) | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1587 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1588 PyObject *mod; |
4494 | 1589 |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1590 /* The special value is removed from sys.path in Python3_Init(). */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1591 static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1592 |
4494 | 1593 if (init_types()) |
1594 return NULL; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1595 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1596 /* Set sys.argv[] to avoid a crash in warn(). */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1597 PySys_SetArgv(1, argv); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1598 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1599 mod = PyModule_Create(&vimmodule); |
2894 | 1600 if (mod == NULL) |
1601 return NULL; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1602 |
4494 | 1603 if (populate_module(mod, PyModule_AddObject)) |
2330 | 1604 return NULL; |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1605 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1606 return mod; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1607 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1608 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1609 /************************************************************************* |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1610 * 4. Utility functions for handling the interface between Vim and Python. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1611 */ |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1612 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1613 /* Convert a Vim line into a Python string. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1614 * All internal newlines are replaced by null characters. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1615 * |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1616 * On errors, the Python exception data is set, and NULL is returned. |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1617 */ |
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
|
1618 static PyObject * |
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
|
1619 LineToString(const char *str) |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1620 { |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1621 PyObject *result; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1622 Py_ssize_t len = strlen(str); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1623 char *tmp,*p; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1624 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1625 tmp = (char *)alloc((unsigned)(len+1)); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1626 p = tmp; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1627 if (p == NULL) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1628 { |
2330 | 1629 PyErr_NoMemory(); |
1630 return NULL; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1631 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1632 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1633 while (*str) |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1634 { |
2330 | 1635 if (*str == '\n') |
1636 *p = '\0'; | |
1637 else | |
1638 *p = *str; | |
1639 | |
1640 ++p; | |
1641 ++str; | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1642 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1643 *p = '\0'; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1644 |
2955 | 1645 result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER); |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1646 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1647 vim_free(tmp); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1648 return result; |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1649 } |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1650 |
3618 | 1651 void |
1652 do_py3eval (char_u *str, typval_T *rettv) | |
1653 { | |
4486 | 1654 DoPyCommand((char *) str, |
1655 (rangeinitializer) init_range_eval, | |
1656 (runner) run_eval, | |
1657 (void *) rettv); | |
3618 | 1658 switch(rettv->v_type) |
1659 { | |
1660 case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; | |
1661 case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; | |
1662 case VAR_FUNC: func_ref(rettv->vval.v_string); break; | |
3796 | 1663 case VAR_UNKNOWN: |
1664 rettv->v_type = VAR_NUMBER; | |
1665 rettv->vval.v_number = 0; | |
1666 break; | |
3618 | 1667 } |
1668 } | |
1669 | |
1670 void | |
1671 set_ref_in_python3 (int copyID) | |
1672 { | |
1673 set_ref_in_py(copyID); | |
1674 } |