annotate src/if_py_both.h @ 34686:83875247fbc0 v9.1.0224

patch 9.1.0224: cursor may move too many lines over "right" & "below" virt text Commit: https://github.com/vim/vim/commit/515f734e687f28f7199b2a8042197624d9f3ec15 Author: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Date: Thu Mar 28 12:01:14 2024 +0100 patch 9.1.0224: cursor may move too many lines over "right" & "below" virt text Problem: If a line has "right" & "below" virtual text properties, where the "below" property may be stored first due to lack of ordering between them, then the line height is calculated to be 1 more and causes the cursor to far over the line. Solution: Remove some unnecessary setting of a `next_right_goes_below = TRUE` flag for "below" and "above" text properties. (Dylan Thacker-Smith) I modified a regression test I recently added to cover this case, leveraging the fact that "after", "right" & "below" text properties are being stored in the reverse of the order they are added in. The previous version of this regression test was crafted to workaround this issue so it can be addressed by this separate patch. closes: #14317 Signed-off-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Mar 2024 12:15:03 +0100
parents daaff6843090
children 3e00ee7b7304
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
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:
diff changeset
2 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
10 * Python extensions by Paul Moore, David Leonard, Roland Puntaier, Nikolay
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
11 * Pavlov.
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:
diff changeset
12 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 * Common code for if_python.c and if_python3.c.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
3734
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
16 #if PY_VERSION_HEX < 0x02050000
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
17 typedef int Py_ssize_t; // Python 2.4 and earlier don't have this type.
3734
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
18 #endif
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
19
19019
75562beba71c patch 8.2.0070: crash when using Python 3 with "debug" encoding
Bram Moolenaar <Bram@vim.org>
parents: 19015
diff changeset
20 // Use values that are known to work, others may make Vim crash.
75562beba71c patch 8.2.0070: crash when using Python 3 with "debug" encoding
Bram Moolenaar <Bram@vim.org>
parents: 19015
diff changeset
21 #define ENC_OPT (enc_utf8 ? "utf-8" : enc_dbcs ? "euc-jp" : (char *)p_enc)
4435
9b800f0a757f updated for version 7.3.966
Bram Moolenaar <bram@vim.org>
parents: 4433
diff changeset
22 #define DOPY_FUNC "_vim_pydo"
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
23
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
24 static const char *vim_special_path = "_vim_path_";
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
25
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
26 #define PyErr_SET_STRING(exc, str) PyErr_SetString(exc, _(str))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
27 #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
28 #define PyErr_SET_VIM(str) PyErr_SET_STRING(VimError, str)
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
29 #define PyErr_FORMAT(exc, str, arg) PyErr_Format(exc, _(str), arg)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
30 #define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
31 #define PyErr_VIM_FORMAT(str, arg) PyErr_FORMAT(VimError, str, arg)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
32
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
33 #ifdef USE_LIMITED_API
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
34 // Limited Python API. Need to call only exposed functions and remap macros.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
35 // PyTypeObject is an opaque struct.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
36
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
37 typedef struct {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
38 lenfunc sq_length;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
39 binaryfunc sq_concat;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
40 ssizeargfunc sq_repeat;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
41 ssizeargfunc sq_item;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
42 void *was_sq_slice;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
43 ssizeobjargproc sq_ass_item;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
44 void *was_sq_ass_slice;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
45 objobjproc sq_contains;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
46
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
47 binaryfunc sq_inplace_concat;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
48 ssizeargfunc sq_inplace_repeat;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
49 } PySequenceMethods;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
50
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
51 typedef struct {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
52 lenfunc mp_length;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
53 binaryfunc mp_subscript;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
54 objobjargproc mp_ass_subscript;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
55 } PyMappingMethods;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
56
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
57 // This struct emulates the concrete _typeobject struct to allow the code to
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
58 // work the same way in both limited and full Python APIs.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
59 struct typeobject_wrapper {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
60 const char *tp_name;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
61 Py_ssize_t tp_basicsize;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
62 unsigned long tp_flags;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
63
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
64 // When adding new slots below, also need to make sure we add ADD_TP_SLOT
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
65 // call in AddHeapType for it.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
66
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
67 destructor tp_dealloc;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
68 reprfunc tp_repr;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
69
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
70 PySequenceMethods *tp_as_sequence;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
71 PyMappingMethods *tp_as_mapping;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
72
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
73 ternaryfunc tp_call;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
74 getattrofunc tp_getattro;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
75 setattrofunc tp_setattro;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
76
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
77 const char *tp_doc;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
78
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
79 traverseproc tp_traverse;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
80
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
81 inquiry tp_clear;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
82
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
83 getiterfunc tp_iter;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
84 iternextfunc tp_iternext;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
85
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
86 struct PyMethodDef *tp_methods;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
87 struct _typeobject *tp_base;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
88 allocfunc tp_alloc;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
89 newfunc tp_new;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
90 freefunc tp_free;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
91 };
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
92
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
93 # define DEFINE_PY_TYPE_OBJECT(type) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
94 static struct typeobject_wrapper type; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
95 static PyTypeObject* type##Ptr = NULL
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
96
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
97 // PyObject_HEAD_INIT_TYPE and PyObject_FINISH_INIT_TYPE need to come in pairs
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
98 // We first initialize with NULL because the type is not allocated until
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
99 // init_types() is called later. It's in FINISH_INIT_TYPE where we fill the
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
100 // type in with the newly allocated type.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
101 # define PyObject_HEAD_INIT_TYPE(type) PyObject_HEAD_INIT(NULL)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
102 # define PyObject_FINISH_INIT_TYPE(obj, type) obj.ob_base.ob_type = type##Ptr
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
103
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
104 # define Py_TYPE_GET_TP_ALLOC(type) ((allocfunc)PyType_GetSlot(type, Py_tp_alloc))
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
105 # define Py_TYPE_GET_TP_METHODS(type) ((PyMethodDef *)PyType_GetSlot(type, Py_tp_methods))
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
106
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
107 // PyObject_NEW is not part of stable ABI, but PyObject_Malloc/Init are.
33404
9b35b4c6df4c patch 9.0.1960: Make CI checks more strict
Christian Brabandt <cb@256bit.org>
parents: 33320
diff changeset
108 static PyObject* Vim_PyObject_New(PyTypeObject *type, size_t objsize)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
109 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
110 PyObject *obj = (PyObject *)PyObject_Malloc(objsize);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
111 if (obj == NULL)
33006
29b2193466e0 patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents: 32952
diff changeset
112 return PyErr_NoMemory();
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
113 return PyObject_Init(obj, type);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
114 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
115 # undef PyObject_NEW
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
116 # define PyObject_NEW(type, typeobj) ((type *)Vim_PyObject_New(typeobj, sizeof(type)))
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
117
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
118 // This is a somewhat convoluted because limited API doesn't expose an easy way
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
119 // to get the tp_name field, and so we have to manually reconstruct it as
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
120 // "__module__.__name__" (with __module__ omitted for builtins to emulate
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
121 // Python behavior). Also, some of the more convenient functions like
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
122 // PyUnicode_AsUTF8AndSize and PyType_GetQualName() are not available until
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
123 // late Python 3 versions, and won't be available if you set Py_LIMITED_API too
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
124 // low.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
125 # define PyErr_FORMAT_TYPE(msg, obj) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
126 do { \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
127 PyObject* qualname = PyObject_GetAttrString((PyObject*)(obj)->ob_type, "__qualname__"); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
128 if (qualname == NULL) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
129 { \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
130 PyErr_FORMAT(PyExc_TypeError, msg, "(NULL)"); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
131 break; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
132 } \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
133 PyObject* module = PyObject_GetAttrString((PyObject*)(obj)->ob_type, "__module__"); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
134 PyObject* full; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
135 if (module == NULL || PyUnicode_CompareWithASCIIString(module, "builtins") == 0 \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
136 || PyUnicode_CompareWithASCIIString(module, "__main__") == 0) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
137 { \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
138 full = qualname; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
139 Py_INCREF(full); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
140 } \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
141 else \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
142 full = PyUnicode_FromFormat("%U.%U", module, qualname); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
143 PyObject* full_bytes = PyUnicode_AsUTF8String(full); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
144 const char* full_str = PyBytes_AsString(full_bytes); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
145 full_str = full_str == NULL ? "(NULL)" : full_str; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
146 PyErr_FORMAT(PyExc_TypeError, msg, full_str); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
147 Py_DECREF(qualname); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
148 Py_XDECREF(module); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
149 Py_XDECREF(full); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
150 Py_XDECREF(full_bytes); \
32952
1c143662a40d patch 9.0.1778: if_py_both: code-style issue
Christian Brabandt <cb@256bit.org>
parents: 32936
diff changeset
151 } while (0)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
152
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
153 # define PyList_GET_ITEM(list, i) PyList_GetItem(list, i)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
154 # define PyList_GET_SIZE(o) PyList_Size(o)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
155 # define PyTuple_GET_ITEM(o, pos) PyTuple_GetItem(o, pos)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
156 # define PyTuple_GET_SIZE(o) PyTuple_Size(o)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
157
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
158 // PyList_SET_ITEM and PyList_SetItem have slightly different behaviors. The
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
159 // former will leave the old item dangling, and the latter will decref on it.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
160 // Since we only use this on new lists, this difference doesn't matter.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
161 # define PyList_SET_ITEM(list, i, item) PyList_SetItem(list, i, item)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
162
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
163 # if Py_LIMITED_API < 0x03080000
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
164 // PyIter_check only became part of stable ABI in 3.8, and there is no easy way
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
165 // to check for it in the API. We simply return false as a compromise. This
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
166 // does mean we should avoid compiling with stable ABI < 3.8.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
167 # undef PyIter_Check
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
168 # define PyIter_Check(obj) (FALSE)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
169 # endif
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
170
33404
9b35b4c6df4c patch 9.0.1960: Make CI checks more strict
Christian Brabandt <cb@256bit.org>
parents: 33320
diff changeset
171 static PyTypeObject* AddHeapType(struct typeobject_wrapper* type_object)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
172 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
173 PyType_Spec type_spec;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
174 type_spec.name = type_object->tp_name;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
175 type_spec.basicsize = type_object->tp_basicsize;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
176 type_spec.itemsize = 0;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
177 type_spec.flags = type_object->tp_flags;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
178
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
179 // We just need to statically allocate a large enough buffer that can hold
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
180 // all slots. We need to leave a null-terminated slot at the end.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
181 PyType_Slot slots[40] = { {0, NULL} };
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
182 size_t slot_i = 0;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
183
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
184 # define ADD_TP_SLOT(slot_name) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
185 if (slot_i >= 40) return NULL; /* this should never happen */ \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
186 if (type_object->slot_name != NULL) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
187 { \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
188 slots[slot_i].slot = Py_##slot_name; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
189 slots[slot_i].pfunc = (void*)type_object->slot_name; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
190 ++slot_i; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
191 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
192 # define ADD_TP_SUB_SLOT(sub_slot, slot_name) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
193 if (slot_i >= 40) return NULL; /* this should never happen */ \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
194 if (type_object->sub_slot != NULL && type_object->sub_slot->slot_name != NULL) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
195 { \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
196 slots[slot_i].slot = Py_##slot_name; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
197 slots[slot_i].pfunc = (void*)type_object->sub_slot->slot_name; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
198 ++slot_i; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
199 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
200
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
201 ADD_TP_SLOT(tp_dealloc)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
202 ADD_TP_SLOT(tp_repr)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
203 ADD_TP_SLOT(tp_call)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
204 ADD_TP_SLOT(tp_getattro)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
205 ADD_TP_SLOT(tp_setattro)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
206 ADD_TP_SLOT(tp_doc)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
207 ADD_TP_SLOT(tp_traverse)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
208 ADD_TP_SLOT(tp_clear)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
209 ADD_TP_SLOT(tp_iter)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
210 ADD_TP_SLOT(tp_iternext)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
211 ADD_TP_SLOT(tp_methods)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
212 ADD_TP_SLOT(tp_base)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
213 ADD_TP_SLOT(tp_alloc)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
214 ADD_TP_SLOT(tp_new)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
215 ADD_TP_SLOT(tp_free)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
216
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
217 ADD_TP_SUB_SLOT(tp_as_sequence, sq_length)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
218 ADD_TP_SUB_SLOT(tp_as_sequence, sq_concat)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
219 ADD_TP_SUB_SLOT(tp_as_sequence, sq_repeat)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
220 ADD_TP_SUB_SLOT(tp_as_sequence, sq_item)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
221 ADD_TP_SUB_SLOT(tp_as_sequence, sq_ass_item)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
222 ADD_TP_SUB_SLOT(tp_as_sequence, sq_contains)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
223 ADD_TP_SUB_SLOT(tp_as_sequence, sq_inplace_concat)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
224 ADD_TP_SUB_SLOT(tp_as_sequence, sq_inplace_repeat)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
225
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
226 ADD_TP_SUB_SLOT(tp_as_mapping, mp_length)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
227 ADD_TP_SUB_SLOT(tp_as_mapping, mp_subscript)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
228 ADD_TP_SUB_SLOT(tp_as_mapping, mp_ass_subscript)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
229 # undef ADD_TP_SLOT
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
230 # undef ADD_TP_SUB_SLOT
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
231
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
232 type_spec.slots = slots;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
233
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
234 PyObject* newtype = PyType_FromSpec(&type_spec);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
235 return (PyTypeObject*)newtype;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
236 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
237
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
238 // Add a heap type, since static types do not work in limited API
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
239 // Each PYTYPE_READY is paired with PYTYPE_CLEANUP.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
240 //
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
241 // Note that we don't call Py_DECREF(type##Ptr) in clean up. The reason for
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
242 // that in 3.7, it's possible to de-allocate a heap type before all instances
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
243 // are cleared, leading to a crash, whereas in 3.8 the semantics were changed
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
244 // and instances hold strong references to types. Since these types are
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
245 // designed to be static, just keep them around to avoid having to write
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
246 // version-specific handling. Vim does not re-start the Python runtime so there
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
247 // will be no long-term leak.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
248 # define PYTYPE_READY(type) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
249 type##Ptr = AddHeapType(&(type)); \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
250 if (type##Ptr == NULL) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
251 return -1;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
252 # define PYTYPE_CLEANUP(type) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
253 type##Ptr = NULL;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
254
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
255 // Limited API does not provide PyRun_* functions. Need to implement manually
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
256 // using PyCompile and PyEval.
33404
9b35b4c6df4c patch 9.0.1960: Make CI checks more strict
Christian Brabandt <cb@256bit.org>
parents: 33320
diff changeset
257 static PyObject* Vim_PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
258 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
259 // Just pass "" for filename for now.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
260 PyObject* compiled = Py_CompileString(str, "", start);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
261 if (compiled == NULL)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
262 return NULL;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
263
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
264 PyObject* eval_result = PyEval_EvalCode(compiled, globals, locals);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
265 Py_DECREF(compiled);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
266 return eval_result;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
267 }
33404
9b35b4c6df4c patch 9.0.1960: Make CI checks more strict
Christian Brabandt <cb@256bit.org>
parents: 33320
diff changeset
268 static int Vim_PyRun_SimpleString(const char *str)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
269 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
270 // This function emulates CPython's implementation.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
271 PyObject* m = PyImport_AddModule("__main__");
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
272 if (m == NULL)
33006
29b2193466e0 patch 9.0.1795: Indentation issues
Christian Brabandt <cb@256bit.org>
parents: 32952
diff changeset
273 return -1;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
274 PyObject* d = PyModule_GetDict(m);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
275 PyObject* output = Vim_PyRun_String(str, Py_file_input, d, d);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
276 if (output == NULL)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
277 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
278 PyErr_PrintEx(TRUE);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
279 return -1;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
280 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
281 Py_DECREF(output);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
282 return 0;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
283 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
284 #define PyRun_String Vim_PyRun_String
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
285 #define PyRun_SimpleString Vim_PyRun_SimpleString
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
286
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
287 #else // !defined(USE_LIMITED_API)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
288
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
289 // Full Python API. Can make use of structs and macros directly.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
290 # define DEFINE_PY_TYPE_OBJECT(type) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
291 static PyTypeObject type; \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
292 static PyTypeObject* type##Ptr = &type
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
293 # define PyObject_HEAD_INIT_TYPE(type) PyObject_HEAD_INIT(&type)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
294
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
295 # define Py_TYPE_GET_TP_ALLOC(type) type->tp_alloc
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
296 # define Py_TYPE_GET_TP_METHODS(type) type->tp_methods
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
297
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
298 # define Py_TYPE_NAME(obj) ((obj)->ob_type->tp_name == NULL \
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
299 ? "(NULL)" \
28226
89c181c99e23 patch 8.2.4639: not sufficient parenthesis in preprocessor macros
Bram Moolenaar <Bram@vim.org>
parents: 27039
diff changeset
300 : (obj)->ob_type->tp_name)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
301 # define PyErr_FORMAT_TYPE(msg, obj) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
302 PyErr_FORMAT(PyExc_TypeError, msg, \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
303 Py_TYPE_NAME(obj))
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
304
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
305 // Add a static type
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
306 # define PYTYPE_READY(type) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
307 if (PyType_Ready(type##Ptr)) \
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
308 return -1;
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
309
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
310 #endif
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
311
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
312
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
313 #define RAISE_NO_EMPTY_KEYS PyErr_SET_STRING(PyExc_ValueError, \
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
314 N_("empty keys are not allowed"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
315 #define RAISE_LOCKED_DICTIONARY PyErr_SET_VIM(N_("dictionary is locked"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
316 #define RAISE_LOCKED_LIST PyErr_SET_VIM(N_("list is locked"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
317 #define RAISE_UNDO_FAIL PyErr_SET_VIM(N_("cannot save undo information"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
318 #define RAISE_DELETE_LINE_FAIL PyErr_SET_VIM(N_("cannot delete line"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
319 #define RAISE_INSERT_LINE_FAIL PyErr_SET_VIM(N_("cannot insert line"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
320 #define RAISE_REPLACE_LINE_FAIL PyErr_SET_VIM(N_("cannot replace line"))
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
321 #define RAISE_KEY_ADD_FAIL(key) \
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
322 PyErr_VIM_FORMAT(N_("failed to add key '%s' to dictionary"), key)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
323 #define RAISE_INVALID_INDEX_TYPE(idx) \
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
324 PyErr_FORMAT_TYPE(N_("index must be int or slice, not %s"), idx);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
325
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
326 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
327 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
328 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
329
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
330 typedef void (*rangeinitializer)(void *);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
331 typedef void (*runner)(const char *, void *
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
332 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
333 , PyGILState_STATE *
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
334 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
335 );
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
336
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
337 static int ConvertFromPyObject(PyObject *, typval_T *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
338 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
339 static int ConvertFromPyMapping(PyObject *, typval_T *);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
340 static int ConvertFromPySequence(PyObject *, typval_T *);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
341 static PyObject *WindowNew(win_T *, tabpage_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
342 static PyObject *BufferNew (buf_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
343 static PyObject *LineToString(const char *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
344
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
345 static PyInt RangeStart;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
346 static PyInt RangeEnd;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
347
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
348 static PyObject *globals;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
349
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
350 static PyObject *py_chdir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
351 static PyObject *py_fchdir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
352 static PyObject *py_getcwd;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
353 static PyObject *vim_module;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
354 static PyObject *vim_special_path_object;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
355
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
356 #if PY_VERSION_HEX >= 0x030700f0
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
357 static PyObject *py_find_spec;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
358 #else
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
359 static PyObject *py_load_module;
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
360 #endif
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
361 static PyObject *py_find_module;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
362
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
363 static PyObject *VimError;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
364
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:
diff changeset
365 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 * obtain a lock on the Vim data structures
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 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:
diff changeset
369 Python_Lock_Vim(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:
diff changeset
370 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374 * release a lock on the Vim data structures
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
375 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 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:
diff changeset
377 Python_Release_Vim(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:
diff changeset
378 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
381 /*
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
382 * The "todecref" argument holds a pointer to PyObject * that must be
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
383 * DECREF'ed after returned char_u * is no longer needed or NULL if all what
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
384 * was needed to generate returned value is object.
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
385 *
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
386 * Use Py_XDECREF to decrement reference count.
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
387 */
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
388 static char_u *
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
389 StringToChars(PyObject *obj, PyObject **todecref)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
390 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
391 char_u *str;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
392
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
393 if (PyBytes_Check(obj))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
394 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
395
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
396 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
397 || str == NULL)
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
398 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
399
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
400 *todecref = NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
401 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
402 else if (PyUnicode_Check(obj))
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
403 {
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
404 PyObject *bytes;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
405
23264
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
406 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT,
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
407 ERRORS_ENCODE_ARG)))
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
408 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
409
23264
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
410 if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
411 || str == NULL)
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
412 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
413 Py_DECREF(bytes);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
414 return NULL;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
415 }
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
416
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
417 *todecref = bytes;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
418 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
419 else
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
420 {
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
421 #if PY_MAJOR_VERSION < 3
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
422 PyErr_FORMAT_TYPE(N_("expected str() or unicode() instance, but got %s"),
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
423 obj);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
424 #else
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
425 PyErr_FORMAT_TYPE(N_("expected bytes() or str() instance, but got %s"),
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
426 obj);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
427 #endif
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
428 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
429 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
430
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
431 return (char_u *) str;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
432 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
433
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
434 #define NUMBER_LONG 1
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
435 #define NUMBER_INT 2
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
436 #define NUMBER_NATURAL 4
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
437 #define NUMBER_UNSIGNED 8
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
438
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
439 static int
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
440 NumberToLong(PyObject *obj, long *result, int flags)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
441 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
442 #if PY_MAJOR_VERSION < 3
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
443 if (PyInt_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
444 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
445 *result = PyInt_AsLong(obj);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
446 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
447 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
448 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
449 else
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
450 #endif
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
451 if (PyLong_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
452 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
453 *result = PyLong_AsLong(obj);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
454 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
455 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
456 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
457 else if (PyNumber_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
458 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
459 PyObject *num;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
460
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
461 if (!(num = PyNumber_Long(obj)))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
462 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
463
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
464 *result = PyLong_AsLong(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
465
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
466 Py_DECREF(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
467
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
468 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
469 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
470 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
471 else
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
472 {
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
473 #if PY_MAJOR_VERSION < 3
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
474 PyErr_FORMAT_TYPE(
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
475 N_("expected int(), long() or something supporting "
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
476 "coercing to long(), but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
477 obj);
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
478 #else
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
479 PyErr_FORMAT_TYPE(
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
480 N_("expected int() or something supporting coercing to int(), "
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
481 "but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
482 obj);
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
483 #endif
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
484 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
485 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
486
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
487 if (flags & NUMBER_INT)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
488 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
489 if (*result > INT_MAX)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
490 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
491 PyErr_SET_STRING(PyExc_OverflowError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
492 N_("value is too large to fit into C int type"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
493 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
494 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
495 else if (*result < INT_MIN)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
496 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
497 PyErr_SET_STRING(PyExc_OverflowError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
498 N_("value is too small to fit into C int type"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
499 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
500 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
501 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
502
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
503 if (flags & NUMBER_NATURAL)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
504 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
505 if (*result <= 0)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
506 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
507 PyErr_SET_STRING(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
508 N_("number must be greater than zero"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
509 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
510 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
511 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
512 else if (flags & NUMBER_UNSIGNED)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
513 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
514 if (*result < 0)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
515 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
516 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
517 N_("number must be greater or equal to zero"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
518 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
519 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
520 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
521
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
522 return 0;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
523 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
524
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
525 static int
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
526 add_string(PyObject *list, char *s)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
527 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
528 PyObject *string;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
529
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
530 if (!(string = PyString_FromString(s)))
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
531 return -1;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
532
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
533 if (PyList_Append(list, string))
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
534 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
535 Py_DECREF(string);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
536 return -1;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
537 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
538
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
539 Py_DECREF(string);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
540 return 0;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
541 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
542
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
543 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
544 ObjectDir(PyObject *self, char **attributes)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
545 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
546 PyMethodDef *method;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
547 char **attr;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
548 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
549
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
550 if (!(ret = PyList_New(0)))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
551 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
552
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
553 if (self)
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
554 for (method = Py_TYPE_GET_TP_METHODS(self->ob_type) ; method->ml_name != NULL ; ++method)
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
555 if (add_string(ret, (char *)method->ml_name))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
556 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
557 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
558 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
559 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
560
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
561 for (attr = attributes ; *attr ; ++attr)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
562 if (add_string(ret, *attr))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
563 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
564 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
565 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
566 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
567
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
568 #if PY_MAJOR_VERSION < 3
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
569 if (add_string(ret, "__members__"))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
570 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
571 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
572 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
573 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
574 #endif
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
575
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
576 return ret;
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
577 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
578
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
579 // Output buffer management
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
580
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
581 // Function to write a line, points to either msg() or emsg().
22572
0fd4d7548b07 patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9
Bram Moolenaar <Bram@vim.org>
parents: 21977
diff changeset
582 typedef int (*writefn)(char *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
583
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
584 DEFINE_PY_TYPE_OBJECT(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:
diff changeset
585
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586 typedef struct
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
588 PyObject_HEAD
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
589 long softspace;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
590 long error;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 } OutputObject;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
592
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
593 static char *OutputAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
594 "softspace",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
595 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
596 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
597
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
598 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
599 OutputDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
600 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
601 return ObjectDir(self, OutputAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
602 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
603
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
604 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
605 OutputSetattr(PyObject *self_obj, char *name, PyObject *valObject)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
606 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
607 OutputObject *self = (OutputObject*)self_obj;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
608 if (valObject == NULL)
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
609 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
610 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
611 N_("can't delete OutputObject attributes"));
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
612 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
613 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
614
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
615 if (strcmp(name, "softspace") == 0)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
616 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
617 if (NumberToLong(valObject, &(self->softspace), NUMBER_UNSIGNED))
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
618 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
619 return 0;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
620 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
621
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
622 PyErr_FORMAT(PyExc_AttributeError, N_("invalid attribute: %s"), name);
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
623 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
624 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
625
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
626 // Buffer IO, we write one whole line at a time.
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
627 static garray_T io_ga = {0, 0, 1, 80, NULL};
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
628 static writefn old_fn = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
629
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
630 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
631 PythonIO_Flush(void)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
632 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
633 if (old_fn != NULL && io_ga.ga_len > 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
634 {
22572
0fd4d7548b07 patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9
Bram Moolenaar <Bram@vim.org>
parents: 21977
diff changeset
635 ((char *)io_ga.ga_data)[io_ga.ga_len] = NUL;
0fd4d7548b07 patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9
Bram Moolenaar <Bram@vim.org>
parents: 21977
diff changeset
636 old_fn((char *)io_ga.ga_data);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
637 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
638 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
639 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
640
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
641 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
642 writer(writefn fn, char_u *str, PyInt n)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
643 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
644 char_u *ptr;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
645
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
646 // Flush when switching output function.
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
647 if (fn != old_fn)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
648 PythonIO_Flush();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
649 old_fn = fn;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
650
18370
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
651 // Write each NL separated line. Text after the last NL is kept for
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
652 // writing later.
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
653 // For normal messages: Do not output when "got_int" was set. This avoids
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
654 // a loop gone crazy flooding the terminal with messages. Also for when
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
655 // "q" is pressed at the more-prompt.
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
656 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
657 && (fn == (writefn)emsg || !got_int))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
658 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
659 PyInt len = ptr - str;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
660
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
661 if (ga_grow(&io_ga, (int)(len + 1)) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
662 break;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
663
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
664 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
665 ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
22572
0fd4d7548b07 patch 8.2.1834: PyEval_InitThreads() is deprecated in Python 3.9
Bram Moolenaar <Bram@vim.org>
parents: 21977
diff changeset
666 fn((char *)io_ga.ga_data);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
667 str = ptr + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
668 n -= len + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
669 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
670 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
671
18370
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
672 // Put the remaining text into io_ga for later printing.
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
673 if (n > 0 && (fn == (writefn)emsg || !got_int)
026034963159 patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents: 17922
diff changeset
674 && ga_grow(&io_ga, (int)(n + 1)) == OK)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
675 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
676 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
677 io_ga.ga_len += (int)n;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
678 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
679 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
680
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
681 static int
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
682 write_output(OutputObject *self, PyObject *string)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
683 {
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
684 Py_ssize_t len = 0;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
685 char *str = NULL;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
686 int error = self->error;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
687
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
688 if (!PyArg_Parse(string, "et#", ENC_OPT, &str, &len))
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
689 return -1;
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:
diff changeset
690
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 Py_BEGIN_ALLOW_THREADS
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
692 Python_Lock_Vim();
16688
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
693 if (error)
e791f29affae patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
694 emsg_severe = TRUE;
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15472
diff changeset
695 writer((writefn)(error ? emsg : msg), (char_u *)str, 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:
diff changeset
696 Python_Release_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
697 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
698 PyMem_Free(str);
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:
diff changeset
699
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
700 return 0;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
701 }
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
702
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
703 static PyObject *
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
704 OutputWrite(OutputObject *self, PyObject *string)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
705 {
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
706 if (write_output(self, string))
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
707 return NULL;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
708
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:
diff changeset
709 Py_INCREF(Py_None);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
710 return Py_None;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
711 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
712
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
713 static PyObject *
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
714 OutputWritelines(OutputObject *self, PyObject *seq)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
715 {
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
716 PyObject *iterator;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
717 PyObject *item;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
718
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
719 if (!(iterator = PyObject_GetIter(seq)))
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
720 return NULL;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
721
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
722 while ((item = PyIter_Next(iterator)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
723 {
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
724 if (write_output(self, item))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
725 {
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
726 Py_DECREF(iterator);
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
727 Py_DECREF(item);
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:
diff changeset
728 return NULL;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 }
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
730 Py_DECREF(item);
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:
diff changeset
731 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
733 Py_DECREF(iterator);
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
734
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
735 // Iterator may have finished due to an exception
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
736 if (PyErr_Occurred())
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
737 return NULL;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
738
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:
diff changeset
739 Py_INCREF(Py_None);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 return Py_None;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
742
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
743 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
744 AlwaysNone(PyObject *self UNUSED, PyObject *args UNUSED)
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
745 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
746 // do nothing
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
747 Py_INCREF(Py_None);
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
748 return Py_None;
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
749 }
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
750 #define ALWAYS_NONE AlwaysNone(NULL, NULL)
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
751
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
752 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
753 AlwaysFalse(PyObject *self UNUSED, PyObject *args UNUSED)
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
754 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
755 // do nothing
7202
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
756 PyObject *ret = Py_False;
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
757 Py_INCREF(ret);
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
758 return ret;
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
759 }
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
760 #define ALWAYS_FALSE AlwaysFalse(NULL, NULL)
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
761
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
762 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
763 AlwaysTrue(PyObject *self UNUSED, PyObject *args UNUSED)
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
764 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
765 // do nothing
7202
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
766 PyObject *ret = Py_True;
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
767 Py_INCREF(ret);
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
768 return ret;
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
769 }
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
770 #define ALWAYS_TRUE AlwaysTrue(NULL, NULL)
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
771
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:
diff changeset
772 /***************/
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
773
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
774 static struct PyMethodDef OutputMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
775 // name, function, calling, doc
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
776 {"write", (PyCFunction)OutputWrite, METH_O, ""},
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
777 {"writelines", (PyCFunction)OutputWritelines, METH_O, ""},
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
778 {"flush", (PyCFunction)AlwaysNone, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
779 {"close", (PyCFunction)AlwaysNone, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
780 {"isatty", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
781 {"readable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
782 {"seekable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
783 {"writable", (PyCFunction)AlwaysTrue, METH_NOARGS, ""},
8967
df5f9284fcba commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents: 8921
diff changeset
784 {"closed", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
785 {"__dir__", (PyCFunction)OutputDir, METH_NOARGS, ""},
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
786 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
787 };
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:
diff changeset
788
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
789 static OutputObject Output =
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
790 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
791 PyObject_HEAD_INIT_TYPE(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:
diff changeset
792 0,
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
793 0
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
796 static OutputObject Error =
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
798 PyObject_HEAD_INIT_TYPE(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:
diff changeset
799 0,
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800 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:
diff changeset
801 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
802
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
803 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:
diff changeset
804 PythonIO_Init_io(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:
diff changeset
805 {
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
806 if (PySys_SetObject("stdout", (PyObject *)(void *)&Output))
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
807 return -1;
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
808 if (PySys_SetObject("stderr", (PyObject *)(void *)&Error))
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
809 return -1;
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:
diff changeset
810
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811 if (PyErr_Occurred())
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812 {
26897
d02d40f0261c patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25326
diff changeset
813 emsg(_(e_python_error_initialising_io_object));
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:
diff changeset
814 return -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:
diff changeset
815 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
816
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
817 return 0;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
818 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
819
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
820 #if PY_VERSION_HEX < 0x030700f0
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
821 static PyObject *call_load_module(char *name, int len, PyObject *find_module_result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
822
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
823 typedef struct
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
824 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
825 PyObject_HEAD
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
826 char *fullname;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
827 PyObject *result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
828 } LoaderObject;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
829 DEFINE_PY_TYPE_OBJECT(LoaderType);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
830
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
831 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
832 LoaderDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
833 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
834 LoaderObject *self = (LoaderObject*)self_obj;
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
835 vim_free(self->fullname);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
836 Py_XDECREF(self->result);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
837 DESTRUCTOR_FINISH(self);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
838 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
839
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
840 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
841 LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
842 {
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
843 char *fullname = self->fullname;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
844 PyObject *result = self->result;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
845 PyObject *module;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
846
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
847 if (!fullname)
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
848 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
849 module = result ? result : Py_None;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
850 Py_INCREF(module);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
851 return module;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
852 }
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
853
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
854 module = call_load_module(fullname, (int)STRLEN(fullname), result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
855
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
856 self->fullname = NULL;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
857 self->result = module;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
858
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
859 vim_free(fullname);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
860 Py_DECREF(result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
861
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
862 if (!module)
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
863 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
864 if (PyErr_Occurred())
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
865 return NULL;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
866
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
867 Py_INCREF(Py_None);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
868 return Py_None;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
869 }
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
870
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
871 Py_INCREF(module);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
872 return module;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
873 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
874
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
875 static struct PyMethodDef LoaderMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
876 // name, function, calling, doc
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
877 {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""},
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
878 { NULL, NULL, 0, NULL}
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
879 };
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
880 #endif
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:
diff changeset
881
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
882 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
883 * Check to see whether a Vim error has been reported, or a keyboard
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:
diff changeset
884 * interrupt has been detected.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
885 */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
886 static void
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
887 VimTryStart(void)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
888 {
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
889 ++trylevel;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
890 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
891
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:
diff changeset
892 static int
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
893 VimTryEnd(void)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
894 {
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
895 --trylevel;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
896 // Without this it stops processing all subsequent Vim script commands and
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
897 // generates strange error messages if I e.g. try calling Test() in a cycle
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
898 did_emsg = FALSE;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
899 // Keyboard interrupt should be preferred over anything else
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
900 if (got_int)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
901 {
5629
91f3908748c2 updated for version 7.4.161
Bram Moolenaar <bram@vim.org>
parents: 5612
diff changeset
902 if (did_throw)
5469
a56f60cf6834 updated for version 7.4.084
Bram Moolenaar <bram@vim.org>
parents: 5426
diff changeset
903 discard_current_exception();
a56f60cf6834 updated for version 7.4.084
Bram Moolenaar <bram@vim.org>
parents: 5426
diff changeset
904 got_int = FALSE;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
905 PyErr_SetNone(PyExc_KeyboardInterrupt);
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
906 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
907 }
5517
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
908 else if (msg_list != NULL && *msg_list != NULL)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
909 {
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
910 int should_free;
15472
0fcc1315c061 patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
911 char *msg;
5517
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
912
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
913 msg = get_exception_string(*msg_list, ET_ERROR, NULL, &should_free);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
914
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
915 if (msg == NULL)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
916 {
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
917 PyErr_NoMemory();
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
918 return -1;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
919 }
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
920
15472
0fcc1315c061 patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
921 PyErr_SetVim(msg);
5517
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
922
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
923 free_global_msglist();
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
924
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
925 if (should_free)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
926 vim_free(msg);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
927
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
928 return -1;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
929 }
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
930 else if (!did_throw)
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
931 return (PyErr_Occurred() ? -1 : 0);
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
932 // Python exception is preferred over Vim one; unlikely to occur though
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
933 else if (PyErr_Occurred())
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
934 {
5629
91f3908748c2 updated for version 7.4.161
Bram Moolenaar <bram@vim.org>
parents: 5612
diff changeset
935 discard_current_exception();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
936 return -1;
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
937 }
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
938 // Finally transform Vim script exception to python one
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
939 else
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
940 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
941 PyErr_SetVim((char *)current_exception->value);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
942 discard_current_exception();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
943 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
944 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
945 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
946
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
947 static int
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
948 VimCheckInterrupt(void)
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:
diff changeset
949 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
950 if (got_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:
diff changeset
951 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
952 PyErr_SetNone(PyExc_KeyboardInterrupt);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
953 return 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:
diff changeset
954 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
955 return 0;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
956 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
957
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
958 // Vim module - Implementation
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
959
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
960 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
961 VimCommand(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
962 {
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
963 char_u *cmd;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
964 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
965 PyObject *todecref;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
966
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
967 if (!(cmd = StringToChars(string, &todecref)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
968 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
969
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
970 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
971 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
972
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
973 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
974 do_cmdline_cmd(cmd);
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 28950
diff changeset
975 update_screen(UPD_VALID);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
976
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
977 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
978 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
979
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
980 if (VimTryEnd())
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
981 ret = NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
982 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
983 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
984
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
985 Py_XINCREF(ret);
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
986 Py_XDECREF(todecref);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
987 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
988 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
989
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
990 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
991 * Function to translate a typval_T into a PyObject; this will recursively
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
992 * translate lists/dictionaries into their Python equivalents.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
993 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
994 * The depth parameter is to avoid infinite recursion, set it to 1 when
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
995 * you call VimToPython.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
996 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
997 static PyObject *
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
998 VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
999 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1000 PyObject *ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1001 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1002 char ptrBuf[sizeof(void *) * 2 + 3];
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1003
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1004 // Avoid infinite recursion
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1005 if (depth > 100)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1006 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1007 Py_INCREF(Py_None);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1008 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1009 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1010 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1011
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1012 // Check if we run into a recursive loop. The item must be in lookup_dict
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1013 // then and we can use it again.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1014 if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1015 || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1016 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1017 sprintf(ptrBuf, "%p",
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1018 our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1019 : (void *)our_tv->vval.v_dict);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1020
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1021 if ((ret = PyDict_GetItemString(lookup_dict, ptrBuf)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1022 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1023 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1024 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1025 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1026 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1027
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1028 if (our_tv->v_type == VAR_STRING)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1029 ret = PyString_FromString(our_tv->vval.v_string == NULL
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
1030 ? "" : (char *)our_tv->vval.v_string);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1031 else if (our_tv->v_type == VAR_NUMBER)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1032 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1033 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1034
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1035 // For backwards compatibility numbers are stored as strings.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1036 sprintf(buf, "%ld", (long)our_tv->vval.v_number);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1037 ret = PyString_FromString((char *)buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1038 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1039 else if (our_tv->v_type == VAR_FLOAT)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1040 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1041 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1042
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1043 sprintf(buf, "%f", our_tv->vval.v_float);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1044 ret = PyString_FromString((char *)buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1045 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1046 else if (our_tv->v_type == VAR_LIST)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1047 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1048 list_T *list = our_tv->vval.v_list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1049 listitem_T *curr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1050
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1051 if (list == NULL)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1052 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1053
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1054 if (!(ret = PyList_New(0)))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1055 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1056
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1057 if (PyDict_SetItemString(lookup_dict, ptrBuf, ret))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1058 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1059 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1060 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1061 }
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1062
20392
4c317d8c1051 patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents: 20369
diff changeset
1063 CHECK_LIST_MATERIALIZE(list);
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
1064 FOR_ALL_LIST_ITEMS(list, curr)
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1065 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1066 if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookup_dict)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1067 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1068 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1069 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1070 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1071 if (PyList_Append(ret, newObj))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1072 {
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1073 Py_DECREF(newObj);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1074 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1075 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1076 }
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1077 Py_DECREF(newObj);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1078 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1079 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1080 else if (our_tv->v_type == VAR_DICT)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1081 {
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1082
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
1083 hashtab_T *ht;
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
1084 long_u todo;
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1085 hashitem_T *hi;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1086 dictitem_T *di;
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
1087
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1088 if (our_tv->vval.v_dict == NULL)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1089 return NULL;
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
1090 ht = &our_tv->vval.v_dict->dv_hashtab;
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1091
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1092 if (!(ret = PyDict_New()))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1093 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1094
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1095 if (PyDict_SetItemString(lookup_dict, ptrBuf, ret))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1096 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1097 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1098 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1099 }
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1100
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
1101 todo = ht->ht_used;
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1102 for (hi = ht->ht_array; todo > 0; ++hi)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1103 {
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1104 if (!HASHITEM_EMPTY(hi))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1105 {
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1106 --todo;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1107
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1108 di = dict_lookup(hi);
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1109 if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookup_dict)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1110 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1111 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1112 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1113 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1114 if (PyDict_SetItemString(ret, (char *)hi->hi_key, newObj))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1115 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1116 Py_DECREF(ret);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1117 Py_DECREF(newObj);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
1118 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1119 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1120 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1121 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1122 }
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1123 else if (our_tv->v_type == VAR_BOOL)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1124 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1125 if (our_tv->vval.v_number == VVAL_FALSE)
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1126 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1127 ret = Py_False;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1128 Py_INCREF(ret);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1129 }
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1130 else
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1131 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1132 ret = Py_True;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1133 Py_INCREF(ret);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1134 }
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1135 return ret;
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1136 }
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1137 else if (our_tv->v_type == VAR_SPECIAL)
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1138 {
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1139 Py_INCREF(Py_None);
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
1140 ret = Py_None;
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1141 return ret;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
1142 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
1143 else if (our_tv->v_type == VAR_BLOB)
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
1144 ret = PyBytes_FromStringAndSize(
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
1145 (char*) our_tv->vval.v_blob->bv_ga.ga_data,
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
1146 (Py_ssize_t) our_tv->vval.v_blob->bv_ga.ga_len);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1147 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1148 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1149 Py_INCREF(Py_None);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1150 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1151 }
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1152
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1153 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1154 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1155
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1156 static PyObject *
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1157 VimEval(PyObject *self UNUSED, PyObject *args)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1158 {
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1159 char_u *expr;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1160 typval_T *our_tv;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1161 PyObject *string;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1162 PyObject *todecref;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1163 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1164 PyObject *lookup_dict;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1165
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1166 if (!PyArg_ParseTuple(args, "O", &string))
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1167 return NULL;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1168
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1169 if (!(expr = StringToChars(string, &todecref)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1170 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1171
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1172 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1173 Python_Lock_Vim();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1174 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1175 our_tv = eval_expr(expr, NULL);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1176 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1177 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1178
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1179 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1180
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1181 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1182 return NULL;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1183
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1184 if (our_tv == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1185 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1186 PyErr_SET_VIM(N_("invalid expression"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1187 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1188 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1189
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1190 // Convert the Vim type into a Python type. Create a dictionary that's
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1191 // used to check for recursive loops.
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
1192 if (!(lookup_dict = PyDict_New()))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1193 ret = NULL;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
1194 else
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
1195 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1196 ret = VimToPython(our_tv, 1, lookup_dict);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
1197 Py_DECREF(lookup_dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
1198 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1199
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1200
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1201 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1202 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1203 free_tv(our_tv);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1204 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1205 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1206
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1207 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1208 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1209
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1210 static PyObject *ConvertToPyObject(typval_T *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1211
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1212 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1213 VimEvalPy(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1214 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1215 typval_T *our_tv;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1216 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1217 char_u *expr;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1218 PyObject *todecref;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1219
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1220 if (!(expr = StringToChars(string, &todecref)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1221 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1222
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1223 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1224 Python_Lock_Vim();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1225 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1226 our_tv = eval_expr(expr, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1227 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1228 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1229
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1230 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1231
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1232 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1233 return NULL;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
1234
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1235 if (our_tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1236 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1237 PyErr_SET_VIM(N_("invalid expression"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1238 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1239 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1240
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1241 ret = ConvertToPyObject(our_tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1242 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1243 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1244 free_tv(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1245 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1246 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1247
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1248 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1249 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1250
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1251 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1252 VimStrwidth(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1253 {
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1254 char_u *str;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1255 PyObject *todecref;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1256 int len;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1257
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1258 if (!(str = StringToChars(string, &todecref)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1259 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1260
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1261 len = mb_string2cells(str, (int)STRLEN(str));
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1262
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1263 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1264
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1265 return PyLong_FromLong(len);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1266 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1267
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1268 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1269 _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1270 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1271 PyObject *ret;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1272 PyObject *newwd;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1273 PyObject *todecref;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1274 char_u *new_dir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1275
4754
be1e4acb30ca updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents: 4722
diff changeset
1276 if (_chdir == NULL)
be1e4acb30ca updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents: 4722
diff changeset
1277 return NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1278 if (!(ret = PyObject_Call(_chdir, args, kwargs)))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1279 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1280
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1281 if (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL)))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1282 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1283 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1284 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1285 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1286
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1287 if (!(new_dir = StringToChars(newwd, &todecref)))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1288 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1289 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1290 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1291 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1292 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1293
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1294 VimTryStart();
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1295
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1296 if (vim_chdir(new_dir))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1297 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1298 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1299 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1300 Py_XDECREF(todecref);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1301
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1302 if (VimTryEnd())
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1303 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1304
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1305 PyErr_SET_VIM(N_("failed to change directory"));
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1306 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1307 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1308
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1309 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1310 Py_XDECREF(todecref);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1311
16576
bcc343175103 patch 8.1.1291: not easy to change directory and restore
Bram Moolenaar <Bram@vim.org>
parents: 16427
diff changeset
1312 post_chdir(CDSCOPE_GLOBAL);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1313
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1314 if (VimTryEnd())
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1315 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1316 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1317 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1318 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1319
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1320 return ret;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1321 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1322
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1323 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1324 VimChdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1325 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1326 return _VimChdir(py_chdir, args, kwargs);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1327 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1328
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1329 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1330 VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1331 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1332 return _VimChdir(py_fchdir, args, kwargs);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1333 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1334
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1335 typedef struct {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1336 PyObject *callable;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1337 PyObject *result;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1338 } map_rtp_data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1339
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1340 static void
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1341 map_rtp_callback(char_u *path, void *_data)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1342 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1343 void **data = (void **) _data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1344 PyObject *pathObject;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1345 map_rtp_data *mr_data = *((map_rtp_data **) data);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1346
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1347 if (!(pathObject = PyString_FromString((char *)path)))
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1348 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1349 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1350 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1351 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1352
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1353 mr_data->result = PyObject_CallFunctionObjArgs(mr_data->callable,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1354 pathObject, NULL);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1355
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1356 Py_DECREF(pathObject);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1357
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1358 if (!mr_data->result || mr_data->result != Py_None)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1359 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1360 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1361 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1362 Py_DECREF(mr_data->result);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1363 mr_data->result = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1364 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1365 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1366
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1367 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1368 VimForeachRTP(PyObject *self UNUSED, PyObject *callable)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1369 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1370 map_rtp_data data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1371
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1372 data.callable = callable;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1373 data.result = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1374
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7949
diff changeset
1375 do_in_runtimepath(NULL, 0, &map_rtp_callback, &data);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1376
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1377 if (data.result == NULL)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1378 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1379 if (PyErr_Occurred())
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1380 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1381 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1382 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1383 Py_INCREF(Py_None);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1384 return Py_None;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1385 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1386 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1387 return data.result;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1388 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1389
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1390 /*
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1391 * _vim_runtimepath_ special path implementation.
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1392 */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1393
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1394 static void
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1395 map_finder_callback(char_u *path, void *_data)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1396 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1397 void **data = (void **) _data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1398 PyObject *list = *((PyObject **) data);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1399 PyObject *pathObject1, *pathObject2;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1400 char *pathbuf;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1401 size_t pathlen;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1402
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1403 pathlen = STRLEN(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1404
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1405 #if PY_MAJOR_VERSION < 3
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1406 # define PY_MAIN_DIR_STRING "python2"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1407 #else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1408 # define PY_MAIN_DIR_STRING "python3"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1409 #endif
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1410 #define PY_ALTERNATE_DIR_STRING "pythonx"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1411
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1412 #define PYTHONX_STRING_LENGTH 7 // STRLEN("pythonx")
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1413 if (!(pathbuf = PyMem_New(char,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1414 pathlen + STRLEN(PATHSEPSTR) + PYTHONX_STRING_LENGTH + 1)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1415 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1416 PyErr_NoMemory();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1417 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1418 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1419 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1420
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1421 mch_memmove(pathbuf, path, pathlen + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1422 add_pathsep((char_u *) pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1423
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1424 pathlen = STRLEN(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1425 mch_memmove(pathbuf + pathlen, PY_MAIN_DIR_STRING,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1426 PYTHONX_STRING_LENGTH + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1427
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1428 if (!(pathObject1 = PyString_FromString(pathbuf)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1429 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1430 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1431 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1432 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1433 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1434
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1435 mch_memmove(pathbuf + pathlen, PY_ALTERNATE_DIR_STRING,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1436 PYTHONX_STRING_LENGTH + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1437
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1438 if (!(pathObject2 = PyString_FromString(pathbuf)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1439 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1440 Py_DECREF(pathObject1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1441 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1442 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1443 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1444 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1445
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1446 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1447
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1448 if (PyList_Append(list, pathObject1)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1449 || PyList_Append(list, pathObject2))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1450 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1451
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1452 Py_DECREF(pathObject1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1453 Py_DECREF(pathObject2);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1454 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1455
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1456 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
1457 Vim_GetPaths(PyObject *self UNUSED, PyObject *args UNUSED)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1458 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1459 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1460
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1461 if (!(ret = PyList_New(0)))
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1462 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1463
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7949
diff changeset
1464 do_in_runtimepath(NULL, 0, &map_finder_callback, ret);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1465
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1466 if (PyErr_Occurred())
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1467 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1468 Py_DECREF(ret);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1469 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1470 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1471
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1472 return ret;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1473 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1474
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1475 #if PY_VERSION_HEX >= 0x030700f0
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1476 static PyObject *
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1477 FinderFindSpec(PyObject *self, PyObject *args)
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1478 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1479 char *fullname;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1480 PyObject *paths;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1481 PyObject *target = Py_None;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1482 PyObject *spec;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1483
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1484 if (!PyArg_ParseTuple(args, "s|O", &fullname, &target))
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1485 return NULL;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1486
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
1487 if (!(paths = Vim_GetPaths(self, NULL)))
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1488 return NULL;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1489
16140
ab815ed87969 patch 8.1.1075: function reference count wrong in Python code
Bram Moolenaar <Bram@vim.org>
parents: 16080
diff changeset
1490 spec = PyObject_CallFunction(py_find_spec, "sOO", fullname, paths, target);
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1491
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1492 Py_DECREF(paths);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1493
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1494 if (!spec)
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1495 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1496 if (PyErr_Occurred())
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1497 return NULL;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1498
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1499 Py_INCREF(Py_None);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1500 return Py_None;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1501 }
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1502
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1503 return spec;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1504 }
16718
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1505
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1506 static PyObject *
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1507 FinderFindModule(PyObject* self UNUSED, PyObject* args UNUSED)
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1508 {
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1509 // Apparently returning None works.
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1510 Py_INCREF(Py_None);
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1511 return Py_None;
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1512 }
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1513 #else
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1514 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1515 call_load_module(char *name, int len, PyObject *find_module_result)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1516 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1517 PyObject *fd, *pathname, *description;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1518
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1519 if (!PyTuple_Check(find_module_result))
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1520 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1521 PyErr_FORMAT_TYPE(
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1522 N_("expected 3-tuple as imp.find_module() result, but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1523 find_module_result);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1524 return NULL;
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1525 }
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1526 if (PyTuple_GET_SIZE(find_module_result) != 3)
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1527 {
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1528 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1529 N_("expected 3-tuple as imp.find_module() result, but got "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1530 "tuple of size %d"),
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1531 (int) PyTuple_GET_SIZE(find_module_result));
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1532 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1533 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1534
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1535 if (!(fd = PyTuple_GET_ITEM(find_module_result, 0))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1536 || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1537 || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1538 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1539 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1540 N_("internal error: imp.find_module returned tuple with NULL"));
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1541 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1542 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1543
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1544 return PyObject_CallFunction(py_load_module,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1545 "s#OOO", name, len, fd, pathname, description);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1546 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1547
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1548 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1549 find_module(char *fullname, char *tail, PyObject *new_path)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1550 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1551 PyObject *find_module_result;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1552 PyObject *module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1553 char *dot;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1554
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1555 if ((dot = (char *)vim_strchr((char_u *) tail, '.')))
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1556 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1557 /*
4859
e48cabe98453 updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents: 4855
diff changeset
1558 * There is a dot in the name: call find_module recursively without the
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1559 * first component
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1560 */
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1561 PyObject *newest_path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1562 int partlen = (int) (dot - 1 - tail);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1563
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1564 if (!(find_module_result = PyObject_CallFunction(py_find_module,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1565 "s#O", tail, partlen, new_path)))
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1566 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1567 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_ImportError))
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1568 PyErr_Clear();
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1569 return NULL;
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1570 }
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1571
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1572 if (!(module = call_load_module(
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1573 fullname,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1574 ((int) (tail - fullname)) + partlen,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1575 find_module_result)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1576 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1577 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1578 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1579 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1580
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1581 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1582
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1583 if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1584 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1585 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1586 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1587 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1588
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1589 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1590
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1591 find_module_result = find_module(fullname, dot + 1, newest_path);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1592
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1593 Py_DECREF(newest_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1594
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1595 return find_module_result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1596 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1597 else
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1598 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1599 if (!(find_module_result = PyObject_CallFunction(py_find_module,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1600 "sO", tail, new_path)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1601 {
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1602 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_ImportError))
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1603 PyErr_Clear();
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1604 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1605 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1606
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1607 return find_module_result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1608 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1609 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1610
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1611 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1612 FinderFindModule(PyObject *self, PyObject *args)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1613 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1614 char *fullname;
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1615 PyObject *result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1616 PyObject *new_path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1617 LoaderObject *loader;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1618
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1619 if (!PyArg_ParseTuple(args, "s", &fullname))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1620 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1621
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
1622 if (!(new_path = Vim_GetPaths(self, NULL)))
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1623 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1624
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1625 result = find_module(fullname, fullname, new_path);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1626
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1627 Py_DECREF(new_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1628
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1629 if (!result)
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1630 {
4984
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1631 if (PyErr_Occurred())
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1632 return NULL;
4984
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1633
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1634 Py_INCREF(Py_None);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1635 return Py_None;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1636 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1637
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1638 if (!(fullname = (char *)vim_strsave((char_u *)fullname)))
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1639 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1640 Py_DECREF(result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1641 PyErr_NoMemory();
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1642 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1643 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1644
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1645 if (!(loader = PyObject_NEW(LoaderObject, LoaderTypePtr)))
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1646 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1647 vim_free(fullname);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1648 Py_DECREF(result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1649 return NULL;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1650 }
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1651
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1652 loader->fullname = fullname;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1653 loader->result = result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1654
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1655 return (PyObject *) loader;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1656 }
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1657 #endif
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1658
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1659 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1660 VimPathHook(PyObject *self UNUSED, PyObject *args)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1661 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1662 char *path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1663
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1664 if (PyArg_ParseTuple(args, "s", &path)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1665 && STRCMP(path, vim_special_path) == 0)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1666 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1667 Py_INCREF(vim_module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1668 return vim_module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1669 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1670
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1671 PyErr_Clear();
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1672 PyErr_SetNone(PyExc_ImportError);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1673 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1674 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1675
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1676 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1677 * Vim module - Definitions
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1678 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1679
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1680 static struct PyMethodDef VimMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1681 // name, function, calling, documentation
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1682 {"command", VimCommand, METH_O, "Execute a Vim ex-mode command" },
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1683 {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" },
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
1684 {"bindeval", VimEvalPy, METH_O, "Like eval(), but returns objects attached to Vim ones"},
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1685 {"strwidth", VimStrwidth, METH_O, "Screen string width, counts <Tab> as having width 1"},
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
1686 {"chdir", (PyCFunction)(void *)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
1687 {"fchdir", (PyCFunction)(void *)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"},
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1688 {"foreach_rtp", VimForeachRTP, METH_O, "Call given callable for each path in &rtp"},
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1689 #if PY_VERSION_HEX >= 0x030700f0
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1690 {"find_spec", FinderFindSpec, METH_VARARGS, "Internal use only, returns spec object for any input it receives"},
16718
9aa87f5aab55 patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents: 16688
diff changeset
1691 #endif
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1692 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"},
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1693 {"path_hook", VimPathHook, METH_VARARGS, "Hook function to install in sys.path_hooks"},
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1694 {"_get_paths", (PyCFunction)Vim_GetPaths, METH_NOARGS, "Get &rtp-based additions to sys.path"},
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1695 { NULL, NULL, 0, NULL}
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1696 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1697
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1698 /*
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1699 * Generic iterator object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1700 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1701
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1702 DEFINE_PY_TYPE_OBJECT(IterType);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1703
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1704 typedef PyObject *(*nextfun)(void **);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1705 typedef void (*destructorfun)(void *);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1706 typedef int (*traversefun)(void *, visitproc, void *);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1707 typedef int (*clearfun)(void **);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1708
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1709 // Main purpose of this object is removing the need for do python
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1710 // initialization (i.e. PyType_Ready and setting type attributes) for a big
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1711 // bunch of objects.
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1712 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1713 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1714 PyObject_HEAD
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1715 void *cur;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1716 nextfun next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1717 destructorfun destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1718 traversefun traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1719 clearfun clear;
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1720 PyObject *iter_object;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1721 } IterObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1722
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1723 static PyObject *
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1724 IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse,
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1725 clearfun clear, PyObject *iter_object)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1726 {
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1727 IterObject *self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1728
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1729 self = PyObject_GC_New(IterObject, IterTypePtr);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1730 self->cur = start;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1731 self->next = next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1732 self->destruct = destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1733 self->traverse = traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1734 self->clear = clear;
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1735 self->iter_object = iter_object;
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1736
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1737 if (iter_object)
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1738 Py_INCREF(iter_object);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1739
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1740 return (PyObject *)(self);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1741 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1742
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1743 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1744 IterDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1745 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1746 IterObject *self = (IterObject*)self_obj;
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1747 if (self->iter_object)
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
1748 Py_DECREF(self->iter_object);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1749 PyObject_GC_UnTrack((void *)(self));
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1750 self->destruct(self->cur);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1751 PyObject_GC_Del((void *)(self));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1752 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1753
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1754 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1755 IterTraverse(PyObject *self_obj, visitproc visit, void *arg)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1756 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1757 IterObject *self = (IterObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1758 if (self->traverse != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1759 return self->traverse(self->cur, visit, arg);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1760 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1761 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1762 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1763
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1764 // Mac OSX defines clear() somewhere.
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1765 #ifdef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1766 # undef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1767 #endif
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1768
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1769 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1770 IterClear(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1771 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1772 IterObject *self = (IterObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1773 if (self->clear != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1774 return self->clear(&self->cur);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1775 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1776 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1777 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1778
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1779 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1780 IterNext(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1781 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1782 IterObject *self = (IterObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1783 return self->next(&self->cur);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1784 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1785
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1786 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1787 IterIter(PyObject *self)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1788 {
4609
12421d8a45d5 updated for version 7.3.1052
Bram Moolenaar <bram@vim.org>
parents: 4607
diff changeset
1789 Py_INCREF(self);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1790 return self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1791 }
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
1792
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1793 typedef struct pylinkedlist_S {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1794 struct pylinkedlist_S *pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1795 struct pylinkedlist_S *pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1796 PyObject *pll_obj;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1797 } pylinkedlist_T;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1798
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1799 static pylinkedlist_T *lastdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1800 static pylinkedlist_T *lastlist = NULL;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
1801 static pylinkedlist_T *lastfunc = NULL;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1802
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1803 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1804 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1805 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1806 if (ref->pll_prev == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1807 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1808 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1809 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1810 *last = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1811 return;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1812 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1813 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1814 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1815 ref->pll_prev->pll_next = ref->pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1816
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1817 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1818 *last = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1819 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1820 ref->pll_next->pll_prev = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1821 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1822
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1823 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1824 pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1825 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1826 if (*last == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1827 ref->pll_prev = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1828 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1829 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1830 (*last)->pll_next = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1831 ref->pll_prev = *last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1832 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1833 ref->pll_next = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1834 ref->pll_obj = self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1835 *last = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1836 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1837
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1838 DEFINE_PY_TYPE_OBJECT(DictionaryType);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1839
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1840 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1841 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1842 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1843 dict_T *dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1844 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1845 } DictionaryObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1846
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1847 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1848
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1849 #define NEW_DICTIONARY(dict) DictionaryNew(DictionaryTypePtr, dict)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1850
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1851 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1852 DictionaryNew(PyTypeObject *subtype, dict_T *dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1853 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1854 DictionaryObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1855
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
1856 self = (DictionaryObject *) Py_TYPE_GET_TP_ALLOC(subtype)(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1857 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1858 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1859 self->dict = dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1860 ++dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1861
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1862 pyll_add((PyObject *)(self), &self->ref, &lastdict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1863
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1864 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1865 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1866
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1867 static dict_T *
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1868 py_dict_alloc(void)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1869 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1870 dict_T *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1871
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1872 if (!(ret = dict_alloc()))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1873 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1874 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1875 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1876 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1877 ++ret->dv_refcount;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1878
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1879 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1880 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1881
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1882 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1883 DictionaryConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1884 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1885 DictionaryObject *self;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1886 dict_T *dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1887
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1888 if (!(dict = py_dict_alloc()))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1889 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1890
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1891 self = (DictionaryObject *) DictionaryNew(subtype, dict);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1892
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1893 --dict->dv_refcount;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1894
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1895 if (kwargs || PyTuple_Size(args))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1896 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1897 PyObject *tmp;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1898 if (!(tmp = DictionaryUpdate(self, args, kwargs)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1899 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1900 Py_DECREF(self);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1901 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1902 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1903
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1904 Py_DECREF(tmp);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1905 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1906
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1907 return (PyObject *)(self);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1908 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1909
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1910 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1911 DictionaryDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1912 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1913 DictionaryObject *self = (DictionaryObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1914 pyll_remove(&self->ref, &lastdict);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1915 dict_unref(self->dict);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1916
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1917 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1918 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1919
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1920 static char *DictionaryAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1921 "locked", "scope",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1922 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1923 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1924
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1925 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
1926 DictionaryDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1927 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1928 return ObjectDir(self, DictionaryAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1929 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1930
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1931 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1932 DictionarySetattr(PyObject *self_obj, char *name, PyObject *valObject)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1933 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
1934 DictionaryObject *self = (DictionaryObject*)self_obj;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1935 if (valObject == NULL)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1936 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1937 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1938 N_("cannot delete vim.Dictionary attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1939 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1940 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1941
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1942 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1943 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1944 if (self->dict->dv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1945 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1946 PyErr_SET_STRING(PyExc_TypeError,
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1947 N_("cannot modify fixed dictionary"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1948 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1949 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1950 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1951 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1952 int istrue = PyObject_IsTrue(valObject);
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1953 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1954 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1955 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1956 self->dict->dv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1957 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1958 self->dict->dv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1959 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1960 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1961 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1962 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1963 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1964 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name);
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1965 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1966 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1967 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1968
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1969 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1970 DictionaryLength(DictionaryObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1971 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1972 return ((PyInt) (self->dict->dv_hashtab.ht_used));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1973 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1974
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1975 #define DICT_FLAG_HAS_DEFAULT 0x01
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1976 #define DICT_FLAG_POP 0x02
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1977 #define DICT_FLAG_NONE_DEFAULT 0x04
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
1978 #define DICT_FLAG_RETURN_BOOL 0x08 // Incompatible with DICT_FLAG_POP
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1979 #define DICT_FLAG_RETURN_PAIR 0x10
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1980
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1981 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1982 _DictionaryItem(DictionaryObject *self, PyObject *args, int flags)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1983 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1984 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1985 PyObject *defObject = ((flags & DICT_FLAG_NONE_DEFAULT)? Py_None : NULL);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1986 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1987 char_u *key;
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1988 dictitem_T *di;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1989 dict_T *dict = self->dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1990 hashitem_T *hi;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1991 PyObject *todecref;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1992
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1993 if (flags & DICT_FLAG_HAS_DEFAULT)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1994 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1995 if (!PyArg_ParseTuple(args, "O|O", &keyObject, &defObject))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1996 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1997 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1998 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1999 keyObject = args;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2000
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2001 if (flags & DICT_FLAG_RETURN_BOOL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2002 defObject = Py_False;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2003
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2004 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2005 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2006
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2007 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2008 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2009 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
2010 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2011 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2012 }
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
2013
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2014 hi = hash_find(&dict->dv_hashtab, key);
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
2015
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2016 Py_XDECREF(todecref);
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
2017
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2018 if (HASHITEM_EMPTY(hi))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2019 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2020 if (defObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2021 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2022 Py_INCREF(defObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2023 return defObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2024 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2025 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2026 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2027 PyErr_SetObject(PyExc_KeyError, keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2028 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2029 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2030 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2031 else if (flags & DICT_FLAG_RETURN_BOOL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2032 {
5666
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
2033 ret = Py_True;
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
2034 Py_INCREF(ret);
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
2035 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2036 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2037
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2038 di = dict_lookup(hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2039
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2040 if (!(ret = ConvertToPyObject(&di->di_tv)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2041 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2042
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2043 if (flags & DICT_FLAG_POP)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2044 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2045 if (dict->dv_lock)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2046 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2047 RAISE_LOCKED_DICTIONARY;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2048 Py_DECREF(ret);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2049 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2050 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2051
31231
684e6dfa2fba patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
2052 hash_remove(&dict->dv_hashtab, hi, "Python remove variable");
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2053 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2054 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2055
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2056 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2057 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2058
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2059 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2060 DictionaryItem(DictionaryObject *self, PyObject *keyObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2061 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2062 return _DictionaryItem(self, keyObject, 0);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2063 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2064
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2065 static int
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2066 DictionaryContains(DictionaryObject *self, PyObject *keyObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2067 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2068 PyObject *rObj = _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2069 int ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2070
5426
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
2071 if (rObj == NULL)
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
2072 return -1;
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
2073
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2074 ret = (rObj == Py_True);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2075
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
2076 Py_DECREF(rObj);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2077
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2078 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2079 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2080
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2081 typedef struct
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2082 {
21319
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2083 int dii_changed;
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2084 hashtab_T *dii_ht;
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2085 hashitem_T *dii_hi;
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2086 long_u dii_todo;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2087 } dictiterinfo_T;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2088
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2089 static PyObject *
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
2090 DictionaryIterNext(void **arg)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2091 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2092 PyObject *ret;
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
2093 dictiterinfo_T **dii = (dictiterinfo_T**)arg;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2094
21319
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2095 if (!(*dii)->dii_todo)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2096 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2097
21319
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2098 if ((*dii)->dii_ht->ht_changed != (*dii)->dii_changed)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2099 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2100 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2101 N_("hashtab changed during iteration"));
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
2102 return NULL;
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
2103 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2104
21319
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2105 while (((*dii)->dii_todo) && HASHITEM_EMPTY((*dii)->dii_hi))
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2106 ++((*dii)->dii_hi);
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2107
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2108 --((*dii)->dii_todo);
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2109
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2110 if (!(ret = PyBytes_FromString((char *)(*dii)->dii_hi->hi_key)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2111 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2112
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2113 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2114 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2115
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2116 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
2117 DictionaryIter(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
2118 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
2119 DictionaryObject *self = (DictionaryObject*)self_obj;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2120 dictiterinfo_T *dii;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2121 hashtab_T *ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2122
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2123 if (!(dii = PyMem_New(dictiterinfo_T, 1)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2124 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2125 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2126 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2127 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2128
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2129 ht = &self->dict->dv_hashtab;
21319
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2130 dii->dii_changed = ht->ht_changed;
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2131 dii->dii_ht = ht;
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2132 dii->dii_hi = ht->ht_array;
fb3dcd8ed14d patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents: 21198
diff changeset
2133 dii->dii_todo = ht->ht_used;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2134
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2135 return IterNew(dii,
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
2136 PyMem_Free, DictionaryIterNext,
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
2137 NULL, NULL, (PyObject *)self);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2138 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2139
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
2140 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
2141 DictionaryAssItem(
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
2142 DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2143 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2144 char_u *key;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2145 typval_T tv;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
2146 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2147 dictitem_T *di;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2148 PyObject *todecref;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2149
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
2150 if (dict->dv_lock)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2151 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2152 RAISE_LOCKED_DICTIONARY;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2153 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2154 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2155
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2156 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2157 return -1;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
2158
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2159 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2160 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2161 RAISE_NO_EMPTY_KEYS;
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
2162 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2163 return -1;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2164 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2165
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
2166 di = dict_find(dict, key, -1);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2167
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2168 if (valObject == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2169 {
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
2170 hashitem_T *hi;
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
2171
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2172 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2173 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2174 Py_XDECREF(todecref);
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
2175 PyErr_SetObject(PyExc_KeyError, keyObject);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2176 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2177 }
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
2178 hi = hash_find(&dict->dv_hashtab, di->di_key);
31231
684e6dfa2fba patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
2179 hash_remove(&dict->dv_hashtab, hi, "Python remove item");
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2180 dictitem_free(di);
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
2181 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2182 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2183 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2184
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2185 if (ConvertFromPyObject(valObject, &tv) == -1)
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
2186 {
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
2187 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2188 return -1;
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
2189 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2190
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2191 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2192 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2193 if (!(di = dictitem_alloc(key)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2194 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2195 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2196 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2197 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2198 }
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2199 di->di_tv.v_type = VAR_UNKNOWN;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2200
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
2201 if (dict_add(dict, di) == FAIL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2202 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2203 dictitem_free(di);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2204 RAISE_KEY_ADD_FAIL(key);
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2205 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2206 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2207 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2208 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2209 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2210 clear_tv(&di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2211
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
2212 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2213
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2214 copy_tv(&tv, &di->di_tv);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
2215 clear_tv(&tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2216 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2217 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2218
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2219 typedef PyObject *(*hi_to_py)(hashitem_T *);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2220
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2221 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2222 DictionaryListObjects(DictionaryObject *self, hi_to_py hiconvert)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2223 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2224 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2225 long_u todo = dict->dv_hashtab.ht_used;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2226 Py_ssize_t i = 0;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2227 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2228 hashitem_T *hi;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2229 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2230
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2231 ret = PyList_New(todo);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2232 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2233 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2234 if (!HASHITEM_EMPTY(hi))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2235 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2236 if (!(newObj = hiconvert(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2237 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2238 Py_DECREF(ret);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2239 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2240 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2241 PyList_SET_ITEM(ret, i, newObj);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2242 --todo;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2243 ++i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2244 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2245 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2246 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2247 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2248
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2249 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2250 dict_key(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2251 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2252 return PyBytes_FromString((char *)(hi->hi_key));
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2253 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2254
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2255 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
2256 DictionaryListKeys(DictionaryObject *self, PyObject *args UNUSED)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2257 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2258 return DictionaryListObjects(self, dict_key);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2259 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2260
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2261 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2262 dict_val(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2263 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2264 dictitem_T *di;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2265
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2266 di = dict_lookup(hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2267 return ConvertToPyObject(&di->di_tv);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2268 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2269
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2270 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
2271 DictionaryListValues(DictionaryObject *self, PyObject *args UNUSED)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2272 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2273 return DictionaryListObjects(self, dict_val);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2274 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2275
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2276 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2277 dict_item(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2278 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2279 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2280 PyObject *valObject;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2281 PyObject *ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2282
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2283 if (!(keyObject = dict_key(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2284 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2285
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2286 if (!(valObject = dict_val(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2287 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2288 Py_DECREF(keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2289 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2290 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2291
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2292 ret = Py_BuildValue("(OO)", keyObject, valObject);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2293
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2294 Py_DECREF(keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2295 Py_DECREF(valObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2296
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2297 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2298 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2299
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2300 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
2301 DictionaryListItems(DictionaryObject *self, PyObject *args UNUSED)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2302 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2303 return DictionaryListObjects(self, dict_item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2304 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2305
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2306 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2307 DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2308 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2309 dict_T *dict = self->dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2310
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2311 if (dict->dv_lock)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2312 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2313 RAISE_LOCKED_DICTIONARY;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2314 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2315 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2316
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2317 if (kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2318 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2319 typval_T tv;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2320
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2321 if (ConvertFromPyMapping(kwargs, &tv) == -1)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2322 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2323
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2324 VimTryStart();
25326
cfbf40f749b0 patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
2325 dict_extend(self->dict, tv.vval.v_dict, (char_u *) "force", NULL);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2326 clear_tv(&tv);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2327 if (VimTryEnd())
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2328 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2329 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2330 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2331 {
5659
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2332 PyObject *obj = NULL;
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2333
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2334 if (!PyArg_ParseTuple(args, "|O", &obj))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2335 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2336
5659
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2337 if (obj == NULL)
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2338 {
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2339 Py_INCREF(Py_None);
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2340 return Py_None;
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2341 }
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2342
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2343 if (PyObject_HasAttrString(obj, "keys"))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2344 return DictionaryUpdate(self, NULL, obj);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2345 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2346 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2347 PyObject *iterator;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2348 PyObject *item;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2349
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2350 if (!(iterator = PyObject_GetIter(obj)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2351 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2352
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2353 while ((item = PyIter_Next(iterator)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2354 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2355 PyObject *fast;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2356 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2357 PyObject *valObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2358 PyObject *todecref;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2359 char_u *key;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2360 dictitem_T *di;
12812
381e67ccf02c patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents: 12806
diff changeset
2361 hashitem_T *hi;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2362
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2363 if (!(fast = PySequence_Fast(item, "")))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2364 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2365 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2366 Py_DECREF(item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2367 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2368 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2369
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2370 Py_DECREF(item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2371
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2372 if (PySequence_Fast_GET_SIZE(fast) != 2)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2373 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2374 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2375 Py_DECREF(fast);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2376 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2377 N_("expected sequence element of size 2, "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2378 "but got sequence of size %d"),
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
2379 (int) PySequence_Fast_GET_SIZE(fast));
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2380 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2381 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2382
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2383 keyObject = PySequence_Fast_GET_ITEM(fast, 0);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2384
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2385 if (!(key = StringToChars(keyObject, &todecref)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2386 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2387 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2388 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2389 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2390 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2391
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2392 di = dictitem_alloc(key);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2393
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2394 Py_XDECREF(todecref);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2395
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2396 if (di == NULL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2397 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2398 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2399 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2400 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2401 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2402 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2403 di->di_tv.v_type = VAR_UNKNOWN;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2404
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2405 valObject = PySequence_Fast_GET_ITEM(fast, 1);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2406
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2407 if (ConvertFromPyObject(valObject, &di->di_tv) == -1)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2408 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2409 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2410 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2411 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2412 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2413 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2414
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2415 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2416
12812
381e67ccf02c patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents: 12806
diff changeset
2417 hi = hash_find(&dict->dv_hashtab, di->di_key);
381e67ccf02c patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents: 12806
diff changeset
2418 if (!HASHITEM_EMPTY(hi) || dict_add(dict, di) == FAIL)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2419 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2420 RAISE_KEY_ADD_FAIL(di->di_key);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2421 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2422 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2423 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2424 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2425 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2426
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2427 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2428
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2429 // Iterator may have finished due to an exception
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2430 if (PyErr_Occurred())
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2431 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2432 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2433 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2434 Py_INCREF(Py_None);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2435 return Py_None;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2436 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2437
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2438 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2439 DictionaryGet(DictionaryObject *self, PyObject *args)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2440 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2441 return _DictionaryItem(self, args,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2442 DICT_FLAG_HAS_DEFAULT|DICT_FLAG_NONE_DEFAULT);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2443 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2444
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2445 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2446 DictionaryPop(DictionaryObject *self, PyObject *args)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2447 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2448 return _DictionaryItem(self, args, DICT_FLAG_HAS_DEFAULT|DICT_FLAG_POP);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2449 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2450
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2451 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
2452 DictionaryPopItem(DictionaryObject *self, PyObject *args UNUSED)
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2453 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2454 hashitem_T *hi;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2455 PyObject *ret;
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2456 PyObject *valObject;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2457 dictitem_T *di;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2458
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2459 if (self->dict->dv_hashtab.ht_used == 0)
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2460 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2461 PyErr_SetNone(PyExc_KeyError);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2462 return NULL;
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2463 }
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2464
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2465 hi = self->dict->dv_hashtab.ht_array;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2466 while (HASHITEM_EMPTY(hi))
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2467 ++hi;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2468
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2469 di = dict_lookup(hi);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2470
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2471 if (!(valObject = ConvertToPyObject(&di->di_tv)))
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2472 return NULL;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2473
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2474 if (!(ret = Py_BuildValue("(" Py_bytes_fmt "O)", hi->hi_key, valObject)))
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2475 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2476 Py_DECREF(valObject);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2477 return NULL;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2478 }
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2479
31231
684e6dfa2fba patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
2480 hash_remove(&self->dict->dv_hashtab, hi, "Python pop item");
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2481 dictitem_free(di);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2482
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2483 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2484 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2485
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2486 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2487 DictionaryHasKey(DictionaryObject *self, PyObject *keyObject)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2488 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2489 return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2490 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2491
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2492 static PySequenceMethods DictionaryAsSeq = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2493 0, // sq_length
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2494 0, // sq_concat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2495 0, // sq_repeat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2496 0, // sq_item
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2497 0, // sq_slice
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2498 0, // sq_ass_item
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2499 0, // sq_ass_slice
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2500 (objobjproc) DictionaryContains, // sq_contains
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2501 0, // sq_inplace_concat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2502 0, // sq_inplace_repeat
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2503 };
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2504
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2505 static PyMappingMethods DictionaryAsMapping = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2506 (lenfunc) DictionaryLength,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2507 (binaryfunc) DictionaryItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2508 (objobjargproc) DictionaryAssItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2509 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2510
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2511 static struct PyMethodDef DictionaryMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
2512 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2513 {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2514 {"items", (PyCFunction)DictionaryListItems, METH_NOARGS, ""},
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
2515 {"update", (PyCFunction)(void *)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""},
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2516 {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2517 {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2518 {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""},
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2519 {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""},
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2520 {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2521 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2522 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2523
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
2524 DEFINE_PY_TYPE_OBJECT(ListType);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2525
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2526 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2527 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2528 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2529 list_T *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2530 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2531 } ListObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2532
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
2533 #define NEW_LIST(list) ListNew(ListTypePtr, list)
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2534
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2535 static PyObject *
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2536 ListNew(PyTypeObject *subtype, list_T *list)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2537 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2538 ListObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2539
21190
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2540 if (list == NULL)
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2541 return NULL;
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2542
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
2543 self = (ListObject *) Py_TYPE_GET_TP_ALLOC(subtype)(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2544 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2545 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2546 self->list = list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2547 ++list->lv_refcount;
20392
4c317d8c1051 patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents: 20369
diff changeset
2548 CHECK_LIST_MATERIALIZE(list);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2549
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2550 pyll_add((PyObject *)(self), &self->ref, &lastlist);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2551
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2552 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2553 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2554
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2555 static list_T *
5166
467efeee8f9e updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents: 5139
diff changeset
2556 py_list_alloc(void)
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2557 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2558 list_T *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2559
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2560 if (!(ret = list_alloc()))
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2561 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2562 PyErr_NoMemory();
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2563 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2564 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2565 ++ret->lv_refcount;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2566
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2567 return ret;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2568 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2569
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2570 static int
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2571 list_py_concat(list_T *l, PyObject *obj, PyObject *lookup_dict)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2572 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2573 PyObject *iterator;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2574 PyObject *item;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2575 listitem_T *li;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2576
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2577 if (!(iterator = PyObject_GetIter(obj)))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2578 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2579
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2580 while ((item = PyIter_Next(iterator)))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2581 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2582 if (!(li = listitem_alloc()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2583 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2584 PyErr_NoMemory();
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2585 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2586 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2587 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2588 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2589 li->li_tv.v_lock = 0;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2590 li->li_tv.v_type = VAR_UNKNOWN;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2591
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2592 if (_ConvertFromPyObject(item, &li->li_tv, lookup_dict) == -1)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2593 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2594 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2595 Py_DECREF(iterator);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19102
diff changeset
2596 listitem_free(l, li);
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2597 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2598 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2599
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2600 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2601
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2602 list_append(l, li);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2603 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2604
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2605 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2606
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2607 // Iterator may have finished due to an exception
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2608 if (PyErr_Occurred())
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2609 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2610
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2611 return 0;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2612 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2613
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2614 static PyObject *
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2615 ListConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2616 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2617 list_T *list;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2618 PyObject *obj = NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2619
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2620 if (kwargs)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2621 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2622 PyErr_SET_STRING(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2623 N_("list constructor does not accept keyword arguments"));
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2624 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2625 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2626
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2627 if (!PyArg_ParseTuple(args, "|O", &obj))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2628 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2630 if (!(list = py_list_alloc()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2631 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2632
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2633 if (obj)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2634 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2635 PyObject *lookup_dict;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2636
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2637 if (!(lookup_dict = PyDict_New()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2638 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2639 list_unref(list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2640 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2641 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2642
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2643 if (list_py_concat(list, obj, lookup_dict) == -1)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2644 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2645 Py_DECREF(lookup_dict);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2646 list_unref(list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2647 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2648 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2649
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2650 Py_DECREF(lookup_dict);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2651 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2652
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2653 return ListNew(subtype, list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2654 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2655
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2656 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
2657 ListDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
2658 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
2659 ListObject *self = (ListObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2660 pyll_remove(&self->ref, &lastlist);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2661 list_unref(self->list);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2662
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2663 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2664 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2665
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2666 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2667 ListLength(ListObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2668 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2669 return ((PyInt) (self->list->lv_len));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2670 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2671
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2672 static PyObject *
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2673 ListIndex(ListObject *self, Py_ssize_t index)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2674 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2675 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2676
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2677 if (index >= ListLength(self))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2678 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2679 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2680 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2681 }
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2682 li = list_find(self->list, (long) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2683 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2684 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2685 // No more suitable format specifications in python-2.3
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
2686 PyErr_VIM_FORMAT(N_("internal error: failed to get Vim list item %d"),
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2687 (int) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2688 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2689 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2690 return ConvertToPyObject(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2691 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2692
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2693 static PyObject *
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2694 ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t step,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2695 Py_ssize_t slicelen)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2696 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2697 PyInt i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2698 PyObject *list;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2699
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2700 if (step == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2701 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2702 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2703 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2704 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2705
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2706 list = PyList_New(slicelen);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2707 if (list == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2708 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2709
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2710 for (i = 0; i < slicelen; ++i)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2711 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2712 PyObject *item;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2713
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2714 item = ListIndex(self, first + i*step);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2715 if (item == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2716 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2717 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2718 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2719 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2720
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2721 PyList_SET_ITEM(list, i, item);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2722 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2723
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2724 return list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2725 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2726
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2727 static PyObject *
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2728 ListItem(ListObject *self, PyObject* idx)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2729 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2730 #if PY_MAJOR_VERSION < 3
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2731 if (PyInt_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2732 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2733 long _idx = PyInt_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2734 return ListIndex(self, _idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2735 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2736 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2737 #endif
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2738 if (PyLong_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2739 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2740 long _idx = PyLong_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2741 return ListIndex(self, _idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2742 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2743 else if (PySlice_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2744 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2745 Py_ssize_t start, stop, step, slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2746
5768
3ee5808a293c updated for version 7.4.228
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
2747 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self),
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2748 &start, &stop, &step, &slicelen) < 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2749 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2750 return ListSlice(self, start, step, slicelen);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2751 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2752 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2753 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2754 RAISE_INVALID_INDEX_TYPE(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2755 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2756 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2757 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2758
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2759 static void
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2760 list_restore(Py_ssize_t numadded, Py_ssize_t numreplaced, Py_ssize_t slicelen,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2761 list_T *l, listitem_T **lis, listitem_T *lastaddedli)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2762 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2763 while (numreplaced--)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2764 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2765 list_insert(l, lis[numreplaced], lis[slicelen + numreplaced]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2766 listitem_remove(l, lis[slicelen + numreplaced]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2767 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2768 while (numadded--)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2769 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2770 listitem_T *next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2771
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2772 next = lastaddedli->li_prev;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2773 listitem_remove(l, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2774 lastaddedli = next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2775 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2776 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2777
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2778 static int
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2779 ListAssSlice(ListObject *self, Py_ssize_t first,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2780 Py_ssize_t step, Py_ssize_t slicelen, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2781 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2782 PyObject *iterator;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2783 PyObject *item;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2784 listitem_T *li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2785 listitem_T *lastaddedli = NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2786 listitem_T *next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2787 typval_T v;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2788 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2789 PyInt i;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2790 PyInt j;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2791 PyInt numreplaced = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2792 PyInt numadded = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2793 PyInt size;
5655
f2c8d86c460d updated for version 7.4.174
Bram Moolenaar <bram@vim.org>
parents: 5629
diff changeset
2794 listitem_T **lis = NULL;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2795
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2796 size = ListLength(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2797
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2798 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2799 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2800 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2801 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2802 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2803
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2804 if (step == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2805 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2806 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2807 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2808 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2809
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2810 if (step != 1 && slicelen == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2811 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2812 // Nothing to do. Only error out if obj has some items.
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2813 int ret = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2814
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2815 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2816 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2817
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2818 if (!(iterator = PyObject_GetIter(obj)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2819 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2820
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2821 if ((item = PyIter_Next(iterator)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2822 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2823 PyErr_FORMAT(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
2824 N_("attempt to assign sequence of size greater than %d "
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2825 "to extended slice"), 0);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2826 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2827 ret = -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2828 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2829 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2830 return ret;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2831 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2832
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2833 if (obj != NULL)
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
2834 // XXX May allocate zero bytes.
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2835 if (!(lis = PyMem_New(listitem_T *, slicelen * 2)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2836 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2837 PyErr_NoMemory();
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2838 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2839 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2840
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2841 if (first == size)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2842 li = NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2843 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2844 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2845 li = list_find(l, (long) first);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2846 if (li == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2847 {
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
2848 PyErr_VIM_FORMAT(N_("internal error: no Vim list item %d"),
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2849 (int)first);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2850 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2851 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2852 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2853 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2854 i = slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2855 while (i-- && li != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2856 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2857 j = step;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2858 next = li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2859 if (step > 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2860 while (next != NULL && ((next = next->li_next) != NULL) && --j);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2861 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2862 while (next != NULL && ((next = next->li_prev) != NULL) && ++j);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2863
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2864 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2865 listitem_remove(l, li);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2866 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2867 lis[slicelen - i - 1] = li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2868
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2869 li = next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2870 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2871 if (li == NULL && i != -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2872 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2873 PyErr_SET_VIM(N_("internal error: not enough list items"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2874 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2875 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2876 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2877 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2878 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2879
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2880 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2881 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2882
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2883 if (!(iterator = PyObject_GetIter(obj)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2884 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2885 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2886 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2887 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2888
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2889 i = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2890 while ((item = PyIter_Next(iterator)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2891 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2892 if (ConvertFromPyObject(item, &v) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2893 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2894 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2895 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2896 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2897 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2898 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2899 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2900 if (list_insert_tv(l, &v, numreplaced < slicelen
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2901 ? lis[numreplaced]
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2902 : li) == FAIL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2903 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2904 clear_tv(&v);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2905 PyErr_SET_VIM(N_("internal error: failed to add item to list"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2906 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2907 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2908 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2909 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2910 if (numreplaced < slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2911 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2912 lis[slicelen + numreplaced] = lis[numreplaced]->li_prev;
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 5768
diff changeset
2913 vimlist_remove(l, lis[numreplaced], lis[numreplaced]);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2914 numreplaced++;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2915 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2916 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2917 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2918 if (li)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2919 lastaddedli = li->li_prev;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2920 else
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19193
diff changeset
2921 lastaddedli = l->lv_u.mat.lv_last;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2922 numadded++;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2923 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2924 clear_tv(&v);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2925 if (step != 1 && i >= slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2926 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2927 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2928 PyErr_FORMAT(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
2929 N_("attempt to assign sequence of size greater than %d "
5668
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2930 "to extended slice"), (int) slicelen);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2931 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2932 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2933 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2934 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2935 ++i;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2936 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2937 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2938
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2939 if (step != 1 && i != slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2940 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2941 PyErr_FORMAT2(PyExc_ValueError,
5668
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2942 N_("attempt to assign sequence of size %d to extended slice "
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2943 "of size %d"), (int) i, (int) slicelen);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2944 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2945 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2946 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2947 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2948
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2949 if (PyErr_Occurred())
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2950 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2951 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2952 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2953 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2954 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2955
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2956 for (i = 0; i < numreplaced; i++)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19102
diff changeset
2957 listitem_free(l, lis[i]);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2958 if (step == 1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2959 for (i = numreplaced; i < slicelen; i++)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2960 listitem_remove(l, lis[i]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2961
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2962 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2963
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2964 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2965 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2966
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2967 static int
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2968 ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2969 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2970 typval_T tv;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2971 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2972 listitem_T *li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2973 Py_ssize_t length = ListLength(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2974
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2975 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2976 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2977 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2978 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2979 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2980 if (index > length || (index == length && obj == NULL))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2981 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2982 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2983 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2984 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2985
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2986 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2987 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2988 li = list_find(l, (long) index);
21190
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2989 if (li == NULL)
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2990 {
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2991 PyErr_VIM_FORMAT(N_("internal error: failed to get Vim "
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2992 "list item %d"), (int) index);
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2993 return -1;
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
2994 }
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 5768
diff changeset
2995 vimlist_remove(l, li, li);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2996 clear_tv(&li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2997 vim_free(li);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2998 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2999 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3000
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3001 if (ConvertFromPyObject(obj, &tv) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3002 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3003
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3004 if (index == length)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3005 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3006 if (list_append_tv(l, &tv) == FAIL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3007 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3008 clear_tv(&tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3009 PyErr_SET_VIM(N_("failed to add item to list"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3010 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3011 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3012 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3013 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3014 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3015 li = list_find(l, (long) index);
21190
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
3016 if (li == NULL)
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
3017 {
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
3018 PyErr_VIM_FORMAT(N_("internal error: failed to get Vim "
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
3019 "list item %d"), (int) index);
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
3020 return -1;
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
3021 }
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3022 clear_tv(&li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3023 copy_tv(&tv, &li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3024 clear_tv(&tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3025 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3026 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3027 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3028
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3029 static int
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3030 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3031 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3032 #if PY_MAJOR_VERSION < 3
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3033 if (PyInt_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3034 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3035 long _idx = PyInt_AsLong(idx);
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3036 return (int)ListAssIndex(self, _idx, obj);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3037 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3038 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3039 #endif
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3040 if (PyLong_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3041 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3042 long _idx = PyLong_AsLong(idx);
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3043 return (int)ListAssIndex(self, _idx, obj);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3044 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3045 else if (PySlice_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3046 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3047 Py_ssize_t start, stop, step, slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3048
5768
3ee5808a293c updated for version 7.4.228
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
3049 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self),
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3050 &start, &stop, &step, &slicelen) < 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3051 return -1;
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3052 return (int)ListAssSlice(self, start, step, slicelen,
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3053 obj);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3054 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3055 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3056 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3057 RAISE_INVALID_INDEX_TYPE(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3058 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3059 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3060 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3061
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3062 static PyObject *
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3063 ListConcatInPlace(ListObject *self, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3064 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3065 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3066 PyObject *lookup_dict;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3067
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3068 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3069 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3070 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3071 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3072 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3073
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3074 if (!(lookup_dict = PyDict_New()))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3075 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3076
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3077 if (list_py_concat(l, obj, lookup_dict) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3078 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3079 Py_DECREF(lookup_dict);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3080 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3081 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3082 Py_DECREF(lookup_dict);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3083
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3084 Py_INCREF(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3085 return (PyObject *)(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3086 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3087
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3088 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3089 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3090 listwatch_T lw;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3091 list_T *list;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3092 } listiterinfo_T;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3093
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3094 static void
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3095 ListIterDestruct(void *arg)
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3096 {
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3097 listiterinfo_T *lii = (listiterinfo_T*)arg;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3098 list_rem_watch(lii->list, &lii->lw);
23992
faca24acb37f patch 8.2.2538: crash when using Python list iterator
Bram Moolenaar <Bram@vim.org>
parents: 23264
diff changeset
3099 list_unref(lii->list);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3100 PyMem_Free(lii);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3101 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3102
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3103 static PyObject *
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3104 ListIterNext(void **arg)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3105 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3106 PyObject *ret;
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3107 listiterinfo_T **lii = (listiterinfo_T**)arg;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3108
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3109 if (!((*lii)->lw.lw_item))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3110 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3111
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3112 if (!(ret = ConvertToPyObject(&((*lii)->lw.lw_item->li_tv))))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3113 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3114
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3115 (*lii)->lw.lw_item = (*lii)->lw.lw_item->li_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3116
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3117 return ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3118 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3119
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3120 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3121 ListIter(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3122 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3123 ListObject *self = (ListObject*)self_obj;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3124 listiterinfo_T *lii;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3125 list_T *l = self->list;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3126
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3127 if (!(lii = PyMem_New(listiterinfo_T, 1)))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3128 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3129 PyErr_NoMemory();
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3130 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3131 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3132
20392
4c317d8c1051 patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents: 20369
diff changeset
3133 CHECK_LIST_MATERIALIZE(l);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3134 list_add_watch(l, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3135 lii->lw.lw_item = l->lv_first;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3136 lii->list = l;
23992
faca24acb37f patch 8.2.2538: crash when using Python list iterator
Bram Moolenaar <Bram@vim.org>
parents: 23264
diff changeset
3137 ++l->lv_refcount;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3138
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3139 return IterNew(lii,
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3140 ListIterDestruct, ListIterNext,
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
3141 NULL, NULL, (PyObject *)self);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3142 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3143
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3144 static char *ListAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3145 "locked",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3146 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3147 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3148
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3149 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3150 ListDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3151 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3152 return ObjectDir(self, ListAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3153 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3154
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3155 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3156 ListSetattr(PyObject *self_obj, char *name, PyObject *valObject)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3157 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3158 ListObject *self = (ListObject*)self_obj;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3159 if (valObject == NULL)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3160 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
3161 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3162 N_("cannot delete vim.List attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3163 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3164 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3165
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3166 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3167 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3168 if (self->list->lv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3169 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3170 PyErr_SET_STRING(PyExc_TypeError, N_("cannot modify fixed list"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3171 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3172 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3173 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3174 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3175 int istrue = PyObject_IsTrue(valObject);
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3176 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3177 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3178 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3179 self->list->lv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3180 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3181 self->list->lv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3182 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3183 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3184 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3185 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3186 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3187 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name);
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3188 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3189 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3190 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
3191
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3192 static PySequenceMethods ListAsSeq = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3193 (lenfunc) ListLength, // sq_length, len(x)
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3194 (binaryfunc) 0, // RangeConcat, sq_concat, x+y
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3195 0, // RangeRepeat, sq_repeat, x*n
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3196 (PyIntArgFunc) ListIndex, // sq_item, x[i]
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3197 0, // was_sq_slice, x[i:j]
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3198 (PyIntObjArgProc) ListAssIndex, // sq_as_item, x[i]=v
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3199 0, // was_sq_ass_slice, x[i:j]=v
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3200 0, // sq_contains
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3201 (binaryfunc) ListConcatInPlace,// sq_inplace_concat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3202 0, // sq_inplace_repeat
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3203 };
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3204
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3205 static PyMappingMethods ListAsMapping = {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3206 /* mp_length */ (lenfunc) ListLength,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3207 /* mp_subscript */ (binaryfunc) ListItem,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3208 /* mp_ass_subscript */ (objobjargproc) ListAssItem,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3209 };
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
3210
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3211 static struct PyMethodDef ListMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3212 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3213 {"__dir__", (PyCFunction)ListDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3214 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3215 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3216
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3217 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3218 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3219 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3220 char_u *name;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3221 int argc;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3222 typval_T *argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3223 dict_T *self;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3224 pylinkedlist_T ref;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3225 int auto_rebind;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3226 } FunctionObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3227
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
3228 DEFINE_PY_TYPE_OBJECT(FunctionType);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3229
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3230 #define NEW_FUNCTION(name, argc, argv, self, pt_auto) \
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
3231 FunctionNew(FunctionTypePtr, (name), (argc), (argv), (self), (pt_auto))
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3232
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3233 static PyObject *
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3234 FunctionNew(PyTypeObject *subtype, char_u *name, int argc, typval_T *argv,
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3235 dict_T *selfdict, int auto_rebind)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3236 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3237 FunctionObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3238
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
3239 self = (FunctionObject *) Py_TYPE_GET_TP_ALLOC(subtype)(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3240 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3241 return NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3242
34074
1629cc65d78d patch 9.1.0006: is*() and to*() function may be unsafe
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
3243 if (isdigit((unsigned char)*name))
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3244 {
20197
7e84afe0831e patch 8.2.0654: building with Python fails
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3245 if (!translated_function_exists(name, FALSE))
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3246 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3247 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3248 N_("unnamed function %s does not exist"), name);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3249 return NULL;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3250 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3251 self->name = vim_strsave(name);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3252 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3253 else
15234
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3254 {
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3255 char_u *p;
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3256
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3257 if ((p = get_expanded_name(name,
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3258 vim_strchr(name, AUTOLOAD_CHAR) == NULL)) == NULL)
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3259 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3260 PyErr_FORMAT(PyExc_ValueError,
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3261 N_("function %s does not exist"), name);
4641
59e6c2bd68e3 updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents: 4635
diff changeset
3262 return NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3263 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3264
15234
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3265 if (p[0] == K_SPECIAL && p[1] == KS_EXTRA && p[2] == (int)KE_SNR)
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3266 {
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3267 char_u *np;
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3268 size_t len = STRLEN(p) + 1;
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3269
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16718
diff changeset
3270 if ((np = alloc(len + 2)) == NULL)
15234
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3271 {
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3272 vim_free(p);
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3273 return NULL;
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3274 }
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3275 mch_memmove(np, "<SNR>", 5);
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3276 mch_memmove(np + 5, p + 3, len - 3);
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3277 vim_free(p);
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3278 self->name = np;
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3279 }
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3280 else
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3281 self->name = p;
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3282 }
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
3283
9725
4a4a71d67131 commit https://github.com/vim/vim/commit/2d3d60a7d4b410668dfc427120205ccf88789db4
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
3284 func_ref(self->name);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3285 self->argc = argc;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3286 self->argv = argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3287 self->self = selfdict;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3288 self->auto_rebind = selfdict == NULL ? TRUE : auto_rebind;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3289
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3290 if (self->argv || self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3291 pyll_add((PyObject *)(self), &self->ref, &lastfunc);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3292
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3293 return (PyObject *)(self);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3294 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3295
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3296 static PyObject *
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3297 FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3298 {
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3299 PyObject *self;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3300 PyObject *selfdictObject;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3301 PyObject *autoRebindObject;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3302 PyObject *argsObject = NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3303 char_u *name;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3304 typval_T selfdicttv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3305 typval_T argstv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3306 list_T *argslist = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3307 dict_T *selfdict = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3308 int argc = 0;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3309 int auto_rebind = TRUE;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3310 typval_T *argv = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3311 typval_T *curtv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3312 listitem_T *li;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3313
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3314 if (kwargs != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3315 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3316 selfdictObject = PyDict_GetItemString(kwargs, "self");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3317 if (selfdictObject != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3318 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3319 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3320 return NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3321 selfdict = selfdicttv.vval.v_dict;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3322 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3323 argsObject = PyDict_GetItemString(kwargs, "args");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3324 if (argsObject != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3325 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3326 if (ConvertFromPySequence(argsObject, &argstv) == -1)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3327 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3328 dict_unref(selfdict);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3329 return NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3330 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3331 argslist = argstv.vval.v_list;
20392
4c317d8c1051 patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents: 20369
diff changeset
3332 CHECK_LIST_MATERIALIZE(argslist);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3333
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3334 argc = argslist->lv_len;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3335 if (argc != 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3336 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3337 argv = PyMem_New(typval_T, (size_t) argc);
8921
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3338 if (argv == NULL)
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3339 {
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3340 PyErr_NoMemory();
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3341 dict_unref(selfdict);
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3342 list_unref(argslist);
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3343 return NULL;
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3344 }
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3345 curtv = argv;
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
3346 FOR_ALL_LIST_ITEMS(argslist, li)
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3347 copy_tv(&li->li_tv, curtv++);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3348 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3349 list_unref(argslist);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3350 }
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3351 if (selfdict != NULL)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3352 {
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3353 auto_rebind = FALSE;
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3354 autoRebindObject = PyDict_GetItemString(kwargs, "auto_rebind");
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3355 if (autoRebindObject != NULL)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3356 {
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3357 auto_rebind = PyObject_IsTrue(autoRebindObject);
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3358 if (auto_rebind == -1)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3359 {
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3360 dict_unref(selfdict);
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3361 list_unref(argslist);
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3362 return NULL;
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3363 }
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3364 }
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3365 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3366 }
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3367
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
3368 if (!PyArg_ParseTuple(args, "et", "ascii", &name))
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3369 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3370 dict_unref(selfdict);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3371 while (argc--)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3372 clear_tv(&argv[argc]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3373 PyMem_Free(argv);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3374 return NULL;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3375 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3376
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3377 self = FunctionNew(subtype, name, argc, argv, selfdict, auto_rebind);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3378
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
3379 PyMem_Free(name);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
3380
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3381 return self;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3382 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3383
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3384 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3385 FunctionDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3386 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3387 FunctionObject *self = (FunctionObject*)self_obj;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3388 int i;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3389 func_unref(self->name);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3390 vim_free(self->name);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3391 for (i = 0; i < self->argc; ++i)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3392 clear_tv(&self->argv[i]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3393 PyMem_Free(self->argv);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3394 dict_unref(self->self);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3395 if (self->argv || self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3396 pyll_remove(&self->ref, &lastfunc);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3397
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3398 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3399 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3400
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3401 static char *FunctionAttrs[] = {
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3402 "softspace", "args", "self", "auto_rebind",
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3403 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3404 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3405
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3406 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3407 FunctionDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3408 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3409 return ObjectDir(self, FunctionAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3410 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3411
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3412 static PyObject *
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3413 FunctionAttr(FunctionObject *self, char *name)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3414 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3415 list_T *list;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3416 int i;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3417 if (strcmp(name, "name") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3418 return PyString_FromString((char *)(self->name));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3419 else if (strcmp(name, "args") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3420 {
9967
45098d7f72b6 commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents: 9725
diff changeset
3421 if (self->argv == NULL || (list = list_alloc()) == NULL)
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3422 return ALWAYS_NONE;
9967
45098d7f72b6 commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents: 9725
diff changeset
3423
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3424 for (i = 0; i < self->argc; ++i)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3425 list_append_tv(list, &self->argv[i]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3426 return NEW_LIST(list);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3427 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3428 else if (strcmp(name, "self") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3429 return self->self == NULL
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3430 ? ALWAYS_NONE
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3431 : NEW_DICTIONARY(self->self);
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3432 else if (strcmp(name, "auto_rebind") == 0)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3433 return self->auto_rebind
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3434 ? ALWAYS_TRUE
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
3435 : ALWAYS_FALSE;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3436 else if (strcmp(name, "__members__") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3437 return ObjectDir(NULL, FunctionAttrs);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3438 return NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3439 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3440
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3441 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3442 * Populate partial_T given function object.
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3443 *
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3444 * "exported" should be set to true when it is needed to construct a partial
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3445 * that may be stored in a variable (i.e. may be freed by Vim).
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3446 */
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3447 static void
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3448 set_partial(FunctionObject *self, partial_T *pt, int exported)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3449 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3450 int i;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3451
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3452 pt->pt_name = self->name;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3453 if (self->argv)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3454 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3455 pt->pt_argc = self->argc;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3456 if (exported)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3457 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
3458 pt->pt_argv = ALLOC_CLEAR_MULT(typval_T, self->argc);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3459 for (i = 0; i < pt->pt_argc; ++i)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3460 copy_tv(&self->argv[i], &pt->pt_argv[i]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3461 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3462 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3463 pt->pt_argv = self->argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3464 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3465 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3466 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3467 pt->pt_argc = 0;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3468 pt->pt_argv = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3469 }
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3470 pt->pt_auto = self->auto_rebind || !exported;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3471 pt->pt_dict = self->self;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3472 if (exported && self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3473 ++pt->pt_dict->dv_refcount;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3474 if (exported)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3475 pt->pt_name = vim_strsave(pt->pt_name);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3476 pt->pt_refcount = 1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3477 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3478
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3479 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3480 FunctionCall(PyObject *self_obj, PyObject *argsObject, PyObject *kwargs)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3481 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3482 FunctionObject *self = (FunctionObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3483 char_u *name = self->name;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3484 typval_T args;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3485 typval_T selfdicttv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3486 typval_T rettv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3487 dict_T *selfdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3488 PyObject *selfdictObject;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3489 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3490 int error;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3491 partial_T pt;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3492 partial_T *pt_ptr = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3493
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3494 if (ConvertFromPySequence(argsObject, &args) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3495 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3496
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3497 if (kwargs != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3498 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3499 selfdictObject = PyDict_GetItemString(kwargs, "self");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3500 if (selfdictObject != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3501 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
3502 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1)
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3503 {
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3504 clear_tv(&args);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3505 return NULL;
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3506 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3507 selfdict = selfdicttv.vval.v_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3508 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3509 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3510
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3511 if (self->argv || self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3512 {
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
3513 CLEAR_FIELD(pt);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3514 set_partial(self, &pt, FALSE);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3515 pt_ptr = &pt;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3516 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3517
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3518 Py_BEGIN_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3519 Python_Lock_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3520
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3521 VimTryStart();
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3522 error = func_call(name, &args, pt_ptr, selfdict, &rettv);
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3523
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3524 Python_Release_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3525 Py_END_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3526
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3527 if (VimTryEnd())
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3528 ret = NULL;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3529 else if (error != OK)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3530 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3531 ret = NULL;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3532 PyErr_VIM_FORMAT(N_("failed to run function %s"), (char *)name);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3533 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3534 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3535 ret = ConvertToPyObject(&rettv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3536
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3537 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3538 clear_tv(&rettv);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3539 if (selfdict != NULL)
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3540 clear_tv(&selfdicttv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3541
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3542 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3543 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3544
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3545 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3546 FunctionRepr(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3547 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3548 FunctionObject *self = (FunctionObject*)self_obj;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3549 PyObject *ret;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3550 garray_T repr_ga;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3551 int i;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3552 char_u *tofree = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3553 typval_T tv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3554 char_u numbuf[NUMBUFLEN];
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3555
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 26978
diff changeset
3556 ga_init2(&repr_ga, sizeof(char), 70);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3557 ga_concat(&repr_ga, (char_u *)"<vim.Function '");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3558 if (self->name)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3559 ga_concat(&repr_ga, self->name);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3560 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3561 ga_concat(&repr_ga, (char_u *)"<NULL>");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3562 ga_append(&repr_ga, '\'');
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3563 if (self->argv)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3564 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3565 ga_concat(&repr_ga, (char_u *)", args=[");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3566 ++emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3567 for (i = 0; i < self->argc; i++)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3568 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3569 if (i != 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3570 ga_concat(&repr_ga, (char_u *)", ");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3571 ga_concat(&repr_ga, tv2string(&self->argv[i], &tofree, numbuf,
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3572 get_copyID()));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3573 vim_free(tofree);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3574 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3575 --emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3576 ga_append(&repr_ga, ']');
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3577 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3578 if (self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3579 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3580 ga_concat(&repr_ga, (char_u *)", self=");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3581 tv.v_type = VAR_DICT;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3582 tv.vval.v_dict = self->self;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3583 ++emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3584 ga_concat(&repr_ga, tv2string(&tv, &tofree, numbuf, get_copyID()));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3585 --emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3586 vim_free(tofree);
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3587 if (self->auto_rebind)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3588 ga_concat(&repr_ga, (char_u *)", auto_rebind=True");
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3589 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3590 ga_append(&repr_ga, '>');
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3591 ret = PyString_FromString((char *)repr_ga.ga_data);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3592 ga_clear(&repr_ga);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3593 return ret;
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3594 }
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3595
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3596 static struct PyMethodDef FunctionMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3597 {"__dir__", (PyCFunction)FunctionDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3598 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3599 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3600
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3601 /*
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3602 * Options object
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3603 */
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3604
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
3605 DEFINE_PY_TYPE_OBJECT(OptionsType);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3606
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3607 typedef int (*checkfun)(void *);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3608
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3609 typedef struct
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3610 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3611 PyObject_HEAD
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3612 int opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3613 void *from;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3614 checkfun Check;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3615 PyObject *fromObj;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3616 } OptionsObject;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3617
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3618 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3619 dummy_check(void *arg UNUSED)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3620 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3621 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3622 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3623
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3624 static PyObject *
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3625 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3626 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3627 OptionsObject *self;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3628
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
3629 self = PyObject_GC_New(OptionsObject, OptionsTypePtr);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3630 if (self == NULL)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3631 return NULL;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3632
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3633 self->opt_type = opt_type;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3634 self->from = from;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3635 self->Check = Check;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3636 self->fromObj = fromObj;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3637 if (fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3638 Py_INCREF(fromObj);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3639
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3640 return (PyObject *)(self);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3641 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3642
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3643 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3644 OptionsDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3645 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3646 OptionsObject *self = (OptionsObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3647 PyObject_GC_UnTrack((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3648 Py_XDECREF(self->fromObj);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3649 PyObject_GC_Del((void *)(self));
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3650 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3651
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3652 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3653 OptionsTraverse(PyObject *self_obj, visitproc visit, void *arg)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3654 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3655 OptionsObject *self = (OptionsObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3656 Py_VISIT(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3657 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3658 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3659
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3660 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3661 OptionsClear(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3662 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3663 OptionsObject *self = (OptionsObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3664 Py_CLEAR(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3665 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3666 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3667
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3668 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3669 OptionsItem(OptionsObject *self, PyObject *keyObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3670 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3671 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3672 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3673 long numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3674 char_u *stringval;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3675 PyObject *todecref;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3676
21198
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
3677 if (self->Check(self->fromObj))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3678 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3679
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3680 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3681 return NULL;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3682
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3683 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3684 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3685 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3686 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3687 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3688 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3689
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3690 flags = get_option_value_strict(key, &numval, &stringval,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3691 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3692
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3693 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3694
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3695 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3696 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3697 PyErr_SetObject(PyExc_KeyError, keyObject);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3698 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3699 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3700
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3701 if (flags & SOPT_UNSET)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3702 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3703 Py_INCREF(Py_None);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3704 return Py_None;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3705 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3706 else if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3707 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3708 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3709 ret = numval ? Py_True : Py_False;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3710 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3711 return ret;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3712 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3713 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3714 return PyInt_FromLong(numval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3715 else if (flags & SOPT_STRING)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3716 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3717 if (stringval)
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3718 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
3719 PyObject *ret = PyBytes_FromString((char *)stringval);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3720 vim_free(stringval);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3721 return ret;
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3722 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3723 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3724 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
3725 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3726 N_("unable to get option value"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3727 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3728 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3729 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3730 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3731 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3732 PyErr_SET_VIM(N_("internal error: unknown option type"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3733 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3734 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3735 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3736
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3737 static int
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3738 OptionsContains(OptionsObject *self, PyObject *keyObject)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3739 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3740 char_u *key;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3741 PyObject *todecref;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3742
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3743 if (!(key = StringToChars(keyObject, &todecref)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3744 return -1;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3745
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3746 if (*key == NUL)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3747 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3748 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3749 return 0;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3750 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3751
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3752 if (get_option_value_strict(key, NULL, NULL, self->opt_type, NULL))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3753 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3754 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3755 return 1;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3756 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3757 else
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3758 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3759 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3760 return 0;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3761 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3762 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3763
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3764 typedef struct
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3765 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3766 void *lastoption;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3767 int opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3768 } optiterinfo_T;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3769
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3770 static PyObject *
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3771 OptionsIterNext(void **arg)
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3772 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3773 char_u *name;
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3774 optiterinfo_T **oii = (optiterinfo_T**)arg;
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3775
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3776 if ((name = option_iter_next(&((*oii)->lastoption), (*oii)->opt_type)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3777 return PyString_FromString((char *)name);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3778
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3779 return NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3780 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3781
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3782 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3783 OptionsIter(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3784 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
3785 OptionsObject *self = (OptionsObject*)self_obj;
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3786 optiterinfo_T *oii;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3787
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3788 if (!(oii = PyMem_New(optiterinfo_T, 1)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3789 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3790 PyErr_NoMemory();
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3791 return NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3792 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3793
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3794 oii->opt_type = self->opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3795 oii->lastoption = NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3796
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3797 return IterNew(oii,
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
3798 PyMem_Free, OptionsIterNext,
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
3799 NULL, NULL, (PyObject *)self);
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3800 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3801
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3802 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3803 set_option_value_err(char_u *key, int numval, char_u *stringval, int opt_flags)
4513
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3804 {
15472
0fcc1315c061 patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3805 char *errmsg;
4513
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3806
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3807 if ((errmsg = set_option_value(key, numval, stringval, opt_flags)))
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3808 {
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3809 if (VimTryEnd())
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3810 return FAIL;
15472
0fcc1315c061 patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3811 PyErr_SetVim(errmsg);
4513
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3812 return FAIL;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3813 }
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3814 return OK;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3815 }
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3816
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3817 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3818 set_option_value_for(
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3819 char_u *key,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3820 int numval,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3821 char_u *stringval,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3822 int opt_flags,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3823 int opt_type,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3824 void *from)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3825 {
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
3826 switchwin_T switchwin;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
3827 bufref_T save_curbuf;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3828 int set_ret = 0;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3829
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3830 VimTryStart();
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3831 switch (opt_type)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3832 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3833 case SREQ_WIN:
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
3834 if (switch_win(&switchwin, (win_T *)from,
4918
0792cc5133ce updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents: 4859
diff changeset
3835 win_find_tabpage((win_T *)from), FALSE) == FAIL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3836 {
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
3837 restore_win(&switchwin, TRUE);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3838 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3839 return -1;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3840 PyErr_SET_VIM(N_("problem while switching windows"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3841 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3842 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3843 set_ret = set_option_value_err(key, numval, stringval, opt_flags);
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
3844 restore_win(&switchwin, TRUE);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3845 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3846 case SREQ_BUF:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3847 switch_buffer(&save_curbuf, (buf_T *)from);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3848 set_ret = set_option_value_err(key, numval, stringval, opt_flags);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
3849 restore_buffer(&save_curbuf);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3850 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3851 case SREQ_GLOBAL:
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3852 set_ret = set_option_value_err(key, numval, stringval, opt_flags);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3853 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3854 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3855 if (set_ret == FAIL)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3856 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3857 return VimTryEnd();
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3858 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3859
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3860 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3861 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3862 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3863 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3864 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3865 int opt_flags;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3866 int ret = 0;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3867 PyObject *todecref;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3868
21198
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
3869 if (self->Check(self->fromObj))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3870 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3871
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3872 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3873 return -1;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3874
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3875 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3876 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3877 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3878 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3879 return -1;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3880 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3881
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3882 flags = get_option_value_strict(key, NULL, NULL,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3883 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3884
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3885 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3886 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3887 PyErr_SetObject(PyExc_KeyError, keyObject);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3888 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3889 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3890 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3891
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3892 if (valObject == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3893 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3894 if (self->opt_type == SREQ_GLOBAL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3895 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3896 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3897 N_("unable to unset global option %s"), key);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3898 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3899 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3900 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3901 else if (!(flags & SOPT_GLOBAL))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3902 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3903 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3904 N_("unable to unset option %s "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3905 "which does not have global value"), key);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3906 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3907 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3908 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3909 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3910 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3911 unset_global_local_option(key, self->from);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3912 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3913 return 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3914 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3915 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3916
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3917 opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3918
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3919 if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3920 {
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3921 int istrue = PyObject_IsTrue(valObject);
4513
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3922
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3923 if (istrue == -1)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3924 ret = -1;
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3925 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3926 ret = set_option_value_for(key, istrue, NULL,
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3927 opt_flags, self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3928 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3929 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3930 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3931 long val;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3932
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3933 if (NumberToLong(valObject, &val, NUMBER_INT))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3934 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3935 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3936 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3937 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3938
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3939 ret = set_option_value_for(key, (int) val, NULL, opt_flags,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3940 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3941 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3942 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3943 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3944 char_u *val;
5525
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3945 PyObject *todecref2;
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3946
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3947 if ((val = StringToChars(valObject, &todecref2)))
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3948 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3949 ret = set_option_value_for(key, 0, val, opt_flags,
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
3950 self->opt_type, self->from);
5525
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3951 Py_XDECREF(todecref2);
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3952 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3953 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3954 ret = -1;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3955 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3956
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3957 Py_XDECREF(todecref);
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3958
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3959 return ret;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3960 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3961
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3962 static PySequenceMethods OptionsAsSeq = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3963 0, // sq_length
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3964 0, // sq_concat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3965 0, // sq_repeat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3966 0, // sq_item
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3967 0, // sq_slice
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3968 0, // sq_ass_item
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3969 0, // sq_ass_slice
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3970 (objobjproc) OptionsContains, // sq_contains
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3971 0, // sq_inplace_concat
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3972 0, // sq_inplace_repeat
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3973 };
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3974
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3975 static PyMappingMethods OptionsAsMapping = {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3976 (lenfunc) NULL,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3977 (binaryfunc) OptionsItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3978 (objobjargproc) OptionsAssItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3979 };
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3980
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
3981 // Tabpage object
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3982
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3983 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3984 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3985 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3986 tabpage_T *tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3987 } TabPageObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3988
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3989 static PyObject *WinListNew(TabPageObject *tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3990
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
3991 DEFINE_PY_TYPE_OBJECT(TabPageType);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3992
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3993 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3994 CheckTabPage(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3995 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3996 if (self->tab == INVALID_TABPAGE_VALUE)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3997 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3998 PyErr_SET_VIM(N_("attempt to refer to deleted tab page"));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3999 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4000 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4001
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4002 return 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4003 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4004
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4005 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4006 TabPageNew(tabpage_T *tab)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4007 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4008 TabPageObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4009
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4010 if (TAB_PYTHON_REF(tab))
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4011 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4012 self = TAB_PYTHON_REF(tab);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4013 Py_INCREF(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4014 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4015 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4016 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4017 self = PyObject_NEW(TabPageObject, TabPageTypePtr);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4018 if (self == NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4019 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4020 self->tab = tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4021 TAB_PYTHON_REF(tab) = self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4022 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4023
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4024 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4025 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4026
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4027 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4028 TabPageDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4029 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4030 TabPageObject *self = (TabPageObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4031 if (self->tab && self->tab != INVALID_TABPAGE_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4032 TAB_PYTHON_REF(self->tab) = NULL;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4033
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4034 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4035 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4036
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4037 static char *TabPageAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4038 "windows", "number", "vars", "window", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4039 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4040 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4041
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4042 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
4043 TabPageDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4044 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4045 return ObjectDir(self, TabPageAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4046 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4047
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4048 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4049 TabPageAttrValid(TabPageObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4050 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4051 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4052
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4053 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4054 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4055
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4056 ret = ((self->tab == INVALID_TABPAGE_VALUE) ? Py_False : Py_True);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4057 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4058 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4059 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4060
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4061 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4062 TabPageAttr(TabPageObject *self, char *name)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4063 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4064 if (strcmp(name, "windows") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4065 return WinListNew(self);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4066 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4067 return PyLong_FromLong((long) get_tab_number(self->tab));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4068 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
4069 return NEW_DICTIONARY(self->tab->tp_vars);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4070 else if (strcmp(name, "window") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4071 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4072 // For current tab window.c does not bother to set or update tp_curwin
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4073 if (self->tab == curtab)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4074 return WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4075 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4076 return WindowNew(self->tab->tp_curwin, self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4077 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4078 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4079 return ObjectDir(NULL, TabPageAttrs);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4080 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4081 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4082
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4083 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4084 TabPageRepr(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4085 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4086 TabPageObject *self = (TabPageObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4087 if (self->tab == INVALID_TABPAGE_VALUE)
27039
dc21c2f9c659 patch 8.2.4048: gcc complains about use of "%p" in printf
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
4088 return PyString_FromFormat("<tabpage object (deleted) at %p>", (void *)self);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4089 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4090 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4091 int t = get_tab_number(self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4092
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4093 if (t == 0)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4094 return PyString_FromFormat("<tabpage object (unknown) at %p>",
27039
dc21c2f9c659 patch 8.2.4048: gcc complains about use of "%p" in printf
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
4095 (void *)self);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4096 else
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4097 return PyString_FromFormat("<tabpage %d>", t - 1);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4098 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4099 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4100
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4101 static struct PyMethodDef TabPageMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4102 // name, function, calling, documentation
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4103 {"__dir__", (PyCFunction)TabPageDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4104 { NULL, NULL, 0, NULL}
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4105 };
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4106
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4107 /*
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4108 * Window list object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4109 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4110
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4111 DEFINE_PY_TYPE_OBJECT(TabListType);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4112 static PySequenceMethods TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4113
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4114 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4115 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4116 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4117 } TabListObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4118
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4119 static TabListObject TheTabPageList =
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4120 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4121 PyObject_HEAD_INIT_TYPE(TabListType)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4122 };
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4123
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4124 static PyInt
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4125 TabListLength(PyObject *self UNUSED)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4126 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4127 tabpage_T *tp = first_tabpage;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4128 PyInt n = 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4129
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4130 while (tp != NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4131 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4132 ++n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4133 tp = tp->tp_next;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4134 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4135
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4136 return n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4137 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4138
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4139 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4140 TabListItem(PyObject *self UNUSED, PyInt n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4141 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4142 tabpage_T *tp;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4143
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4144 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, --n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4145 if (n == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4146 return TabPageNew(tp);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4147
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4148 PyErr_SET_STRING(PyExc_IndexError, N_("no such tab page"));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4149 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4150 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4151
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
4152 /*
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
4153 * Window object
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4154 */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4155
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4156 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4157 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4158 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4159 win_T *win;
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4160 TabPageObject *tabObject;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4161 } WindowObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4162
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4163 DEFINE_PY_TYPE_OBJECT(WindowType);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4164
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4165 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4166 CheckWindow(WindowObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4167 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4168 if (self->win == INVALID_WINDOW_VALUE)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4169 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4170 PyErr_SET_VIM(N_("attempt to refer to deleted window"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4171 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4172 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4173
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4174 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4175 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4176
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4177 static int
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4178 CheckWindowCb(void *self)
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4179 {
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4180 return CheckWindow((WindowObject*)self);
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4181 }
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4182
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4183 static PyObject *
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4184 WindowNew(win_T *win, tabpage_T *tab)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4185 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4186 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4187 * We need to handle deletion of windows underneath us.
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4188 * If we add a "w_python*_ref" field to the win_T structure,
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4189 * then we can get at it in win_free() in vim. We then
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4190 * need to create only ONE Python object per window - if
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4191 * we try to create a second, just INCREF the existing one
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4192 * and return it. The (single) Python object referring to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4193 * the window is stored in "w_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4194 * On a win_free() we set the Python object's win_T* field
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4195 * to an invalid value. We trap all uses of a window
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4196 * object, and reject them if the win_T* field is invalid.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4197 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4198 * Python2 and Python3 get different fields and different objects:
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4199 * w_python_ref and w_python3_ref fields respectively.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4200 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4201
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4202 WindowObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4203
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4204 if (WIN_PYTHON_REF(win))
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4205 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4206 self = WIN_PYTHON_REF(win);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4207 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4208 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4209 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4210 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4211 self = PyObject_GC_New(WindowObject, WindowTypePtr);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4212 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4213 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4214 self->win = win;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4215 WIN_PYTHON_REF(win) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4216 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4217
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4218 self->tabObject = ((TabPageObject *)(TabPageNew(tab)));
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4219
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4220 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4221 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4222
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4223 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4224 WindowDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4225 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4226 WindowObject *self = (WindowObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4227 PyObject_GC_UnTrack((void *)(self));
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4228 if (self->win && self->win != INVALID_WINDOW_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4229 WIN_PYTHON_REF(self->win) = NULL;
21190
10eb6c38938c patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents: 21083
diff changeset
4230 Py_XDECREF(((PyObject *)(self->tabObject)));
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4231 PyObject_GC_Del((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4232 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4233
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4234 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4235 WindowTraverse(PyObject *self_obj, visitproc visit, void *arg)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4236 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4237 WindowObject *self = (WindowObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4238 Py_VISIT(((PyObject *)(self->tabObject)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4239 return 0;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4240 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4241
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4242 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4243 WindowClear(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4244 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4245 WindowObject *self = (WindowObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4246 Py_CLEAR(self->tabObject);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4247 return 0;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4248 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4249
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4250 static win_T *
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4251 get_firstwin(TabPageObject *tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4252 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4253 if (tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4254 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4255 if (CheckTabPage(tabObject))
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4256 return NULL;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4257 // For current tab window.c does not bother to set or update tp_firstwin
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4258 else if (tabObject->tab == curtab)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4259 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4260 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4261 return tabObject->tab->tp_firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4262 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4263 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4264 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4265 }
14047
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4266
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4267 // Use the same order as in the WindowAttr() function.
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4268 static char *WindowAttrs[] = {
14047
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4269 "buffer",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4270 "cursor",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4271 "height",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4272 "row",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4273 "width",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4274 "col",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4275 "vars",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4276 "options",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4277 "number",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4278 "tabpage",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
4279 "valid",
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4280 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4281 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4282
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4283 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
4284 WindowDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4285 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4286 return ObjectDir(self, WindowAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4287 }
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4288
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4289 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4290 WindowAttrValid(WindowObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4291 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4292 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4293
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4294 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4295 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4296
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4297 ret = ((self->win == INVALID_WINDOW_VALUE) ? Py_False : Py_True);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4298 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4299 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4300 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4301
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4302 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4303 WindowAttr(WindowObject *self, char *name)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4304 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4305 if (strcmp(name, "buffer") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4306 return (PyObject *)BufferNew(self->win->w_buffer);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4307 else if (strcmp(name, "cursor") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4308 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4309 pos_T *pos = &self->win->w_cursor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4310
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4311 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4312 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4313 else if (strcmp(name, "height") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4314 return PyLong_FromLong((long)(self->win->w_height));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
4315 else if (strcmp(name, "row") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4316 return PyLong_FromLong((long)(self->win->w_winrow));
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4317 else if (strcmp(name, "width") == 0)
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
4318 return PyLong_FromLong((long)(self->win->w_width));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
4319 else if (strcmp(name, "col") == 0)
12513
3ca08bf99396 patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
4320 return PyLong_FromLong((long)(self->win->w_wincol));
4323
f1eab4f77a6f updated for version 7.3.911
Bram Moolenaar <bram@vim.org>
parents: 4321
diff changeset
4321 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
4322 return NEW_DICTIONARY(self->win->w_vars);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4323 else if (strcmp(name, "options") == 0)
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
4324 return OptionsNew(SREQ_WIN, self->win, CheckWindowCb,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4325 (PyObject *) self);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
4326 else if (strcmp(name, "number") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4327 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4328 if (CheckTabPage(self->tabObject))
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4329 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4330 return PyLong_FromLong((long)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4331 get_win_number(self->win, get_firstwin(self->tabObject)));
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4332 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4333 else if (strcmp(name, "tabpage") == 0)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4334 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4335 Py_INCREF(self->tabObject);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4336 return (PyObject *)(self->tabObject);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4337 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4338 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4339 return ObjectDir(NULL, WindowAttrs);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4340 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4341 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4342 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4343
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4344 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4345 WindowSetattr(PyObject *self_obj, char *name, PyObject *valObject)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4346 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4347 WindowObject *self = (WindowObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4348 if (CheckWindow(self))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4349 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4350
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4351 if (strcmp(name, "buffer") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4352 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4353 PyErr_SET_STRING(PyExc_TypeError, N_("readonly attribute: buffer"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4354 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4355 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4356 else if (strcmp(name, "cursor") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4357 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4358 long lnum;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4359 long col;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4360
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4361 if (!PyArg_Parse(valObject, "(ll)", &lnum, &col))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4362 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4363
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4364 if (lnum <= 0 || lnum > self->win->w_buffer->b_ml.ml_line_count)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4365 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4366 PyErr_SET_VIM(N_("cursor position outside buffer"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4367 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4368 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4369
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4370 // Check for keyboard interrupts
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4371 if (VimCheckInterrupt())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4372 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4373
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4374 self->win->w_cursor.lnum = lnum;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4375 self->win->w_cursor.col = col;
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14373
diff changeset
4376 self->win->w_set_curswant = TRUE;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4377 self->win->w_cursor.coladd = 0;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4378 // When column is out of range silently correct it.
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4379 check_cursor_col_win(self->win);
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
4380
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 28950
diff changeset
4381 update_screen(UPD_VALID);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4382 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4383 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4384 else if (strcmp(name, "height") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4385 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4386 long height;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4387 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4388
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
4389 if (NumberToLong(valObject, &height, NUMBER_INT|NUMBER_UNSIGNED))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4390 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4391
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4392 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4393 need_mouse_correct = TRUE;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4394 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4395 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4396 curwin = self->win;
31422
c3c8136ecfa0 patch 9.0.1044: setting window height using Python may cause errors
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
4397 curbuf = curwin->w_buffer;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4398
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4399 VimTryStart();
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4400 win_setheight((int) height);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4401 curwin = savewin;
31422
c3c8136ecfa0 patch 9.0.1044: setting window height using Python may cause errors
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
4402 curbuf = curwin->w_buffer;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4403 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4404 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4405
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4406 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4407 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4408 else if (strcmp(name, "width") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4409 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4410 long width;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4411 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4412
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
4413 if (NumberToLong(valObject, &width, NUMBER_INT|NUMBER_UNSIGNED))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4414 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4415
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4416 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4417 need_mouse_correct = TRUE;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4418 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4419 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4420 curwin = self->win;
31422
c3c8136ecfa0 patch 9.0.1044: setting window height using Python may cause errors
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
4421 curbuf = curwin->w_buffer;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4422
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4423 VimTryStart();
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4424 win_setwidth((int) width);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4425 curwin = savewin;
31422
c3c8136ecfa0 patch 9.0.1044: setting window height using Python may cause errors
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
4426 curbuf = curwin->w_buffer;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4427 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4428 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4429
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4430 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4431 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4432 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4433 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4434 PyErr_SetString(PyExc_AttributeError, name);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4435 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4436 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4437 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4438
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4439 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4440 WindowRepr(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4441 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
4442 WindowObject *self = (WindowObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4443 if (self->win == INVALID_WINDOW_VALUE)
27039
dc21c2f9c659 patch 8.2.4048: gcc complains about use of "%p" in printf
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
4444 return PyString_FromFormat("<window object (deleted) at %p>", (void *)self);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4445 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4446 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4447 int w = get_win_number(self->win, firstwin);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
4448
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
4449 if (w == 0)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4450 return PyString_FromFormat("<window object (unknown) at %p>",
27039
dc21c2f9c659 patch 8.2.4048: gcc complains about use of "%p" in printf
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
4451 (void *)self);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4452 else
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4453 return PyString_FromFormat("<window %d>", w - 1);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4454 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4455 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4456
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4457 static struct PyMethodDef WindowMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4458 // name, function, calling, documentation
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4459 {"__dir__", (PyCFunction)WindowDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4460 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4461 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4462
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4463 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4464 * Window list object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4465 */
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4466
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4467 DEFINE_PY_TYPE_OBJECT(WinListType);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4468 static PySequenceMethods WinListAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4469
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4470 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4471 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4472 PyObject_HEAD
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4473 TabPageObject *tabObject;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4474 } WinListObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4475
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4476 static WinListObject TheWindowList =
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4477 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4478 PyObject_HEAD_INIT_TYPE(WinListType)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4479 NULL
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4480 };
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4481
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4482 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4483 WinListNew(TabPageObject *tabObject)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4484 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4485 WinListObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4486
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4487 self = PyObject_NEW(WinListObject, WinListTypePtr);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4488 self->tabObject = tabObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4489 Py_INCREF(tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4490
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4491 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4492 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4493
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4494 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4495 WinListDestructor(WinListObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4496 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4497 TabPageObject *tabObject = self->tabObject;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4498
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4499 if (tabObject)
4523
57393dc4b811 updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents: 4513
diff changeset
4500 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4501 Py_DECREF((PyObject *)(tabObject));
4523
57393dc4b811 updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents: 4513
diff changeset
4502 }
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4503
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4504 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4505 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4506
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4507 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4508 WinListLength(WinListObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4509 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4510 win_T *w;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4511 PyInt n = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4512
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4513 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4514 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4515
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4516 while (w != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4517 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4518 ++n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4519 w = W_NEXT(w);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4520 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4521
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4522 return n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4523 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4524
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4525 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4526 WinListItem(WinListObject *self, PyInt n)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4527 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4528 win_T *w;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4529
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4530 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4531 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4532
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4533 for (; w != NULL; w = W_NEXT(w), --n)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4534 if (n == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4535 return WindowNew(w, self->tabObject? self->tabObject->tab: curtab);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4536
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4537 PyErr_SET_STRING(PyExc_IndexError, N_("no such window"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4538 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4539 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4540
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4541 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4542 * Convert a Python string into a Vim line.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4543 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4544 * The result is in allocated memory. All internal nulls are replaced by
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4545 * newline characters. It is an error for the string to contain newline
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4546 * characters.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4547 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4548 * On errors, the Python exception data is set, and NULL is returned.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4549 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4550 static char *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4551 StringToLine(PyObject *obj)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4552 {
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4553 char *str;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4554 char *save;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4555 PyObject *bytes = NULL;
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
4556 Py_ssize_t len = 0;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4557 PyInt i;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4558 char *p;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4559
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4560 if (PyBytes_Check(obj))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4561 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4562 if (PyBytes_AsStringAndSize(obj, &str, &len) == -1
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4563 || str == NULL)
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4564 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4565 }
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4566 else if (PyUnicode_Check(obj))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4567 {
23264
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
4568 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT,
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
4569 ERRORS_ENCODE_ARG)))
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4570 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4571
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4572 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4573 || str == NULL)
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4574 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4575 Py_DECREF(bytes);
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4576 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4577 }
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4578 }
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4579 else
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4580 {
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4581 #if PY_MAJOR_VERSION < 3
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4582 PyErr_FORMAT_TYPE(
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4583 N_("expected str() or unicode() instance, but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4584 obj);
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4585 #else
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4586 PyErr_FORMAT_TYPE(
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4587 N_("expected bytes() or str() instance, but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
4588 obj);
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4589 #endif
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4590 return NULL;
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4591 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4592
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4593 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4594 * Error checking: String must not contain newlines, as we
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4595 * are replacing a single line, and we must replace it with
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4596 * a single line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4597 * A trailing newline is removed, so that append(f.readlines()) works.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4598 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4599 p = memchr(str, '\n', len);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4600 if (p != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4601 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4602 if (p == str + len - 1)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4603 --len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4604 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4605 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4606 PyErr_SET_VIM(N_("string cannot contain newlines"));
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
4607 Py_XDECREF(bytes);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4608 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4609 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4610 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4611
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4612 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4613 * Create a copy of the string, with internal nulls replaced by
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
4614 * newline characters, as is the Vim convention.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4615 */
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
4616 save = alloc(len+1);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4617 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4618 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4619 PyErr_NoMemory();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
4620 Py_XDECREF(bytes);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4621 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4622 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4623
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4624 for (i = 0; i < len; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4625 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4626 if (str[i] == '\0')
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4627 save[i] = '\n';
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4628 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4629 save[i] = str[i];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4630 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4631
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4632 save[i] = '\0';
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4633 Py_XDECREF(bytes); // Python 2 does nothing here
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4634
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4635 return save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4636 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4637
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4638 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4639 * Get a line from the specified buffer. The line number is
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4640 * in Vim format (1-based). The line is returned as a Python
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4641 * string object.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4642 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4643 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4644 GetBufferLine(buf_T *buf, PyInt n)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4645 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4646 return LineToString((char *)ml_get_buf(buf, (linenr_T)n, FALSE));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4647 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4648
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4649
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4650 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4651 * Get a list of lines from the specified buffer. The line numbers
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4652 * are in Vim format (1-based). The range is from lo up to, but not
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4653 * including, hi. The list is returned as a Python list of string objects.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4654 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4655 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4656 GetBufferLineList(buf_T *buf, PyInt lo, PyInt hi)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4657 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4658 PyInt i;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4659 PyInt n = hi - lo;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4660 PyObject *list = PyList_New(n);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4661
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4662 if (list == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4663 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4664
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4665 for (i = 0; i < n; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4666 {
21198
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4667 linenr_T lnum = (linenr_T)(lo + i);
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4668 char *text;
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4669 PyObject *string;
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4670
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4671 if (lnum > buf->b_ml.ml_line_count)
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4672 text = "";
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4673 else
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4674 text = (char *)ml_get_buf(buf, lnum, FALSE);
8531ddd7dd63 patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents: 21190
diff changeset
4675 string = LineToString(text);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4676 if (string == NULL)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4677 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4678 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4679 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4680 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4681
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4682 PyList_SET_ITEM(list, i, string);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4683 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4684
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4685 // The ownership of the Python list is passed to the caller (ie,
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4686 // the caller should Py_DECREF() the object when it is finished
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4687 // with it).
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4688
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4689 return list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4690 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4691
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4692 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4693 * Check if deleting lines made the cursor position invalid.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4694 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4695 * deleted).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4696 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4697 static void
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4698 py_fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4699 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4700 if (curwin->w_cursor.lnum >= lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4701 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4702 // Adjust the cursor position if it's in/after the changed
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4703 // lines.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4704 if (curwin->w_cursor.lnum >= hi)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4705 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4706 curwin->w_cursor.lnum += extra;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4707 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4708 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4709 else if (extra < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4710 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4711 curwin->w_cursor.lnum = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4712 check_cursor();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4713 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4714 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4715 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4716 changed_cline_bef_curs();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4717 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4718 invalidate_botline();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4719 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4720
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4721 /*
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4722 * Replace a line in the specified buffer. The line number is
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4723 * in Vim format (1-based). The replacement line is given as
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4724 * a Python string object. The object is checked for validity
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4725 * and correct format. Errors are returned as a value of FAIL.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4726 * The return value is OK on success.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4727 * If OK is returned and len_change is not NULL, *len_change
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4728 * is set to the change in the buffer length.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4729 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4730 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4731 SetBufferLine(buf_T *buf, PyInt n, PyObject *line, PyInt *len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4732 {
11447
698ee9d4fe9f patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents: 10942
diff changeset
4733 bufref_T save_curbuf = {NULL, 0, 0};
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4734 switchwin_T switchwin;
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4735
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4736 // First of all, we check the type of the supplied Python object.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4737 // There are three cases:
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4738 // 1. NULL, or None - this is a deletion.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4739 // 2. A string - this is a replacement.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4740 // 3. Anything else - this is an error.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4741 if (line == Py_None || line == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4742 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4743 PyErr_Clear();
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4744 switchwin.sw_curwin = NULL;
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4745 switch_to_win_for_buf(buf, &switchwin, &save_curbuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4746
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4747 VimTryStart();
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4748
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4749 if (u_savedel((linenr_T)n, 1L) == FAIL)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
4750 RAISE_UNDO_FAIL;
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
4751 else if (ml_delete((linenr_T)n) == FAIL)
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4752 RAISE_DELETE_LINE_FAIL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4753 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4754 {
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4755 if (buf == curbuf && (switchwin.sw_curwin != NULL
16080
bf8cf5c3b784 patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents: 15818
diff changeset
4756 || save_curbuf.br_buf == NULL))
bf8cf5c3b784 patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents: 15818
diff changeset
4757 // Using an existing window for the buffer, adjust the cursor
bf8cf5c3b784 patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents: 15818
diff changeset
4758 // position.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4759 py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4760 if (save_curbuf.br_buf == NULL)
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4761 // Only adjust marks if we managed to switch to a window that
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4762 // holds the buffer, otherwise line numbers will be invalid.
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4763 deleted_lines_mark((linenr_T)n, 1L);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4764 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4765
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4766 restore_win_for_buf(&switchwin, &save_curbuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4767
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4768 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4769 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4770
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4771 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4772 *len_change = -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4773
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4774 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4775 }
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4776 else if (PyBytes_Check(line) || PyUnicode_Check(line))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4777 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4778 char *save = StringToLine(line);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4779
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4780 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4781 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4782
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4783 VimTryStart();
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4784
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4785 // We do not need to free "save" if ml_replace() consumes it.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4786 PyErr_Clear();
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4787 switch_to_win_for_buf(buf, &switchwin, &save_curbuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4788
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4789 if (u_savesub((linenr_T)n) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4790 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
4791 RAISE_UNDO_FAIL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4792 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4793 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4794 else if (ml_replace((linenr_T)n, (char_u *)save, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4795 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4796 RAISE_REPLACE_LINE_FAIL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4797 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4798 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4799 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4800 changed_bytes((linenr_T)n, 0);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4801
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4802 restore_win_for_buf(&switchwin, &save_curbuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4803
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4804 // Check that the cursor is not beyond the end of the line now.
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4805 if (buf == curbuf)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4806 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4807
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4808 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4809 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4810
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4811 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4812 *len_change = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4813
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4814 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4815 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4816 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4817 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4818 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4819 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4820 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4821 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4822
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4823 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4824 * Replace a range of lines in the specified buffer. The line numbers are in
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4825 * Vim format (1-based). The range is from lo up to, but not including, hi.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4826 * The replacement lines are given as a Python list of string objects. The
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4827 * list is checked for validity and correct format. Errors are returned as a
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4828 * value of FAIL. The return value is OK on success.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4829 * If OK is returned and len_change is not NULL, *len_change
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4830 * is set to the change in the buffer length.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4831 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4832 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4833 SetBufferLineList(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4834 buf_T *buf,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4835 PyInt lo,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4836 PyInt hi,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4837 PyObject *list,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4838 PyInt *len_change)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4839 {
11447
698ee9d4fe9f patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents: 10942
diff changeset
4840 bufref_T save_curbuf = {NULL, 0, 0};
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4841 switchwin_T switchwin;
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4842
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4843 // First of all, we check the type of the supplied Python object.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4844 // There are three cases:
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4845 // 1. NULL, or None - this is a deletion.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4846 // 2. A list - this is a replacement.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4847 // 3. Anything else - this is an error.
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4848 if (list == Py_None || list == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4849 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4850 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4851 PyInt n = (int)(hi - lo);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4852
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4853 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4854 VimTryStart();
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4855 switchwin.sw_curwin = NULL;
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4856 switch_to_win_for_buf(buf, &switchwin, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4857
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4858 if (u_savedel((linenr_T)lo, (long)n) == FAIL)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
4859 RAISE_UNDO_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4860 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4861 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4862 for (i = 0; i < n; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4863 {
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
4864 if (ml_delete((linenr_T)lo) == FAIL)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4865 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4866 RAISE_DELETE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4867 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4868 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4869 }
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4870 if (buf == curbuf && (switchwin.sw_curwin != NULL
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4871 || save_curbuf.br_buf == NULL))
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4872 // Using an existing window for the buffer, adjust the cursor
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4873 // position.
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4874 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4875 if (save_curbuf.br_buf == NULL)
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4876 // Only adjust marks if we managed to switch to a window that
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4877 // holds the buffer, otherwise line numbers will be invalid.
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4878 deleted_lines_mark((linenr_T)lo, (long)i);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4879 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4880
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4881 restore_win_for_buf(&switchwin, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4882
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4883 if (VimTryEnd())
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4884 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4885
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4886 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4887 *len_change = -n;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4888
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4889 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4890 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4891 else if (PyList_Check(list))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4892 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4893 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4894 PyInt new_len = PyList_Size(list);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4895 PyInt old_len = hi - lo;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4896 PyInt extra = 0; // lines added to text, can be negative
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4897 char **array;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4898
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4899 if (new_len == 0) // avoid allocating zero bytes
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4900 array = NULL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4901 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4902 {
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4903 array = PyMem_New(char *, new_len);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4904 if (array == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4905 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4906 PyErr_NoMemory();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4907 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4908 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4909 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4910
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4911 for (i = 0; i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4912 {
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4913 PyObject *line;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4914
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4915 if (!(line = PyList_GetItem(list, i)) ||
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4916 !(array[i] = StringToLine(line)))
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4917 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4918 while (i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4919 vim_free(array[--i]);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4920 PyMem_Free(array);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4921 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4922 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4923 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4924
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4925 VimTryStart();
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4926 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
4927
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4928 // START of region without "return". Must call restore_buffer()!
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4929 switchwin.sw_curwin = NULL;
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
4930 switch_to_win_for_buf(buf, &switchwin, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4931
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4932 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
4933 RAISE_UNDO_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4934
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4935 // If the size of the range is reducing (ie, new_len < old_len) we
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4936 // need to delete some old_len. We do this at the start, by
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4937 // repeatedly deleting line "lo".
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4938 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4939 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4940 for (i = 0; i < old_len - new_len; ++i)
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20392
diff changeset
4941 if (ml_delete((linenr_T)lo) == FAIL)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4942 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4943 RAISE_DELETE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4944 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4945 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4946 extra -= i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4947 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4948
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4949 // For as long as possible, replace the existing old_len with the
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4950 // new old_len. This is a more efficient operation, as it requires
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4951 // less memory allocation and freeing.
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4952 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4953 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4954 for (i = 0; i < old_len && i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4955 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4956 == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4957 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4958 RAISE_REPLACE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4959 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4960 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4961 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4962 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4963 i = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4964
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4965 // Now we may need to insert the remaining new old_len. If we do, we
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4966 // must free the strings as we finish with them (we can't pass the
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
4967 // responsibility to Vim in this case).
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4968 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4969 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4970 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4971 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4972 if (ml_append((linenr_T)(lo + i - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4973 (char_u *)array[i], 0, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4974 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4975 RAISE_INSERT_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4976 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4977 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4978 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4979 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4980 ++extra;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4981 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4982 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4983
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4984 // Free any left-over old_len, as a result of an error
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4985 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4986 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4987 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4988 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4989 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4990
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4991 // Free the array of old_len. All of its contents have now
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4992 // been dealt with (either freed, or the responsibility passed
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4993 // to vim.
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4994 PyMem_Free(array);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4995
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4996 // Adjust marks. Invalidate any which lie in the
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4997 // changed range, and move any in the remainder of the buffer.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4998 // Only adjust marks if we managed to switch to a window that holds
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
4999 // the buffer, otherwise line numbers will be invalid.
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5000 if (save_curbuf.br_buf == NULL)
28950
44481ae7c7ce patch 8.2.4997: Python: changing hidden buffer can cause display mess up
Bram Moolenaar <Bram@vim.org>
parents: 28844
diff changeset
5001 {
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
5002 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5003 (long)MAXLNUM, (long)extra);
28950
44481ae7c7ce patch 8.2.4997: Python: changing hidden buffer can cause display mess up
Bram Moolenaar <Bram@vim.org>
parents: 28844
diff changeset
5004 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
44481ae7c7ce patch 8.2.4997: Python: changing hidden buffer can cause display mess up
Bram Moolenaar <Bram@vim.org>
parents: 28844
diff changeset
5005 }
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5006
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5007 if (buf == curbuf && (switchwin.sw_curwin != NULL
16080
bf8cf5c3b784 patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents: 15818
diff changeset
5008 || save_curbuf.br_buf == NULL))
bf8cf5c3b784 patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents: 15818
diff changeset
5009 // Using an existing window for the buffer, adjust the cursor
bf8cf5c3b784 patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents: 15818
diff changeset
5010 // position.
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5011 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5012
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5013 // END of region without "return".
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5014 restore_win_for_buf(&switchwin, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5015
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5016 if (VimTryEnd())
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5017 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5018
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5019 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5020 *len_change = new_len - old_len;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5021
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5022 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5023 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5024 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5025 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5026 PyErr_BadArgument();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5027 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5028 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5029 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5030
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5031 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5032 * Insert a number of lines into the specified buffer after the specified line.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5033 * The line number is in Vim format (1-based). The lines to be inserted are
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5034 * given as a Python list of string objects or as a single string. The lines
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5035 * to be added are checked for validity and correct format. Errors are
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5036 * returned as a value of FAIL. The return value is OK on success.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5037 * If OK is returned and len_change is not NULL, *len_change
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5038 * is set to the change in the buffer length.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5039 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5040 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5041 InsertBufferLines(buf_T *buf, PyInt n, PyObject *lines, PyInt *len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5042 {
11447
698ee9d4fe9f patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents: 10942
diff changeset
5043 bufref_T save_curbuf = {NULL, 0, 0};
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5044 switchwin_T switchwin;
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
5045
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5046 // First of all, we check the type of the supplied Python object.
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5047 // It must be a string or a list, or the call is in error.
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
5048 if (PyBytes_Check(lines) || PyUnicode_Check(lines))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5049 {
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
5050 char *str = StringToLine(lines);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5051
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5052 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5053 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5054
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5055 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5056 VimTryStart();
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5057 switch_to_win_for_buf(buf, &switchwin, &save_curbuf);
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
5058
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
5059 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5060 RAISE_UNDO_FAIL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5061 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5062 RAISE_INSERT_LINE_FAIL;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5063 else if (save_curbuf.br_buf == NULL)
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5064 // Only adjust marks if we managed to switch to a window that
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5065 // holds the buffer, otherwise line numbers will be invalid.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5066 appended_lines_mark((linenr_T)n, 1L);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5067
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5068 vim_free(str);
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5069 restore_win_for_buf(&switchwin, &save_curbuf);
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 28950
diff changeset
5070 update_screen(UPD_VALID);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5071
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5072 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5073 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5074
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5075 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5076 *len_change = 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5077
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5078 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5079 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5080 else if (PyList_Check(lines))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5081 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5082 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5083 PyInt size = PyList_Size(lines);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5084 char **array;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5085
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5086 array = PyMem_New(char *, size);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5087 if (array == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5088 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5089 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5090 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5091 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5092
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5093 for (i = 0; i < size; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5094 {
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5095 PyObject *line;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5096
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5097 if (!(line = PyList_GetItem(lines, i)) ||
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5098 !(array[i] = StringToLine(line)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5099 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5100 while (i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5101 vim_free(array[--i]);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5102 PyMem_Free(array);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5103 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5104 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5105 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5106
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5107 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5108 VimTryStart();
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5109 switch_to_win_for_buf(buf, &switchwin, &save_curbuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5110
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5111 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5112 RAISE_UNDO_FAIL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5113 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5114 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5115 for (i = 0; i < size; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5116 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5117 if (ml_append((linenr_T)(n + i),
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5118 (char_u *)array[i], 0, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5119 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5120 RAISE_INSERT_LINE_FAIL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5121
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5122 // Free the rest of the lines
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5123 while (i < size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5124 vim_free(array[i++]);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5125
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5126 break;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5127 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5128 vim_free(array[i]);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5129 }
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5130 if (i > 0 && save_curbuf.br_buf == NULL)
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5131 // Only adjust marks if we managed to switch to a window that
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5132 // holds the buffer, otherwise line numbers will be invalid.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5133 appended_lines_mark((linenr_T)n, (long)i);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5134 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5135
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5136 // Free the array of lines. All of its contents have now
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5137 // been freed.
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5138 PyMem_Free(array);
26978
aa613a3084b9 patch 8.2.4018: ml_get error when win_execute redraws with Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 26966
diff changeset
5139 restore_win_for_buf(&switchwin, &save_curbuf);
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
5140
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 28950
diff changeset
5141 update_screen(UPD_VALID);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5142
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5143 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5144 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5145
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5146 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5147 *len_change = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5148
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5149 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5150 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5151 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5152 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5153 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5154 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5155 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5156 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5157
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5158 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5159 * Common routines for buffers and line ranges
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5160 * -------------------------------------------
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5161 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5162
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5163 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5164 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5165 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5166 buf_T *buf;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5167 } BufferObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5168
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5169 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5170 CheckBuffer(BufferObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5171 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5172 if (self->buf == INVALID_BUFFER_VALUE)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5173 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5174 PyErr_SET_VIM(N_("attempt to refer to deleted buffer"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5175 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5176 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5177
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5178 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5179 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5180
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5181 static int
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5182 CheckBufferCb(void *self)
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5183 {
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5184 return CheckBuffer((BufferObject*)self);
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5185 }
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5186
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5187 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5188 RBItem(BufferObject *self, PyInt n, PyInt start, PyInt end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5189 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5190 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5191 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5192
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5193 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5194 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5195
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
5196 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
5197 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
5198
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5199 if (n < 0 || n > end - start)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5200 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5201 PyErr_SET_STRING(PyExc_IndexError, N_("line number out of range"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5202 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5203 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5204
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5205 return GetBufferLine(self->buf, n+start);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5206 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5207
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5208 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5209 RBSlice(BufferObject *self, PyInt lo, PyInt hi, PyInt start, PyInt end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5210 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5211 PyInt size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5212
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5213 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5214 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5215
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5216 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5217 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5218
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5219 size = end - start + 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5220
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5221 if (lo < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5222 lo = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5223 else if (lo > size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5224 lo = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5225 if (hi < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5226 hi = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5227 if (hi < lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5228 hi = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5229 else if (hi > size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5230 hi = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5231
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5232 return GetBufferLineList(self->buf, lo+start, hi+start);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5233 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5234
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5235 static PyInt
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5236 RBAsItem(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5237 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5238 PyInt n,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5239 PyObject *valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5240 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5241 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5242 PyInt *new_end)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5243 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5244 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5245
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5246 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5247 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5248
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5249 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5250 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5251
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
5252 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
5253 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
5254
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5255 if (n < 0 || n > end - start)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5256 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5257 PyErr_SET_STRING(PyExc_IndexError, N_("line number out of range"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5258 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5259 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5260
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5261 if (SetBufferLine(self->buf, n+start, valObject, &len_change) == FAIL)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5262 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5263
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5264 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5265 *new_end = end + len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5266
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5267 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5268 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5269
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5270 static PyInt
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5271 RBAsSlice(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5272 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5273 PyInt lo,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5274 PyInt hi,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5275 PyObject *valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5276 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5277 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5278 PyInt *new_end)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5279 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5280 PyInt size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5281 PyInt len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5282
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5283 // Self must be a valid buffer
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5284 if (CheckBuffer(self))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5285 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5286
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5287 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5288 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5289
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5290 // Sort out the slice range
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5291 size = end - start + 1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5292
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5293 if (lo < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5294 lo = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5295 else if (lo > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5296 lo = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5297 if (hi < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5298 hi = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5299 if (hi < lo)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5300 hi = lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5301 else if (hi > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5302 hi = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5303
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5304 if (SetBufferLineList(self->buf, lo + start, hi + start,
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5305 valObject, &len_change) == FAIL)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5306 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5307
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5308 if (new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5309 *new_end = end + len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5310
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5311 return 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5312 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
5313
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5314
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5315 static PyObject *
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5316 RBAppend(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5317 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5318 PyObject *args,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5319 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5320 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5321 PyInt *new_end)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5322 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5323 PyObject *lines;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5324 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5325 PyInt max;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5326 PyInt n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5327
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5328 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5329 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5330
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5331 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5332 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
5333
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5334 max = n = end - start + 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5335
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5336 if (!PyArg_ParseTuple(args, "O|n", &lines, &n))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5337 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5338
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5339 if (n < 0 || n > max)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5340 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5341 PyErr_SET_STRING(PyExc_IndexError, N_("line number out of range"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5342 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5343 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5344
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5345 if (InsertBufferLines(self->buf, n + start - 1, lines, &len_change) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5346 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5347
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5348 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5349 *new_end = end + len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5350
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5351 Py_INCREF(Py_None);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5352 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5353 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5354
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5355 // Range object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5356
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5357 DEFINE_PY_TYPE_OBJECT(RangeType);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5358 static PySequenceMethods RangeAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5359 static PyMappingMethods RangeAsMapping;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5360
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5361 typedef struct
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5362 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5363 PyObject_HEAD
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5364 BufferObject *buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5365 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5366 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5367 } RangeObject;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5368
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5369 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5370 RangeNew(buf_T *buf, PyInt start, PyInt end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5371 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5372 BufferObject *bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5373 RangeObject *self;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5374 self = PyObject_GC_New(RangeObject, RangeTypePtr);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5375 if (self == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5376 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5377
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5378 bufr = (BufferObject *)BufferNew(buf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5379 if (bufr == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5380 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5381 Py_DECREF(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5382 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5383 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5384 Py_INCREF(bufr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5385
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5386 self->buf = bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5387 self->start = start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5388 self->end = end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5389
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5390 return (PyObject *)(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5391 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5392
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5393 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5394 RangeDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5395 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5396 RangeObject *self = (RangeObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5397 PyObject_GC_UnTrack((void *)(self));
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5398 Py_XDECREF(self->buf);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5399 PyObject_GC_Del((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5400 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5401
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5402 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5403 RangeTraverse(PyObject *self_obj, visitproc visit, void *arg)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5404 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5405 RangeObject *self = (RangeObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5406 Py_VISIT(((PyObject *)(self->buf)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5407 return 0;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5408 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5409
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5410 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5411 RangeClear(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5412 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5413 RangeObject *self = (RangeObject*)self_obj;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5414 Py_CLEAR(self->buf);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5415 return 0;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5416 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5417
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5418 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5419 RangeLength(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5420 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5421 // HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION?
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5422 if (CheckBuffer(self->buf))
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5423 return -1; // ???
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5424
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5425 return (self->end - self->start + 1);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5426 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5427
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5428 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5429 RangeItem(RangeObject *self, PyInt n)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5430 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5431 return RBItem(self->buf, n, self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5432 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5433
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5434 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5435 RangeSlice(RangeObject *self, PyInt lo, PyInt hi)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5436 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5437 return RBSlice(self->buf, lo, hi, self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5438 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5439
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5440 static char *RangeAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5441 "start", "end",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5442 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5443 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5444
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5445 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
5446 RangeDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5447 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5448 return ObjectDir(self, RangeAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5449 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5450
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5451 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5452 RangeAppend(RangeObject *self, PyObject *args)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5453 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5454 return RBAppend(self->buf, args, self->start, self->end, &self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5455 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5456
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5457 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5458 RangeRepr(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5459 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5460 RangeObject *self = (RangeObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5461 if (self->buf->buf == INVALID_BUFFER_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5462 return PyString_FromFormat("<range object (for deleted buffer) at %p>",
27039
dc21c2f9c659 patch 8.2.4048: gcc complains about use of "%p" in printf
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
5463 (void *)self);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5464 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5465 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5466 char *name = (char *)self->buf->buf->b_fname;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5467
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5468 if (name == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5469 name = "";
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5470
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5471 return PyString_FromFormat("<range %s (%d:%d)>",
4653
b943fd24c351 updated for version 7.3.1074
Bram Moolenaar <bram@vim.org>
parents: 4645
diff changeset
5472 name, (int)self->start, (int)self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5473 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5474 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5475
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5476 static struct PyMethodDef RangeMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5477 // name, function, calling, documentation
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5478 {"append", (PyCFunction)RangeAppend, METH_VARARGS, "Append data to the Vim range" },
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5479 {"__dir__", (PyCFunction)RangeDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5480 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5481 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5482
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5483 DEFINE_PY_TYPE_OBJECT(BufferType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5484 static PySequenceMethods BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5485 static PyMappingMethods BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5486
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5487 static PyObject *
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5488 BufferNew(buf_T *buf)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5489 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5490 /*
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5491 * We need to handle deletion of buffers underneath us.
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5492 * If we add a "b_python*_ref" field to the buf_T structure,
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5493 * then we can get at it in buf_freeall() in vim. We then
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5494 * need to create only ONE Python object per buffer - if
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5495 * we try to create a second, just INCREF the existing one
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5496 * and return it. The (single) Python object referring to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5497 * the buffer is stored in "b_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5498 * Question: what to do on a buf_freeall(). We'll probably
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5499 * have to either delete the Python object (DECREF it to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5500 * zero - a bad idea, as it leaves dangling refs!) or
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5501 * set the buf_T * value to an invalid value (-1?), which
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5502 * means we need checks in all access functions... Bah.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5503 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5504 * Python2 and Python3 get different fields and different objects:
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5505 * b_python_ref and b_python3_ref fields respectively.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5506 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5507
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5508 BufferObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5509
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5510 if (BUF_PYTHON_REF(buf) != NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5511 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5512 self = BUF_PYTHON_REF(buf);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5513 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5514 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5515 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5516 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5517 self = PyObject_NEW(BufferObject, BufferTypePtr);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5518 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5519 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5520 self->buf = buf;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5521 BUF_PYTHON_REF(buf) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5522 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5523
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5524 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5525 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5526
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5527 static void
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5528 BufferDestructor(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5529 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5530 BufferObject *self = (BufferObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5531 if (self->buf && self->buf != INVALID_BUFFER_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5532 BUF_PYTHON_REF(self->buf) = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5533
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5534 DESTRUCTOR_FINISH(self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5535 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5536
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5537 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5538 BufferLength(BufferObject *self)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5539 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5540 // HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION?
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5541 if (CheckBuffer(self))
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5542 return -1; // ???
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5543
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5544 return (PyInt)(self->buf->b_ml.ml_line_count);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5545 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5546
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5547 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5548 BufferItem(BufferObject *self, PyInt n)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5549 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5550 return RBItem(self, n, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5551 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5552
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5553 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5554 BufferSlice(BufferObject *self, PyInt lo, PyInt hi)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5555 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5556 return RBSlice(self, lo, hi, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5557 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5558
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5559 static char *BufferAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5560 "name", "number", "vars", "options", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5561 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5562 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5563
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5564 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
5565 BufferDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5566 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5567 return ObjectDir(self, BufferAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5568 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5569
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5570 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5571 BufferAttrValid(BufferObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5572 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5573 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5574
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5575 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5576 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5577
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5578 ret = ((self->buf == INVALID_BUFFER_VALUE) ? Py_False : Py_True);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5579 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5580 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5581 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5582
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5583 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5584 BufferAttr(BufferObject *self, char *name)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5585 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5586 if (strcmp(name, "name") == 0)
4597
00eecb2f8e3e updated for version 7.3.1046
Bram Moolenaar <bram@vim.org>
parents: 4595
diff changeset
5587 return PyString_FromString((self->buf->b_ffname == NULL
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5588 ? "" : (char *)self->buf->b_ffname));
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5589 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5590 return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5591 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5592 return NEW_DICTIONARY(self->buf->b_vars);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5593 else if (strcmp(name, "options") == 0)
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5594 return OptionsNew(SREQ_BUF, self->buf, CheckBufferCb,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5595 (PyObject *) self);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5596 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5597 return ObjectDir(NULL, BufferAttrs);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5598 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5599 return NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5600 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5601
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5602 static int
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5603 BufferSetattr(PyObject *self_obj, char *name, PyObject *valObject)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5604 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5605 BufferObject *self = (BufferObject*)self_obj;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5606 if (CheckBuffer(self))
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5607 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5608
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5609 if (strcmp(name, "name") == 0)
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5610 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5611 char_u *val;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5612 aco_save_T aco;
31273
25b9669741b2 patch 9.0.0970: Coverity warns for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 31263
diff changeset
5613 int ren_ret = OK;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5614 PyObject *todecref;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5615
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5616 if (!(val = StringToChars(valObject, &todecref)))
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5617 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5618
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5619 VimTryStart();
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5620 // Using aucmd_*: autocommands will be executed by rename_buffer
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5621 aucmd_prepbuf(&aco, self->buf);
31263
d8e7d725a666 patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents: 31231
diff changeset
5622 if (curbuf == self->buf)
d8e7d725a666 patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents: 31231
diff changeset
5623 {
d8e7d725a666 patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents: 31231
diff changeset
5624 ren_ret = rename_buffer(val);
d8e7d725a666 patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents: 31231
diff changeset
5625 aucmd_restbuf(&aco);
d8e7d725a666 patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents: 31231
diff changeset
5626 }
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5627 Py_XDECREF(todecref);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5628 if (VimTryEnd())
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5629 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5630
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5631 if (ren_ret == FAIL)
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5632 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5633 PyErr_SET_VIM(N_("failed to rename buffer"));
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5634 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5635 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5636 return 0;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5637 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5638 else
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5639 {
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5640 PyErr_SetString(PyExc_AttributeError, name);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5641 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5642 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5643 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5644
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5645 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5646 BufferAppend(BufferObject *self, PyObject *args)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5647 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5648 return RBAppend(self, args, 1, -1, NULL);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5649 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5650
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5651 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5652 BufferMark(BufferObject *self, PyObject *pmarkObject)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5653 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5654 pos_T *posp;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5655 char_u *pmark;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5656 char_u mark;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5657 bufref_T savebuf;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5658 PyObject *todecref;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5659
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5660 if (CheckBuffer(self))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5661 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5662
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5663 if (!(pmark = StringToChars(pmarkObject, &todecref)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5664 return NULL;
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5665
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5666 if (pmark[0] == '\0' || pmark[1] != '\0')
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5667 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5668 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5669 N_("mark name must be a single character"));
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
5670 Py_XDECREF(todecref);
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5671 return NULL;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5672 }
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5673
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5674 mark = *pmark;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5675
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5676 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5677
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5678 VimTryStart();
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5679 switch_buffer(&savebuf, self->buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5680 posp = getmark(mark, FALSE);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5681 restore_buffer(&savebuf);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5682 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5683 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5684
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5685 if (posp == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5686 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5687 PyErr_SET_VIM(N_("invalid mark name"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5688 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5689 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5690
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5691 if (posp->lnum <= 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5692 {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5693 // Or raise an error?
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5694 Py_INCREF(Py_None);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5695 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5696 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5697
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5698 return Py_BuildValue("(ll)", (long)(posp->lnum), (long)(posp->col));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5699 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5700
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5701 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5702 BufferRange(BufferObject *self, PyObject *args)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5703 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5704 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5705 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5706
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5707 if (CheckBuffer(self))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5708 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5709
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5710 if (!PyArg_ParseTuple(args, "nn", &start, &end))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5711 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5712
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5713 return RangeNew(self->buf, start, end);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5714 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5715
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5716 static PyObject *
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5717 BufferRepr(PyObject *self_obj)
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5718 {
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5719 BufferObject *self = (BufferObject*)self_obj;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5720 if (self->buf == INVALID_BUFFER_VALUE)
27039
dc21c2f9c659 patch 8.2.4048: gcc complains about use of "%p" in printf
Bram Moolenaar <Bram@vim.org>
parents: 27028
diff changeset
5721 return PyString_FromFormat("<buffer object (deleted) at %p>", (void *)self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5722 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5723 {
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5724 char *name = (char *)self->buf->b_fname;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5725
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5726 if (name == NULL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5727 name = "";
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5728
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5729 return PyString_FromFormat("<buffer %s>", name);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5730 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5731 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5732
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5733 static struct PyMethodDef BufferMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5734 // name, function, calling, documentation
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5735 {"append", (PyCFunction)BufferAppend, METH_VARARGS, "Append data to Vim buffer" },
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5736 {"mark", (PyCFunction)BufferMark, METH_O, "Return (row,col) representing position of named mark" },
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5737 {"range", (PyCFunction)BufferRange, METH_VARARGS, "Return a range object which represents the part of the given buffer between line numbers s and e" },
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5738 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5739 { NULL, NULL, 0, NULL}
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5740 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5741
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5742 /*
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5743 * Buffer list object - Implementation
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5744 */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5745
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5746 DEFINE_PY_TYPE_OBJECT(BufMapType);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5747
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5748 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5749 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5750 PyObject_HEAD
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5751 } BufMapObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5752
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5753 static BufMapObject TheBufferMap =
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5754 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5755 PyObject_HEAD_INIT_TYPE(BufMapType)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5756 };
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5757
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5758 static PyInt
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5759 BufMapLength(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5760 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5761 buf_T *b = firstbuf;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5762 PyInt n = 0;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5763
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5764 while (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5765 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5766 ++n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5767 b = b->b_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5768 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5769
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5770 return n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5771 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5772
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5773 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5774 BufMapItem(PyObject *self UNUSED, PyObject *keyObject)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5775 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5776 buf_T *b;
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5777 long bnr;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5778
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5779 if (NumberToLong(keyObject, &bnr, NUMBER_INT|NUMBER_NATURAL))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5780 return NULL;
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5781
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5782 b = buflist_findnr((int) bnr);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5783
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5784 if (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5785 return BufferNew(b);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5786 else
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5787 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
5788 PyErr_SetObject(PyExc_KeyError, keyObject);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5789 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5790 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5791 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5792
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5793 static void
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5794 BufMapIterDestruct(void* arg)
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5795 {
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5796 PyObject *buffer = (PyObject*)arg;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5797 // Iteration was stopped before all buffers were processed
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5798 if (buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5799 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5800 Py_DECREF(buffer);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5801 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5802 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5803
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5804 static int
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5805 BufMapIterTraverse(void *iter, visitproc visit, void *arg)
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5806 {
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5807 PyObject *buffer = (PyObject*)iter;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5808 if (buffer)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5809 Py_VISIT(buffer);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5810 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5811 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5812
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5813 static int
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5814 BufMapIterClear(void **iter)
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5815 {
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5816 PyObject **buffer = (PyObject**)iter;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5817 if (*buffer)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5818 Py_CLEAR(*buffer);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5819 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5820 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5821
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5822 static PyObject *
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5823 BufMapIterNext(void **arg)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5824 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5825 PyObject *next;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5826 PyObject *ret;
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5827 PyObject **buffer = (PyObject**)arg;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5828
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5829 if (!*buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5830 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5831
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5832 ret = *buffer;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5833
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5834 if (CheckBuffer((BufferObject *)(ret)))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5835 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5836 *buffer = NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5837 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5838 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5839
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5840 if (!((BufferObject *)(ret))->buf->b_next)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5841 next = NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5842 else if (!(next = BufferNew(((BufferObject *)(ret))->buf->b_next)))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5843 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5844 *buffer = next;
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5845 // Do not increment reference: we no longer hold it (decref), but whoever
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5846 // on other side will hold (incref). Decref+incref = nothing.
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5847 return ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5848 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5849
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5850 static PyObject *
21977
d1a7088c6efe patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents: 21319
diff changeset
5851 BufMapIter(PyObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5852 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5853 PyObject *buffer;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5854
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5855 buffer = BufferNew(firstbuf);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5856 return IterNew(buffer,
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5857 BufMapIterDestruct, BufMapIterNext,
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
5858 BufMapIterTraverse, BufMapIterClear,
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
5859 self);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5860 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5861
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5862 static PyMappingMethods BufMapAsMapping = {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5863 (lenfunc) BufMapLength,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5864 (binaryfunc) BufMapItem,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5865 (objobjargproc) 0,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5866 };
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5867
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
5868 // Current items object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5869
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5870 static char *CurrentAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5871 "buffer", "window", "line", "range", "tabpage",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5872 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5873 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5874
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5875 static PyObject *
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
5876 CurrentDir(PyObject *self, PyObject *args UNUSED)
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5877 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5878 return ObjectDir(self, CurrentAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5879 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5880
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5881 static PyObject *
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5882 CurrentGetattr(PyObject *self UNUSED, char *name)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5883 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5884 if (strcmp(name, "buffer") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5885 return (PyObject *)BufferNew(curbuf);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5886 else if (strcmp(name, "window") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
5887 return (PyObject *)WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
5888 else if (strcmp(name, "tabpage") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
5889 return (PyObject *)TabPageNew(curtab);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5890 else if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5891 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5892 else if (strcmp(name, "range") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5893 return RangeNew(curbuf, RangeStart, RangeEnd);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5894 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5895 return ObjectDir(NULL, CurrentAttrs);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5896 else
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5897 #if PY_MAJOR_VERSION < 3
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5898 return Py_FindMethod(WindowMethods, self, name);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5899 #else
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5900 return NULL;
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5901 #endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5902 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5903
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5904 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5905 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *valObject)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5906 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5907 if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5908 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5909 if (SetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum, valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5910 NULL) == FAIL)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5911 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5912
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5913 return 0;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5914 }
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5915 else if (strcmp(name, "buffer") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5916 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5917 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5918
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5919 if (valObject->ob_type != BufferTypePtr)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5920 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5921 PyErr_FORMAT_TYPE(
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5922 N_("expected vim.Buffer object, but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5923 valObject);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5924 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5925 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5926
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5927 if (CheckBuffer((BufferObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5928 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5929 count = ((BufferObject *)(valObject))->buf->b_fnum;
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5930
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5931 VimTryStart();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5932 if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5933 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5934 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5935 return -1;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5936 PyErr_VIM_FORMAT(N_("failed to switch to buffer %d"), count);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5937 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5938 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5939
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5940 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5941 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5942 else if (strcmp(name, "window") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5943 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5944 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5945
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5946 if (valObject->ob_type != WindowTypePtr)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5947 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5948 PyErr_FORMAT_TYPE(
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5949 N_("expected vim.Window object, but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5950 valObject);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5951 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5952 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5953
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5954 if (CheckWindow((WindowObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5955 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5956 count = get_win_number(((WindowObject *)(valObject))->win, firstwin);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5957
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5958 if (!count)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5959 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5960 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5961 N_("failed to find window in the current tab page"));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5962 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5963 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5964
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5965 VimTryStart();
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5966 win_goto(((WindowObject *)(valObject))->win);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5967 if (((WindowObject *)(valObject))->win != curwin)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5968 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5969 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5970 return -1;
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5971 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5972 N_("did not switch to the specified window"));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5973 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5974 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5975
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5976 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5977 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5978 else if (strcmp(name, "tabpage") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5979 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5980 if (valObject->ob_type != TabPageTypePtr)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5981 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5982 PyErr_FORMAT_TYPE(
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5983 N_("expected vim.TabPage object, but got %s"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
5984 valObject);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5985 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5986 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5987
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5988 if (CheckTabPage((TabPageObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5989 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5990
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5991 VimTryStart();
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5992 goto_tabpage_tp(((TabPageObject *)(valObject))->tab, TRUE, TRUE);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5993 if (((TabPageObject *)(valObject))->tab != curtab)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5994 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5995 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5996 return -1;
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5997 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5998 N_("did not switch to the specified tab page"));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5999 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
6000 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
6001
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
6002 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
6003 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6004 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6005 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6006 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6007 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6008 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6009 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6010
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6011 static struct PyMethodDef CurrentMethods[] = {
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
6012 // name, function, calling, documentation
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6013 {"__dir__", (PyCFunction)CurrentDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6014 { NULL, NULL, 0, NULL}
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6015 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6016
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6017 static void
33295
a43861545866 patch 9.0.1913: if_python: undefined behaviour for function pointers
Christian Brabandt <cb@256bit.org>
parents: 33006
diff changeset
6018 init_range_cmd(void *arg)
a43861545866 patch 9.0.1913: if_python: undefined behaviour for function pointers
Christian Brabandt <cb@256bit.org>
parents: 33006
diff changeset
6019 {
a43861545866 patch 9.0.1913: if_python: undefined behaviour for function pointers
Christian Brabandt <cb@256bit.org>
parents: 33006
diff changeset
6020 exarg_T *eap = (exarg_T*)arg;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6021 RangeStart = eap->line1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6022 RangeEnd = eap->line2;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6023 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6024
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6025 static void
33295
a43861545866 patch 9.0.1913: if_python: undefined behaviour for function pointers
Christian Brabandt <cb@256bit.org>
parents: 33006
diff changeset
6026 init_range_eval(void *rettv UNUSED)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6027 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6028 RangeStart = (PyInt) curwin->w_cursor.lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6029 RangeEnd = RangeStart;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6030 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6031
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6032 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6033 run_cmd(const char *cmd, void *arg UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6034 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6035 , PyGILState_STATE *pygilstate UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6036 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6037 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6038 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6039 PyObject *run_ret;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6040 run_ret = PyRun_String((char *)cmd, Py_file_input, globals, globals);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6041 if (run_ret != NULL)
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6042 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6043 Py_DECREF(run_ret);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6044 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6045 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6046 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
6047 emsg(_(e_cant_handle_systemexit_of_python_exception_in_vim));
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6048 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6049 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6050 else
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6051 PyErr_PrintEx(1);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6052 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6053
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6054 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n ";
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6055 static int code_hdr_len = 30;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6056
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6057 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6058 run_do(const char *cmd, void *arg UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6059 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6060 , PyGILState_STATE *pygilstate
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6061 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6062 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6063 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6064 PyInt lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6065 size_t len;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6066 char *code;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6067 int status;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6068 PyObject *pyfunc, *pymain;
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6069 PyObject *run_ret;
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6070 buf_T *was_curbuf = curbuf;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6071
4575
626e9ccb7c48 updated for version 7.3.1035
Bram Moolenaar <bram@vim.org>
parents: 4523
diff changeset
6072 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6073 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6074 emsg(_("cannot save undo information"));
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6075 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6076 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6077
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6078 len = code_hdr_len + STRLEN(cmd);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6079 code = PyMem_New(char, len + 1);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6080 memcpy(code, code_hdr, code_hdr_len);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6081 STRCPY(code + code_hdr_len, cmd);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6082 run_ret = PyRun_String(code, Py_file_input, globals, globals);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6083 status = -1;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6084 if (run_ret != NULL)
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6085 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6086 status = 0;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6087 Py_DECREF(run_ret);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6088 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6089 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6090 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6091 PyMem_Free(code);
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
6092 emsg(_(e_cant_handle_systemexit_of_python_exception_in_vim));
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6093 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6094 return;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6095 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6096 else
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6097 PyErr_PrintEx(1);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6098
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6099 PyMem_Free(code);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6100
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6101 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6102 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6103 emsg(_("failed to run the code"));
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6104 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6105 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6106
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6107 status = 0;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6108 pymain = PyImport_AddModule("__main__");
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6109 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6110 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6111 PyGILState_Release(*pygilstate);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6112 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6113
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6114 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6115 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6116 PyObject *line;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6117 PyObject *linenr;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6118 PyObject *ret;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6119
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6120 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6121 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6122 #endif
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
6123 // Check the line number, the command my have deleted lines.
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6124 if (lnum > curbuf->b_ml.ml_line_count
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6125 || !(line = GetBufferLine(curbuf, lnum)))
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6126 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6127 if (!(linenr = PyInt_FromLong((long) lnum)))
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6128 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6129 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6130 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6131 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6132 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6133 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6134 Py_DECREF(linenr);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6135 if (!ret)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6136 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6137
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
6138 // Check that the command didn't switch to another buffer.
34234
daaff6843090 patch 9.1.0062: Internal error when :luado/perldo/pydo etc delete lines
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
6139 // Check the line number, the command my have deleted lines.
daaff6843090 patch 9.1.0062: Internal error when :luado/perldo/pydo etc delete lines
Christian Brabandt <cb@256bit.org>
parents: 34074
diff changeset
6140 if (curbuf != was_curbuf || lnum > curbuf->b_ml.ml_line_count)
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6141 {
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6142 Py_XDECREF(ret);
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6143 goto err;
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6144 }
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6145
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6146 if (ret != Py_None)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6147 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL)
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6148 {
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6149 Py_XDECREF(ret);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6150 goto err;
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
6151 }
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6152
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6153 Py_XDECREF(ret);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6154 PythonIO_Flush();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6155 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6156 PyGILState_Release(*pygilstate);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6157 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6158 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6159 goto out;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6160 err:
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6161 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6162 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6163 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6164 PyErr_PrintEx(0);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6165 PythonIO_Flush();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6166 status = 1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6167 out:
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6168 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6169 if (!status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6170 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6171 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6172 Py_DECREF(pyfunc);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6173 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6174 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6175 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6176 check_cursor();
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 28950
diff changeset
6177 update_curbuf(UPD_NOT_VALID);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6178 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6179
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6180 static void
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
6181 run_eval(const char *cmd, void *arg
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6182 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6183 , PyGILState_STATE *pygilstate UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6184 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
6185 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6186 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6187 PyObject *run_ret;
33303
924e9cb09df7 patch 9.0.1917: undefined behaviour with python function pointer
Christian Brabandt <cb@256bit.org>
parents: 33295
diff changeset
6188 typval_T *rettv = (typval_T*)arg;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6189
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6190 run_ret = PyRun_String((char *)cmd, Py_eval_input, globals, globals);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6191 if (run_ret == NULL)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6192 {
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
6193 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6194 {
26966
ac75c145f0a9 patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
6195 emsg(_(e_cant_handle_systemexit_of_python_exception_in_vim));
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6196 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
6197 }
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
6198 else
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
6199 {
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
6200 if (PyErr_Occurred() && !msg_silent)
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
6201 PyErr_PrintEx(0);
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
6202 emsg(_(e_eval_did_not_return_valid_python_object));
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
6203 }
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6204 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6205 else
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6206 {
12806
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6207 if (ConvertFromPyObject(run_ret, rettv) == -1)
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
6208 emsg(_(e_failed_to_convert_returned_python_object_to_vim_value));
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6209 Py_DECREF(run_ret);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6210 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6211 PyErr_Clear();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6212 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
6213
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6214 static int
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6215 set_ref_in_py(const int copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6216 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6217 pylinkedlist_T *cur;
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6218 list_T *ll;
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6219 int i;
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6220 int abort = FALSE;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6221 FunctionObject *func;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6222
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6223 if (lastdict != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6224 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6225 for (cur = lastdict ; !abort && cur != NULL ; cur = cur->pll_prev)
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6226 abort = set_ref_in_dict(((DictionaryObject *)(cur->pll_obj))->dict,
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6227 copyID);
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6228 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6229
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6230 if (lastlist != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6231 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6232 for (cur = lastlist ; !abort && cur != NULL ; cur = cur->pll_prev)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6233 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6234 ll = ((ListObject *) (cur->pll_obj))->list;
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6235 abort = set_ref_in_list(ll, copyID);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6236 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6237 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6238
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6239 if (lastfunc != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6240 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6241 for (cur = lastfunc ; !abort && cur != NULL ; cur = cur->pll_prev)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6242 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6243 func = (FunctionObject *) cur->pll_obj;
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
6244 abort = set_ref_in_dict(func->self, copyID);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6245 if (func->argc)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6246 for (i = 0; !abort && i < func->argc; ++i)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6247 abort = abort
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6248 || set_ref_in_item(&func->argv[i], copyID, NULL, NULL);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6249 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6250 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6251
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
6252 return abort;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6253 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6254
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6255 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6256 set_string_copy(char_u *str, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6257 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6258 tv->vval.v_string = vim_strsave(str);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6259 if (tv->vval.v_string == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6260 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6261 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6262 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6263 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6264 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6265 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6266
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6267 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6268 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6269 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6270 dict_T *dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6271 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6272 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6273 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6274 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6275 Py_ssize_t iter = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6276
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
6277 if (!(dict = py_dict_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6278 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6279
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6280 tv->v_type = VAR_DICT;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6281 tv->vval.v_dict = dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6282
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6283 while (PyDict_Next(obj, &iter, &keyObject, &valObject))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6284 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6285 PyObject *todecref = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6286
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6287 if (keyObject == NULL || valObject == NULL)
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6288 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6289 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6290 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6291 }
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6292
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6293 if (!(key = StringToChars(keyObject, &todecref)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6294 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6295 dict_unref(dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6296 return -1;
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6297 }
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
6298
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6299 if (*key == NUL)
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6300 {
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6301 dict_unref(dict);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6302 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
6303 RAISE_NO_EMPTY_KEYS;
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6304 return -1;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6305 }
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6306
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6307 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6308
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6309 Py_XDECREF(todecref);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6310
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6311 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6312 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6313 PyErr_NoMemory();
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6314 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6315 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6316 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6317
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6318 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6319 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6320 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6321 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6322 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6323 }
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6324
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6325 if (dict_add(dict, di) == FAIL)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6326 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6327 RAISE_KEY_ADD_FAIL(di->di_key);
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6328 clear_tv(&di->di_tv);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6329 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6330 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6331 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6332 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6333 }
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6334
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6335 --dict->dv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6336 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6337 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6338
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6339 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6340 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6341 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6342 dict_T *dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6343 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6344 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6345 PyObject *list;
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6346 PyObject *iterator;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6347 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6348 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6349
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
6350 if (!(dict = py_dict_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6351 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6352
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6353 tv->v_type = VAR_DICT;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6354 tv->vval.v_dict = dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6355
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6356 if (!(list = PyMapping_Keys(obj)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6357 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6358 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6359 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6360 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6361
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6362 if (!(iterator = PyObject_GetIter(list)))
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6363 {
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6364 dict_unref(dict);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6365 Py_DECREF(list);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6366 return -1;
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6367 }
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6368 Py_DECREF(list);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6369
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6370 while ((keyObject = PyIter_Next(iterator)))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6371 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6372 PyObject *todecref;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6373
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6374 if (!(key = StringToChars(keyObject, &todecref)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6375 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6376 Py_DECREF(keyObject);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6377 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6378 dict_unref(dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6379 return -1;
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6380 }
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
6381
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6382 if (*key == NUL)
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6383 {
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6384 Py_DECREF(keyObject);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6385 Py_DECREF(iterator);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6386 Py_XDECREF(todecref);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6387 dict_unref(dict);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
6388 RAISE_NO_EMPTY_KEYS;
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6389 return -1;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6390 }
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6391
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6392 if (!(valObject = PyObject_GetItem(obj, keyObject)))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6393 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6394 Py_DECREF(keyObject);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6395 Py_DECREF(iterator);
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6396 Py_XDECREF(todecref);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6397 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6398 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6399 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6400
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6401 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6402
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6403 Py_DECREF(keyObject);
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6404 Py_XDECREF(todecref);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6405
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6406 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6407 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6408 Py_DECREF(iterator);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6409 Py_DECREF(valObject);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6410 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6411 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6412 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6413 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6414
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6415 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6416 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6417 Py_DECREF(iterator);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6418 Py_DECREF(valObject);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6419 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6420 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6421 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6422 }
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6423
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6424 Py_DECREF(valObject);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6425
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6426 if (dict_add(dict, di) == FAIL)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6427 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6428 RAISE_KEY_ADD_FAIL(di->di_key);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6429 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6430 dictitem_free(di);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6431 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6432 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6433 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6434 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6435 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6436 --dict->dv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6437 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6438 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6439
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6440 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6441 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6442 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6443 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6444
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6445 if (!(l = py_list_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6446 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6447
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6448 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6449 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6450
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6451 if (list_py_concat(l, obj, lookup_dict) == -1)
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6452 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6453 list_unref(l);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6454 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6455 }
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6456
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6457 --l->lv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6458 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6459 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6460
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6461 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6462
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6463 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6464 convert_dl(PyObject *obj, typval_T *tv,
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6465 pytotvfunc py_to_tv, PyObject *lookup_dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6466 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6467 PyObject *capsule;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6468 char hexBuf[sizeof(void *) * 2 + 3];
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6469
13353
8412df1479a3 patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents: 12812
diff changeset
6470 sprintf(hexBuf, "%p", (void *)obj);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6471
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6472 #ifdef PY_USE_CAPSULE
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6473 capsule = PyDict_GetItemString(lookup_dict, hexBuf);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6474 #else
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6475 capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6476 #endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6477 if (capsule == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6478 {
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6479 #ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6480 capsule = PyCapsule_New(tv, NULL, NULL);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6481 #else
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6482 capsule = PyCObject_FromVoidPtr(tv, NULL);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6483 #endif
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6484 if (PyDict_SetItemString(lookup_dict, hexBuf, capsule))
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6485 {
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6486 Py_DECREF(capsule);
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6487 tv->v_type = VAR_UNKNOWN;
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6488 return -1;
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6489 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6490
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6491 Py_DECREF(capsule);
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6492
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6493 if (py_to_tv(obj, tv, lookup_dict) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6494 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6495 tv->v_type = VAR_UNKNOWN;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6496 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6497 }
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
6498 // As we are not using copy_tv which increments reference count we must
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
6499 // do it ourself.
7949
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6500 if (tv->v_type == VAR_DICT)
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6501 ++tv->vval.v_dict->dv_refcount;
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6502 else if (tv->v_type == VAR_LIST)
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6503 ++tv->vval.v_list->lv_refcount;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6504 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6505 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6506 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6507 typval_T *v;
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6508
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6509 #ifdef PY_USE_CAPSULE
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6510 v = PyCapsule_GetPointer(capsule, NULL);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6511 #else
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6512 v = PyCObject_AsVoidPtr(capsule);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
6513 #endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6514 copy_tv(v, tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6515 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6516 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6517 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6518
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6519 static int
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6520 ConvertFromPyMapping(PyObject *obj, typval_T *tv)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6521 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6522 PyObject *lookup_dict;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6523 int ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6524
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6525 if (!(lookup_dict = PyDict_New()))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6526 return -1;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6527
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6528 if (PyType_IsSubtype(obj->ob_type, DictionaryTypePtr))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6529 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6530 tv->v_type = VAR_DICT;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6531 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6532 ++tv->vval.v_dict->dv_refcount;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6533 ret = 0;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6534 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6535 else if (PyDict_Check(obj))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6536 ret = convert_dl(obj, tv, pydict_to_tv, lookup_dict);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6537 else if (PyMapping_Check(obj))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6538 ret = convert_dl(obj, tv, pymap_to_tv, lookup_dict);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6539 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6540 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6541 PyErr_FORMAT_TYPE(
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
6542 N_("unable to convert %s to a Vim dictionary"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6543 obj);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6544 ret = -1;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6545 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6546 Py_DECREF(lookup_dict);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6547 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6548 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6549
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6550 static int
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6551 ConvertFromPySequence(PyObject *obj, typval_T *tv)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6552 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6553 PyObject *lookup_dict;
8915
8cbf472483fa commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents: 8913
diff changeset
6554 int ret;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6555
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6556 if (!(lookup_dict = PyDict_New()))
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6557 return -1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6558
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6559 if (PyType_IsSubtype(obj->ob_type, ListTypePtr))
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6560 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6561 tv->v_type = VAR_LIST;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6562 tv->vval.v_list = (((ListObject *)(obj))->list);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6563 ++tv->vval.v_list->lv_refcount;
8915
8cbf472483fa commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents: 8913
diff changeset
6564 ret = 0;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6565 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6566 else if (PyIter_Check(obj) || PySequence_Check(obj))
8915
8cbf472483fa commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents: 8913
diff changeset
6567 ret = convert_dl(obj, tv, pyseq_to_tv, lookup_dict);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6568 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6569 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6570 PyErr_FORMAT_TYPE(
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
6571 N_("unable to convert %s to a Vim list"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6572 obj);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6573 ret = -1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6574 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6575 Py_DECREF(lookup_dict);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6576 return ret;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6577 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6578
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6579 static int
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6580 ConvertFromPyObject(PyObject *obj, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6581 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6582 PyObject *lookup_dict;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6583 int ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6584
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6585 if (!(lookup_dict = PyDict_New()))
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6586 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6587 ret = _ConvertFromPyObject(obj, tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6588 Py_DECREF(lookup_dict);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6589 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6590 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6591
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6592 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6593 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6594 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6595 if (PyType_IsSubtype(obj->ob_type, DictionaryTypePtr))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6596 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6597 tv->v_type = VAR_DICT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6598 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6599 ++tv->vval.v_dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6600 }
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6601 else if (PyType_IsSubtype(obj->ob_type, ListTypePtr))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6602 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6603 tv->v_type = VAR_LIST;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6604 tv->vval.v_list = (((ListObject *)(obj))->list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6605 ++tv->vval.v_list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6606 }
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6607 else if (PyType_IsSubtype(obj->ob_type, FunctionTypePtr))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6608 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6609 FunctionObject *func = (FunctionObject *) obj;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6610 if (func->self != NULL || func->argv != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6611 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
6612 partial_T *pt = ALLOC_CLEAR_ONE(partial_T);
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
6613
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6614 set_partial(func, pt, TRUE);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6615 tv->vval.v_partial = pt;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6616 tv->v_type = VAR_PARTIAL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6617 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6618 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6619 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6620 if (set_string_copy(func->name, tv) == -1)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6621 return -1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6622
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6623 tv->v_type = VAR_FUNC;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6624 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6625 func_ref(func->name);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6626 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6627 else if (PyBytes_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6628 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6629 char_u *str;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6630
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6631 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1)
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
6632 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6633 if (str == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6634 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6635
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6636 if (set_string_copy(str, tv) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6637 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6638
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6639 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6640 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6641 else if (PyUnicode_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6642 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6643 PyObject *bytes;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6644 char_u *str;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6645
23264
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
6646 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, ERRORS_ENCODE_ARG);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6647 if (bytes == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6648 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6649
23264
f9526a3c9bbf patch 8.2.2178: Python 3: non-utf8 character cannot be handled
Bram Moolenaar <Bram@vim.org>
parents: 22669
diff changeset
6650 if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1)
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
6651 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6652 if (str == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6653 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6654
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6655 if (set_string_copy(str, tv))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6656 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6657 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6658 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6659 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6660 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6661
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6662 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6663 }
4321
d8d9c591c50f updated for version 7.3.910
Bram Moolenaar <bram@vim.org>
parents: 4319
diff changeset
6664 #if PY_MAJOR_VERSION < 3
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6665 else if (PyInt_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6666 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6667 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6668 tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6669 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6670 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6671 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6672 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6673 else if (PyLong_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6674 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6675 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6676 tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6677 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6678 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6679 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6680 else if (PyDict_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6681 return convert_dl(obj, tv, pydict_to_tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6682 else if (PyFloat_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6683 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6684 tv->v_type = VAR_FLOAT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6685 tv->vval.v_float = (float_T) PyFloat_AsDouble(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6686 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6687 else if (PyObject_HasAttrString(obj, "keys"))
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6688 return convert_dl(obj, tv, pymap_to_tv, lookup_dict);
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
6689 // PyObject_GetIter can create built-in iterator for any sequence object
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6690 else if (PyIter_Check(obj) || PySequence_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6691 return convert_dl(obj, tv, pyseq_to_tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6692 else if (PyMapping_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6693 return convert_dl(obj, tv, pymap_to_tv, lookup_dict);
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6694 else if (PyNumber_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6695 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6696 PyObject *num;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6697
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6698 if (!(num = PyNumber_Long(obj)))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6699 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6700
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6701 tv->v_type = VAR_NUMBER;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6702 tv->vval.v_number = (varnumber_T) PyLong_AsLong(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6703
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6704 Py_DECREF(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6705 }
12806
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6706 else if (obj == Py_None)
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6707 {
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6708 tv->v_type = VAR_SPECIAL;
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6709 tv->vval.v_number = VVAL_NONE;
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6710 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6711 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6712 {
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6713 PyErr_FORMAT_TYPE(
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
6714 N_("unable to convert %s to a Vim structure"),
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6715 obj);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6716 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6717 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6718 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6719 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6720
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6721 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6722 ConvertToPyObject(typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6723 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6724 typval_T *argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6725 int i;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6726 if (tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6727 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
6728 PyErr_SET_VIM(N_("internal error: NULL reference passed"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6729 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6730 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6731 switch (tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6732 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6733 case VAR_STRING:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
6734 return PyBytes_FromString(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
6735 ? "" : (char *)tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6736 case VAR_NUMBER:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6737 return PyLong_FromLong((long) tv->vval.v_number);
19193
9f98957582d6 patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
6738 case VAR_FLOAT:
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6739 return PyFloat_FromDouble((double) tv->vval.v_float);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6740 case VAR_LIST:
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6741 return NEW_LIST(tv->vval.v_list);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6742 case VAR_DICT:
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6743 return NEW_DICTIONARY(tv->vval.v_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6744 case VAR_FUNC:
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6745 return NEW_FUNCTION(tv->vval.v_string == NULL
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6746 ? (char_u *)"" : tv->vval.v_string,
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
6747 0, NULL, NULL, TRUE);
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6748 case VAR_PARTIAL:
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6749 if (tv->vval.v_partial->pt_argc)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6750 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6751 argv = PyMem_New(typval_T, (size_t)tv->vval.v_partial->pt_argc);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6752 for (i = 0; i < tv->vval.v_partial->pt_argc; i++)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6753 copy_tv(&tv->vval.v_partial->pt_argv[i], &argv[i]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6754 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6755 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6756 argv = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6757 if (tv->vval.v_partial->pt_dict != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6758 tv->vval.v_partial->pt_dict->dv_refcount++;
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6759 return NEW_FUNCTION(tv->vval.v_partial == NULL
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9487
diff changeset
6760 ? (char_u *)"" : partial_name(tv->vval.v_partial),
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6761 tv->vval.v_partial->pt_argc, argv,
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
6762 tv->vval.v_partial->pt_dict,
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
6763 tv->vval.v_partial->pt_auto);
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
6764 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
6765 return PyBytes_FromStringAndSize(
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
6766 (char*) tv->vval.v_blob->bv_ga.ga_data,
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
6767 (Py_ssize_t) tv->vval.v_blob->bv_ga.ga_len);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6768 case VAR_UNKNOWN:
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
6769 case VAR_ANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19102
diff changeset
6770 case VAR_VOID:
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6771 case VAR_CHANNEL:
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6772 case VAR_JOB:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 23992
diff changeset
6773 case VAR_INSTR:
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31273
diff changeset
6774 case VAR_CLASS:
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31273
diff changeset
6775 case VAR_OBJECT:
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33404
diff changeset
6776 case VAR_TYPEALIAS:
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6777 Py_INCREF(Py_None);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6778 return Py_None;
19102
ba9f50bfda83 patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents: 19019
diff changeset
6779 case VAR_BOOL:
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6780 case VAR_SPECIAL:
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6781 switch (tv->vval.v_number)
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6782 {
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
6783 case VVAL_FALSE: return ALWAYS_FALSE;
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
6784 case VVAL_TRUE: return ALWAYS_TRUE;
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6785 case VVAL_NONE:
22669
3ceb24835183 patch 8.2.1883: compiler warnings when using Python
Bram Moolenaar <Bram@vim.org>
parents: 22572
diff changeset
6786 case VVAL_NULL: return ALWAYS_NONE;
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6787 }
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
6788 PyErr_SET_VIM(N_("internal error: invalid value type"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6789 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6790 }
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6791 return NULL;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6792 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6793
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6794 DEFINE_PY_TYPE_OBJECT(CurrentType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6795
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6796 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6797 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6798 PyObject_HEAD
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6799 } CurrentObject;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6800
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6801 static CurrentObject TheCurrent =
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6802 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6803 PyObject_HEAD_INIT_TYPE(CurrentType)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6804 };
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6805
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6806 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6807 init_structs(void)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6808 {
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6809 CLEAR_FIELD(OutputType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6810 OutputType.tp_name = "vim.message";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6811 OutputType.tp_basicsize = sizeof(OutputObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6812 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6813 OutputType.tp_doc = "vim message object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6814 OutputType.tp_methods = OutputMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6815 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6816 OutputType.tp_getattro = OutputGetattro;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6817 OutputType.tp_setattro = OutputSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6818 OutputType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6819 OutputType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6820 OutputType.tp_free = call_PyObject_Free;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6821 # ifndef USE_LIMITED_API
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6822 // The std printer type is only exposed in full API. It is not essential
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6823 // anyway and so in limited API we don't set it.
13952
76a65058766f patch 8.0.1846: Python interface is incompatible with lldb
Christian Brabandt <cb@256bit.org>
parents: 13353
diff changeset
6824 OutputType.tp_base = &PyStdPrinter_Type;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6825 # endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6826 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6827 OutputType.tp_getattr = OutputGetattr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6828 OutputType.tp_setattr = OutputSetattr;
13952
76a65058766f patch 8.0.1846: Python interface is incompatible with lldb
Christian Brabandt <cb@256bit.org>
parents: 13353
diff changeset
6829 // Disabled, because this causes a crash in test86
76a65058766f patch 8.0.1846: Python interface is incompatible with lldb
Christian Brabandt <cb@256bit.org>
parents: 13353
diff changeset
6830 // OutputType.tp_base = &PyFile_Type;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6831 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6832
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6833 CLEAR_FIELD(IterType);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6834 IterType.tp_name = "vim.iter";
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6835 IterType.tp_basicsize = sizeof(IterObject);
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6836 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6837 IterType.tp_doc = "generic iterator object";
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6838 IterType.tp_iter = IterIter;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6839 IterType.tp_iternext = IterNext;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6840 IterType.tp_dealloc = IterDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6841 IterType.tp_traverse = IterTraverse;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6842 IterType.tp_clear = IterClear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6843
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6844 CLEAR_FIELD(BufferType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6845 BufferType.tp_name = "vim.buffer";
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6846 BufferType.tp_basicsize = sizeof(BufferObject);
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6847 BufferType.tp_dealloc = BufferDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6848 BufferType.tp_repr = BufferRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6849 BufferType.tp_as_sequence = &BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6850 BufferType.tp_as_mapping = &BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6851 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6852 BufferType.tp_doc = "vim buffer object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6853 BufferType.tp_methods = BufferMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6854 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6855 BufferType.tp_getattro = BufferGetattro;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6856 BufferType.tp_setattro = BufferSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6857 BufferType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6858 BufferType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6859 BufferType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6860 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6861 BufferType.tp_getattr = BufferGetattr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6862 BufferType.tp_setattr = BufferSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6863 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6864
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6865 CLEAR_FIELD(WindowType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6866 WindowType.tp_name = "vim.window";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6867 WindowType.tp_basicsize = sizeof(WindowObject);
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6868 WindowType.tp_dealloc = WindowDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6869 WindowType.tp_repr = WindowRepr;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6870 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6871 WindowType.tp_doc = "vim Window object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6872 WindowType.tp_methods = WindowMethods;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6873 WindowType.tp_traverse = WindowTraverse;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6874 WindowType.tp_clear = WindowClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6875 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6876 WindowType.tp_getattro = WindowGetattro;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6877 WindowType.tp_setattro = WindowSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6878 WindowType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6879 WindowType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6880 WindowType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6881 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6882 WindowType.tp_getattr = WindowGetattr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6883 WindowType.tp_setattr = WindowSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6884 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6885
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6886 CLEAR_FIELD(TabPageType);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6887 TabPageType.tp_name = "vim.tabpage";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6888 TabPageType.tp_basicsize = sizeof(TabPageObject);
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6889 TabPageType.tp_dealloc = TabPageDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6890 TabPageType.tp_repr = TabPageRepr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6891 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6892 TabPageType.tp_doc = "vim tab page object";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6893 TabPageType.tp_methods = TabPageMethods;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6894 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6895 TabPageType.tp_getattro = TabPageGetattro;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6896 TabPageType.tp_alloc = call_PyType_GenericAlloc;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6897 TabPageType.tp_new = call_PyType_GenericNew;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6898 TabPageType.tp_free = call_PyObject_Free;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6899 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6900 TabPageType.tp_getattr = TabPageGetattr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6901 #endif
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6902
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6903 CLEAR_FIELD(BufMapType);
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6904 BufMapType.tp_name = "vim.bufferlist";
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6905 BufMapType.tp_basicsize = sizeof(BufMapObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6906 BufMapType.tp_as_mapping = &BufMapAsMapping;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6907 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6908 BufMapType.tp_iter = BufMapIter;
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6909 BufMapType.tp_doc = "vim buffer list";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6910
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6911 CLEAR_FIELD(WinListType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6912 WinListType.tp_name = "vim.windowlist";
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6913 WinListType.tp_basicsize = sizeof(WinListObject);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6914 WinListType.tp_as_sequence = &WinListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6915 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6916 WinListType.tp_doc = "vim window list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6917 WinListType.tp_dealloc = (destructor)WinListDestructor;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6918
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6919 CLEAR_FIELD(TabListType);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6920 TabListType.tp_name = "vim.tabpagelist";
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
6921 TabListType.tp_basicsize = sizeof(TabListObject);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6922 TabListType.tp_as_sequence = &TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6923 TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6924 TabListType.tp_doc = "vim tab page list";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6925
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6926 CLEAR_FIELD(RangeType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6927 RangeType.tp_name = "vim.range";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6928 RangeType.tp_basicsize = sizeof(RangeObject);
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6929 RangeType.tp_dealloc = RangeDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6930 RangeType.tp_repr = RangeRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6931 RangeType.tp_as_sequence = &RangeAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6932 RangeType.tp_as_mapping = &RangeAsMapping;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6933 RangeType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6934 RangeType.tp_doc = "vim Range object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6935 RangeType.tp_methods = RangeMethods;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6936 RangeType.tp_traverse = RangeTraverse;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6937 RangeType.tp_clear = RangeClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6938 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6939 RangeType.tp_getattro = RangeGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6940 RangeType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6941 RangeType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6942 RangeType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6943 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6944 RangeType.tp_getattr = RangeGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6945 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6946
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6947 CLEAR_FIELD(CurrentType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6948 CurrentType.tp_name = "vim.currentdata";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6949 CurrentType.tp_basicsize = sizeof(CurrentObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6950 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6951 CurrentType.tp_doc = "vim current object";
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6952 CurrentType.tp_methods = CurrentMethods;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6953 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6954 CurrentType.tp_getattro = CurrentGetattro;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6955 CurrentType.tp_setattro = CurrentSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6956 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6957 CurrentType.tp_getattr = CurrentGetattr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6958 CurrentType.tp_setattr = CurrentSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6959 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6960
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6961 CLEAR_FIELD(DictionaryType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6962 DictionaryType.tp_name = "vim.dictionary";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6963 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6964 DictionaryType.tp_dealloc = DictionaryDestructor;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6965 DictionaryType.tp_as_sequence = &DictionaryAsSeq;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6966 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6967 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
6968 DictionaryType.tp_doc = "dictionary pushing modifications to Vim structure";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6969 DictionaryType.tp_methods = DictionaryMethods;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6970 DictionaryType.tp_iter = DictionaryIter;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6971 DictionaryType.tp_new = DictionaryConstructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6972 DictionaryType.tp_alloc = PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6973 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6974 DictionaryType.tp_getattro = DictionaryGetattro;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6975 DictionaryType.tp_setattro = DictionarySetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6976 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6977 DictionaryType.tp_getattr = DictionaryGetattr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6978 DictionaryType.tp_setattr = DictionarySetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6979 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6980
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
6981 CLEAR_FIELD(ListType);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6982 ListType.tp_name = "vim.list";
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6983 ListType.tp_dealloc = ListDestructor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6984 ListType.tp_basicsize = sizeof(ListObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6985 ListType.tp_as_sequence = &ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6986 ListType.tp_as_mapping = &ListAsMapping;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6987 ListType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
6988 ListType.tp_doc = "list pushing modifications to Vim structure";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6989 ListType.tp_methods = ListMethods;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6990 ListType.tp_iter = ListIter;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6991 ListType.tp_new = ListConstructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6992 ListType.tp_alloc = PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6993 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6994 ListType.tp_getattro = ListGetattro;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6995 ListType.tp_setattro = ListSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6996 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6997 ListType.tp_getattr = ListGetattr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
6998 ListType.tp_setattr = ListSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6999 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7000
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
7001 CLEAR_FIELD(FunctionType);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
7002 FunctionType.tp_name = "vim.function";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7003 FunctionType.tp_basicsize = sizeof(FunctionObject);
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7004 FunctionType.tp_dealloc = FunctionDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7005 FunctionType.tp_call = FunctionCall;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
7006 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
20369
6e1e4d7a7b39 patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents: 20197
diff changeset
7007 FunctionType.tp_doc = "object that calls Vim function";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7008 FunctionType.tp_methods = FunctionMethods;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7009 FunctionType.tp_repr = FunctionRepr;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7010 FunctionType.tp_new = FunctionConstructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7011 FunctionType.tp_alloc = PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7012 #if PY_MAJOR_VERSION >= 3
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7013 FunctionType.tp_getattro = FunctionGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7014 #else
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7015 FunctionType.tp_getattr = FunctionGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7016 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7017
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
7018 CLEAR_FIELD(OptionsType);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
7019 OptionsType.tp_name = "vim.options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
7020 OptionsType.tp_basicsize = sizeof(OptionsObject);
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
7021 OptionsType.tp_as_sequence = &OptionsAsSeq;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
7022 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
7023 OptionsType.tp_doc = "object for manipulating options";
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7024 OptionsType.tp_iter = OptionsIter;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
7025 OptionsType.tp_as_mapping = &OptionsAsMapping;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7026 OptionsType.tp_dealloc = OptionsDestructor;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7027 OptionsType.tp_traverse = OptionsTraverse;
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7028 OptionsType.tp_clear = OptionsClear;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
7029
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7030 #if PY_VERSION_HEX < 0x030700f0
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
7031 CLEAR_FIELD(LoaderType);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7032 LoaderType.tp_name = "vim.Loader";
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7033 LoaderType.tp_basicsize = sizeof(LoaderObject);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7034 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7035 LoaderType.tp_doc = "vim message object";
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7036 LoaderType.tp_methods = LoaderMethods;
33320
a9f0f0eae10e patch 9.0.1925: if_python: still undefined behaviour with function pointer
Christian Brabandt <cb@256bit.org>
parents: 33303
diff changeset
7037 LoaderType.tp_dealloc = LoaderDestructor;
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7038 #endif
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7039
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7040 #if PY_MAJOR_VERSION >= 3
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19922
diff changeset
7041 CLEAR_FIELD(vimmodule);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7042 vimmodule.m_name = "vim";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7043 vimmodule.m_doc = "Vim Python interface\n";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7044 vimmodule.m_size = -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7045 vimmodule.m_methods = VimMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7046 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
7047 }
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7048
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7049 static int
5166
467efeee8f9e updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents: 5139
diff changeset
7050 init_types(void)
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7051 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7052 PYTYPE_READY(IterType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7053 PYTYPE_READY(BufferType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7054 PYTYPE_READY(RangeType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7055 PYTYPE_READY(WindowType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7056 PYTYPE_READY(TabPageType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7057 PYTYPE_READY(BufMapType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7058 PYTYPE_READY(WinListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7059 PYTYPE_READY(TabListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7060 PYTYPE_READY(CurrentType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7061 PYTYPE_READY(DictionaryType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7062 PYTYPE_READY(ListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7063 PYTYPE_READY(FunctionType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7064 PYTYPE_READY(OptionsType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7065 PYTYPE_READY(OutputType);
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7066 #if PY_VERSION_HEX < 0x030700f0
4851
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
7067 PYTYPE_READY(LoaderType);
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7068 #endif
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7069
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7070 #ifdef USE_LIMITED_API
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7071 // We need to finish initializing all the static objects because the types
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7072 // are only just allocated on the heap now.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7073 // Each PyObject_HEAD_INIT_TYPE should correspond to a
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7074 // PyObject_FINISH_INIT_TYPE below.
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7075 PyObject_FINISH_INIT_TYPE(Output, OutputType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7076 PyObject_FINISH_INIT_TYPE(Error, OutputType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7077 PyObject_FINISH_INIT_TYPE(TheBufferMap, BufMapType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7078 PyObject_FINISH_INIT_TYPE(TheWindowList, WinListType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7079 PyObject_FINISH_INIT_TYPE(TheCurrent, CurrentType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7080 PyObject_FINISH_INIT_TYPE(TheTabPageList, TabListType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7081 #endif
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7082 return 0;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7083 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7084
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7085 #ifdef USE_LIMITED_API
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7086 static void
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7087 shutdown_types(void)
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7088 {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7089 PYTYPE_CLEANUP(IterType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7090 PYTYPE_CLEANUP(BufferType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7091 PYTYPE_CLEANUP(RangeType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7092 PYTYPE_CLEANUP(WindowType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7093 PYTYPE_CLEANUP(TabPageType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7094 PYTYPE_CLEANUP(BufMapType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7095 PYTYPE_CLEANUP(WinListType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7096 PYTYPE_CLEANUP(TabListType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7097 PYTYPE_CLEANUP(CurrentType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7098 PYTYPE_CLEANUP(DictionaryType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7099 PYTYPE_CLEANUP(ListType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7100 PYTYPE_CLEANUP(FunctionType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7101 PYTYPE_CLEANUP(OptionsType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7102 PYTYPE_CLEANUP(OutputType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7103 # if PY_VERSION_HEX < 0x030700f0
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7104 PYTYPE_CLEANUP(LoaderType);
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7105 # endif
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7106 }
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7107 #endif
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7108
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7109 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
7110 init_sys_path(void)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7111 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7112 PyObject *path;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7113 PyObject *path_hook;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7114 PyObject *path_hooks;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7115
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7116 if (!(path_hook = PyObject_GetAttrString(vim_module, "path_hook")))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7117 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7118
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7119 if (!(path_hooks = PySys_GetObject("path_hooks")))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7120 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7121 PyErr_Clear();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7122 path_hooks = PyList_New(1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7123 PyList_SET_ITEM(path_hooks, 0, path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7124 if (PySys_SetObject("path_hooks", path_hooks))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7125 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7126 Py_DECREF(path_hooks);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7127 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7128 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7129 Py_DECREF(path_hooks);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7130 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7131 else if (PyList_Check(path_hooks))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7132 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7133 if (PyList_Append(path_hooks, path_hook))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7134 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7135 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7136 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7137 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7138 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7139 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7140 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7141 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7142 VimTryStart();
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
7143 emsg(_("Failed to set path hook: sys.path_hooks is not a list\n"
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7144 "You should now do the following:\n"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7145 "- append vim.path_hook to sys.path_hooks\n"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7146 "- append vim.VIM_SPECIAL_PATH to sys.path\n"));
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
7147 VimTryEnd(); // Discard the error
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7148 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7149 return 0;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7150 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7151
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7152 if (!(path = PySys_GetObject("path")))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7153 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7154 PyErr_Clear();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7155 path = PyList_New(1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7156 Py_INCREF(vim_special_path_object);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7157 PyList_SET_ITEM(path, 0, vim_special_path_object);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7158 if (PySys_SetObject("path", path))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7159 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7160 Py_DECREF(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7161 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7162 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7163 Py_DECREF(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7164 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7165 else if (PyList_Check(path))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7166 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7167 if (PyList_Append(path, vim_special_path_object))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7168 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7169 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7170 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7171 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7172 VimTryStart();
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
7173 emsg(_("Failed to set path: sys.path is not a list\n"
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7174 "You should now append vim.VIM_SPECIAL_PATH to sys.path"));
18753
6e3dc2d630c2 patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18370
diff changeset
7175 VimTryEnd(); // Discard the error
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7176 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7177
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7178 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7179 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7180
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7181 static struct numeric_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7182 char *name;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7183 int val;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7184 } numeric_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7185 {"VAR_LOCKED", VAR_LOCKED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7186 {"VAR_FIXED", VAR_FIXED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7187 {"VAR_SCOPE", VAR_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7188 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7189 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7190
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7191 struct object_constant {
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7192 char *name;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7193 PyObject *valObject;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7194 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7195
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7196 #define ADD_OBJECT(m, name, obj) \
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
7197 if (PyModule_AddObject(m, name, obj)) \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7198 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7199
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7200 #define ADD_CHECKED_OBJECT(m, name, obj) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7201 { \
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7202 PyObject *valObject = obj; \
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7203 if (!valObject) \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7204 return -1; \
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7205 ADD_OBJECT(m, name, valObject); \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7206 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7207
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7208 static int
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
7209 populate_module(PyObject *m)
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7210 {
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7211 int i;
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7212 PyObject *other_module;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7213 PyObject *attr;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7214 PyObject *imp;
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7215 #if PY_VERSION_HEX >= 0x030700f0
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7216 PyObject *dict;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7217 PyObject *cls;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7218 #endif
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7219
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7220 for (i = 0; i < (int)(sizeof(numeric_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7221 / sizeof(struct numeric_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7222 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7223 ADD_CHECKED_OBJECT(m, numeric_constants[i].name,
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7224 PyInt_FromLong(numeric_constants[i].val));
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7225
32936
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7226 struct object_constant object_constants[] = {
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7227 {"buffers", (PyObject *)(void *)&TheBufferMap},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7228 {"windows", (PyObject *)(void *)&TheWindowList},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7229 {"tabpages", (PyObject *)(void *)&TheTabPageList},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7230 {"current", (PyObject *)(void *)&TheCurrent},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7231
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7232 {"Buffer", (PyObject *)BufferTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7233 {"Range", (PyObject *)RangeTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7234 {"Window", (PyObject *)WindowTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7235 {"TabPage", (PyObject *)TabPageTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7236 {"Dictionary", (PyObject *)DictionaryTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7237 {"List", (PyObject *)ListTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7238 {"Function", (PyObject *)FunctionTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7239 {"Options", (PyObject *)OptionsTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7240 #if PY_VERSION_HEX < 0x030700f0
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7241 {"_Loader", (PyObject *)LoaderTypePtr},
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7242 #endif
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7243 };
c517845bd10e patch 9.0.1776: No support for stable Python 3 ABI
Christian Brabandt <cb@256bit.org>
parents: 31422
diff changeset
7244
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7245 for (i = 0; i < (int)(sizeof(object_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7246 / sizeof(struct object_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7247 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7248 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7249 PyObject *valObject;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7250
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7251 valObject = object_constants[i].valObject;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7252 Py_INCREF(valObject);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
7253 ADD_OBJECT(m, object_constants[i].name, valObject);
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7254 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7255
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7256 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL)))
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7257 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7258 ADD_OBJECT(m, "error", VimError);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7259
17922
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
7260 ADD_CHECKED_OBJECT(m, "vars", NEW_DICTIONARY(get_globvar_dict()));
4d63d47d87ef patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
7261 ADD_CHECKED_OBJECT(m, "vvars", NEW_DICTIONARY(get_vimvar_dict()));
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7262 ADD_CHECKED_OBJECT(m, "options",
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7263 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7264
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7265 if (!(other_module = PyImport_ImportModule("os")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7266 return -1;
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7267 ADD_OBJECT(m, "os", other_module);
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7268
9161
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
7269 #if PY_MAJOR_VERSION >= 3
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7270 if (!(py_getcwd = PyObject_GetAttrString(other_module, "getcwd")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7271 return -1;
9161
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
7272 #else
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
7273 if (!(py_getcwd = PyObject_GetAttrString(other_module, "getcwdu")))
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
7274 return -1;
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
7275 #endif
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7276 ADD_OBJECT(m, "_getcwd", py_getcwd)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7277
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7278 if (!(py_chdir = PyObject_GetAttrString(other_module, "chdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7279 return -1;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7280 ADD_OBJECT(m, "_chdir", py_chdir);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
7281 if (!(attr = PyObject_GetAttrString(m, "chdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7282 return -1;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7283 if (PyObject_SetAttrString(other_module, "chdir", attr))
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7284 {
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7285 Py_DECREF(attr);
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7286 return -1;
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7287 }
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7288 Py_DECREF(attr);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7289
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
7290 if ((py_fchdir = PyObject_GetAttrString(other_module, "fchdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7291 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7292 ADD_OBJECT(m, "_fchdir", py_fchdir);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
7293 if (!(attr = PyObject_GetAttrString(m, "fchdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7294 return -1;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7295 if (PyObject_SetAttrString(other_module, "fchdir", attr))
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7296 {
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7297 Py_DECREF(attr);
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7298 return -1;
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7299 }
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
7300 Py_DECREF(attr);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7301 }
4722
3534e9b4fa42 updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents: 4706
diff changeset
7302 else
3534e9b4fa42 updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents: 4706
diff changeset
7303 PyErr_Clear();
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
7304
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7305 if (!(vim_special_path_object = PyString_FromString(vim_special_path)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7306 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7307
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7308 ADD_OBJECT(m, "VIM_SPECIAL_PATH", vim_special_path_object);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7309
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7310 #if PY_VERSION_HEX >= 0x030700f0
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7311 if (!(imp = PyImport_ImportModule("importlib.machinery")))
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7312 return -1;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7313
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7314 dict = PyModule_GetDict(imp);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7315
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7316 if (!(cls = PyDict_GetItemString(dict, "PathFinder")))
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7317 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7318 Py_DECREF(imp);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7319 return -1;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7320 }
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7321
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7322 if (!(py_find_spec = PyObject_GetAttrString(cls, "find_spec")))
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7323 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7324 Py_DECREF(imp);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7325 return -1;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7326 }
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7327
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
7328 if ((py_find_module = PyObject_GetAttrString(cls, "find_module")))
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
7329 {
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
7330 // find_module() is deprecated, this may stop working in some later
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
7331 // version.
28844
c0403cd5ca06 patch 8.2.4945: inconsistent use of white space
Bram Moolenaar <Bram@vim.org>
parents: 28226
diff changeset
7332 ADD_OBJECT(m, "_find_module", py_find_module);
15818
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
7333 }
89486329d9e6 patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
7334
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7335 Py_DECREF(imp);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7336
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7337 ADD_OBJECT(m, "_find_spec", py_find_spec);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7338 #else
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7339 if (!(imp = PyImport_ImportModule("imp")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7340 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7341
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7342 if (!(py_find_module = PyObject_GetAttrString(imp, "find_module")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7343 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7344 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7345 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7346 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7347
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7348 if (!(py_load_module = PyObject_GetAttrString(imp, "load_module")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7349 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7350 Py_DECREF(py_find_module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7351 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7352 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7353 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7354
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7355 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
7356
4851
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
7357 ADD_OBJECT(m, "_find_module", py_find_module);
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
7358 ADD_OBJECT(m, "_load_module", py_load_module);
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
7359 #endif
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
7360
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7361 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
7362 }