annotate src/if_python3.c @ 3800:15cdcb8ddcfb v7.3.658

updated for version 7.3.658 Problem: NUL bytes truncate strings when converted from Python. Solution: Handle truncation as an error. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Wed, 05 Sep 2012 19:09:11 +0200
parents 3958b0e672d6
children 5e909c379a1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0b4a515b1254 updated for version 7.3.132
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
25 /* uncomment this if used with the debug version of python */
0b4a515b1254 updated for version 7.3.132
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
26 /* #define Py_DEBUG */
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 #include "vim.h"
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 #include <limits.h>
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 /* Python.h defines _POSIX_THREADS itself (if needed) */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 #ifdef _POSIX_THREADS
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 # undef _POSIX_THREADS
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36
2404
eb4718cb2a76 Include old Python changes in Python 3 interface.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
37 #if defined(_WIN32) && defined(HAVE_FCNTL_H)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 # undef HAVE_FCNTL_H
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 #ifdef _DEBUG
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 # undef _DEBUG
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 #define PY_SSIZE_T_CLEAN
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 #ifdef F_BLANK
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 # undef F_BLANK
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50
2340
99c1eba60b2d Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
51 #ifdef HAVE_STDARG_H
99c1eba60b2d Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
52 # 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
53 #endif
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 #ifdef _POSIX_C_SOURCE /* defined in feature.h */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 # undef _POSIX_C_SOURCE
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 #endif
2340
99c1eba60b2d Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
57 #ifdef _XOPEN_SOURCE
99c1eba60b2d Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
58 # 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
59 #endif
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 #include <Python.h>
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 #if defined(MACOS) && !defined(MACOS_X_UNIX)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 # include "macglue.h"
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 # include <CodeFragments.h>
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 #undef main /* Defined in python.h - aargh */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 #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
68
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 static void init_structs(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70
2955
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
71 /* The "surrogateescape" error handler is new in Python 3.1 */
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
72 #if PY_VERSION_HEX >= 0x030100f0
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
73 # define CODEC_ERROR_HANDLER "surrogateescape"
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
74 #else
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
75 # define CODEC_ERROR_HANDLER NULL
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
76 #endif
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
77
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
78 /* Python 3 does not support CObjects, always use Capsules */
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
79 #define PY_USE_CAPSULE
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
80
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
81 #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
82 #define PyString_Check(obj) PyUnicode_Check(obj)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
83 #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
84 #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
85 #define PyString_AsString(obj) PyBytes_AsString(obj)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
86 #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
87 #define PyString_FromString(repr) PyUnicode_FromString(repr)
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3798
diff changeset
88 #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
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
89
2716
0b4a515b1254 updated for version 7.3.132
Bram Moolenaar <bram@vim.org>
parents: 2641
diff changeset
90 #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91
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
92 # 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
93 # 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
94 # 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
95 # define HINSTANCE void*
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
96 # 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
97 # 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
98 # 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
99 # 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
100 # 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
101 # 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
102 # 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
103 # else
2612
fa5dee44df3f updated for version 7.3.034
Bram Moolenaar <bram@vim.org>
parents: 2554
diff changeset
104 # 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
105 # 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
106 # 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
107 # endif
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 * Wrapper defines
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 */
2528
8bc2e8390c11 When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that
Bram Moolenaar <bram@vim.org>
parents: 2447
diff changeset
111 # undef PyArg_Parse
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 # 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
113 # undef PyArg_ParseTuple
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 # define PyArg_ParseTuple py3_PyArg_ParseTuple
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
115 # define PyMem_Free py3_PyMem_Free
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
116 # define PyMem_Malloc py3_PyMem_Malloc
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 # define PyDict_SetItemString py3_PyDict_SetItemString
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 # define PyErr_BadArgument py3_PyErr_BadArgument
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 # define PyErr_Clear py3_PyErr_Clear
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 # define PyErr_NoMemory py3_PyErr_NoMemory
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 # define PyErr_Occurred py3_PyErr_Occurred
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 # define PyErr_SetNone py3_PyErr_SetNone
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 # define PyErr_SetString py3_PyErr_SetString
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 # define PyEval_InitThreads py3_PyEval_InitThreads
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 # define PyEval_RestoreThread py3_PyEval_RestoreThread
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 # define PyEval_SaveThread py3_PyEval_SaveThread
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 # define PyGILState_Ensure py3_PyGILState_Ensure
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 # define PyGILState_Release py3_PyGILState_Release
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 # define PyLong_AsLong py3_PyLong_AsLong
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 # define PyLong_FromLong py3_PyLong_FromLong
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 # define PyList_GetItem py3_PyList_GetItem
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 # define PyList_Append py3_PyList_Append
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 # define PyList_New py3_PyList_New
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 # define PyList_SetItem py3_PyList_SetItem
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 # define PyList_Size py3_PyList_Size
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
136 # define PySequence_Check py3_PySequence_Check
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
137 # define PySequence_Size py3_PySequence_Size
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
138 # define PySequence_GetItem py3_PySequence_GetItem
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
139 # define PyTuple_Size py3_PyTuple_Size
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
140 # define PyTuple_GetItem py3_PyTuple_GetItem
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141 # define PySlice_GetIndicesEx py3_PySlice_GetIndicesEx
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 # define PyImport_ImportModule py3_PyImport_ImportModule
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
143 # define PyImport_AddModule py3_PyImport_AddModule
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 # define PyObject_Init py3__PyObject_Init
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 # define PyDict_New py3_PyDict_New
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 # define PyDict_GetItemString py3_PyDict_GetItemString
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
147 # define PyDict_Next py3_PyDict_Next
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
148 # define PyMapping_Check py3_PyMapping_Check
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
149 # define PyMapping_Items py3_PyMapping_Items
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
150 # define PyIter_Next py3_PyIter_Next
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
151 # define PyObject_GetIter py3_PyObject_GetIter
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 # define PyModule_GetDict py3_PyModule_GetDict
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 #undef PyRun_SimpleString
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 # define PyRun_SimpleString py3_PyRun_SimpleString
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
155 #undef PyRun_String
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
156 # define PyRun_String py3_PyRun_String
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 # define PySys_SetObject py3_PySys_SetObject
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 # define PySys_SetArgv py3_PySys_SetArgv
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 # define PyType_Type (*py3_PyType_Type)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 # define PyType_Ready py3_PyType_Ready
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 #undef Py_BuildValue
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 # define Py_BuildValue py3_Py_BuildValue
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
163 # define Py_SetPythonHome py3_Py_SetPythonHome
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 # define Py_Initialize py3_Py_Initialize
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 # define Py_Finalize py3_Py_Finalize
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 # define Py_IsInitialized py3_Py_IsInitialized
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 # define _Py_NoneStruct (*py3__Py_NoneStruct)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
168 # define _PyObject_NextNotImplemented (*py3__PyObject_NextNotImplemented)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 # define PyModule_AddObject py3_PyModule_AddObject
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 # define PyImport_AppendInittab py3_PyImport_AppendInittab
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 # define _PyUnicode_AsString py3__PyUnicode_AsString
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
172 # undef PyUnicode_AsEncodedString
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
173 # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
174 # undef PyBytes_AsString
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
175 # define PyBytes_AsString py3_PyBytes_AsString
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
176 # define PyBytes_AsStringAndSize py3_PyBytes_AsStringAndSize
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
177 # undef PyBytes_FromString
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
178 # define PyBytes_FromString py3_PyBytes_FromString
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
179 # define PyFloat_FromDouble py3_PyFloat_FromDouble
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
180 # define PyFloat_AsDouble py3_PyFloat_AsDouble
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 # define PySlice_Type (*py3_PySlice_Type)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
183 # define PyFloat_Type (*py3_PyFloat_Type)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
184 # 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
185 # 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
186 # 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
187 # 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
188 # define _Py_Dealloc py3__Py_Dealloc
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
189 # 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
190 # 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
191 # 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
192 # 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
193 # 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
194 # endif
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 # define PyType_GenericAlloc py3_PyType_GenericAlloc
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 # define PyType_GenericNew py3_PyType_GenericNew
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 # define PyModule_Create2 py3_PyModule_Create2
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
198 # undef PyUnicode_FromString
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 # define PyUnicode_FromString py3_PyUnicode_FromString
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
200 # undef PyUnicode_Decode
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
201 # define PyUnicode_Decode py3_PyUnicode_Decode
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
202 # define PyType_IsSubtype py3_PyType_IsSubtype
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
203 # define PyCapsule_New py3_PyCapsule_New
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
204 # define PyCapsule_GetPointer py3_PyCapsule_GetPointer
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205
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
206 # 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
207 # 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
208 # define PyObject_NEW(type, typeobj) \
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 ( (type *) PyObject_Init( \
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
210 (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
211 # 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
212
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 * Pointers for dynamic link
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216 static int (*py3_PySys_SetArgv)(int, wchar_t **);
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
217 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
218 static void (*py3_Py_Initialize)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 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
220 static PyGILState_STATE (*py3_PyGILState_Ensure)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 static void (*py3_PyGILState_Release)(PyGILState_STATE);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 static int (*py3_PySys_SetObject)(char *, PyObject *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 static PyObject* (*py3_PyList_Append)(PyObject *, PyObject *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 static Py_ssize_t (*py3_PyList_Size)(PyObject *);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
225 static int (*py3_PySequence_Check)(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
226 static Py_ssize_t (*py3_PySequence_Size)(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
227 static PyObject* (*py3_PySequence_GetItem)(PyObject *, Py_ssize_t);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
228 static Py_ssize_t (*py3_PyTuple_Size)(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
229 static PyObject* (*py3_PyTuple_GetItem)(PyObject *, Py_ssize_t);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
230 static int (*py3_PyMapping_Check)(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
231 static PyObject* (*py3_PyMapping_Items)(PyObject *);
3083
dc60200a16b2 updated for version 7.3.313
Bram Moolenaar <bram@vim.org>
parents: 3074
diff changeset
232 static int (*py3_PySlice_GetIndicesEx)(PyObject *r, Py_ssize_t length,
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
233 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
234 static PyObject* (*py3_PyErr_NoMemory)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 static void (*py3_Py_Finalize)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 static void (*py3_PyErr_SetString)(PyObject *, const char *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237 static int (*py3_PyRun_SimpleString)(char *);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
238 static PyObject* (*py3_PyRun_String)(char *, int, PyObject *, PyObject *);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 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
240 static PyObject* (*py3_PyImport_ImportModule)(const char *);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
241 static PyObject* (*py3_PyImport_AddModule)(const char *);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 static int (*py3_PyErr_BadArgument)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 static PyTypeObject* py3_PyType_Type;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244 static PyObject* (*py3_PyErr_Occurred)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245 static PyObject* (*py3_PyModule_GetDict)(PyObject *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246 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
247 static PyObject* (*py3_PyDict_GetItemString)(PyObject *, const char *);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
248 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
249 static PyObject* (*py3_PyLong_FromLong)(long);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 static PyObject* (*py3_PyDict_New)(void);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
251 static PyObject* (*py3_PyIter_Next)(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
252 static PyObject* (*py3_PyObject_GetIter)(PyObject *);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253 static PyObject* (*py3_Py_BuildValue)(char *, ...);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 static int (*py3_PyType_Ready)(PyTypeObject *type);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 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
256 static PyObject* (*py3_PyUnicode_FromString)(const char *u);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
257 static PyObject* (*py3_PyUnicode_Decode)(const char *u, Py_ssize_t size,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
258 const char *encoding, const char *errors);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 static long (*py3_PyLong_AsLong)(PyObject *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260 static void (*py3_PyErr_SetNone)(PyObject *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 static void (*py3_PyEval_InitThreads)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 static void(*py3_PyEval_RestoreThread)(PyThreadState *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263 static PyThreadState*(*py3_PyEval_SaveThread)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 static int (*py3_PyArg_Parse)(PyObject *, char *, ...);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265 static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
266 static int (*py3_PyMem_Free)(void *);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
267 static void* (*py3_PyMem_Malloc)(size_t);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268 static int (*py3_Py_IsInitialized)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 static void (*py3_PyErr_Clear)(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
270 static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
271 static iternextfunc py3__PyObject_NextNotImplemented;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 static PyObject* py3__Py_NoneStruct;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 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
274 static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 static char* (*py3__PyUnicode_AsString)(PyObject *unicode);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
276 static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
277 static char* (*py3_PyBytes_AsString)(PyObject *bytes);
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
278 static int (*py3_PyBytes_AsStringAndSize)(PyObject *bytes, char **buffer, int *length);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
279 static PyObject* (*py3_PyBytes_FromString)(char *str);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
280 static PyObject* (*py3_PyFloat_FromDouble)(double num);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
281 static double (*py3_PyFloat_AsDouble)(PyObject *);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 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
283 static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 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
285 static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 static PyTypeObject* py3_PySlice_Type;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
287 static PyTypeObject* py3_PyFloat_Type;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
288 static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
289 static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
290 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
291 # ifdef Py_DEBUG
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292 static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293 static Py_ssize_t* py3__Py_RefTotal;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 static void (*py3__Py_Dealloc)(PyObject *obj);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 static void (*py3__PyObject_DebugFree)(void*);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 static void* (*py3__PyObject_DebugMalloc)(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
297 # else
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298 static void (*py3_PyObject_Free)(void*);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299 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
300 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
301 static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 /* Imported exception objects */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 static PyObject *p3imp_PyExc_AttributeError;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307 static PyObject *p3imp_PyExc_IndexError;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
308 static PyObject *p3imp_PyExc_KeyboardInterrupt;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309 static PyObject *p3imp_PyExc_TypeError;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
310 static PyObject *p3imp_PyExc_ValueError;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
311
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312 # define PyExc_AttributeError p3imp_PyExc_AttributeError
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313 # define PyExc_IndexError p3imp_PyExc_IndexError
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 # define PyExc_KeyboardInterrupt p3imp_PyExc_KeyboardInterrupt
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 # define PyExc_TypeError p3imp_PyExc_TypeError
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 # define PyExc_ValueError p3imp_PyExc_ValueError
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 * Table of name to function pointer of python.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321 # define PYTHON_PROC FARPROC
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322 static struct
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 char *name;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 PYTHON_PROC *ptr;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 } py3_funcname_table[] =
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 {"PySys_SetArgv", (PYTHON_PROC*)&py3_PySys_SetArgv},
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
329 {"Py_SetPythonHome", (PYTHON_PROC*)&py3_Py_SetPythonHome},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
332 {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
333 {"PyMem_Malloc", (PYTHON_PROC*)&py3_PyMem_Malloc},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 {"PyList_New", (PYTHON_PROC*)&py3_PyList_New},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 {"PySys_SetObject", (PYTHON_PROC*)&py3_PySys_SetObject},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 {"PyList_Append", (PYTHON_PROC*)&py3_PyList_Append},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 {"PyList_Size", (PYTHON_PROC*)&py3_PyList_Size},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
340 {"PySequence_Check", (PYTHON_PROC*)&py3_PySequence_Check},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
341 {"PySequence_Size", (PYTHON_PROC*)&py3_PySequence_Size},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
342 {"PySequence_GetItem", (PYTHON_PROC*)&py3_PySequence_GetItem},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
343 {"PyTuple_Size", (PYTHON_PROC*)&py3_PyTuple_Size},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
344 {"PyTuple_GetItem", (PYTHON_PROC*)&py3_PyTuple_GetItem},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
345 {"PySlice_GetIndicesEx", (PYTHON_PROC*)&py3_PySlice_GetIndicesEx},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 {"PyErr_NoMemory", (PYTHON_PROC*)&py3_PyErr_NoMemory},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
347 {"Py_Finalize", (PYTHON_PROC*)&py3_Py_Finalize},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348 {"PyErr_SetString", (PYTHON_PROC*)&py3_PyErr_SetString},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 {"PyRun_SimpleString", (PYTHON_PROC*)&py3_PyRun_SimpleString},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
350 {"PyRun_String", (PYTHON_PROC*)&py3_PyRun_String},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 {"PyList_GetItem", (PYTHON_PROC*)&py3_PyList_GetItem},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 {"PyImport_ImportModule", (PYTHON_PROC*)&py3_PyImport_ImportModule},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
353 {"PyImport_AddModule", (PYTHON_PROC*)&py3_PyImport_AddModule},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 {"PyErr_BadArgument", (PYTHON_PROC*)&py3_PyErr_BadArgument},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 {"PyType_Type", (PYTHON_PROC*)&py3_PyType_Type},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 {"PyErr_Occurred", (PYTHON_PROC*)&py3_PyErr_Occurred},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 {"PyModule_GetDict", (PYTHON_PROC*)&py3_PyModule_GetDict},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
358 {"PyList_SetItem", (PYTHON_PROC*)&py3_PyList_SetItem},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
359 {"PyDict_GetItemString", (PYTHON_PROC*)&py3_PyDict_GetItemString},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
360 {"PyDict_Next", (PYTHON_PROC*)&py3_PyDict_Next},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
361 {"PyMapping_Check", (PYTHON_PROC*)&py3_PyMapping_Check},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
362 {"PyMapping_Items", (PYTHON_PROC*)&py3_PyMapping_Items},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
363 {"PyIter_Next", (PYTHON_PROC*)&py3_PyIter_Next},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
364 {"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 {"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 {"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 {"Py_BuildValue", (PYTHON_PROC*)&py3_Py_BuildValue},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 {"PyType_Ready", (PYTHON_PROC*)&py3_PyType_Ready},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 {"PyDict_SetItemString", (PYTHON_PROC*)&py3_PyDict_SetItemString},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 {"PyLong_AsLong", (PYTHON_PROC*)&py3_PyLong_AsLong},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 {"PyErr_SetNone", (PYTHON_PROC*)&py3_PyErr_SetNone},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 {"PyEval_InitThreads", (PYTHON_PROC*)&py3_PyEval_InitThreads},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 {"PyEval_RestoreThread", (PYTHON_PROC*)&py3_PyEval_RestoreThread},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374 {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
375 {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
377 {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&py3__PyObject_NextNotImplemented},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 {"PyObject_Init", (PYTHON_PROC*)&py3__PyObject_Init},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 {"PyModule_AddObject", (PYTHON_PROC*)&py3_PyModule_AddObject},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
383 {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
384 {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
385 {"PyBytes_AsStringAndSize", (PYTHON_PROC*)&py3_PyBytes_AsStringAndSize},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
386 {"PyBytes_FromString", (PYTHON_PROC*)&py3_PyBytes_FromString},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
387 {"PyFloat_FromDouble", (PYTHON_PROC*)&py3_PyFloat_FromDouble},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
388 {"PyFloat_AsDouble", (PYTHON_PROC*)&py3_PyFloat_AsDouble},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389 {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
394 {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type},
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
395 {"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
396 # ifdef Py_DEBUG
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 {"_Py_RefTotal", (PYTHON_PROC*)&py3__Py_RefTotal},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 {"_Py_Dealloc", (PYTHON_PROC*)&py3__Py_Dealloc},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 {"_PyObject_DebugFree", (PYTHON_PROC*)&py3__PyObject_DebugFree},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 {"_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
402 # else
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 {"PyObject_Malloc", (PYTHON_PROC*)&py3_PyObject_Malloc},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404 {"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
405 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
406 {"PyType_IsSubtype", (PYTHON_PROC*)&py3_PyType_IsSubtype},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
407 {"PyCapsule_New", (PYTHON_PROC*)&py3_PyCapsule_New},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
408 {"PyCapsule_GetPointer", (PYTHON_PROC*)&py3_PyCapsule_GetPointer},
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409 {"", NULL},
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
410 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413 * Free python.dll
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 */
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
415 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
416 end_dynamic_python3(void)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 {
2384
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
418 if (hinstPy3 != 0)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
420 close_dll(hinstPy3);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
421 hinstPy3 = 0;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
424
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 * Load library and get all pointers.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427 * Parameter 'libname' provides name of DLL.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428 * Return OK or FAIL.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
429 */
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
430 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
431 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
432 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 int i;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
434 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
435
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
436 # 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
437 /* 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
438 * 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
439 * 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
440 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
441 {
3032
e4f3fa1a474e updated for version 7.3.288
Bram Moolenaar <bram@vim.org>
parents: 2955
diff changeset
442 if (verbose)
e4f3fa1a474e updated for version 7.3.288
Bram Moolenaar <bram@vim.org>
parents: 2955
diff changeset
443 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
444 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
445 }
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
446 # 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
447
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
448 if (hinstPy3 != 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
449 return OK;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
450 hinstPy3 = load_dll(libname);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
452 if (!hinstPy3)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
453 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
454 if (verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
455 EMSG2(_(e_loadlib), libname);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
456 return FAIL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
459 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
460 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
461 if ((*py3_funcname_table[i].ptr = symbol_from_dll(hinstPy3,
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
462 py3_funcname_table[i].name)) == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
463 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
464 close_dll(hinstPy3);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
465 hinstPy3 = 0;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
466 if (verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
467 EMSG2(_(e_loadfunc), py3_funcname_table[i].name);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
468 return FAIL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
469 }
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
471
2342
f6540762173d Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents: 2340
diff changeset
472 /* 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
473 * will be present in the library. */
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
474 ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
475 ucs_decode = symbol_from_dll(hinstPy3,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
476 "PyUnicodeUCS2_Decode");
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
477 ucs_as_encoded_string = symbol_from_dll(hinstPy3,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
478 "PyUnicodeUCS2_AsEncodedString");
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
479 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
480 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
481 ucs_from_string = symbol_from_dll(hinstPy3,
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
482 "PyUnicodeUCS4_FromString");
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
483 ucs_decode = symbol_from_dll(hinstPy3,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
484 "PyUnicodeUCS4_Decode");
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
485 ucs_as_encoded_string = symbol_from_dll(hinstPy3,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
486 "PyUnicodeUCS4_AsEncodedString");
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
487 }
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
488 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
489 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
490 py3_PyUnicode_FromString = ucs_from_string;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
491 py3_PyUnicode_Decode = ucs_decode;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
492 py3_PyUnicode_AsEncodedString = ucs_as_encoded_string;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
493 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
494 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
495 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
496 close_dll(hinstPy3);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
497 hinstPy3 = 0;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
498 if (verbose)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
499 EMSG2(_(e_loadfunc), "PyUnicode_UCSX_*");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
500 return FAIL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
501 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
502
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
503 return OK;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
504 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
505
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
506 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507 * 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
508 * TRUE, else FALSE.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
509 */
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
510 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
511 python3_enabled(int verbose)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
512 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513 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
514 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
515
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 /* 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
517 * 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
518 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
519 static void get_py3_exceptions __ARGS((void));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
520
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
521 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
522 get_py3_exceptions()
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524 PyObject *exmod = PyImport_ImportModule("builtins");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 PyObject *exdict = PyModule_GetDict(exmod);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
526 p3imp_PyExc_AttributeError = PyDict_GetItemString(exdict, "AttributeError");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 p3imp_PyExc_IndexError = PyDict_GetItemString(exdict, "IndexError");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528 p3imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 p3imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 p3imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 Py_XINCREF(p3imp_PyExc_AttributeError);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532 Py_XINCREF(p3imp_PyExc_IndexError);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
533 Py_XINCREF(p3imp_PyExc_KeyboardInterrupt);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
534 Py_XINCREF(p3imp_PyExc_TypeError);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
535 Py_XINCREF(p3imp_PyExc_ValueError);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
536 Py_XDECREF(exmod);
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 #endif /* DYNAMIC_PYTHON3 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
539
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
540 static PyObject *BufferNew (buf_T *);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
541 static PyObject *WindowNew(win_T *);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
542 static PyObject *LineToString(const char *);
3310
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
543 static PyObject *BufferDir(PyObject *, PyObject *);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
544
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
545 static PyTypeObject RangeType;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
546
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
547 static int py3initialised = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
548
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
549 #define PYINITIALISED py3initialised
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
550
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
551 #define DICTKEY_DECL PyObject *bytes = NULL;
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
552
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
553 #define DICTKEY_GET(err) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
554 if (PyBytes_Check(keyObject)) \
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
555 { \
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3798
diff changeset
556 if (PyString_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
557 return err; \
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
558 } \
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
559 else if (PyUnicode_Check(keyObject)) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
560 { \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
561 bytes = PyString_AsBytes(keyObject); \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
562 if (bytes == NULL) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
563 return err; \
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3798
diff changeset
564 if (PyString_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
565 return err; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
566 } \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
567 else \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
568 { \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
569 PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
570 return err; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
571 }
3798
3958b0e672d6 updated for version 7.3.657
Bram Moolenaar <bram@vim.org>
parents: 3796
diff changeset
572
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
573 #define DICTKEY_UNREF \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
574 if (bytes != NULL) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
575 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
576
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
577 /*
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
578 * Include the code shared with if_python.c
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents: 2384
diff changeset
579 */
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
580 #include "if_py_both.h"
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents: 2384
diff changeset
581
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
582 #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
583
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
584 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
585 call_PyObject_Free(void *p)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587 #ifdef Py_DEBUG
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
588 _PyObject_DebugFree(p);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
589 #else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
590 PyObject_Free(p);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
592 }
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
593
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents: 2384
diff changeset
594 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
595 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
596 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
597 return PyType_GenericNew(type,args,kwds);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 }
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
599
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
600 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
601 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
602 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
603 return PyType_GenericAlloc(type,nitems);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
604 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606 /******************************************************
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 * Internal function prototypes.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
610 static Py_ssize_t RangeStart;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
611 static Py_ssize_t RangeEnd;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
612
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
613 static PyObject *globals;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
614
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 static int PythonIO_Init(void);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
616 static void PythonIO_Fini(void);
2342
f6540762173d Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents: 2340
diff changeset
617 PyMODINIT_FUNC Py3Init_vim(void);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
618
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 /******************************************************
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 * 1. Python interpreter main program.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
622
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
623 static PyGILState_STATE pygilstate = PyGILState_UNLOCKED;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
624
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
625 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
626 python3_end()
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628 static int recurse = 0;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630 /* 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
631 if (recurse != 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
632 return;
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 ++recurse;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
636 #ifdef DYNAMIC_PYTHON3
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
637 if (hinstPy3)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 if (Py_IsInitialized())
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
640 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 // acquire lock before finalizing
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
642 pygilstate = PyGILState_Ensure();
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
644 PythonIO_Fini();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
645 Py_Finalize();
2329
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 #ifdef DYNAMIC_PYTHON3
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649 end_dynamic_python3();
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 --recurse;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654
2384
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
655 #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
656 int
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
657 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
658 {
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
659 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
660 }
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
661 #endif
aeea25941392 Temporary solution for crashing when using both :py and :py3: disallow both in
Bram Moolenaar <bram@vim.org>
parents: 2374
diff changeset
662
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
663 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
664 Python3_Init(void)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 if (!py3initialised)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
668 #ifdef DYNAMIC_PYTHON3
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
669 if (!python3_enabled(TRUE))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
670 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
671 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded."));
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
672 goto fail;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
673 }
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 init_structs();
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677
2641
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
678
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
679 #ifdef PYTHON3_HOME
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
680 Py_SetPythonHome(PYTHON3_HOME);
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
681 #endif
b803b2776880 updated for version 7.3.062
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
682
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
683 #if !defined(MACOS) || defined(MACOS_X_UNIX)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
684 Py_Initialize();
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
685 #else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
686 PyMac_Initialize();
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
687 #endif
2877
6bbdb9c7a425 updated for version 7.3.212
Bram Moolenaar <bram@vim.org>
parents: 2716
diff changeset
688 /* initialise threads, must be after Py_Initialize() */
6bbdb9c7a425 updated for version 7.3.212
Bram Moolenaar <bram@vim.org>
parents: 2716
diff changeset
689 PyEval_InitThreads();
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 #ifdef DYNAMIC_PYTHON3
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
692 get_py3_exceptions();
2329
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
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
695 if (PythonIO_Init())
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
696 goto fail;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
697
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
698 PyImport_AppendInittab("vim", Py3Init_vim);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
699
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
700 globals = PyModule_GetDict(PyImport_AddModule("__main__"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
701
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
702 /* Remove the element from sys.path that was added because of our
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
703 * argv[0] value in Py3Init_vim(). Previously we used an empty
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
704 * string, but dependinding on the OS we then get an empty entry or
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
705 * the current directory in sys.path.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
706 * Only after vim has been imported, the element does exist in
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
707 * sys.path.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
708 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
709 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
710
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
711 // lock is created and acquired in PyEval_InitThreads() and thread
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
712 // state is created in Py_Initialize()
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
713 // there _PyGILState_NoteThreadState() also sets gilcounter to 1
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
714 // (python must have threads enabled!)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
715 // so the following does both: unlock GIL and save thread state in TLS
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
716 // without deleting thread state
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
717 PyGILState_Release(pygilstate);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
718
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
719 py3initialised = 1;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
720 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
721
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 return 0;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
723
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
724 fail:
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 /* 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
726 * This is OK, as it is possible to call this function even
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
727 * if PythonIO_Init() has not completed successfully (it will
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
728 * not do anything in this case).
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
730 PythonIO_Flush();
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
731 return -1;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
733
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
734 /*
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
735 * External interface
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
736 */
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
737 static void
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
738 DoPy3Command(exarg_T *eap, const char *cmd, typval_T *rettv)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 #if defined(MACOS) && !defined(MACOS_X_UNIX)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
741 GrafPtr oldPort;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
742 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
743 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
744 char *saved_locale;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
745 #endif
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
746 PyObject *cmdstr;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
747 PyObject *cmdbytes;
2329
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 #if defined(MACOS) && !defined(MACOS_X_UNIX)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 GetPort(&oldPort);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751 /* Check if the Python library is available */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
752 if ((Ptr)PyMac_Initialize == (Ptr)kUnresolvedCFragSymbolAddress)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
753 goto theend;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755 if (Python3_Init())
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
756 goto theend;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
758 if (rettv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
759 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
760 RangeStart = eap->line1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
761 RangeEnd = eap->line2;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
762 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
763 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
764 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
765 RangeStart = (PyInt) curwin->w_cursor.lnum;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
766 RangeEnd = RangeStart;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
767 }
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
768 Python_Release_Vim(); /* leave vim */
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
770 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
771 /* 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
772 saved_locale = setlocale(LC_NUMERIC, NULL);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
773 if (saved_locale == NULL || STRCMP(saved_locale, "C") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
774 saved_locale = NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
775 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
776 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
777 /* Need to make a copy, value may change when setting new locale. */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
778 saved_locale = (char *)vim_strsave((char_u *)saved_locale);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
779 (void)setlocale(LC_NUMERIC, "C");
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
781 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 pygilstate = PyGILState_Ensure();
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
785 /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
786 * SyntaxError (unicode error). */
2955
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
787 cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
788 (char *)ENC_OPT, CODEC_ERROR_HANDLER);
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
789 cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
790 Py_XDECREF(cmdstr);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
791 if (rettv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
792 PyRun_SimpleString(PyBytes_AsString(cmdbytes));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
793 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
794 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
795 PyObject *r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
796
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
797 r = PyRun_String(PyBytes_AsString(cmdbytes), Py_eval_input,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
798 globals, globals);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
799 if (r == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
800 EMSG(_("E860: Eval did not return a valid python 3 object"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
801 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
802 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
803 if (ConvertFromPyObject(r, rettv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
804 EMSG(_("E861: Failed to convert returned python 3 object to vim value"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
805 Py_DECREF(r);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
806 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
807 PyErr_Clear();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
808 }
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
809 Py_XDECREF(cmdbytes);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811 PyGILState_Release(pygilstate);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
813 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 if (saved_locale != NULL)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
815 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
816 (void)setlocale(LC_NUMERIC, saved_locale);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
817 vim_free(saved_locale);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
818 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
819 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
821 Python_Lock_Vim(); /* enter vim */
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
822 PythonIO_Flush();
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 #if defined(MACOS) && !defined(MACOS_X_UNIX)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
824 SetPort(oldPort);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
825 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
827 theend:
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
828 return; /* keeps lint happy */
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
829 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
830
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
831 /*
2350
06feaf4fe36a Rename some "python3" symbols to "py3", as the command name.
Bram Moolenaar <bram@vim.org>
parents: 2342
diff changeset
832 * ":py3"
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
833 */
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
834 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
835 ex_py3(exarg_T *eap)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
836 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
837 char_u *script;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
838
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
839 script = script_get(eap, eap->arg);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
840 if (!eap->skip)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
841 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
842 if (script == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
843 DoPy3Command(eap, (char *)eap->arg, NULL);
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
844 else
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
845 DoPy3Command(eap, (char *)script, NULL);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
846 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
847 vim_free(script);
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
850 #define BUFFER_SIZE 2048
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
851
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
852 /*
2340
99c1eba60b2d Make automatic prototype generation work with more interfaces.
Bram Moolenaar <bram@vim.org>
parents: 2330
diff changeset
853 * ":py3file"
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
854 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
855 void
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
856 ex_py3file(exarg_T *eap)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
857 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
858 static char buffer[BUFFER_SIZE];
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
859 const char *file;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
860 char *p;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
861 int i;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
862
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863 /* 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
864 * 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
865 * 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
866 * compatible between the two. Yuk.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
867 *
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
868 * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec'))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
869 *
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
870 * Using bytes so that Python can detect the source encoding as it normally
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
871 * 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
872 *
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
873 * 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
874 * Python won't mangle the file name.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
875 */
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 strcpy(buffer, "exec(compile(open('");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
878 p = buffer + 19; /* size of "exec(compile(open('" */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
879
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
880 for (i=0; i<2; ++i)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
881 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
882 file = (char *)eap->arg;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
883 while (*file && p < buffer + (BUFFER_SIZE - 3))
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
884 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
885 if (*file == '\\' || *file == '\'')
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
886 *p++ = '\\';
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
887 *p++ = *file++;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
888 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
889 /* If we didn't finish the file name, we hit a buffer overflow */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
890 if (*file != '\0')
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
891 return;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
892 if (i==0)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
893 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
894 strcpy(p,"','rb').read(),'");
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
895 p += 16;
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
896 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
897 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
898 {
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
899 strcpy(p,"','exec'))");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
900 p += 10;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
901 }
2329
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
904
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
905 /* Execute the file */
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
906 DoPy3Command(eap, buffer, NULL);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
907 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
908
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
909 /******************************************************
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
910 * 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
911 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
912
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
913 /* Implementation functions
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
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
916 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
917 OutputGetattro(PyObject *self, PyObject *nameobj)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
918 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
919 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
920 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
921 name = _PyUnicode_AsString(nameobj);
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 if (strcmp(name, "softspace") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
924 return PyLong_FromLong(((OutputObject *)(self))->softspace);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
925
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
926 return PyObject_GenericGetAttr(self, nameobj);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
927 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
928
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
929 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
930 OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
931 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
932 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
933 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
934 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
935
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
936 if (val == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
937 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
938 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
939 return -1;
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
942 if (strcmp(name, "softspace") == 0)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
943 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
944 if (!PyLong_Check(val))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
945 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
946 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
947 return -1;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
948 }
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
949
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
950 ((OutputObject *)(self))->softspace = PyLong_AsLong(val);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
951 return 0;
2329
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 PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
955 return -1;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
956 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
957
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
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
960 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
961 PythonIO_Init(void)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
962 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
963 PyType_Ready(&OutputType);
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
964 return PythonIO_Init_io();
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
965 }
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
966
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
967 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
968 PythonIO_Fini(void)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
969 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
970 PySys_SetObject("stdout", NULL);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
971 PySys_SetObject("stderr", NULL);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
972 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
973
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
974 /******************************************************
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
975 * 3. Implementation of the Vim module for Python
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
978 /* Window type - Implementation functions
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
982 #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
983
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
984 /* Buffer type - Implementation functions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
985 * --------------------------------------
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
986 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
987
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
988 #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
989
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
990 static Py_ssize_t BufferLength(PyObject *);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
991 static PyObject *BufferItem(PyObject *, Py_ssize_t);
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
992 static PyObject* BufferSubscript(PyObject *self, PyObject *idx);
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
993 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
994
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
995
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
996 /* Line range type - Implementation functions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
997 * --------------------------------------
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
998 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
999
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1000 #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
1001
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1002 static PyObject* RangeSubscript(PyObject *self, PyObject *idx);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1003 static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1004 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
1005
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1006 /* Current objects type - Implementation functions
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1010 static PySequenceMethods BufferAsSeq = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1011 (lenfunc) BufferLength, /* sq_length, len(x) */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1012 (binaryfunc) 0, /* sq_concat, x+y */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1013 (ssizeargfunc) 0, /* sq_repeat, x*n */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1014 (ssizeargfunc) BufferItem, /* sq_item, x[i] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1015 0, /* was_sq_slice, x[i:j] */
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1016 0, /* sq_ass_item, x[i]=v */
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1017 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
1018 0, /* sq_contains */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1019 0, /* sq_inplace_concat */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1020 0, /* sq_inplace_repeat */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1021 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1022
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1023 PyMappingMethods BufferAsMapping = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1024 /* mp_length */ (lenfunc)BufferLength,
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1025 /* mp_subscript */ (binaryfunc)BufferSubscript,
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1026 /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript,
2329
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
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1030 /* Buffer object - Definitions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1031 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1032
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1033 static PyTypeObject BufferType;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1034
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
1035 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
1036 BufferNew(buf_T *buf)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1037 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1038 /* We need to handle deletion of buffers underneath us.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1039 * If we add a "b_python3_ref" field to the buf_T structure,
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1040 * then we can get at it in buf_freeall() in vim. We then
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1041 * need to create only ONE Python object per buffer - if
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1042 * we try to create a second, just INCREF the existing one
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1043 * and return it. The (single) Python object referring to
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1044 * the buffer is stored in "b_python3_ref".
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1045 * Question: what to do on a buf_freeall(). We'll probably
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1046 * have to either delete the Python object (DECREF it to
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1047 * zero - a bad idea, as it leaves dangling refs!) or
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1048 * set the buf_T * value to an invalid value (-1?), which
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1049 * means we need checks in all access functions... Bah.
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 BufferObject *self;
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 if (buf->b_python3_ref != NULL)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1055 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1056 self = buf->b_python3_ref;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1057 Py_INCREF(self);
2329
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 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1060 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1061 self = PyObject_NEW(BufferObject, &BufferType);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1062 buf->b_python3_ref = self;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1063 if (self == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1064 return NULL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1065 self->buf = buf;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1066 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1067
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1068 return (PyObject *)(self);
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
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
1071 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
1072 BufferDestructor(PyObject *self)
2329
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 BufferObject *this = (BufferObject *)(self);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1075
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1076 if (this->buf && this->buf != INVALID_BUFFER_VALUE)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1077 this->buf->b_python3_ref = NULL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1078
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1079 Py_TYPE(self)->tp_free((PyObject*)self);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1080 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1081
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
1082 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
1083 BufferGetattro(PyObject *self, PyObject*nameobj)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1084 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1085 BufferObject *this = (BufferObject *)(self);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1086
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1087 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1088 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1089 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1090
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1091 if (CheckBuffer(this))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1092 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1093
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1094 if (strcmp(name, "name") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1095 return Py_BuildValue("s", this->buf->b_ffname);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1096 else if (strcmp(name, "number") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1097 return Py_BuildValue("n", this->buf->b_fnum);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1098 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1099 return PyObject_GenericGetAttr(self, nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1100 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1101
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
1102 static PyObject *
3310
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1103 BufferDir(PyObject *self UNUSED, PyObject *args UNUSED)
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1104 {
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1105 return Py_BuildValue("[sssss]", "name", "number",
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1106 "append", "mark", "range");
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1107 }
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1108
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3083
diff changeset
1109 static PyObject *
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
1110 BufferRepr(PyObject *self)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1111 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1112 static char repr[100];
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1113 BufferObject *this = (BufferObject *)(self);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1114
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1115 if (this->buf == INVALID_BUFFER_VALUE)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1116 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1117 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1118 return PyUnicode_FromString(repr);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1119 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1120 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1121 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1122 char *name = (char *)this->buf->b_fname;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1123 Py_ssize_t len;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1124
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1125 if (name == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1126 name = "";
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1127 len = strlen(name);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1128
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1129 if (len > 35)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1130 name = name + (35 - len);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1131
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1132 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1133
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1134 return PyUnicode_FromString(repr);
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 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1137
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1138 /******************/
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1139
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
1140 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
1141 BufferLength(PyObject *self)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1142 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1143 if (CheckBuffer((BufferObject *)(self)))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1144 return -1;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1145
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1146 return (Py_ssize_t)(((BufferObject *)(self))->buf->b_ml.ml_line_count);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1147 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1148
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
1149 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
1150 BufferItem(PyObject *self, Py_ssize_t n)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1151 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1152 return RBItem((BufferObject *)(self), n, 1,
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1153 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1154 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1155
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
1156 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
1157 BufferSlice(PyObject *self, Py_ssize_t lo, Py_ssize_t hi)
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
1158 {
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
1159 return RBSlice((BufferObject *)(self), lo, hi, 1,
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
1160 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count);
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
1161 }
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
1162
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
1163 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
1164 BufferSubscript(PyObject *self, PyObject* idx)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1165 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1166 if (PyLong_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1167 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1168 long _idx = PyLong_AsLong(idx);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1169 return BufferItem(self,_idx);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1170 } else if (PySlice_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1171 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1172 Py_ssize_t start, stop, step, slicelen;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1173
3074
6eae1b42c668 updated for version 7.3.309
Bram Moolenaar <bram@vim.org>
parents: 3070
diff changeset
1174 if (PySlice_GetIndicesEx((PyObject *)idx,
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1175 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1176 &start, &stop,
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1177 &step, &slicelen) < 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1178 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1179 return NULL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1180 }
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1181 return BufferSlice(self, start, stop);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1182 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1183 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1184 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1185 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1186 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1187 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1188 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1189
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1190 static Py_ssize_t
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1191 BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1192 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1193 if (PyLong_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1194 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1195 long n = PyLong_AsLong(idx);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1196 return RBAsItem((BufferObject *)(self), n, val, 1,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1197 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1198 NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1199 } else if (PySlice_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1200 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1201 Py_ssize_t start, stop, step, slicelen;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1202
3074
6eae1b42c668 updated for version 7.3.309
Bram Moolenaar <bram@vim.org>
parents: 3070
diff changeset
1203 if (PySlice_GetIndicesEx((PyObject *)idx,
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1204 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1205 &start, &stop,
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1206 &step, &slicelen) < 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1207 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1208 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1209 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1210 return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1211 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1212 NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1213 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1214 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1215 {
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1216 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1217 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1218 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1219 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1220
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1221 static PySequenceMethods RangeAsSeq = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1222 (lenfunc) RangeLength, /* sq_length, len(x) */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1223 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1224 (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1225 (ssizeargfunc) RangeItem, /* sq_item, x[i] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1226 0, /* was_sq_slice, x[i:j] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1227 (ssizeobjargproc) RangeAsItem, /* sq_as_item, x[i]=v */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1228 0, /* sq_ass_slice, x[i:j]=v */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1229 0, /* sq_contains */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1230 0, /* sq_inplace_concat */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1231 0, /* sq_inplace_repeat */
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1232 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1233
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1234 PyMappingMethods RangeAsMapping = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1235 /* mp_length */ (lenfunc)RangeLength,
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1236 /* mp_subscript */ (binaryfunc)RangeSubscript,
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1237 /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript,
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1238 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1239
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1240 /* Line range object - Implementation
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1241 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1242
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
1243 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
1244 RangeDestructor(PyObject *self)
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 Py_DECREF(((RangeObject *)(self))->buf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1247 Py_TYPE(self)->tp_free((PyObject*)self);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1248 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1249
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
1250 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
1251 RangeGetattro(PyObject *self, PyObject *nameobj)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1252 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1253 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1254 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1255 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1256
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1257 if (strcmp(name, "start") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1258 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
1259 else if (strcmp(name, "end") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1260 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
1261 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1262 return PyObject_GenericGetAttr(self, nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1263 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1264
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1265 /****************/
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1266
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
1267 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
1268 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
1269 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1270 return RBAsItem(((RangeObject *)(self))->buf, n, val,
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1271 ((RangeObject *)(self))->start,
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1272 ((RangeObject *)(self))->end,
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1273 &((RangeObject *)(self))->end);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1274 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1275
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1276 static Py_ssize_t
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1277 RangeAsSlice(PyObject *self, Py_ssize_t lo, Py_ssize_t hi, PyObject *val)
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1278 {
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1279 return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1280 ((RangeObject *)(self))->start,
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1281 ((RangeObject *)(self))->end,
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1282 &((RangeObject *)(self))->end);
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1283 }
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1284
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
1285 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
1286 RangeSubscript(PyObject *self, PyObject* idx)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1287 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1288 if (PyLong_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1289 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1290 long _idx = PyLong_AsLong(idx);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1291 return RangeItem(self,_idx);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1292 } else if (PySlice_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1293 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1294 Py_ssize_t start, stop, step, slicelen;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1295
3074
6eae1b42c668 updated for version 7.3.309
Bram Moolenaar <bram@vim.org>
parents: 3070
diff changeset
1296 if (PySlice_GetIndicesEx((PyObject *)idx,
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1297 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1298 &start, &stop,
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1299 &step, &slicelen) < 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1300 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1301 return NULL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1302 }
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1303 return RangeSlice(self, start, stop);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1304 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1305 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1306 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1307 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1308 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1309 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1310 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1311
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1312 static Py_ssize_t
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1313 RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1314 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1315 if (PyLong_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1316 {
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1317 long n = PyLong_AsLong(idx);
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1318 return RangeAsItem(self, n, val);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1319 } else if (PySlice_Check(idx))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1320 {
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1321 Py_ssize_t start, stop, step, slicelen;
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1322
3074
6eae1b42c668 updated for version 7.3.309
Bram Moolenaar <bram@vim.org>
parents: 3070
diff changeset
1323 if (PySlice_GetIndicesEx((PyObject *)idx,
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1324 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1325 &start, &stop,
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1326 &step, &slicelen) < 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1327 {
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1328 return -1;
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1329 }
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1330 return RangeAsSlice(self, start, stop, val);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1331 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1332 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1333 {
3070
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1334 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1335 return -1;
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1336 }
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1337 }
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1338
880b7dd69331 updated for version 7.3.307
Bram Moolenaar <bram@vim.org>
parents: 3032
diff changeset
1339
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1340 /* Buffer list object - Definitions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1341 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1342
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1343 typedef struct
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1344 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1345 PyObject_HEAD
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
1346 } BufListObject;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1347
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1348 static PySequenceMethods BufListAsSeq = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1349 (lenfunc) BufListLength, /* sq_length, len(x) */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1350 (binaryfunc) 0, /* sq_concat, x+y */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1351 (ssizeargfunc) 0, /* sq_repeat, x*n */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1352 (ssizeargfunc) BufListItem, /* sq_item, x[i] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1353 0, /* was_sq_slice, x[i:j] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1354 (ssizeobjargproc) 0, /* sq_as_item, x[i]=v */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1355 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
1356 0, /* sq_contains */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1357 0, /* sq_inplace_concat */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1358 0, /* sq_inplace_repeat */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1359 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1360
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1361 static PyTypeObject BufListType;
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 /* Window object - Definitions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1364 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1365
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1366 static struct PyMethodDef WindowMethods[] = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1367 /* name, function, calling, documentation */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1368 { NULL, NULL, 0, NULL }
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1369 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1370
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1371 static PyTypeObject WindowType;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1372
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1373 /* Window object - Implementation
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1374 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1375
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
1376 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
1377 WindowNew(win_T *win)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1378 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1379 /* We need to handle deletion of windows underneath us.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1380 * If we add a "w_python3_ref" field to the win_T structure,
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1381 * then we can get at it in win_free() in vim. We then
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1382 * need to create only ONE Python object per window - if
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1383 * we try to create a second, just INCREF the existing one
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1384 * and return it. The (single) Python object referring to
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1385 * the window is stored in "w_python3_ref".
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1386 * On a win_free() we set the Python object's win_T* field
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1387 * to an invalid value. We trap all uses of a window
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1388 * object, and reject them if the win_T* field is invalid.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1389 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1390
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1391 WindowObject *self;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1392
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1393 if (win->w_python3_ref)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1394 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1395 self = win->w_python3_ref;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1396 Py_INCREF(self);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1397 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1398 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1399 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1400 self = PyObject_NEW(WindowObject, &WindowType);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1401 if (self == NULL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1402 return NULL;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1403 self->win = win;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1404 win->w_python3_ref = self;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1405 }
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 return (PyObject *)(self);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1408 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1409
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
1410 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
1411 WindowDestructor(PyObject *self)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1412 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1413 WindowObject *this = (WindowObject *)(self);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1414
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1415 if (this->win && this->win != INVALID_WINDOW_VALUE)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1416 this->win->w_python3_ref = NULL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1417
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1418 Py_TYPE(self)->tp_free((PyObject*)self);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1419 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1420
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
1421 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
1422 WindowGetattro(PyObject *self, PyObject *nameobj)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1423 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1424 WindowObject *this = (WindowObject *)(self);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1425
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1426 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1427 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1428 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1429
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1430
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1431 if (CheckWindow(this))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1432 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1433
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1434 if (strcmp(name, "buffer") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1435 return (PyObject *)BufferNew(this->win->w_buffer);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1436 else if (strcmp(name, "cursor") == 0)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1437 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1438 pos_T *pos = &this->win->w_cursor;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1439
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1440 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1441 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1442 else if (strcmp(name, "height") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1443 return Py_BuildValue("l", (long)(this->win->w_height));
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1444 #ifdef FEAT_VERTSPLIT
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1445 else if (strcmp(name, "width") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1446 return Py_BuildValue("l", (long)(W_WIDTH(this->win)));
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1447 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1448 else if (strcmp(name,"__members__") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1449 return Py_BuildValue("[sss]", "buffer", "cursor", "height");
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1450 else
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1451 return PyObject_GenericGetAttr(self, nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1452 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1453
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents: 2384
diff changeset
1454 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
1455 WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1456 {
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
1457 char *name = "";
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1458
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1459 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1460 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1461
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
1462 return WindowSetattr(self, name, val);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1463 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1464
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1465 /* Window list object - Definitions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1466 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1467
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1468 typedef struct
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1469 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1470 PyObject_HEAD
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1471 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1472 WinListObject;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1473
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1474 static PySequenceMethods WinListAsSeq = {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1475 (lenfunc) WinListLength, /* sq_length, len(x) */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1476 (binaryfunc) 0, /* sq_concat, x+y */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1477 (ssizeargfunc) 0, /* sq_repeat, x*n */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1478 (ssizeargfunc) WinListItem, /* sq_item, x[i] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1479 0, /* sq_slice, x[i:j] */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1480 (ssizeobjargproc)0, /* sq_as_item, x[i]=v */
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1481 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
1482 0, /* sq_contains */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1483 0, /* sq_inplace_concat */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1484 0, /* sq_inplace_repeat */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1485 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1486
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1487 static PyTypeObject WinListType;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1488
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1489 /* Current items object - Definitions
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1490 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1491
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1492 typedef struct
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1493 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1494 PyObject_HEAD
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2404
diff changeset
1495 } CurrentObject;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1496
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1497 static PyTypeObject CurrentType;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1498
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1499 /* Current items object - Implementation
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1500 */
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
1501 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
1502 CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1503 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1504 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1505 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1506 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1507
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1508 if (strcmp(name, "buffer") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1509 return (PyObject *)BufferNew(curbuf);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1510 else if (strcmp(name, "window") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1511 return (PyObject *)WindowNew(curwin);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1512 else if (strcmp(name, "line") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1513 return GetBufferLine(curbuf, (Py_ssize_t)curwin->w_cursor.lnum);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1514 else if (strcmp(name, "range") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1515 return RangeNew(curbuf, RangeStart, RangeEnd);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1516 else if (strcmp(name,"__members__") == 0)
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1517 return Py_BuildValue("[ssss]", "buffer", "window", "line", "range");
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1518 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1519 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1520 PyErr_SetString(PyExc_AttributeError, name);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1521 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1522 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1523 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1524
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
1525 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
1526 CurrentSetattro(PyObject *self UNUSED, PyObject *nameobj, PyObject *value)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1527 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1528 char *name = "";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1529 if (PyUnicode_Check(nameobj))
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1530 name = _PyUnicode_AsString(nameobj);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1531
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1532 if (strcmp(name, "line") == 0)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1533 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1534 if (SetBufferLine(curbuf, (Py_ssize_t)curwin->w_cursor.lnum, value, NULL) == FAIL)
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1535 return -1;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1536
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1537 return 0;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1538 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1539 else
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1540 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1541 PyErr_SetString(PyExc_AttributeError, name);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1542 return -1;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1543 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1544 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1545
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1546 /* Dictionary object - Definitions
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1547 */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1548
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1549 static PyInt DictionaryLength(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1550
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1551 static PyMappingMethods DictionaryAsMapping = {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1552 /* mp_length */ (lenfunc) DictionaryLength,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1553 /* mp_subscript */ (binaryfunc) DictionaryItem,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1554 /* mp_ass_subscript */ (objobjargproc) DictionaryAssItem,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1555 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1556
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1557 static PyTypeObject DictionaryType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1558
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1559 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1560 DictionaryDestructor(PyObject *self)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1561 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1562 DictionaryObject *this = (DictionaryObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1563
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1564 pyll_remove(&this->ref, &lastdict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1565 dict_unref(this->dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1566
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1567 Py_TYPE(self)->tp_free((PyObject*)self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1568 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1569
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1570 /* List object - Definitions
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1571 */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1572
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1573 static PyInt ListLength(PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1574 static PyObject *ListItem(PyObject *, Py_ssize_t);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1575
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1576 static PySequenceMethods ListAsSeq = {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1577 (lenfunc) ListLength, /* sq_length, len(x) */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1578 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1579 (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1580 (ssizeargfunc) ListItem, /* sq_item, x[i] */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1581 (void *) 0, /* was_sq_slice, x[i:j] */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1582 (ssizeobjargproc) ListAssItem, /* sq_as_item, x[i]=v */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1583 (void *) 0, /* was_sq_ass_slice, x[i:j]=v */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1584 0, /* sq_contains */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1585 (binaryfunc) ListConcatInPlace,/* sq_inplace_concat */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1586 0, /* sq_inplace_repeat */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1587 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1588
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1589 static PyObject *ListSubscript(PyObject *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1590 static Py_ssize_t ListAsSubscript(PyObject *, PyObject *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1591
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1592 static PyMappingMethods ListAsMapping = {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1593 /* mp_length */ (lenfunc) ListLength,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1594 /* mp_subscript */ (binaryfunc) ListSubscript,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1595 /* mp_ass_subscript */ (objobjargproc) ListAsSubscript,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1596 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1597
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1598 static PyTypeObject ListType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1599
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1600 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1601 ListSubscript(PyObject *self, PyObject* idxObject)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1602 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1603 if (PyLong_Check(idxObject))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1604 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1605 long idx = PyLong_AsLong(idxObject);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1606 return ListItem(self, idx);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1607 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1608 else if (PySlice_Check(idxObject))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1609 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1610 Py_ssize_t start, stop, step, slicelen;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1611
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1612 if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1613 &step, &slicelen) < 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1614 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1615 return ListSlice(self, start, stop);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1616 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1617 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1618 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1619 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1620 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1621 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1622 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1623
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1624 static Py_ssize_t
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1625 ListAsSubscript(PyObject *self, PyObject *idxObject, PyObject *obj)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1626 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1627 if (PyLong_Check(idxObject))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1628 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1629 long idx = PyLong_AsLong(idxObject);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1630 return ListAssItem(self, idx, obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1631 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1632 else if (PySlice_Check(idxObject))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1633 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1634 Py_ssize_t start, stop, step, slicelen;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1635
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1636 if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1637 &step, &slicelen) < 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1638 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1639 return ListAssSlice(self, start, stop, obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1640 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1641 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1642 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1643 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1644 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1645 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1646 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1647
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1648 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1649 ListDestructor(PyObject *self)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1650 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1651 ListObject *this = (ListObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1652
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1653 pyll_remove(&this->ref, &lastlist);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1654 list_unref(this->list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1655
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1656 Py_TYPE(self)->tp_free((PyObject*)self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1657 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1658
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1659 /* Function object - Definitions
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1660 */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1661
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1662 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1663 FunctionDestructor(PyObject *self)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1664 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1665 FunctionObject *this = (FunctionObject *) (self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1666
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1667 func_unref(this->name);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1668 PyMem_Del(this->name);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1669
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1670 Py_TYPE(self)->tp_free((PyObject*)self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1671 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1672
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1673 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1674 FunctionGetattro(PyObject *self, PyObject *nameobj)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1675 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1676 FunctionObject *this = (FunctionObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1677 char *name = "";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1678 if (PyUnicode_Check(nameobj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1679 name = _PyUnicode_AsString(nameobj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1680
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1681 if (strcmp(name, "name") == 0)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1682 return PyUnicode_FromString((char *)(this->name));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1683
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1684 return PyObject_GenericGetAttr(self, nameobj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1685 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1686
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1687 /* External interface
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1688 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1689
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1690 void
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1691 python3_buffer_free(buf_T *buf)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1692 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1693 if (buf->b_python3_ref != NULL)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1694 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1695 BufferObject *bp = buf->b_python3_ref;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1696 bp->buf = INVALID_BUFFER_VALUE;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1697 buf->b_python3_ref = NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1700
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701 #if defined(FEAT_WINDOWS) || defined(PROTO)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1702 void
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1703 python3_window_free(win_T *win)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1704 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1705 if (win->w_python3_ref != NULL)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1706 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1707 WindowObject *wp = win->w_python3_ref;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1708 wp->win = INVALID_WINDOW_VALUE;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1709 win->w_python3_ref = NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1710 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1711 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1712 #endif
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1713
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1714 static BufListObject TheBufferList =
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1715 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1716 PyObject_HEAD_INIT(&BufListType)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1717 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1718
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1719 static WinListObject TheWindowList =
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1720 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1721 PyObject_HEAD_INIT(&WinListType)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1722 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1723
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1724 static CurrentObject TheCurrent =
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1725 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1726 PyObject_HEAD_INIT(&CurrentType)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1727 };
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1728
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1729 PyDoc_STRVAR(vim_module_doc,"vim python interface\n");
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1730
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1731 static struct PyModuleDef vimmodule;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1732
2342
f6540762173d Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents: 2340
diff changeset
1733 #ifndef PROTO
f6540762173d Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents: 2340
diff changeset
1734 PyMODINIT_FUNC Py3Init_vim(void)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1735 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1736 PyObject *mod;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1737 /* 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
1738 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
1739
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1740 PyType_Ready(&BufferType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1741 PyType_Ready(&RangeType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1742 PyType_Ready(&WindowType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1743 PyType_Ready(&BufListType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1744 PyType_Ready(&WinListType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1745 PyType_Ready(&CurrentType);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1746 PyType_Ready(&DictionaryType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1747 PyType_Ready(&ListType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1748 PyType_Ready(&FunctionType);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1749
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1750 /* 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
1751 PySys_SetArgv(1, argv);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1752
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1753 mod = PyModule_Create(&vimmodule);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1754 if (mod == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1755 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1756
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1757 VimError = PyErr_NewException("vim.error", NULL, NULL);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2877
diff changeset
1758 Py_INCREF(VimError);
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1759
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1760 PyModule_AddObject(mod, "error", VimError);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1761 Py_INCREF((PyObject *)(void *)&TheBufferList);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1762 PyModule_AddObject(mod, "buffers", (PyObject *)(void *)&TheBufferList);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1763 Py_INCREF((PyObject *)(void *)&TheCurrent);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1764 PyModule_AddObject(mod, "current", (PyObject *)(void *)&TheCurrent);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1765 Py_INCREF((PyObject *)(void *)&TheWindowList);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1766 PyModule_AddObject(mod, "windows", (PyObject *)(void *)&TheWindowList);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1767
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1768 if (PyErr_Occurred())
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1769 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1770
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1771 return mod;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1772 }
2342
f6540762173d Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents: 2340
diff changeset
1773 #endif
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1774
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1775 /*************************************************************************
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1776 * 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
1777 */
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1778
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1779 /* Convert a Vim line into a Python string.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1780 * All internal newlines are replaced by null characters.
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1781 *
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1782 * 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
1783 */
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
1784 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
1785 LineToString(const char *str)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1786 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1787 PyObject *result;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1788 Py_ssize_t len = strlen(str);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1789 char *tmp,*p;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1790
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1791 tmp = (char *)alloc((unsigned)(len+1));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1792 p = tmp;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1793 if (p == NULL)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1794 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1795 PyErr_NoMemory();
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1796 return NULL;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1797 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1798
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1799 while (*str)
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1800 {
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1801 if (*str == '\n')
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1802 *p = '\0';
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1803 else
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1804 *p = *str;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1805
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1806 ++p;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1807 ++str;
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1808 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1809 *p = '\0';
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1810
2955
f909f4f0f38c updated for version 7.3.250
Bram Moolenaar <bram@vim.org>
parents: 2927
diff changeset
1811 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
1812
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1813 vim_free(tmp);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1814 return result;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1815 }
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1816
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1817 void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1818 do_py3eval (char_u *str, typval_T *rettv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1819 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1820 DoPy3Command(NULL, (char *) str, rettv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1821 switch(rettv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1822 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1823 case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1824 case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1825 case VAR_FUNC: func_ref(rettv->vval.v_string); break;
3796
a2f61b2b8e77 updated for version 7.3.656
Bram Moolenaar <bram@vim.org>
parents: 3638
diff changeset
1826 case VAR_UNKNOWN:
a2f61b2b8e77 updated for version 7.3.656
Bram Moolenaar <bram@vim.org>
parents: 3638
diff changeset
1827 rettv->v_type = VAR_NUMBER;
a2f61b2b8e77 updated for version 7.3.656
Bram Moolenaar <bram@vim.org>
parents: 3638
diff changeset
1828 rettv->vval.v_number = 0;
a2f61b2b8e77 updated for version 7.3.656
Bram Moolenaar <bram@vim.org>
parents: 3638
diff changeset
1829 break;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1830 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1831 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1832
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1833 void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1834 set_ref_in_python3 (int copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1835 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1836 set_ref_in_py(copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1837 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1838
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
1839 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
1840 init_structs(void)
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1841 {
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1842 vim_memset(&OutputType, 0, sizeof(OutputType));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1843 OutputType.tp_name = "vim.message";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1844 OutputType.tp_basicsize = sizeof(OutputObject);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1845 OutputType.tp_getattro = OutputGetattro;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1846 OutputType.tp_setattro = OutputSetattro;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1847 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1848 OutputType.tp_doc = "vim message object";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1849 OutputType.tp_methods = OutputMethods;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1850 OutputType.tp_alloc = call_PyType_GenericAlloc;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1851 OutputType.tp_new = call_PyType_GenericNew;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1852 OutputType.tp_free = call_PyObject_Free;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1853
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1854 vim_memset(&BufferType, 0, sizeof(BufferType));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1855 BufferType.tp_name = "vim.buffer";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1856 BufferType.tp_basicsize = sizeof(BufferType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1857 BufferType.tp_dealloc = BufferDestructor;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1858 BufferType.tp_repr = BufferRepr;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1859 BufferType.tp_as_sequence = &BufferAsSeq;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1860 BufferType.tp_as_mapping = &BufferAsMapping;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1861 BufferType.tp_getattro = BufferGetattro;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1862 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1863 BufferType.tp_doc = "vim buffer object";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1864 BufferType.tp_methods = BufferMethods;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1865 BufferType.tp_alloc = call_PyType_GenericAlloc;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1866 BufferType.tp_new = call_PyType_GenericNew;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1867 BufferType.tp_free = call_PyObject_Free;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1868
2330
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1869 vim_memset(&WindowType, 0, sizeof(WindowType));
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1870 WindowType.tp_name = "vim.window";
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1871 WindowType.tp_basicsize = sizeof(WindowObject);
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1872 WindowType.tp_dealloc = WindowDestructor;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1873 WindowType.tp_repr = WindowRepr;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1874 WindowType.tp_getattro = WindowGetattro;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1875 WindowType.tp_setattro = WindowSetattro;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1876 WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1877 WindowType.tp_doc = "vim Window object";
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1878 WindowType.tp_methods = WindowMethods;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1879 WindowType.tp_alloc = call_PyType_GenericAlloc;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1880 WindowType.tp_new = call_PyType_GenericNew;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1881 WindowType.tp_free = call_PyObject_Free;
ea4bf6df1a8a Whitespace cleanup.
Bram Moolenaar <bram@vim.org>
parents: 2329
diff changeset
1882
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1883 vim_memset(&BufListType, 0, sizeof(BufListType));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1884 BufListType.tp_name = "vim.bufferlist";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1885 BufListType.tp_basicsize = sizeof(BufListObject);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1886 BufListType.tp_as_sequence = &BufListAsSeq;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1887 BufListType.tp_flags = Py_TPFLAGS_DEFAULT;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1888 BufferType.tp_doc = "vim buffer list";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1889
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1890 vim_memset(&WinListType, 0, sizeof(WinListType));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1891 WinListType.tp_name = "vim.windowlist";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1892 WinListType.tp_basicsize = sizeof(WinListType);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1893 WinListType.tp_as_sequence = &WinListAsSeq;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1894 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1895 WinListType.tp_doc = "vim window list";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1896
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1897 vim_memset(&RangeType, 0, sizeof(RangeType));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1898 RangeType.tp_name = "vim.range";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1899 RangeType.tp_basicsize = sizeof(RangeObject);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1900 RangeType.tp_dealloc = RangeDestructor;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1901 RangeType.tp_repr = RangeRepr;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1902 RangeType.tp_as_sequence = &RangeAsSeq;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1903 RangeType.tp_as_mapping = &RangeAsMapping;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1904 RangeType.tp_getattro = RangeGetattro;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1905 RangeType.tp_flags = Py_TPFLAGS_DEFAULT;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1906 RangeType.tp_doc = "vim Range object";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1907 RangeType.tp_methods = RangeMethods;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1908 RangeType.tp_alloc = call_PyType_GenericAlloc;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1909 RangeType.tp_new = call_PyType_GenericNew;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1910 RangeType.tp_free = call_PyObject_Free;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1911
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1912 vim_memset(&CurrentType, 0, sizeof(CurrentType));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1913 CurrentType.tp_name = "vim.currentdata";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1914 CurrentType.tp_basicsize = sizeof(CurrentObject);
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1915 CurrentType.tp_getattro = CurrentGetattro;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1916 CurrentType.tp_setattro = CurrentSetattro;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1917 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1918 CurrentType.tp_doc = "vim current object";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1919
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1920 vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1921 DictionaryType.tp_name = "vim.dictionary";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1922 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1923 DictionaryType.tp_dealloc = DictionaryDestructor;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1924 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1925 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1926 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1927 DictionaryType.tp_methods = DictionaryMethods;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1928
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1929 vim_memset(&ListType, 0, sizeof(ListType));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1930 ListType.tp_name = "vim.list";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1931 ListType.tp_dealloc = ListDestructor;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1932 ListType.tp_basicsize = sizeof(ListObject);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1933 ListType.tp_as_sequence = &ListAsSeq;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1934 ListType.tp_as_mapping = &ListAsMapping;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1935 ListType.tp_flags = Py_TPFLAGS_DEFAULT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1936 ListType.tp_doc = "list pushing modifications to vim structure";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1937 ListType.tp_methods = ListMethods;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1938
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1939 vim_memset(&FunctionType, 0, sizeof(FunctionType));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1940 FunctionType.tp_name = "vim.list";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1941 FunctionType.tp_basicsize = sizeof(FunctionObject);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1942 FunctionType.tp_getattro = FunctionGetattro;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1943 FunctionType.tp_dealloc = FunctionDestructor;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1944 FunctionType.tp_call = FunctionCall;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1945 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1946 FunctionType.tp_doc = "object that calls vim function";
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1947 FunctionType.tp_methods = FunctionMethods;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3310
diff changeset
1948
2329
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949 vim_memset(&vimmodule, 0, sizeof(vimmodule));
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1950 vimmodule.m_name = "vim";
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1951 vimmodule.m_doc = vim_module_doc;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1952 vimmodule.m_size = -1;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1953 vimmodule.m_methods = VimMethods;
ad2889f48843 Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1954 }