Mercurial > vim
annotate src/if_py_both.h @ 18954:f9bd54e7f8ee
Added tag v8.2.0037 for changeset 30c965c6f85578a2d956de22970ff781b4239946
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 24 Dec 2019 15:45:04 +0100 |
parents | 6e3dc2d630c2 |
children | a3d9a5e14c1f |
rev | line source |
---|---|
3618 | 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 | 10 * Python extensions by Paul Moore, David Leonard, Roland Puntaier, Nikolay |
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 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
16 static char_u e_py_systemexit[] = "E880: Can't handle SystemExit of %s exception in vim"; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
17 |
3734 | 18 #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
|
19 typedef int Py_ssize_t; // Python 2.4 and earlier don't have this type. |
3734 | 20 #endif |
21 | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
22 #define ENC_OPT ((char *)p_enc) |
4435 | 23 #define DOPY_FUNC "_vim_pydo" |
2919 | 24 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
25 static const char *vim_special_path = "_vim_path_"; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
26 |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
27 #define PyErr_SET_STRING(exc, str) PyErr_SetString(exc, _(str)) |
4385 | 28 #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
|
29 #define PyErr_SET_VIM(str) PyErr_SET_STRING(VimError, str) |
5608 | 30 #define PyErr_FORMAT(exc, str, arg) PyErr_Format(exc, _(str), arg) |
31 #define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2) | |
32 #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
|
33 |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
34 #define Py_TYPE_NAME(obj) (obj->ob_type->tp_name == NULL \ |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
35 ? "(NULL)" \ |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
36 : obj->ob_type->tp_name) |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
37 |
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
38 #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
|
39 N_("empty keys are not allowed")) |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
40 #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
|
41 #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
|
42 #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
|
43 #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
|
44 #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
|
45 #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
|
46 #define RAISE_KEY_ADD_FAIL(key) \ |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
47 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
|
48 #define RAISE_INVALID_INDEX_TYPE(idx) \ |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
49 PyErr_FORMAT(PyExc_TypeError, N_("index must be int or slice, not %s"), \ |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
50 Py_TYPE_NAME(idx)); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
51 |
4385 | 52 #define INVALID_BUFFER_VALUE ((buf_T *)(-1)) |
53 #define INVALID_WINDOW_VALUE ((win_T *)(-1)) | |
4401 | 54 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1)) |
4385 | 55 |
4486 | 56 typedef void (*rangeinitializer)(void *); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
57 typedef void (*runner)(const char *, void * |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
58 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
59 , PyGILState_STATE * |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
60 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
61 ); |
4486 | 62 |
4385 | 63 static int ConvertFromPyObject(PyObject *, typval_T *); |
64 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
65 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
|
66 static int ConvertFromPySequence(PyObject *, typval_T *); |
4431 | 67 static PyObject *WindowNew(win_T *, tabpage_T *); |
68 static PyObject *BufferNew (buf_T *); | |
69 static PyObject *LineToString(const char *); | |
4385 | 70 |
71 static PyInt RangeStart; | |
72 static PyInt RangeEnd; | |
73 | |
4486 | 74 static PyObject *globals; |
75 | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
76 static PyObject *py_chdir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
77 static PyObject *py_fchdir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
78 static PyObject *py_getcwd; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
79 static PyObject *vim_module; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
80 static PyObject *vim_special_path_object; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
81 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
82 #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
|
83 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
|
84 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
85 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
|
86 #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
|
87 static PyObject *py_find_module; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
88 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
89 static PyObject *VimError; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
90 |
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
|
91 /* |
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
|
92 * 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
|
93 */ |
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
|
94 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
|
95 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
|
96 { |
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
|
97 } |
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
|
98 |
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
|
99 /* |
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
|
100 * 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
|
101 */ |
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
|
102 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
|
103 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
|
104 { |
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
|
105 } |
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
|
106 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
107 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
108 * 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
|
109 * 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
|
110 * was needed to generate returned value is object. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
111 * |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
112 * Use Py_XDECREF to decrement reference count. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
113 */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
114 static char_u * |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
115 StringToChars(PyObject *obj, PyObject **todecref) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
116 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
117 char_u *str; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
118 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
119 if (PyBytes_Check(obj)) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
120 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
121 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
122 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
123 || str == NULL) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
124 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
125 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
126 *todecref = NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
127 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
128 else if (PyUnicode_Check(obj)) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
129 { |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
130 PyObject *bytes; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
131 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
132 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
133 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
134 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
135 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
136 || str == NULL) |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
137 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
138 Py_DECREF(bytes); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
139 return NULL; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
140 } |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
141 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
142 *todecref = bytes; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
143 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
144 else |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
145 { |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
146 #if PY_MAJOR_VERSION < 3 |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
147 PyErr_FORMAT(PyExc_TypeError, |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
148 N_("expected str() or unicode() instance, but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
149 Py_TYPE_NAME(obj)); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
150 #else |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
151 PyErr_FORMAT(PyExc_TypeError, |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
152 N_("expected bytes() or str() instance, but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
153 Py_TYPE_NAME(obj)); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
154 #endif |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
155 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
156 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
157 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
158 return (char_u *) str; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
159 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
160 |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
161 #define NUMBER_LONG 1 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
162 #define NUMBER_INT 2 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
163 #define NUMBER_NATURAL 4 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
164 #define NUMBER_UNSIGNED 8 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
165 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
166 static int |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
167 NumberToLong(PyObject *obj, long *result, int flags) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
168 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
169 #if PY_MAJOR_VERSION < 3 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
170 if (PyInt_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
171 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
172 *result = PyInt_AsLong(obj); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
173 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
174 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
175 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
176 else |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
177 #endif |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
178 if (PyLong_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
179 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
180 *result = PyLong_AsLong(obj); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
181 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
182 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
183 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
184 else if (PyNumber_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
185 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
186 PyObject *num; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
187 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
188 if (!(num = PyNumber_Long(obj))) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
189 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
190 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
191 *result = PyLong_AsLong(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
192 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
193 Py_DECREF(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
194 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
195 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
196 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
197 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
198 else |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
199 { |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
200 #if PY_MAJOR_VERSION < 3 |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
201 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
202 N_("expected int(), long() or something supporting " |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
203 "coercing to long(), but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
204 Py_TYPE_NAME(obj)); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
205 #else |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
206 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
207 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
|
208 "but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
209 Py_TYPE_NAME(obj)); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
210 #endif |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
211 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
212 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
213 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
214 if (flags & NUMBER_INT) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
215 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
216 if (*result > INT_MAX) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
217 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
218 PyErr_SET_STRING(PyExc_OverflowError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
219 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
|
220 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
221 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
222 else if (*result < INT_MIN) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
223 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
224 PyErr_SET_STRING(PyExc_OverflowError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
225 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
|
226 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
227 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
228 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
229 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
230 if (flags & NUMBER_NATURAL) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
231 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
232 if (*result <= 0) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
233 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
234 PyErr_SET_STRING(PyExc_ValueError, |
5695 | 235 N_("number must be greater than zero")); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
236 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
237 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
238 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
239 else if (flags & NUMBER_UNSIGNED) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
240 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
241 if (*result < 0) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
242 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
243 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
244 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
|
245 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
246 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
247 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
248 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
249 return 0; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
250 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
251 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
252 static int |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
253 add_string(PyObject *list, char *s) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
254 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
255 PyObject *string; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
256 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
257 if (!(string = PyString_FromString(s))) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
258 return -1; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
259 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
260 if (PyList_Append(list, string)) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
261 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
262 Py_DECREF(string); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
263 return -1; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
264 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
265 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
266 Py_DECREF(string); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
267 return 0; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
268 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
269 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
270 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
271 ObjectDir(PyObject *self, char **attributes) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
272 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
273 PyMethodDef *method; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
274 char **attr; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
275 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
276 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
277 if (!(ret = PyList_New(0))) |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
278 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
279 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
280 if (self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
281 for (method = self->ob_type->tp_methods ; method->ml_name != NULL ; ++method) |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
282 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
|
283 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
284 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
285 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
286 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
287 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
288 for (attr = attributes ; *attr ; ++attr) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
289 if (add_string(ret, *attr)) |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
290 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
291 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
292 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
293 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
294 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
295 #if PY_MAJOR_VERSION < 3 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
296 if (add_string(ret, "__members__")) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
297 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
298 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
299 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
300 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
301 #endif |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
302 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
303 return ret; |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
304 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
305 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
306 // Output buffer management |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
307 |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
308 // Function to write a line, points to either msg() or emsg(). |
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
|
309 typedef void (*writefn)(char_u *); |
4385 | 310 |
311 static PyTypeObject 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
|
312 |
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
|
313 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
|
314 { |
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
|
315 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
|
316 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
|
317 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
|
318 } 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
|
319 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
320 static char *OutputAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
321 "softspace", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
322 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
323 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
324 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
325 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
326 OutputDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
327 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
328 return ObjectDir(self, OutputAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
329 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
330 |
3826 | 331 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
332 OutputSetattr(OutputObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
333 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
334 if (valObject == NULL) |
3826 | 335 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
336 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
337 N_("can't delete OutputObject attributes")); |
3826 | 338 return -1; |
339 } | |
340 | |
341 if (strcmp(name, "softspace") == 0) | |
342 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
343 if (NumberToLong(valObject, &(self->softspace), NUMBER_UNSIGNED)) |
3826 | 344 return -1; |
345 return 0; | |
346 } | |
347 | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
348 PyErr_FORMAT(PyExc_AttributeError, N_("invalid attribute: %s"), name); |
3826 | 349 return -1; |
350 } | |
351 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
352 // Buffer IO, we write one whole line at a time. |
4385 | 353 static garray_T io_ga = {0, 0, 1, 80, NULL}; |
354 static writefn old_fn = NULL; | |
355 | |
356 static void | |
357 PythonIO_Flush(void) | |
358 { | |
359 if (old_fn != NULL && io_ga.ga_len > 0) | |
360 { | |
361 ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL; | |
362 old_fn((char_u *)io_ga.ga_data); | |
363 } | |
364 io_ga.ga_len = 0; | |
365 } | |
366 | |
367 static void | |
368 writer(writefn fn, char_u *str, PyInt n) | |
369 { | |
370 char_u *ptr; | |
371 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
372 // Flush when switching output function. |
4385 | 373 if (fn != old_fn) |
374 PythonIO_Flush(); | |
375 old_fn = fn; | |
376 | |
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
|
377 // 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
|
378 // 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
|
379 // 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
|
380 // 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
|
381 // "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
|
382 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
|
383 && (fn == (writefn)emsg || !got_int)) |
4385 | 384 { |
385 PyInt len = ptr - str; | |
386 | |
387 if (ga_grow(&io_ga, (int)(len + 1)) == FAIL) | |
388 break; | |
389 | |
390 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len); | |
391 ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL; | |
392 fn((char_u *)io_ga.ga_data); | |
393 str = ptr + 1; | |
394 n -= len + 1; | |
395 io_ga.ga_len = 0; | |
396 } | |
397 | |
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
|
398 // 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
|
399 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
|
400 && ga_grow(&io_ga, (int)(n + 1)) == OK) |
4385 | 401 { |
402 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n); | |
403 io_ga.ga_len += (int)n; | |
404 } | |
405 } | |
406 | |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
407 static int |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
408 write_output(OutputObject *self, PyObject *string) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
409 { |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
410 Py_ssize_t len = 0; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
411 char *str = NULL; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
412 int error = self->error; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
413 |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
414 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
|
415 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
|
416 |
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
|
417 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
|
418 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
|
419 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
|
420 emsg_severe = TRUE; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15472
diff
changeset
|
421 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
|
422 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
|
423 Py_END_ALLOW_THREADS |
2894 | 424 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
|
425 |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
426 return 0; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
427 } |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
428 |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
429 static PyObject * |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
430 OutputWrite(OutputObject *self, PyObject *string) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
431 { |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
432 if (write_output(self, string)) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
433 return NULL; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
434 |
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
|
435 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
|
436 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
|
437 } |
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
|
438 |
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
|
439 static PyObject * |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
440 OutputWritelines(OutputObject *self, PyObject *seq) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
441 { |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
442 PyObject *iterator; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
443 PyObject *item; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
444 |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
445 if (!(iterator = PyObject_GetIter(seq))) |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
446 return NULL; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
447 |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
448 while ((item = PyIter_Next(iterator))) |
3618 | 449 { |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
450 if (write_output(self, item)) |
3618 | 451 { |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
452 Py_DECREF(iterator); |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
453 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
|
454 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
|
455 } |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
456 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
|
457 } |
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
|
458 |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
459 Py_DECREF(iterator); |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
460 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
461 // 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
|
462 if (PyErr_Occurred()) |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
463 return NULL; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
464 |
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
|
465 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
|
466 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
|
467 } |
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
|
468 |
2727 | 469 static PyObject * |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
470 AlwaysNone(PyObject *self UNUSED) |
2727 | 471 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
472 // do nothing |
2727 | 473 Py_INCREF(Py_None); |
474 return Py_None; | |
475 } | |
476 | |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
477 static PyObject * |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
478 AlwaysFalse(PyObject *self UNUSED) |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
479 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
480 // do nothing |
7202
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
481 PyObject *ret = Py_False; |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
482 Py_INCREF(ret); |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
483 return ret; |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
484 } |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
485 |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
486 static PyObject * |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
487 AlwaysTrue(PyObject *self UNUSED) |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
488 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
489 // do nothing |
7202
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
490 PyObject *ret = Py_True; |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
491 Py_INCREF(ret); |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
492 return ret; |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
493 } |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
494 |
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
|
495 /***************/ |
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
|
496 |
4385 | 497 static struct PyMethodDef OutputMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
498 // name, function, calling, doc |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
499 {"write", (PyCFunction)OutputWrite, METH_O, ""}, |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
500 {"writelines", (PyCFunction)OutputWritelines, METH_O, ""}, |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
501 {"flush", (PyCFunction)AlwaysNone, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
502 {"close", (PyCFunction)AlwaysNone, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
503 {"isatty", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
504 {"readable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
505 {"seekable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
506 {"writable", (PyCFunction)AlwaysTrue, METH_NOARGS, ""}, |
8967
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8921
diff
changeset
|
507 {"closed", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
508 {"__dir__", (PyCFunction)OutputDir, METH_NOARGS, ""}, |
4492 | 509 { NULL, NULL, 0, NULL} |
4385 | 510 }; |
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
|
511 |
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
|
512 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
|
513 { |
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
|
514 PyObject_HEAD_INIT(&OutputType) |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
515 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
|
516 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
|
517 }; |
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
|
518 |
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
|
519 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
|
520 { |
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
|
521 PyObject_HEAD_INIT(&OutputType) |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
522 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
|
523 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
|
524 }; |
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
|
525 |
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
|
526 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
|
527 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
|
528 { |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
529 if (PySys_SetObject("stdout", (PyObject *)(void *)&Output)) |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
530 return -1; |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
531 if (PySys_SetObject("stderr", (PyObject *)(void *)&Error)) |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
532 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
|
533 |
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
|
534 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
|
535 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
536 emsg(_("E264: Python: Error initialising I/O objects")); |
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
|
537 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
|
538 } |
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
|
539 |
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
|
540 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
|
541 } |
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
|
542 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
543 #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
|
544 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
|
545 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
546 typedef struct |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
547 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
548 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
|
549 char *fullname; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
550 PyObject *result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
551 } LoaderObject; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
552 static PyTypeObject LoaderType; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
553 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
554 static void |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
555 LoaderDestructor(LoaderObject *self) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
556 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
557 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
|
558 Py_XDECREF(self->result); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
559 DESTRUCTOR_FINISH(self); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
560 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
561 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
562 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
563 LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
564 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
565 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
|
566 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
|
567 PyObject *module; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
568 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
569 if (!fullname) |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
570 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
571 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
|
572 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
|
573 return module; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
574 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
575 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
576 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
|
577 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
578 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
|
579 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
|
580 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
581 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
|
582 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
|
583 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
584 if (!module) |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
585 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
586 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
|
587 return NULL; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
588 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
589 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
|
590 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
|
591 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
592 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
593 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
|
594 return module; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
595 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
596 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
597 static struct PyMethodDef LoaderMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
598 // name, function, calling, doc |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
599 {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""}, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
600 { NULL, NULL, 0, NULL} |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
601 }; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
602 #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
|
603 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
604 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
605 * 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
|
606 * 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
|
607 */ |
4498 | 608 static void |
609 VimTryStart(void) | |
610 { | |
611 ++trylevel; | |
612 } | |
613 | |
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
|
614 static int |
4498 | 615 VimTryEnd(void) |
616 { | |
617 --trylevel; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
618 // 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
|
619 // 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
|
620 did_emsg = FALSE; |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
621 // Keyboard interrupt should be preferred over anything else |
4498 | 622 if (got_int) |
623 { | |
5629 | 624 if (did_throw) |
5469 | 625 discard_current_exception(); |
626 got_int = FALSE; | |
4498 | 627 PyErr_SetNone(PyExc_KeyboardInterrupt); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
628 return -1; |
4498 | 629 } |
5517 | 630 else if (msg_list != NULL && *msg_list != NULL) |
631 { | |
632 int should_free; | |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
633 char *msg; |
5517 | 634 |
635 msg = get_exception_string(*msg_list, ET_ERROR, NULL, &should_free); | |
636 | |
637 if (msg == NULL) | |
638 { | |
639 PyErr_NoMemory(); | |
640 return -1; | |
641 } | |
642 | |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
643 PyErr_SetVim(msg); |
5517 | 644 |
645 free_global_msglist(); | |
646 | |
647 if (should_free) | |
648 vim_free(msg); | |
649 | |
650 return -1; | |
651 } | |
4498 | 652 else if (!did_throw) |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
653 return (PyErr_Occurred() ? -1 : 0); |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
654 // Python exception is preferred over vim one; unlikely to occur though |
4498 | 655 else if (PyErr_Occurred()) |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
656 { |
5629 | 657 discard_current_exception(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
658 return -1; |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
659 } |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
660 // Finally transform Vim script exception to python one |
4498 | 661 else |
662 { | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
663 PyErr_SetVim((char *)current_exception->value); |
4498 | 664 discard_current_exception(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
665 return -1; |
4498 | 666 } |
667 } | |
668 | |
669 static int | |
670 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
|
671 { |
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
|
672 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
|
673 { |
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
|
674 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
|
675 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
|
676 } |
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
|
677 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
|
678 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
679 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
680 // Vim module - Implementation |
4385 | 681 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
682 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
683 VimCommand(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
684 { |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
685 char_u *cmd; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
686 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
687 PyObject *todecref; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
688 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
689 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
|
690 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
691 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
692 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
|
693 Python_Lock_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
694 |
4498 | 695 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
696 do_cmdline_cmd(cmd); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
697 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
698 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
699 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
700 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
|
701 |
4498 | 702 if (VimTryEnd()) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
703 ret = NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
704 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
705 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
706 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
707 Py_XINCREF(ret); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
708 Py_XDECREF(todecref); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
709 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
710 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
711 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
712 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
713 * 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
|
714 * 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
|
715 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
716 * 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
|
717 * you call VimToPython. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
718 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
719 static PyObject * |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
720 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
|
721 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
722 PyObject *ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
723 PyObject *newObj; |
3618 | 724 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
|
725 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
726 // 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
|
727 if (depth > 100) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
728 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
729 Py_INCREF(Py_None); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
730 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
731 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
732 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
733 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
734 // 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
|
735 // 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
|
736 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
|
737 || (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
|
738 { |
3618 | 739 sprintf(ptrBuf, "%p", |
740 our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list | |
741 : (void *)our_tv->vval.v_dict); | |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
742 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
743 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
|
744 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
745 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
746 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
747 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
748 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
749 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
750 if (our_tv->v_type == VAR_STRING) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
751 ret = PyString_FromString(our_tv->vval.v_string == NULL |
3852 | 752 ? "" : (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
|
753 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
|
754 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
755 char buf[NUMBUFLEN]; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
756 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
757 // 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
|
758 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
|
759 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
|
760 } |
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
|
761 #ifdef FEAT_FLOAT |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
762 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
|
763 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
764 char buf[NUMBUFLEN]; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
765 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
766 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
|
767 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
|
768 } |
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
|
769 #endif |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
770 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
|
771 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
772 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
|
773 listitem_T *curr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
774 |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
775 if (list == NULL) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
776 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
777 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
778 if (!(ret = PyList_New(0))) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
779 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
780 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
781 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
|
782 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
783 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
784 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
785 } |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
786 |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
787 for (curr = list->lv_first; curr != NULL; curr = curr->li_next) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
788 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
789 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
|
790 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
791 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
792 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
793 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
794 if (PyList_Append(ret, newObj)) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
795 { |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
796 Py_DECREF(newObj); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
797 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
798 return NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
799 } |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
800 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
|
801 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
802 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
803 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
|
804 { |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
805 |
6598 | 806 hashtab_T *ht; |
807 long_u todo; | |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
808 hashitem_T *hi; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
809 dictitem_T *di; |
6598 | 810 |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
811 if (our_tv->vval.v_dict == NULL) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
812 return NULL; |
6598 | 813 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
|
814 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
815 if (!(ret = PyDict_New())) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
816 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
817 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
818 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
|
819 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
820 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
821 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
822 } |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
823 |
6598 | 824 todo = ht->ht_used; |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
825 for (hi = ht->ht_array; todo > 0; ++hi) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
826 { |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
827 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
|
828 { |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
829 --todo; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
830 |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
831 di = dict_lookup(hi); |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
832 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
|
833 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
834 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
835 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
836 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
837 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
|
838 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
839 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
|
840 Py_DECREF(newObj); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
841 return NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
842 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
843 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
844 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
845 } |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
846 else if (our_tv->v_type == VAR_SPECIAL) |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
847 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
848 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
|
849 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
850 ret = Py_False; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
851 Py_INCREF(ret); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
852 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
853 else if (our_tv->vval.v_number == VVAL_TRUE) |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
854 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
855 ret = Py_True; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
856 Py_INCREF(ret); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
857 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
858 else |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
859 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
860 Py_INCREF(Py_None); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
861 ret = Py_None; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
862 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
863 return ret; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
864 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
865 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
|
866 ret = PyBytes_FromStringAndSize( |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
867 (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
|
868 (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
|
869 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
870 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
871 Py_INCREF(Py_None); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
872 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
873 } |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
874 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
875 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
876 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
877 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
878 static PyObject * |
4500 | 879 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
|
880 { |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
881 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
|
882 typval_T *our_tv; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
883 PyObject *string; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
884 PyObject *todecref; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
885 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
886 PyObject *lookup_dict; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
887 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
888 if (!PyArg_ParseTuple(args, "O", &string)) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
889 return NULL; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
890 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
891 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
|
892 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
893 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
894 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
|
895 Python_Lock_Vim(); |
4498 | 896 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
897 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
|
898 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
899 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
|
900 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
901 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
902 |
4498 | 903 if (VimTryEnd()) |
904 return NULL; | |
905 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
906 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
|
907 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
908 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
|
909 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
910 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
911 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
912 // 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
|
913 // used to check for recursive loops. |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
914 if (!(lookup_dict = PyDict_New())) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
915 ret = NULL; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
916 else |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
917 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
918 ret = VimToPython(our_tv, 1, lookup_dict); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
919 Py_DECREF(lookup_dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
920 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
921 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
922 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
923 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
|
924 Python_Lock_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
925 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
|
926 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
927 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
|
928 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
929 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
930 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
931 |
3618 | 932 static PyObject *ConvertToPyObject(typval_T *); |
933 | |
934 static PyObject * | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
935 VimEvalPy(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
936 { |
3618 | 937 typval_T *our_tv; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
938 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
939 char_u *expr; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
940 PyObject *todecref; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
941 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
942 if (!(expr = StringToChars(string, &todecref))) |
3618 | 943 return NULL; |
944 | |
945 Py_BEGIN_ALLOW_THREADS | |
946 Python_Lock_Vim(); | |
4498 | 947 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
948 our_tv = eval_expr(expr, NULL); |
3618 | 949 Python_Release_Vim(); |
950 Py_END_ALLOW_THREADS | |
951 | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
952 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
953 |
4498 | 954 if (VimTryEnd()) |
955 return NULL; | |
956 | |
3618 | 957 if (our_tv == NULL) |
958 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
959 PyErr_SET_VIM(N_("invalid expression")); |
3618 | 960 return NULL; |
961 } | |
962 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
963 ret = ConvertToPyObject(our_tv); |
3618 | 964 Py_BEGIN_ALLOW_THREADS |
965 Python_Lock_Vim(); | |
966 free_tv(our_tv); | |
967 Python_Release_Vim(); | |
968 Py_END_ALLOW_THREADS | |
969 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
970 return ret; |
3618 | 971 } |
972 | |
973 static PyObject * | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
974 VimStrwidth(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
975 { |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
976 char_u *str; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
977 PyObject *todecref; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
978 int len; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
979 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
980 if (!(str = StringToChars(string, &todecref))) |
3618 | 981 return NULL; |
982 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
983 len = mb_string2cells(str, (int)STRLEN(str)); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
984 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
985 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
986 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
987 return PyLong_FromLong(len); |
3618 | 988 } |
989 | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
990 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
991 _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
992 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
993 PyObject *ret; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
994 PyObject *newwd; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
995 PyObject *todecref; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
996 char_u *new_dir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
997 |
4754
be1e4acb30ca
updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents:
4722
diff
changeset
|
998 if (_chdir == NULL) |
be1e4acb30ca
updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents:
4722
diff
changeset
|
999 return NULL; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1000 if (!(ret = PyObject_Call(_chdir, args, kwargs))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1001 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1002 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1003 if (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL))) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1004 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1005 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1006 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1007 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1008 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1009 if (!(new_dir = StringToChars(newwd, &todecref))) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1010 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1011 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1012 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1013 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1014 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1015 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1016 VimTryStart(); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1017 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1018 if (vim_chdir(new_dir)) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1019 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1020 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1021 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1022 Py_XDECREF(todecref); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1023 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1024 if (VimTryEnd()) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1025 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1026 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1027 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
|
1028 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1029 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1030 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1031 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1032 Py_XDECREF(todecref); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1033 |
16576
bcc343175103
patch 8.1.1291: not easy to change directory and restore
Bram Moolenaar <Bram@vim.org>
parents:
16427
diff
changeset
|
1034 post_chdir(CDSCOPE_GLOBAL); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1035 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1036 if (VimTryEnd()) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1037 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1038 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1039 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1040 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1041 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1042 return ret; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1043 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1044 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1045 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1046 VimChdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1047 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1048 return _VimChdir(py_chdir, args, kwargs); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1049 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1050 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1051 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1052 VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1053 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1054 return _VimChdir(py_fchdir, args, kwargs); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1055 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1056 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1057 typedef struct { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1058 PyObject *callable; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1059 PyObject *result; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1060 } map_rtp_data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1061 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1062 static void |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1063 map_rtp_callback(char_u *path, void *_data) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1064 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1065 void **data = (void **) _data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1066 PyObject *pathObject; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1067 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
|
1068 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1069 if (!(pathObject = PyString_FromString((char *)path))) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1070 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1071 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1072 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1073 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1074 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1075 mr_data->result = PyObject_CallFunctionObjArgs(mr_data->callable, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1076 pathObject, NULL); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1077 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1078 Py_DECREF(pathObject); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1079 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1080 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
|
1081 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1082 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1083 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1084 Py_DECREF(mr_data->result); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1085 mr_data->result = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1086 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1087 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1088 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1089 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1090 VimForeachRTP(PyObject *self UNUSED, PyObject *callable) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1091 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1092 map_rtp_data data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1093 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1094 data.callable = callable; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1095 data.result = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1096 |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7949
diff
changeset
|
1097 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
|
1098 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1099 if (data.result == NULL) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1100 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1101 if (PyErr_Occurred()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1102 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1103 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1104 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1105 Py_INCREF(Py_None); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1106 return Py_None; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1107 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1108 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1109 return data.result; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1110 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1111 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1112 /* |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1113 * _vim_runtimepath_ special path implementation. |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1114 */ |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1115 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1116 static void |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1117 map_finder_callback(char_u *path, void *_data) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1118 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1119 void **data = (void **) _data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1120 PyObject *list = *((PyObject **) data); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1121 PyObject *pathObject1, *pathObject2; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1122 char *pathbuf; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1123 size_t pathlen; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1124 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1125 pathlen = STRLEN(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1126 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1127 #if PY_MAJOR_VERSION < 3 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1128 # define PY_MAIN_DIR_STRING "python2" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1129 #else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1130 # define PY_MAIN_DIR_STRING "python3" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1131 #endif |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1132 #define PY_ALTERNATE_DIR_STRING "pythonx" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1133 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1134 #define PYTHONX_STRING_LENGTH 7 // STRLEN("pythonx") |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1135 if (!(pathbuf = PyMem_New(char, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1136 pathlen + STRLEN(PATHSEPSTR) + PYTHONX_STRING_LENGTH + 1))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1137 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1138 PyErr_NoMemory(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1139 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1140 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1141 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1142 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1143 mch_memmove(pathbuf, path, pathlen + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1144 add_pathsep((char_u *) pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1145 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1146 pathlen = STRLEN(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1147 mch_memmove(pathbuf + pathlen, PY_MAIN_DIR_STRING, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1148 PYTHONX_STRING_LENGTH + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1149 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1150 if (!(pathObject1 = PyString_FromString(pathbuf))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1151 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1152 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1153 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1154 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1155 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1156 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1157 mch_memmove(pathbuf + pathlen, PY_ALTERNATE_DIR_STRING, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1158 PYTHONX_STRING_LENGTH + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1159 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1160 if (!(pathObject2 = PyString_FromString(pathbuf))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1161 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1162 Py_DECREF(pathObject1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1163 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1164 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1165 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1166 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1167 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1168 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1169 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1170 if (PyList_Append(list, pathObject1) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1171 || PyList_Append(list, pathObject2)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1172 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1173 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1174 Py_DECREF(pathObject1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1175 Py_DECREF(pathObject2); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1176 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1177 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1178 static PyObject * |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1179 Vim_GetPaths(PyObject *self UNUSED) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1180 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1181 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1182 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1183 if (!(ret = PyList_New(0))) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1184 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1185 |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7949
diff
changeset
|
1186 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
|
1187 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1188 if (PyErr_Occurred()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1189 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1190 Py_DECREF(ret); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1191 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1192 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1193 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1194 return ret; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1195 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1196 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1197 #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
|
1198 static PyObject * |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1199 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
|
1200 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1201 char *fullname; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1202 PyObject *paths; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1203 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
|
1204 PyObject *spec; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1205 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1206 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
|
1207 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1208 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1209 if (!(paths = Vim_GetPaths(self))) |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1210 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1211 |
16140
ab815ed87969
patch 8.1.1075: function reference count wrong in Python code
Bram Moolenaar <Bram@vim.org>
parents:
16080
diff
changeset
|
1212 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
|
1213 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1214 Py_DECREF(paths); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1215 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1216 if (!spec) |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1217 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1218 if (PyErr_Occurred()) |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1219 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1220 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1221 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
|
1222 return Py_None; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1223 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1224 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1225 return spec; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1226 } |
16718
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1227 |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1228 static PyObject * |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1229 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
|
1230 { |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1231 // 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
|
1232 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
|
1233 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
|
1234 } |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1235 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1236 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1237 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
|
1238 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1239 PyObject *fd, *pathname, *description; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1240 |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1241 if (!PyTuple_Check(find_module_result)) |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1242 { |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1243 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1244 N_("expected 3-tuple as imp.find_module() result, but got %s"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1245 Py_TYPE_NAME(find_module_result)); |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1246 return NULL; |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1247 } |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1248 if (PyTuple_GET_SIZE(find_module_result) != 3) |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1249 { |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1250 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1251 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
|
1252 "tuple of size %d"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1253 (int) PyTuple_GET_SIZE(find_module_result)); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1254 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1255 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1256 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1257 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
|
1258 || !(pathname = PyTuple_GET_ITEM(find_module_result, 1)) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1259 || !(description = PyTuple_GET_ITEM(find_module_result, 2))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1260 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1261 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1262 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
|
1263 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1264 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1265 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1266 return PyObject_CallFunction(py_load_module, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1267 "s#OOO", name, len, fd, pathname, description); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1268 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1269 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1270 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1271 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
|
1272 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1273 PyObject *find_module_result; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1274 PyObject *module; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1275 char *dot; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1276 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1277 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
|
1278 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1279 /* |
4859
e48cabe98453
updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents:
4855
diff
changeset
|
1280 * 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
|
1281 * first component |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1282 */ |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1283 PyObject *newest_path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1284 int partlen = (int) (dot - 1 - tail); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1285 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1286 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
|
1287 "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
|
1288 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1289 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
|
1290 PyErr_Clear(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1291 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
|
1292 } |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1293 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1294 if (!(module = call_load_module( |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1295 fullname, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1296 ((int) (tail - fullname)) + partlen, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1297 find_module_result))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1298 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1299 Py_DECREF(find_module_result); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1300 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1301 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1302 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1303 Py_DECREF(find_module_result); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1304 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1305 if (!(newest_path = PyObject_GetAttrString(module, "__path__"))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1306 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1307 Py_DECREF(module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1308 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1309 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1310 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1311 Py_DECREF(module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1312 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1313 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
|
1314 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1315 Py_DECREF(newest_path); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1316 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1317 return find_module_result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1318 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1319 else |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1320 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1321 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
|
1322 "sO", tail, new_path))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1323 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1324 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
|
1325 PyErr_Clear(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1326 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1327 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1328 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1329 return find_module_result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1330 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1331 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1332 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1333 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1334 FinderFindModule(PyObject *self, PyObject *args) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1335 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1336 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
|
1337 PyObject *result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1338 PyObject *new_path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1339 LoaderObject *loader; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1340 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1341 if (!PyArg_ParseTuple(args, "s", &fullname)) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1342 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1343 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1344 if (!(new_path = Vim_GetPaths(self))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1345 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1346 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1347 result = find_module(fullname, fullname, new_path); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1348 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1349 Py_DECREF(new_path); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1350 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1351 if (!result) |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1352 { |
4984
5b2c8f3b3906
updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
1353 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
|
1354 return NULL; |
4984
5b2c8f3b3906
updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
1355 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1356 Py_INCREF(Py_None); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1357 return Py_None; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1358 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1359 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1360 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
|
1361 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1362 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
|
1363 PyErr_NoMemory(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1364 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1365 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1366 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1367 if (!(loader = PyObject_NEW(LoaderObject, &LoaderType))) |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1368 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1369 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
|
1370 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
|
1371 return NULL; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1372 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1373 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1374 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
|
1375 loader->result = result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1376 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1377 return (PyObject *) loader; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1378 } |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1379 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1380 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1381 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1382 VimPathHook(PyObject *self UNUSED, PyObject *args) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1383 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1384 char *path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1385 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1386 if (PyArg_ParseTuple(args, "s", &path) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1387 && STRCMP(path, vim_special_path) == 0) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1388 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1389 Py_INCREF(vim_module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1390 return vim_module; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1391 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1392 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1393 PyErr_Clear(); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1394 PyErr_SetNone(PyExc_ImportError); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1395 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1396 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1397 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1398 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1399 * Vim module - Definitions |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1400 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1401 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1402 static struct PyMethodDef VimMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1403 // name, function, calling, documentation |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1404 {"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
|
1405 {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" }, |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1406 {"bindeval", VimEvalPy, METH_O, "Like eval(), but returns objects attached to vim ones"}, |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1407 {"strwidth", VimStrwidth, METH_O, "Screen string width, counts <Tab> as having width 1"}, |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1408 {"chdir", (PyCFunction)VimChdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1409 {"fchdir", (PyCFunction)VimFchdir, METH_VARARGS|METH_KEYWORDS, "Change directory"}, |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1410 {"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
|
1411 #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
|
1412 {"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
|
1413 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1414 {"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
|
1415 {"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
|
1416 {"_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
|
1417 { 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
|
1418 }; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1419 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1420 /* |
4397 | 1421 * 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
|
1422 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1423 |
4397 | 1424 static PyTypeObject IterType; |
1425 | |
1426 typedef PyObject *(*nextfun)(void **); | |
1427 typedef void (*destructorfun)(void *); | |
4433 | 1428 typedef int (*traversefun)(void *, visitproc, void *); |
1429 typedef int (*clearfun)(void **); | |
4397 | 1430 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1431 // 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
|
1432 // 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
|
1433 // bunch of objects. |
4319 | 1434 typedef struct |
1435 { | |
1436 PyObject_HEAD | |
4397 | 1437 void *cur; |
1438 nextfun next; | |
1439 destructorfun destruct; | |
4433 | 1440 traversefun traverse; |
1441 clearfun clear; | |
4397 | 1442 } IterObject; |
1443 | |
1444 static PyObject * | |
4433 | 1445 IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse, |
1446 clearfun clear) | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1447 { |
4397 | 1448 IterObject *self; |
1449 | |
4500 | 1450 self = PyObject_GC_New(IterObject, &IterType); |
4397 | 1451 self->cur = start; |
1452 self->next = next; | |
1453 self->destruct = destruct; | |
4433 | 1454 self->traverse = traverse; |
1455 self->clear = clear; | |
4397 | 1456 |
1457 return (PyObject *)(self); | |
1458 } | |
1459 | |
1460 static void | |
4488 | 1461 IterDestructor(IterObject *self) |
4397 | 1462 { |
4500 | 1463 PyObject_GC_UnTrack((void *)(self)); |
4488 | 1464 self->destruct(self->cur); |
4500 | 1465 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
|
1466 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1467 |
4433 | 1468 static int |
4488 | 1469 IterTraverse(IterObject *self, visitproc visit, void *arg) |
4433 | 1470 { |
4488 | 1471 if (self->traverse != NULL) |
1472 return self->traverse(self->cur, visit, arg); | |
4433 | 1473 else |
1474 return 0; | |
1475 } | |
1476 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1477 // Mac OSX defines clear() somewhere. |
4438 | 1478 #ifdef clear |
1479 # undef clear | |
1480 #endif | |
1481 | |
4433 | 1482 static int |
4488 | 1483 IterClear(IterObject *self) |
4433 | 1484 { |
4488 | 1485 if (self->clear != NULL) |
1486 return self->clear(&self->cur); | |
4433 | 1487 else |
1488 return 0; | |
1489 } | |
1490 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1491 static PyObject * |
4488 | 1492 IterNext(IterObject *self) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1493 { |
4488 | 1494 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
|
1495 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1496 |
4397 | 1497 static PyObject * |
1498 IterIter(PyObject *self) | |
1499 { | |
4609
12421d8a45d5
updated for version 7.3.1052
Bram Moolenaar <bram@vim.org>
parents:
4607
diff
changeset
|
1500 Py_INCREF(self); |
4397 | 1501 return self; |
1502 } | |
4393 | 1503 |
3618 | 1504 typedef struct pylinkedlist_S { |
1505 struct pylinkedlist_S *pll_next; | |
1506 struct pylinkedlist_S *pll_prev; | |
1507 PyObject *pll_obj; | |
1508 } pylinkedlist_T; | |
1509 | |
1510 static pylinkedlist_T *lastdict = NULL; | |
1511 static pylinkedlist_T *lastlist = NULL; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
1512 static pylinkedlist_T *lastfunc = NULL; |
3618 | 1513 |
1514 static void | |
1515 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last) | |
1516 { | |
1517 if (ref->pll_prev == NULL) | |
1518 { | |
1519 if (ref->pll_next == NULL) | |
1520 { | |
1521 *last = NULL; | |
1522 return; | |
1523 } | |
1524 } | |
1525 else | |
1526 ref->pll_prev->pll_next = ref->pll_next; | |
1527 | |
1528 if (ref->pll_next == NULL) | |
1529 *last = ref->pll_prev; | |
1530 else | |
1531 ref->pll_next->pll_prev = ref->pll_prev; | |
1532 } | |
1533 | |
1534 static void | |
1535 pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last) | |
1536 { | |
1537 if (*last == NULL) | |
1538 ref->pll_prev = NULL; | |
1539 else | |
1540 { | |
1541 (*last)->pll_next = ref; | |
1542 ref->pll_prev = *last; | |
1543 } | |
1544 ref->pll_next = NULL; | |
1545 ref->pll_obj = self; | |
1546 *last = ref; | |
1547 } | |
1548 | |
1549 static PyTypeObject DictionaryType; | |
1550 | |
1551 typedef struct | |
1552 { | |
1553 PyObject_HEAD | |
1554 dict_T *dict; | |
1555 pylinkedlist_T ref; | |
1556 } DictionaryObject; | |
1557 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1558 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1559 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1560 #define NEW_DICTIONARY(dict) DictionaryNew(&DictionaryType, dict) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1561 |
3618 | 1562 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1563 DictionaryNew(PyTypeObject *subtype, dict_T *dict) |
3618 | 1564 { |
1565 DictionaryObject *self; | |
1566 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1567 self = (DictionaryObject *) subtype->tp_alloc(subtype, 0); |
3618 | 1568 if (self == NULL) |
1569 return NULL; | |
1570 self->dict = dict; | |
1571 ++dict->dv_refcount; | |
1572 | |
1573 pyll_add((PyObject *)(self), &self->ref, &lastdict); | |
1574 | |
1575 return (PyObject *)(self); | |
1576 } | |
1577 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1578 static dict_T * |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1579 py_dict_alloc(void) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1580 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1581 dict_T *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1582 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1583 if (!(ret = dict_alloc())) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1584 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1585 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1586 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1587 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1588 ++ret->dv_refcount; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1589 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1590 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1591 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1592 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1593 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1594 DictionaryConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1595 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1596 DictionaryObject *self; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1597 dict_T *dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1598 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1599 if (!(dict = py_dict_alloc())) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1600 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1601 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1602 self = (DictionaryObject *) DictionaryNew(subtype, dict); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1603 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1604 --dict->dv_refcount; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1605 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1606 if (kwargs || PyTuple_Size(args)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1607 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1608 PyObject *tmp; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1609 if (!(tmp = DictionaryUpdate(self, args, kwargs))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1610 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1611 Py_DECREF(self); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1612 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1613 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1614 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1615 Py_DECREF(tmp); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1616 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1617 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1618 return (PyObject *)(self); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1619 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1620 |
4319 | 1621 static void |
4488 | 1622 DictionaryDestructor(DictionaryObject *self) |
4319 | 1623 { |
4488 | 1624 pyll_remove(&self->ref, &lastdict); |
1625 dict_unref(self->dict); | |
4319 | 1626 |
1627 DESTRUCTOR_FINISH(self); | |
1628 } | |
1629 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1630 static char *DictionaryAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1631 "locked", "scope", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1632 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1633 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1634 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1635 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1636 DictionaryDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1637 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1638 return ObjectDir(self, DictionaryAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1639 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1640 |
3618 | 1641 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1642 DictionarySetattr(DictionaryObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1643 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1644 if (valObject == NULL) |
3828 | 1645 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1646 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1647 N_("cannot delete vim.Dictionary attributes")); |
3828 | 1648 return -1; |
1649 } | |
1650 | |
1651 if (strcmp(name, "locked") == 0) | |
1652 { | |
4488 | 1653 if (self->dict->dv_lock == VAR_FIXED) |
3828 | 1654 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1655 PyErr_SET_STRING(PyExc_TypeError, |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1656 N_("cannot modify fixed dictionary")); |
3828 | 1657 return -1; |
1658 } | |
1659 else | |
1660 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1661 int istrue = PyObject_IsTrue(valObject); |
4411 | 1662 if (istrue == -1) |
1663 return -1; | |
1664 else if (istrue) | |
4488 | 1665 self->dict->dv_lock = VAR_LOCKED; |
3828 | 1666 else |
4488 | 1667 self->dict->dv_lock = 0; |
3828 | 1668 } |
1669 return 0; | |
1670 } | |
1671 else | |
1672 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1673 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name); |
3828 | 1674 return -1; |
1675 } | |
1676 } | |
1677 | |
1678 static PyInt | |
4488 | 1679 DictionaryLength(DictionaryObject *self) |
3618 | 1680 { |
4488 | 1681 return ((PyInt) (self->dict->dv_hashtab.ht_used)); |
3618 | 1682 } |
1683 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1684 #define DICT_FLAG_HAS_DEFAULT 0x01 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1685 #define DICT_FLAG_POP 0x02 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1686 #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
|
1687 #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
|
1688 #define DICT_FLAG_RETURN_PAIR 0x10 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1689 |
3618 | 1690 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1691 _DictionaryItem(DictionaryObject *self, PyObject *args, int flags) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1692 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1693 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1694 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
|
1695 PyObject *ret; |
3618 | 1696 char_u *key; |
3792 | 1697 dictitem_T *di; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1698 dict_T *dict = self->dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1699 hashitem_T *hi; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1700 PyObject *todecref; |
3618 | 1701 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1702 if (flags & DICT_FLAG_HAS_DEFAULT) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1703 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1704 if (!PyArg_ParseTuple(args, "O|O", &keyObject, &defObject)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1705 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1706 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1707 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1708 keyObject = args; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1709 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1710 if (flags & DICT_FLAG_RETURN_BOOL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1711 defObject = Py_False; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1712 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1713 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1714 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1715 |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1716 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1717 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1718 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
1719 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1720 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1721 } |
3792 | 1722 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1723 hi = hash_find(&dict->dv_hashtab, key); |
3792 | 1724 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1725 Py_XDECREF(todecref); |
3824 | 1726 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1727 if (HASHITEM_EMPTY(hi)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1728 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1729 if (defObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1730 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1731 Py_INCREF(defObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1732 return defObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1733 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1734 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1735 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1736 PyErr_SetObject(PyExc_KeyError, keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1737 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1738 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1739 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1740 else if (flags & DICT_FLAG_RETURN_BOOL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1741 { |
5666 | 1742 ret = Py_True; |
1743 Py_INCREF(ret); | |
1744 return ret; | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1745 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1746 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1747 di = dict_lookup(hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1748 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1749 if (!(ret = ConvertToPyObject(&di->di_tv))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1750 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1751 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1752 if (flags & DICT_FLAG_POP) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1753 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1754 if (dict->dv_lock) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1755 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1756 RAISE_LOCKED_DICTIONARY; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1757 Py_DECREF(ret); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1758 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1759 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1760 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1761 hash_remove(&dict->dv_hashtab, hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1762 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1763 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1764 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1765 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1766 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1767 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1768 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1769 DictionaryItem(DictionaryObject *self, PyObject *keyObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1770 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1771 return _DictionaryItem(self, keyObject, 0); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1772 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1773 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1774 static int |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1775 DictionaryContains(DictionaryObject *self, PyObject *keyObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1776 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1777 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
|
1778 int ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1779 |
5426 | 1780 if (rObj == NULL) |
1781 return -1; | |
1782 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1783 ret = (rObj == Py_True); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1784 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
1785 Py_DECREF(rObj); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1786 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1787 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1788 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1789 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1790 typedef struct |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1791 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1792 hashitem_T *ht_array; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1793 long_u ht_used; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1794 hashtab_T *ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1795 hashitem_T *hi; |
4667
9e7ef781d494
updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents:
4659
diff
changeset
|
1796 long_u todo; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1797 } dictiterinfo_T; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1798 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1799 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1800 DictionaryIterNext(dictiterinfo_T **dii) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1801 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1802 PyObject *ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1803 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1804 if (!(*dii)->todo) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1805 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1806 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1807 if ((*dii)->ht->ht_array != (*dii)->ht_array || |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1808 (*dii)->ht->ht_used != (*dii)->ht_used) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1809 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1810 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1811 N_("hashtab changed during iteration")); |
3792 | 1812 return NULL; |
1813 } | |
3618 | 1814 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1815 while (((*dii)->todo) && HASHITEM_EMPTY((*dii)->hi)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1816 ++((*dii)->hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1817 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1818 --((*dii)->todo); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1819 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1820 if (!(ret = PyBytes_FromString((char *)(*dii)->hi->hi_key))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1821 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1822 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1823 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1824 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1825 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1826 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1827 DictionaryIter(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1828 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1829 dictiterinfo_T *dii; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1830 hashtab_T *ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1831 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1832 if (!(dii = PyMem_New(dictiterinfo_T, 1))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1833 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1834 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1835 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1836 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1837 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1838 ht = &self->dict->dv_hashtab; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1839 dii->ht_array = ht->ht_array; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1840 dii->ht_used = ht->ht_used; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1841 dii->ht = ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1842 dii->hi = dii->ht_array; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1843 dii->todo = dii->ht_used; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1844 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1845 return IterNew(dii, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1846 (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1847 NULL, NULL); |
3618 | 1848 } |
1849 | |
1850 static PyInt | |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1851 DictionaryAssItem( |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1852 DictionaryObject *self, PyObject *keyObject, PyObject *valObject) |
3618 | 1853 { |
1854 char_u *key; | |
1855 typval_T tv; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1856 dict_T *dict = self->dict; |
3618 | 1857 dictitem_T *di; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1858 PyObject *todecref; |
3618 | 1859 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1860 if (dict->dv_lock) |
3618 | 1861 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1862 RAISE_LOCKED_DICTIONARY; |
3618 | 1863 return -1; |
1864 } | |
1865 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1866 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1867 return -1; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
1868 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1869 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1870 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1871 RAISE_NO_EMPTY_KEYS; |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1872 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1873 return -1; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1874 } |
3618 | 1875 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1876 di = dict_find(dict, key, -1); |
3618 | 1877 |
1878 if (valObject == NULL) | |
1879 { | |
3636 | 1880 hashitem_T *hi; |
1881 | |
3618 | 1882 if (di == NULL) |
1883 { | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1884 Py_XDECREF(todecref); |
4403 | 1885 PyErr_SetObject(PyExc_KeyError, keyObject); |
3618 | 1886 return -1; |
1887 } | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1888 hi = hash_find(&dict->dv_hashtab, di->di_key); |
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1889 hash_remove(&dict->dv_hashtab, hi); |
3618 | 1890 dictitem_free(di); |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1891 Py_XDECREF(todecref); |
3618 | 1892 return 0; |
1893 } | |
1894 | |
1895 if (ConvertFromPyObject(valObject, &tv) == -1) | |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1896 { |
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1897 Py_XDECREF(todecref); |
3618 | 1898 return -1; |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1899 } |
3618 | 1900 |
1901 if (di == NULL) | |
1902 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1903 if (!(di = dictitem_alloc(key))) |
3618 | 1904 { |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1905 Py_XDECREF(todecref); |
3618 | 1906 PyErr_NoMemory(); |
1907 return -1; | |
1908 } | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1909 di->di_tv.v_type = VAR_UNKNOWN; |
3618 | 1910 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1911 if (dict_add(dict, di) == FAIL) |
3618 | 1912 { |
1913 vim_free(di); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1914 dictitem_free(di); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1915 RAISE_KEY_ADD_FAIL(key); |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1916 Py_XDECREF(todecref); |
3618 | 1917 return -1; |
1918 } | |
1919 } | |
1920 else | |
1921 clear_tv(&di->di_tv); | |
1922 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1923 Py_XDECREF(todecref); |
3618 | 1924 |
1925 copy_tv(&tv, &di->di_tv); | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1926 clear_tv(&tv); |
3618 | 1927 return 0; |
1928 } | |
1929 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1930 typedef PyObject *(*hi_to_py)(hashitem_T *); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1931 |
3618 | 1932 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1933 DictionaryListObjects(DictionaryObject *self, hi_to_py hiconvert) |
3618 | 1934 { |
4488 | 1935 dict_T *dict = self->dict; |
3618 | 1936 long_u todo = dict->dv_hashtab.ht_used; |
1937 Py_ssize_t i = 0; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1938 PyObject *ret; |
3618 | 1939 hashitem_T *hi; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1940 PyObject *newObj; |
3618 | 1941 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1942 ret = PyList_New(todo); |
3618 | 1943 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi) |
1944 { | |
1945 if (!HASHITEM_EMPTY(hi)) | |
1946 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1947 if (!(newObj = hiconvert(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1948 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1949 Py_DECREF(ret); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1950 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1951 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1952 PyList_SET_ITEM(ret, i, newObj); |
3618 | 1953 --todo; |
1954 ++i; | |
1955 } | |
1956 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1957 return ret; |
3618 | 1958 } |
1959 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1960 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1961 dict_key(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1962 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1963 return PyBytes_FromString((char *)(hi->hi_key)); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1964 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1965 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1966 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1967 DictionaryListKeys(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1968 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1969 return DictionaryListObjects(self, dict_key); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1970 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1971 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1972 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1973 dict_val(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1974 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1975 dictitem_T *di; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1976 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1977 di = dict_lookup(hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1978 return ConvertToPyObject(&di->di_tv); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1979 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1980 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1981 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1982 DictionaryListValues(DictionaryObject *self) |
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 return DictionaryListObjects(self, dict_val); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1985 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1986 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1987 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1988 dict_item(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1989 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1990 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1991 PyObject *valObject; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1992 PyObject *ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1993 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1994 if (!(keyObject = dict_key(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1995 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1996 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1997 if (!(valObject = dict_val(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1998 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1999 Py_DECREF(keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2000 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2001 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2002 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2003 ret = Py_BuildValue("(OO)", keyObject, valObject); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2004 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2005 Py_DECREF(keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2006 Py_DECREF(valObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2007 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2008 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2009 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2010 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2011 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2012 DictionaryListItems(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2013 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2014 return DictionaryListObjects(self, dict_item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2015 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2016 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2017 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2018 DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs) |
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 dict_T *dict = self->dict; |
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 if (dict->dv_lock) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2023 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2024 RAISE_LOCKED_DICTIONARY; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2025 return NULL; |
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 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2028 if (kwargs) |
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 typval_T tv; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2031 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2032 if (ConvertFromPyMapping(kwargs, &tv) == -1) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2033 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2034 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2035 VimTryStart(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2036 dict_extend(self->dict, tv.vval.v_dict, (char_u *) "force"); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2037 clear_tv(&tv); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2038 if (VimTryEnd()) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2039 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2040 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2041 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2042 { |
5659 | 2043 PyObject *obj = NULL; |
2044 | |
2045 if (!PyArg_ParseTuple(args, "|O", &obj)) | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2046 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2047 |
5659 | 2048 if (obj == NULL) |
2049 { | |
2050 Py_INCREF(Py_None); | |
2051 return Py_None; | |
2052 } | |
2053 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2054 if (PyObject_HasAttrString(obj, "keys")) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2055 return DictionaryUpdate(self, NULL, obj); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2056 else |
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 PyObject *iterator; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2059 PyObject *item; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2060 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2061 if (!(iterator = PyObject_GetIter(obj))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2062 return NULL; |
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 while ((item = PyIter_Next(iterator))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2065 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2066 PyObject *fast; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2067 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2068 PyObject *valObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2069 PyObject *todecref; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2070 char_u *key; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2071 dictitem_T *di; |
12812
381e67ccf02c
patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents:
12806
diff
changeset
|
2072 hashitem_T *hi; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2073 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2074 if (!(fast = PySequence_Fast(item, ""))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2075 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2076 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2077 Py_DECREF(item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2078 return NULL; |
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 Py_DECREF(item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2082 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2083 if (PySequence_Fast_GET_SIZE(fast) != 2) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2084 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2085 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2086 Py_DECREF(fast); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2087 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2088 N_("expected sequence element of size 2, " |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2089 "but got sequence of size %d"), |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
2090 (int) PySequence_Fast_GET_SIZE(fast)); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2091 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2092 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2093 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2094 keyObject = PySequence_Fast_GET_ITEM(fast, 0); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2095 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2096 if (!(key = StringToChars(keyObject, &todecref))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2097 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2098 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2099 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2100 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2101 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2102 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2103 di = dictitem_alloc(key); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2104 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2105 Py_XDECREF(todecref); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2106 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2107 if (di == NULL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2108 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2109 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2110 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2111 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2112 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2113 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2114 di->di_tv.v_type = VAR_UNKNOWN; |
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 valObject = PySequence_Fast_GET_ITEM(fast, 1); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2117 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2118 if (ConvertFromPyObject(valObject, &di->di_tv) == -1) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2119 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2120 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2121 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2122 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2123 return NULL; |
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 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2126 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2127 |
12812
381e67ccf02c
patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents:
12806
diff
changeset
|
2128 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
|
2129 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
|
2130 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2131 RAISE_KEY_ADD_FAIL(di->di_key); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2132 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2133 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2134 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2135 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2136 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2137 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2138 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2139 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2140 // 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
|
2141 if (PyErr_Occurred()) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2142 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2143 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2144 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2145 Py_INCREF(Py_None); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2146 return Py_None; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2147 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2148 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2149 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2150 DictionaryGet(DictionaryObject *self, PyObject *args) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2151 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2152 return _DictionaryItem(self, args, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2153 DICT_FLAG_HAS_DEFAULT|DICT_FLAG_NONE_DEFAULT); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2154 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2155 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2156 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2157 DictionaryPop(DictionaryObject *self, PyObject *args) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2158 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2159 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
|
2160 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2161 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2162 static PyObject * |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2163 DictionaryPopItem(DictionaryObject *self) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2164 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2165 hashitem_T *hi; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2166 PyObject *ret; |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2167 PyObject *valObject; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2168 dictitem_T *di; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2169 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2170 if (self->dict->dv_hashtab.ht_used == 0) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2171 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2172 PyErr_SetNone(PyExc_KeyError); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2173 return NULL; |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2174 } |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2175 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2176 hi = self->dict->dv_hashtab.ht_array; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2177 while (HASHITEM_EMPTY(hi)) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2178 ++hi; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2179 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2180 di = dict_lookup(hi); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2181 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2182 if (!(valObject = ConvertToPyObject(&di->di_tv))) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2183 return NULL; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2184 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2185 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
|
2186 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2187 Py_DECREF(valObject); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2188 return NULL; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2189 } |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2190 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2191 hash_remove(&self->dict->dv_hashtab, hi); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2192 dictitem_free(di); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2193 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2194 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2195 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2196 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2197 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2198 DictionaryHasKey(DictionaryObject *self, PyObject *keyObject) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2199 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2200 return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2201 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2202 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2203 static PySequenceMethods DictionaryAsSeq = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2204 0, // sq_length |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2205 0, // sq_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2206 0, // sq_repeat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2207 0, // sq_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2208 0, // sq_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2209 0, // sq_ass_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2210 0, // sq_ass_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2211 (objobjproc) DictionaryContains, // sq_contains |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2212 0, // sq_inplace_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2213 0, // sq_inplace_repeat |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2214 }; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2215 |
4385 | 2216 static PyMappingMethods DictionaryAsMapping = { |
2217 (lenfunc) DictionaryLength, | |
2218 (binaryfunc) DictionaryItem, | |
2219 (objobjargproc) DictionaryAssItem, | |
2220 }; | |
2221 | |
3618 | 2222 static struct PyMethodDef DictionaryMethods[] = { |
4492 | 2223 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""}, |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2224 {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2225 {"items", (PyCFunction)DictionaryListItems, METH_NOARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2226 {"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2227 {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2228 {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""}, |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2229 {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""}, |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2230 {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""}, |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2231 {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2232 { NULL, NULL, 0, NULL} |
3618 | 2233 }; |
2234 | |
2235 static PyTypeObject ListType; | |
2236 | |
2237 typedef struct | |
2238 { | |
2239 PyObject_HEAD | |
2240 list_T *list; | |
2241 pylinkedlist_T ref; | |
2242 } ListObject; | |
2243 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2244 #define NEW_LIST(list) ListNew(&ListType, list) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2245 |
3618 | 2246 static PyObject * |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2247 ListNew(PyTypeObject *subtype, list_T *list) |
3618 | 2248 { |
2249 ListObject *self; | |
2250 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2251 self = (ListObject *) subtype->tp_alloc(subtype, 0); |
3618 | 2252 if (self == NULL) |
2253 return NULL; | |
2254 self->list = list; | |
2255 ++list->lv_refcount; | |
2256 | |
2257 pyll_add((PyObject *)(self), &self->ref, &lastlist); | |
2258 | |
2259 return (PyObject *)(self); | |
2260 } | |
2261 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2262 static list_T * |
5166
467efeee8f9e
updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents:
5139
diff
changeset
|
2263 py_list_alloc(void) |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2264 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2265 list_T *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2266 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2267 if (!(ret = list_alloc())) |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2268 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2269 PyErr_NoMemory(); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2270 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2271 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2272 ++ret->lv_refcount; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2273 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2274 return ret; |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2275 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2276 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2277 static int |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2278 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
|
2279 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2280 PyObject *iterator; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2281 PyObject *item; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2282 listitem_T *li; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2283 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2284 if (!(iterator = PyObject_GetIter(obj))) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2285 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2286 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2287 while ((item = PyIter_Next(iterator))) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2288 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2289 if (!(li = listitem_alloc())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2290 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2291 PyErr_NoMemory(); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2292 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2293 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2294 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2295 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2296 li->li_tv.v_lock = 0; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2297 li->li_tv.v_type = VAR_UNKNOWN; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2298 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2299 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
|
2300 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2301 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2302 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2303 listitem_free(li); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2304 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2305 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2306 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2307 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2308 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2309 list_append(l, li); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2310 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2311 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2312 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2313 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2314 // 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
|
2315 if (PyErr_Occurred()) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2316 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2317 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2318 return 0; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2319 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2320 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2321 static PyObject * |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2322 ListConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2323 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2324 list_T *list; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2325 PyObject *obj = NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2326 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2327 if (kwargs) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2328 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
2329 PyErr_SET_STRING(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2330 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
|
2331 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2332 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2333 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2334 if (!PyArg_ParseTuple(args, "|O", &obj)) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2335 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2336 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2337 if (!(list = py_list_alloc())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2338 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2339 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2340 if (obj) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2341 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2342 PyObject *lookup_dict; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2343 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2344 if (!(lookup_dict = PyDict_New())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2345 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2346 list_unref(list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2347 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2348 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2349 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2350 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
|
2351 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2352 Py_DECREF(lookup_dict); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2353 list_unref(list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2354 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2355 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2356 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2357 Py_DECREF(lookup_dict); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2358 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2359 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2360 return ListNew(subtype, list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2361 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2362 |
4319 | 2363 static void |
4488 | 2364 ListDestructor(ListObject *self) |
4319 | 2365 { |
4488 | 2366 pyll_remove(&self->ref, &lastlist); |
2367 list_unref(self->list); | |
4319 | 2368 |
2369 DESTRUCTOR_FINISH(self); | |
2370 } | |
2371 | |
3618 | 2372 static PyInt |
4488 | 2373 ListLength(ListObject *self) |
3618 | 2374 { |
4488 | 2375 return ((PyInt) (self->list->lv_len)); |
3618 | 2376 } |
2377 | |
2378 static PyObject * | |
5608 | 2379 ListIndex(ListObject *self, Py_ssize_t index) |
3618 | 2380 { |
2381 listitem_T *li; | |
2382 | |
4488 | 2383 if (index >= ListLength(self)) |
3618 | 2384 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2385 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range")); |
3618 | 2386 return NULL; |
2387 } | |
4488 | 2388 li = list_find(self->list, (long) index); |
3618 | 2389 if (li == NULL) |
2390 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2391 // No more suitable format specifications in python-2.3 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2392 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
|
2393 (int) index); |
3618 | 2394 return NULL; |
2395 } | |
2396 return ConvertToPyObject(&li->li_tv); | |
2397 } | |
2398 | |
2399 static PyObject * | |
5608 | 2400 ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t step, |
2401 Py_ssize_t slicelen) | |
3618 | 2402 { |
2403 PyInt i; | |
2404 PyObject *list; | |
5608 | 2405 |
2406 if (step == 0) | |
2407 { | |
2408 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero")); | |
2409 return NULL; | |
2410 } | |
2411 | |
2412 list = PyList_New(slicelen); | |
3618 | 2413 if (list == NULL) |
2414 return NULL; | |
2415 | |
5608 | 2416 for (i = 0; i < slicelen; ++i) |
2417 { | |
2418 PyObject *item; | |
2419 | |
2420 item = ListIndex(self, first + i*step); | |
3618 | 2421 if (item == NULL) |
2422 { | |
2423 Py_DECREF(list); | |
2424 return NULL; | |
2425 } | |
2426 | |
5608 | 2427 PyList_SET_ITEM(list, i, item); |
3618 | 2428 } |
2429 | |
2430 return list; | |
2431 } | |
2432 | |
5608 | 2433 static PyObject * |
2434 ListItem(ListObject *self, PyObject* idx) | |
2435 { | |
2436 #if PY_MAJOR_VERSION < 3 | |
2437 if (PyInt_Check(idx)) | |
2438 { | |
2439 long _idx = PyInt_AsLong(idx); | |
2440 return ListIndex(self, _idx); | |
2441 } | |
2442 else | |
2443 #endif | |
2444 if (PyLong_Check(idx)) | |
2445 { | |
2446 long _idx = PyLong_AsLong(idx); | |
2447 return ListIndex(self, _idx); | |
2448 } | |
2449 else if (PySlice_Check(idx)) | |
2450 { | |
2451 Py_ssize_t start, stop, step, slicelen; | |
2452 | |
5768 | 2453 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), |
5608 | 2454 &start, &stop, &step, &slicelen) < 0) |
2455 return NULL; | |
2456 return ListSlice(self, start, step, slicelen); | |
2457 } | |
2458 else | |
2459 { | |
2460 RAISE_INVALID_INDEX_TYPE(idx); | |
2461 return NULL; | |
2462 } | |
2463 } | |
2464 | |
2465 static void | |
2466 list_restore(Py_ssize_t numadded, Py_ssize_t numreplaced, Py_ssize_t slicelen, | |
2467 list_T *l, listitem_T **lis, listitem_T *lastaddedli) | |
2468 { | |
2469 while (numreplaced--) | |
2470 { | |
2471 list_insert(l, lis[numreplaced], lis[slicelen + numreplaced]); | |
2472 listitem_remove(l, lis[slicelen + numreplaced]); | |
2473 } | |
2474 while (numadded--) | |
2475 { | |
2476 listitem_T *next; | |
2477 | |
2478 next = lastaddedli->li_prev; | |
2479 listitem_remove(l, lastaddedli); | |
2480 lastaddedli = next; | |
2481 } | |
2482 } | |
2483 | |
2484 static int | |
2485 ListAssSlice(ListObject *self, Py_ssize_t first, | |
2486 Py_ssize_t step, Py_ssize_t slicelen, PyObject *obj) | |
2487 { | |
2488 PyObject *iterator; | |
2489 PyObject *item; | |
2490 listitem_T *li; | |
2491 listitem_T *lastaddedli = NULL; | |
2492 listitem_T *next; | |
2493 typval_T v; | |
2494 list_T *l = self->list; | |
2495 PyInt i; | |
2496 PyInt j; | |
2497 PyInt numreplaced = 0; | |
2498 PyInt numadded = 0; | |
2499 PyInt size; | |
5655 | 2500 listitem_T **lis = NULL; |
5608 | 2501 |
2502 size = ListLength(self); | |
2503 | |
2504 if (l->lv_lock) | |
2505 { | |
2506 RAISE_LOCKED_LIST; | |
2507 return -1; | |
2508 } | |
2509 | |
2510 if (step == 0) | |
2511 { | |
2512 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero")); | |
2513 return -1; | |
2514 } | |
2515 | |
2516 if (step != 1 && slicelen == 0) | |
2517 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2518 // Nothing to do. Only error out if obj has some items. |
5608 | 2519 int ret = 0; |
2520 | |
2521 if (obj == NULL) | |
2522 return 0; | |
2523 | |
2524 if (!(iterator = PyObject_GetIter(obj))) | |
2525 return -1; | |
2526 | |
2527 if ((item = PyIter_Next(iterator))) | |
2528 { | |
2529 PyErr_FORMAT(PyExc_ValueError, | |
5695 | 2530 N_("attempt to assign sequence of size greater than %d " |
5608 | 2531 "to extended slice"), 0); |
2532 Py_DECREF(item); | |
2533 ret = -1; | |
2534 } | |
2535 Py_DECREF(iterator); | |
2536 return ret; | |
2537 } | |
2538 | |
2539 if (obj != NULL) | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2540 // XXX May allocate zero bytes. |
5608 | 2541 if (!(lis = PyMem_New(listitem_T *, slicelen * 2))) |
2542 { | |
2543 PyErr_NoMemory(); | |
2544 return -1; | |
2545 } | |
2546 | |
2547 if (first == size) | |
2548 li = NULL; | |
2549 else | |
2550 { | |
2551 li = list_find(l, (long) first); | |
2552 if (li == NULL) | |
2553 { | |
2554 PyErr_VIM_FORMAT(N_("internal error: no vim list item %d"), | |
2555 (int)first); | |
2556 if (obj != NULL) | |
2557 PyMem_Free(lis); | |
2558 return -1; | |
2559 } | |
2560 i = slicelen; | |
2561 while (i-- && li != NULL) | |
2562 { | |
2563 j = step; | |
2564 next = li; | |
2565 if (step > 0) | |
2566 while (next != NULL && ((next = next->li_next) != NULL) && --j); | |
2567 else | |
2568 while (next != NULL && ((next = next->li_prev) != NULL) && ++j); | |
2569 | |
2570 if (obj == NULL) | |
2571 listitem_remove(l, li); | |
2572 else | |
2573 lis[slicelen - i - 1] = li; | |
2574 | |
2575 li = next; | |
2576 } | |
2577 if (li == NULL && i != -1) | |
2578 { | |
2579 PyErr_SET_VIM(N_("internal error: not enough list items")); | |
2580 if (obj != NULL) | |
2581 PyMem_Free(lis); | |
2582 return -1; | |
2583 } | |
2584 } | |
2585 | |
2586 if (obj == NULL) | |
2587 return 0; | |
2588 | |
2589 if (!(iterator = PyObject_GetIter(obj))) | |
2590 { | |
2591 PyMem_Free(lis); | |
2592 return -1; | |
2593 } | |
2594 | |
2595 i = 0; | |
2596 while ((item = PyIter_Next(iterator))) | |
2597 { | |
2598 if (ConvertFromPyObject(item, &v) == -1) | |
2599 { | |
2600 Py_DECREF(iterator); | |
2601 Py_DECREF(item); | |
2602 PyMem_Free(lis); | |
2603 return -1; | |
2604 } | |
2605 Py_DECREF(item); | |
2606 if (list_insert_tv(l, &v, numreplaced < slicelen | |
2607 ? lis[numreplaced] | |
2608 : li) == FAIL) | |
2609 { | |
2610 clear_tv(&v); | |
2611 PyErr_SET_VIM(N_("internal error: failed to add item to list")); | |
2612 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); | |
2613 PyMem_Free(lis); | |
2614 return -1; | |
2615 } | |
2616 if (numreplaced < slicelen) | |
2617 { | |
2618 lis[slicelen + numreplaced] = lis[numreplaced]->li_prev; | |
5871 | 2619 vimlist_remove(l, lis[numreplaced], lis[numreplaced]); |
5608 | 2620 numreplaced++; |
2621 } | |
2622 else | |
2623 { | |
2624 if (li) | |
2625 lastaddedli = li->li_prev; | |
2626 else | |
2627 lastaddedli = l->lv_last; | |
2628 numadded++; | |
2629 } | |
2630 clear_tv(&v); | |
2631 if (step != 1 && i >= slicelen) | |
2632 { | |
2633 Py_DECREF(iterator); | |
2634 PyErr_FORMAT(PyExc_ValueError, | |
5695 | 2635 N_("attempt to assign sequence of size greater than %d " |
5668 | 2636 "to extended slice"), (int) slicelen); |
5608 | 2637 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); |
2638 PyMem_Free(lis); | |
2639 return -1; | |
2640 } | |
2641 ++i; | |
2642 } | |
2643 Py_DECREF(iterator); | |
2644 | |
2645 if (step != 1 && i != slicelen) | |
2646 { | |
2647 PyErr_FORMAT2(PyExc_ValueError, | |
5668 | 2648 N_("attempt to assign sequence of size %d to extended slice " |
2649 "of size %d"), (int) i, (int) slicelen); | |
5608 | 2650 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); |
2651 PyMem_Free(lis); | |
2652 return -1; | |
2653 } | |
2654 | |
2655 if (PyErr_Occurred()) | |
2656 { | |
2657 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); | |
2658 PyMem_Free(lis); | |
2659 return -1; | |
2660 } | |
2661 | |
2662 for (i = 0; i < numreplaced; i++) | |
2663 listitem_free(lis[i]); | |
2664 if (step == 1) | |
2665 for (i = numreplaced; i < slicelen; i++) | |
2666 listitem_remove(l, lis[i]); | |
2667 | |
2668 PyMem_Free(lis); | |
2669 | |
2670 return 0; | |
2671 } | |
2672 | |
2673 static int | |
2674 ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj) | |
2675 { | |
2676 typval_T tv; | |
2677 list_T *l = self->list; | |
2678 listitem_T *li; | |
2679 Py_ssize_t length = ListLength(self); | |
2680 | |
2681 if (l->lv_lock) | |
2682 { | |
2683 RAISE_LOCKED_LIST; | |
2684 return -1; | |
2685 } | |
2686 if (index > length || (index == length && obj == NULL)) | |
2687 { | |
2688 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range")); | |
2689 return -1; | |
2690 } | |
2691 | |
2692 if (obj == NULL) | |
2693 { | |
2694 li = list_find(l, (long) index); | |
5871 | 2695 vimlist_remove(l, li, li); |
5608 | 2696 clear_tv(&li->li_tv); |
2697 vim_free(li); | |
2698 return 0; | |
2699 } | |
2700 | |
2701 if (ConvertFromPyObject(obj, &tv) == -1) | |
2702 return -1; | |
2703 | |
2704 if (index == length) | |
2705 { | |
2706 if (list_append_tv(l, &tv) == FAIL) | |
2707 { | |
2708 clear_tv(&tv); | |
2709 PyErr_SET_VIM(N_("failed to add item to list")); | |
2710 return -1; | |
2711 } | |
2712 } | |
2713 else | |
2714 { | |
2715 li = list_find(l, (long) index); | |
2716 clear_tv(&li->li_tv); | |
2717 copy_tv(&tv, &li->li_tv); | |
2718 clear_tv(&tv); | |
2719 } | |
2720 return 0; | |
2721 } | |
2722 | |
2723 static Py_ssize_t | |
2724 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj) | |
2725 { | |
2726 #if PY_MAJOR_VERSION < 3 | |
2727 if (PyInt_Check(idx)) | |
2728 { | |
2729 long _idx = PyInt_AsLong(idx); | |
2730 return ListAssIndex(self, _idx, obj); | |
2731 } | |
2732 else | |
2733 #endif | |
2734 if (PyLong_Check(idx)) | |
2735 { | |
2736 long _idx = PyLong_AsLong(idx); | |
2737 return ListAssIndex(self, _idx, obj); | |
2738 } | |
2739 else if (PySlice_Check(idx)) | |
2740 { | |
2741 Py_ssize_t start, stop, step, slicelen; | |
2742 | |
5768 | 2743 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), |
5608 | 2744 &start, &stop, &step, &slicelen) < 0) |
2745 return -1; | |
2746 return ListAssSlice(self, start, step, slicelen, | |
2747 obj); | |
2748 } | |
2749 else | |
2750 { | |
2751 RAISE_INVALID_INDEX_TYPE(idx); | |
2752 return -1; | |
2753 } | |
2754 } | |
2755 | |
2756 static PyObject * | |
2757 ListConcatInPlace(ListObject *self, PyObject *obj) | |
2758 { | |
2759 list_T *l = self->list; | |
2760 PyObject *lookup_dict; | |
2761 | |
2762 if (l->lv_lock) | |
2763 { | |
2764 RAISE_LOCKED_LIST; | |
2765 return NULL; | |
2766 } | |
2767 | |
2768 if (!(lookup_dict = PyDict_New())) | |
2769 return NULL; | |
2770 | |
2771 if (list_py_concat(l, obj, lookup_dict) == -1) | |
2772 { | |
2773 Py_DECREF(lookup_dict); | |
2774 return NULL; | |
2775 } | |
2776 Py_DECREF(lookup_dict); | |
2777 | |
2778 Py_INCREF(self); | |
2779 return (PyObject *)(self); | |
2780 } | |
2781 | |
4397 | 2782 typedef struct |
2783 { | |
2784 listwatch_T lw; | |
2785 list_T *list; | |
2786 } listiterinfo_T; | |
2787 | |
2788 static void | |
2789 ListIterDestruct(listiterinfo_T *lii) | |
2790 { | |
2791 list_rem_watch(lii->list, &lii->lw); | |
2792 PyMem_Free(lii); | |
2793 } | |
2794 | |
2795 static PyObject * | |
2796 ListIterNext(listiterinfo_T **lii) | |
2797 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2798 PyObject *ret; |
4397 | 2799 |
2800 if (!((*lii)->lw.lw_item)) | |
2801 return NULL; | |
2802 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2803 if (!(ret = ConvertToPyObject(&((*lii)->lw.lw_item->li_tv)))) |
4397 | 2804 return NULL; |
2805 | |
2806 (*lii)->lw.lw_item = (*lii)->lw.lw_item->li_next; | |
2807 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2808 return ret; |
4397 | 2809 } |
2810 | |
2811 static PyObject * | |
4488 | 2812 ListIter(ListObject *self) |
4397 | 2813 { |
2814 listiterinfo_T *lii; | |
4488 | 2815 list_T *l = self->list; |
4397 | 2816 |
2817 if (!(lii = PyMem_New(listiterinfo_T, 1))) | |
2818 { | |
2819 PyErr_NoMemory(); | |
2820 return NULL; | |
2821 } | |
2822 | |
2823 list_add_watch(l, &lii->lw); | |
2824 lii->lw.lw_item = l->lv_first; | |
2825 lii->list = l; | |
2826 | |
2827 return IterNew(lii, | |
4433 | 2828 (destructorfun) ListIterDestruct, (nextfun) ListIterNext, |
2829 NULL, NULL); | |
4397 | 2830 } |
2831 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2832 static char *ListAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2833 "locked", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2834 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2835 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2836 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2837 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2838 ListDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2839 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2840 return ObjectDir(self, ListAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2841 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2842 |
3828 | 2843 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2844 ListSetattr(ListObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2845 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2846 if (valObject == NULL) |
3828 | 2847 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
2848 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2849 N_("cannot delete vim.List attributes")); |
3828 | 2850 return -1; |
2851 } | |
2852 | |
2853 if (strcmp(name, "locked") == 0) | |
2854 { | |
4488 | 2855 if (self->list->lv_lock == VAR_FIXED) |
3828 | 2856 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2857 PyErr_SET_STRING(PyExc_TypeError, N_("cannot modify fixed list")); |
3828 | 2858 return -1; |
2859 } | |
2860 else | |
2861 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2862 int istrue = PyObject_IsTrue(valObject); |
4411 | 2863 if (istrue == -1) |
2864 return -1; | |
2865 else if (istrue) | |
4488 | 2866 self->list->lv_lock = VAR_LOCKED; |
3828 | 2867 else |
4488 | 2868 self->list->lv_lock = 0; |
3828 | 2869 } |
2870 return 0; | |
2871 } | |
2872 else | |
2873 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2874 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name); |
3828 | 2875 return -1; |
2876 } | |
2877 } | |
2878 | |
5608 | 2879 static PySequenceMethods ListAsSeq = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2880 (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
|
2881 (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
|
2882 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
|
2883 (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
|
2884 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
|
2885 (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
|
2886 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
|
2887 0, // sq_contains |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2888 (binaryfunc) ListConcatInPlace,// sq_inplace_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2889 0, // sq_inplace_repeat |
5608 | 2890 }; |
2891 | |
2892 static PyMappingMethods ListAsMapping = { | |
2893 /* mp_length */ (lenfunc) ListLength, | |
2894 /* mp_subscript */ (binaryfunc) ListItem, | |
2895 /* mp_ass_subscript */ (objobjargproc) ListAssItem, | |
2896 }; | |
2897 | |
3618 | 2898 static struct PyMethodDef ListMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2899 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2900 {"__dir__", (PyCFunction)ListDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2901 { NULL, NULL, 0, NULL} |
3618 | 2902 }; |
2903 | |
2904 typedef struct | |
2905 { | |
2906 PyObject_HEAD | |
2907 char_u *name; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2908 int argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2909 typval_T *argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2910 dict_T *self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2911 pylinkedlist_T ref; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2912 int auto_rebind; |
3618 | 2913 } FunctionObject; |
2914 | |
2915 static PyTypeObject FunctionType; | |
2916 | |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2917 #define NEW_FUNCTION(name, argc, argv, self, pt_auto) \ |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2918 FunctionNew(&FunctionType, (name), (argc), (argv), (self), (pt_auto)) |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2919 |
3618 | 2920 static PyObject * |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2921 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
|
2922 dict_T *selfdict, int auto_rebind) |
3618 | 2923 { |
2924 FunctionObject *self; | |
2925 | |
15234
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2926 self = (FunctionObject *)subtype->tp_alloc(subtype, 0); |
3618 | 2927 if (self == NULL) |
2928 return NULL; | |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2929 |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2930 if (isdigit(*name)) |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2931 { |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2932 if (!translated_function_exists(name)) |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2933 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2934 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2935 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
|
2936 return NULL; |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2937 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2938 self->name = vim_strsave(name); |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2939 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2940 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
|
2941 { |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2942 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
|
2943 |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2944 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
|
2945 vim_strchr(name, AUTOLOAD_CHAR) == NULL)) == NULL) |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2946 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2947 PyErr_FORMAT(PyExc_ValueError, |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2948 N_("function %s does not exist"), name); |
4641
59e6c2bd68e3
updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
2949 return NULL; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2950 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2951 |
15234
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2952 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
|
2953 { |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2954 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
|
2955 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
|
2956 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16718
diff
changeset
|
2957 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
|
2958 { |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2959 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
|
2960 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
|
2961 } |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2962 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
|
2963 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
|
2964 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
|
2965 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
|
2966 } |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2967 else |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2968 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
|
2969 } |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2970 |
9725
4a4a71d67131
commit https://github.com/vim/vim/commit/2d3d60a7d4b410668dfc427120205ccf88789db4
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
2971 func_ref(self->name); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2972 self->argc = argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2973 self->argv = argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2974 self->self = selfdict; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2975 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
|
2976 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2977 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2978 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
|
2979 |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2980 return (PyObject *)(self); |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2981 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2982 |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2983 static PyObject * |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2984 FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2985 { |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2986 PyObject *self; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2987 PyObject *selfdictObject; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2988 PyObject *autoRebindObject; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2989 PyObject *argsObject = NULL; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2990 char_u *name; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2991 typval_T selfdicttv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2992 typval_T argstv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2993 list_T *argslist = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2994 dict_T *selfdict = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2995 int argc = 0; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2996 int auto_rebind = TRUE; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2997 typval_T *argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2998 typval_T *curtv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2999 listitem_T *li; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3000 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3001 if (kwargs != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3002 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3003 selfdictObject = PyDict_GetItemString(kwargs, "self"); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3004 if (selfdictObject != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3005 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3006 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3007 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3008 selfdict = selfdicttv.vval.v_dict; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3009 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3010 argsObject = PyDict_GetItemString(kwargs, "args"); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3011 if (argsObject != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3012 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3013 if (ConvertFromPySequence(argsObject, &argstv) == -1) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3014 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3015 dict_unref(selfdict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3016 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3017 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3018 argslist = argstv.vval.v_list; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3019 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3020 argc = argslist->lv_len; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3021 if (argc != 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3022 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3023 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
|
3024 if (argv == NULL) |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3025 { |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3026 PyErr_NoMemory(); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3027 dict_unref(selfdict); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3028 list_unref(argslist); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3029 return NULL; |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3030 } |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3031 curtv = argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3032 for (li = argslist->lv_first; li != NULL; li = li->li_next) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3033 copy_tv(&li->li_tv, curtv++); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3034 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3035 list_unref(argslist); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3036 } |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3037 if (selfdict != NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3038 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3039 auto_rebind = FALSE; |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3040 autoRebindObject = PyDict_GetItemString(kwargs, "auto_rebind"); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3041 if (autoRebindObject != NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3042 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3043 auto_rebind = PyObject_IsTrue(autoRebindObject); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3044 if (auto_rebind == -1) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3045 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3046 dict_unref(selfdict); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3047 list_unref(argslist); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3048 return NULL; |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3049 } |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3050 } |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3051 } |
3618 | 3052 } |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3053 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3054 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
|
3055 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3056 dict_unref(selfdict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3057 while (argc--) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3058 clear_tv(&argv[argc]); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3059 PyMem_Free(argv); |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3060 return NULL; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3061 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3062 |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3063 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
|
3064 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3065 PyMem_Free(name); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3066 |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3067 return self; |
3618 | 3068 } |
3069 | |
4319 | 3070 static void |
4488 | 3071 FunctionDestructor(FunctionObject *self) |
4319 | 3072 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3073 int i; |
4488 | 3074 func_unref(self->name); |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3075 vim_free(self->name); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3076 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
|
3077 clear_tv(&self->argv[i]); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3078 PyMem_Free(self->argv); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3079 dict_unref(self->self); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3080 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3081 pyll_remove(&self->ref, &lastfunc); |
4319 | 3082 |
3083 DESTRUCTOR_FINISH(self); | |
3084 } | |
3085 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3086 static char *FunctionAttrs[] = { |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3087 "softspace", "args", "self", "auto_rebind", |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3088 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3089 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3090 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3091 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3092 FunctionDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3093 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3094 return ObjectDir(self, FunctionAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3095 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3096 |
3618 | 3097 static PyObject * |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3098 FunctionAttr(FunctionObject *self, char *name) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3099 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3100 list_T *list; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3101 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3102 if (strcmp(name, "name") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3103 return PyString_FromString((char *)(self->name)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3104 else if (strcmp(name, "args") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3105 { |
9967
45098d7f72b6
commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents:
9725
diff
changeset
|
3106 if (self->argv == NULL || (list = list_alloc()) == NULL) |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3107 return AlwaysNone(NULL); |
9967
45098d7f72b6
commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents:
9725
diff
changeset
|
3108 |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3109 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
|
3110 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
|
3111 return NEW_LIST(list); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3112 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3113 else if (strcmp(name, "self") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3114 return self->self == NULL |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3115 ? AlwaysNone(NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3116 : NEW_DICTIONARY(self->self); |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3117 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
|
3118 return self->auto_rebind |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3119 ? AlwaysTrue(NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3120 : AlwaysFalse(NULL); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3121 else if (strcmp(name, "__members__") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3122 return ObjectDir(NULL, FunctionAttrs); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3123 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3124 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3125 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3126 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3127 * 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
|
3128 * |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3129 * "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
|
3130 * 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
|
3131 */ |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3132 static void |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3133 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
|
3134 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3135 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3136 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3137 pt->pt_name = self->name; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3138 if (self->argv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3139 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3140 pt->pt_argc = self->argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3141 if (exported) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3142 { |
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
|
3143 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
|
3144 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
|
3145 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
|
3146 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3147 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3148 pt->pt_argv = self->argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3149 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3150 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3151 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3152 pt->pt_argc = 0; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3153 pt->pt_argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3154 } |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3155 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
|
3156 pt->pt_dict = self->self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3157 if (exported && self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3158 ++pt->pt_dict->dv_refcount; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3159 if (exported) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3160 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
|
3161 pt->pt_refcount = 1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3162 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3163 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3164 static PyObject * |
4488 | 3165 FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs) |
3618 | 3166 { |
4488 | 3167 char_u *name = self->name; |
3618 | 3168 typval_T args; |
3169 typval_T selfdicttv; | |
3170 typval_T rettv; | |
3171 dict_T *selfdict = NULL; | |
3172 PyObject *selfdictObject; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3173 PyObject *ret; |
3618 | 3174 int error; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3175 partial_T pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3176 partial_T *pt_ptr = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3177 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3178 if (ConvertFromPySequence(argsObject, &args) == -1) |
3618 | 3179 return NULL; |
3180 | |
3181 if (kwargs != NULL) | |
3182 { | |
3183 selfdictObject = PyDict_GetItemString(kwargs, "self"); | |
3184 if (selfdictObject != NULL) | |
3185 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3186 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1) |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3187 { |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3188 clear_tv(&args); |
3618 | 3189 return NULL; |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3190 } |
3618 | 3191 selfdict = selfdicttv.vval.v_dict; |
3192 } | |
3193 } | |
3194 | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3195 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3196 { |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3197 vim_memset(&pt, 0, sizeof(partial_T)); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3198 set_partial(self, &pt, FALSE); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3199 pt_ptr = &pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3200 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3201 |
4415 | 3202 Py_BEGIN_ALLOW_THREADS |
3203 Python_Lock_Vim(); | |
3204 | |
4498 | 3205 VimTryStart(); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3206 error = func_call(name, &args, pt_ptr, selfdict, &rettv); |
4415 | 3207 |
3208 Python_Release_Vim(); | |
3209 Py_END_ALLOW_THREADS | |
3210 | |
4498 | 3211 if (VimTryEnd()) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3212 ret = NULL; |
4498 | 3213 else if (error != OK) |
3618 | 3214 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3215 ret = NULL; |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3216 PyErr_VIM_FORMAT(N_("failed to run function %s"), (char *)name); |
3618 | 3217 } |
3218 else | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3219 ret = ConvertToPyObject(&rettv); |
3618 | 3220 |
3221 clear_tv(&args); | |
3222 clear_tv(&rettv); | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3223 if (selfdict != NULL) |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3224 clear_tv(&selfdicttv); |
3618 | 3225 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3226 return ret; |
3618 | 3227 } |
3228 | |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3229 static PyObject * |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3230 FunctionRepr(FunctionObject *self) |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3231 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3232 PyObject *ret; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3233 garray_T repr_ga; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3234 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3235 char_u *tofree = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3236 typval_T tv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3237 char_u numbuf[NUMBUFLEN]; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3238 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3239 ga_init2(&repr_ga, (int)sizeof(char), 70); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3240 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
|
3241 if (self->name) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3242 ga_concat(&repr_ga, self->name); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3243 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3244 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
|
3245 ga_append(&repr_ga, '\''); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3246 if (self->argv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3247 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3248 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
|
3249 ++emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3250 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
|
3251 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3252 if (i != 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3253 ga_concat(&repr_ga, (char_u *)", "); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3254 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
|
3255 get_copyID())); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3256 vim_free(tofree); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3257 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3258 --emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3259 ga_append(&repr_ga, ']'); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3260 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3261 if (self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3262 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3263 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
|
3264 tv.v_type = VAR_DICT; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3265 tv.vval.v_dict = self->self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3266 ++emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3267 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
|
3268 --emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3269 vim_free(tofree); |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3270 if (self->auto_rebind) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3271 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
|
3272 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3273 ga_append(&repr_ga, '>'); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3274 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
|
3275 ga_clear(&repr_ga); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3276 return ret; |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3277 } |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3278 |
3618 | 3279 static struct PyMethodDef FunctionMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3280 {"__dir__", (PyCFunction)FunctionDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3281 { NULL, NULL, 0, NULL} |
3618 | 3282 }; |
3283 | |
4350 | 3284 /* |
3285 * Options object | |
3286 */ | |
3287 | |
3288 static PyTypeObject OptionsType; | |
3289 | |
3290 typedef int (*checkfun)(void *); | |
3291 | |
3292 typedef struct | |
3293 { | |
3294 PyObject_HEAD | |
5610 | 3295 int opt_type; |
3296 void *from; | |
3297 checkfun Check; | |
3298 PyObject *fromObj; | |
4350 | 3299 } OptionsObject; |
3300 | |
4433 | 3301 static int |
3302 dummy_check(void *arg UNUSED) | |
3303 { | |
3304 return 0; | |
3305 } | |
3306 | |
3307 static PyObject * | |
3308 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj) | |
3309 { | |
3310 OptionsObject *self; | |
3311 | |
4500 | 3312 self = PyObject_GC_New(OptionsObject, &OptionsType); |
4433 | 3313 if (self == NULL) |
3314 return NULL; | |
3315 | |
3316 self->opt_type = opt_type; | |
3317 self->from = from; | |
3318 self->Check = Check; | |
3319 self->fromObj = fromObj; | |
3320 if (fromObj) | |
3321 Py_INCREF(fromObj); | |
3322 | |
3323 return (PyObject *)(self); | |
3324 } | |
3325 | |
3326 static void | |
4488 | 3327 OptionsDestructor(OptionsObject *self) |
4433 | 3328 { |
4500 | 3329 PyObject_GC_UnTrack((void *)(self)); |
3330 Py_XDECREF(self->fromObj); | |
3331 PyObject_GC_Del((void *)(self)); | |
4433 | 3332 } |
3333 | |
3334 static int | |
4488 | 3335 OptionsTraverse(OptionsObject *self, visitproc visit, void *arg) |
4433 | 3336 { |
4488 | 3337 Py_VISIT(self->fromObj); |
4433 | 3338 return 0; |
3339 } | |
3340 | |
3341 static int | |
4488 | 3342 OptionsClear(OptionsObject *self) |
4433 | 3343 { |
4488 | 3344 Py_CLEAR(self->fromObj); |
4433 | 3345 return 0; |
3346 } | |
3347 | |
4350 | 3348 static PyObject * |
4488 | 3349 OptionsItem(OptionsObject *self, PyObject *keyObject) |
4350 | 3350 { |
3351 char_u *key; | |
3352 int flags; | |
3353 long numval; | |
3354 char_u *stringval; | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3355 PyObject *todecref; |
4350 | 3356 |
4488 | 3357 if (self->Check(self->from)) |
4350 | 3358 return NULL; |
3359 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3360 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3361 return NULL; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3362 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3363 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3364 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3365 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3366 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3367 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3368 } |
4350 | 3369 |
3370 flags = get_option_value_strict(key, &numval, &stringval, | |
4488 | 3371 self->opt_type, self->from); |
4350 | 3372 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3373 Py_XDECREF(todecref); |
4350 | 3374 |
3375 if (flags == 0) | |
3376 { | |
4403 | 3377 PyErr_SetObject(PyExc_KeyError, keyObject); |
4350 | 3378 return NULL; |
3379 } | |
3380 | |
3381 if (flags & SOPT_UNSET) | |
3382 { | |
3383 Py_INCREF(Py_None); | |
3384 return Py_None; | |
3385 } | |
3386 else if (flags & SOPT_BOOL) | |
3387 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3388 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3389 ret = numval ? Py_True : Py_False; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3390 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3391 return ret; |
4350 | 3392 } |
3393 else if (flags & SOPT_NUM) | |
3394 return PyInt_FromLong(numval); | |
3395 else if (flags & SOPT_STRING) | |
3396 { | |
3397 if (stringval) | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3398 { |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
3399 PyObject *ret = PyBytes_FromString((char *)stringval); |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3400 vim_free(stringval); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3401 return ret; |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3402 } |
4350 | 3403 else |
3404 { | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
3405 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3406 N_("unable to get option value")); |
4350 | 3407 return NULL; |
3408 } | |
3409 } | |
3410 else | |
3411 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3412 PyErr_SET_VIM(N_("internal error: unknown option type")); |
4350 | 3413 return NULL; |
3414 } | |
3415 } | |
3416 | |
3417 static int | |
5610 | 3418 OptionsContains(OptionsObject *self, PyObject *keyObject) |
3419 { | |
3420 char_u *key; | |
3421 PyObject *todecref; | |
3422 | |
3423 if (!(key = StringToChars(keyObject, &todecref))) | |
3424 return -1; | |
3425 | |
3426 if (*key == NUL) | |
3427 { | |
3428 Py_XDECREF(todecref); | |
3429 return 0; | |
3430 } | |
3431 | |
3432 if (get_option_value_strict(key, NULL, NULL, self->opt_type, NULL)) | |
3433 { | |
3434 Py_XDECREF(todecref); | |
3435 return 1; | |
3436 } | |
3437 else | |
3438 { | |
3439 Py_XDECREF(todecref); | |
3440 return 0; | |
3441 } | |
3442 } | |
3443 | |
3444 typedef struct | |
3445 { | |
3446 void *lastoption; | |
3447 int opt_type; | |
3448 } optiterinfo_T; | |
3449 | |
3450 static PyObject * | |
3451 OptionsIterNext(optiterinfo_T **oii) | |
3452 { | |
3453 char_u *name; | |
3454 | |
3455 if ((name = option_iter_next(&((*oii)->lastoption), (*oii)->opt_type))) | |
3456 return PyString_FromString((char *)name); | |
3457 | |
3458 return NULL; | |
3459 } | |
3460 | |
3461 static PyObject * | |
3462 OptionsIter(OptionsObject *self) | |
3463 { | |
3464 optiterinfo_T *oii; | |
3465 | |
3466 if (!(oii = PyMem_New(optiterinfo_T, 1))) | |
3467 { | |
3468 PyErr_NoMemory(); | |
3469 return NULL; | |
3470 } | |
3471 | |
3472 oii->opt_type = self->opt_type; | |
3473 oii->lastoption = NULL; | |
3474 | |
3475 return IterNew(oii, | |
3476 (destructorfun) PyMem_Free, (nextfun) OptionsIterNext, | |
3477 NULL, NULL); | |
3478 } | |
3479 | |
3480 static int | |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3481 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
|
3482 { |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3483 char *errmsg; |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3484 |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3485 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
|
3486 { |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3487 if (VimTryEnd()) |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3488 return FAIL; |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3489 PyErr_SetVim(errmsg); |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3490 return FAIL; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3491 } |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3492 return OK; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3493 } |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3494 |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3495 static int |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3496 set_option_value_for( |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3497 char_u *key, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3498 int numval, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3499 char_u *stringval, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3500 int opt_flags, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3501 int opt_type, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3502 void *from) |
4350 | 3503 { |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3504 win_T *save_curwin = NULL; |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3505 tabpage_T *save_curtab = NULL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
3506 bufref_T save_curbuf; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3507 int set_ret = 0; |
4498 | 3508 |
3509 VimTryStart(); | |
4350 | 3510 switch (opt_type) |
3511 { | |
3512 case SREQ_WIN: | |
4429 | 3513 if (switch_win(&save_curwin, &save_curtab, (win_T *)from, |
4918
0792cc5133ce
updated for version 7.3.1204
Bram Moolenaar <bram@vim.org>
parents:
4859
diff
changeset
|
3514 win_find_tabpage((win_T *)from), FALSE) == FAIL) |
4350 | 3515 { |
6454 | 3516 restore_win(save_curwin, save_curtab, TRUE); |
4498 | 3517 if (VimTryEnd()) |
3518 return -1; | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3519 PyErr_SET_VIM(N_("problem while switching windows")); |
4350 | 3520 return -1; |
3521 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3522 set_ret = set_option_value_err(key, numval, stringval, opt_flags); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3523 restore_win(save_curwin, save_curtab, TRUE); |
4350 | 3524 break; |
3525 case SREQ_BUF: | |
4429 | 3526 switch_buffer(&save_curbuf, (buf_T *)from); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3527 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
|
3528 restore_buffer(&save_curbuf); |
4350 | 3529 break; |
3530 case SREQ_GLOBAL: | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3531 set_ret = set_option_value_err(key, numval, stringval, opt_flags); |
4350 | 3532 break; |
3533 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3534 if (set_ret == FAIL) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3535 return -1; |
4498 | 3536 return VimTryEnd(); |
4350 | 3537 } |
3538 | |
3539 static int | |
4488 | 3540 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject) |
4350 | 3541 { |
3542 char_u *key; | |
3543 int flags; | |
3544 int opt_flags; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3545 int ret = 0; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3546 PyObject *todecref; |
4350 | 3547 |
4488 | 3548 if (self->Check(self->from)) |
4350 | 3549 return -1; |
3550 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3551 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3552 return -1; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3553 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3554 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3555 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3556 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3557 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3558 return -1; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3559 } |
4350 | 3560 |
3561 flags = get_option_value_strict(key, NULL, NULL, | |
4488 | 3562 self->opt_type, self->from); |
4350 | 3563 |
3564 if (flags == 0) | |
3565 { | |
4403 | 3566 PyErr_SetObject(PyExc_KeyError, keyObject); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3567 Py_XDECREF(todecref); |
4350 | 3568 return -1; |
3569 } | |
3570 | |
3571 if (valObject == NULL) | |
3572 { | |
4488 | 3573 if (self->opt_type == SREQ_GLOBAL) |
4350 | 3574 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
3575 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3576 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
|
3577 Py_XDECREF(todecref); |
4350 | 3578 return -1; |
3579 } | |
3580 else if (!(flags & SOPT_GLOBAL)) | |
3581 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
3582 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3583 N_("unable to unset option %s " |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3584 "which does not have global value"), key); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3585 Py_XDECREF(todecref); |
4350 | 3586 return -1; |
3587 } | |
3588 else | |
3589 { | |
4488 | 3590 unset_global_local_option(key, self->from); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3591 Py_XDECREF(todecref); |
4350 | 3592 return 0; |
3593 } | |
3594 } | |
3595 | |
4488 | 3596 opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL); |
4350 | 3597 |
3598 if (flags & SOPT_BOOL) | |
3599 { | |
4411 | 3600 int istrue = PyObject_IsTrue(valObject); |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3601 |
4411 | 3602 if (istrue == -1) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3603 ret = -1; |
4587
63c9b681c3db
updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents:
4575
diff
changeset
|
3604 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3605 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
|
3606 opt_flags, self->opt_type, self->from); |
4350 | 3607 } |
3608 else if (flags & SOPT_NUM) | |
3609 { | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3610 long val; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3611 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3612 if (NumberToLong(valObject, &val, NUMBER_INT)) |
4350 | 3613 { |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3614 Py_XDECREF(todecref); |
4350 | 3615 return -1; |
3616 } | |
3617 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3618 ret = set_option_value_for(key, (int) val, NULL, opt_flags, |
4488 | 3619 self->opt_type, self->from); |
4350 | 3620 } |
3621 else | |
3622 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3623 char_u *val; |
5525 | 3624 PyObject *todecref2; |
3625 | |
3626 if ((val = StringToChars(valObject, &todecref2))) | |
3627 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3628 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
|
3629 self->opt_type, self->from); |
5525 | 3630 Py_XDECREF(todecref2); |
3631 } | |
4350 | 3632 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3633 ret = -1; |
4350 | 3634 } |
3635 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3636 Py_XDECREF(todecref); |
4587
63c9b681c3db
updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents:
4575
diff
changeset
|
3637 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3638 return ret; |
4350 | 3639 } |
3640 | |
5610 | 3641 static PySequenceMethods OptionsAsSeq = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3642 0, // sq_length |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3643 0, // sq_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3644 0, // sq_repeat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3645 0, // sq_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3646 0, // sq_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3647 0, // sq_ass_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3648 0, // sq_ass_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3649 (objobjproc) OptionsContains, // sq_contains |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3650 0, // sq_inplace_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3651 0, // sq_inplace_repeat |
5610 | 3652 }; |
3653 | |
4350 | 3654 static PyMappingMethods OptionsAsMapping = { |
3655 (lenfunc) NULL, | |
3656 (binaryfunc) OptionsItem, | |
3657 (objobjargproc) OptionsAssItem, | |
3658 }; | |
3659 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3660 // Tabpage object |
4401 | 3661 |
3662 typedef struct | |
3663 { | |
3664 PyObject_HEAD | |
3665 tabpage_T *tab; | |
3666 } TabPageObject; | |
3667 | |
3668 static PyObject *WinListNew(TabPageObject *tabObject); | |
3669 | |
3670 static PyTypeObject TabPageType; | |
3671 | |
3672 static int | |
4488 | 3673 CheckTabPage(TabPageObject *self) |
4401 | 3674 { |
4488 | 3675 if (self->tab == INVALID_TABPAGE_VALUE) |
4401 | 3676 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3677 PyErr_SET_VIM(N_("attempt to refer to deleted tab page")); |
4401 | 3678 return -1; |
3679 } | |
3680 | |
3681 return 0; | |
3682 } | |
3683 | |
3684 static PyObject * | |
3685 TabPageNew(tabpage_T *tab) | |
3686 { | |
3687 TabPageObject *self; | |
3688 | |
3689 if (TAB_PYTHON_REF(tab)) | |
3690 { | |
3691 self = TAB_PYTHON_REF(tab); | |
3692 Py_INCREF(self); | |
3693 } | |
3694 else | |
3695 { | |
3696 self = PyObject_NEW(TabPageObject, &TabPageType); | |
3697 if (self == NULL) | |
3698 return NULL; | |
3699 self->tab = tab; | |
3700 TAB_PYTHON_REF(tab) = self; | |
3701 } | |
3702 | |
3703 return (PyObject *)(self); | |
3704 } | |
3705 | |
3706 static void | |
4488 | 3707 TabPageDestructor(TabPageObject *self) |
4401 | 3708 { |
4488 | 3709 if (self->tab && self->tab != INVALID_TABPAGE_VALUE) |
3710 TAB_PYTHON_REF(self->tab) = NULL; | |
4401 | 3711 |
3712 DESTRUCTOR_FINISH(self); | |
3713 } | |
3714 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3715 static char *TabPageAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3716 "windows", "number", "vars", "window", "valid", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3717 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3718 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3719 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3720 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3721 TabPageDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3722 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3723 return ObjectDir(self, TabPageAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3724 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3725 |
4401 | 3726 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3727 TabPageAttrValid(TabPageObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3728 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3729 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3730 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3731 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3732 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3733 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3734 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
|
3735 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3736 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3737 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3738 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3739 static PyObject * |
4488 | 3740 TabPageAttr(TabPageObject *self, char *name) |
4401 | 3741 { |
3742 if (strcmp(name, "windows") == 0) | |
4488 | 3743 return WinListNew(self); |
4401 | 3744 else if (strcmp(name, "number") == 0) |
4488 | 3745 return PyLong_FromLong((long) get_tab_number(self->tab)); |
4401 | 3746 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3747 return NEW_DICTIONARY(self->tab->tp_vars); |
4401 | 3748 else if (strcmp(name, "window") == 0) |
3749 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3750 // For current tab window.c does not bother to set or update tp_curwin |
4488 | 3751 if (self->tab == curtab) |
4431 | 3752 return WindowNew(curwin, curtab); |
4401 | 3753 else |
4488 | 3754 return WindowNew(self->tab->tp_curwin, self->tab); |
4401 | 3755 } |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3756 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3757 return ObjectDir(NULL, TabPageAttrs); |
4401 | 3758 return NULL; |
3759 } | |
3760 | |
3761 static PyObject * | |
4488 | 3762 TabPageRepr(TabPageObject *self) |
4401 | 3763 { |
4488 | 3764 if (self->tab == INVALID_TABPAGE_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3765 return PyString_FromFormat("<tabpage object (deleted) at %p>", (self)); |
4401 | 3766 else |
3767 { | |
4488 | 3768 int t = get_tab_number(self->tab); |
4401 | 3769 |
3770 if (t == 0) | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3771 return PyString_FromFormat("<tabpage object (unknown) at %p>", |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3772 (self)); |
4401 | 3773 else |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3774 return PyString_FromFormat("<tabpage %d>", t - 1); |
4401 | 3775 } |
3776 } | |
3777 | |
3778 static struct PyMethodDef TabPageMethods[] = { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3779 // name, function, calling, documentation |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3780 {"__dir__", (PyCFunction)TabPageDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3781 { NULL, NULL, 0, NULL} |
4401 | 3782 }; |
3783 | |
3784 /* | |
3785 * Window list object | |
3786 */ | |
3787 | |
3788 static PyTypeObject TabListType; | |
3789 static PySequenceMethods TabListAsSeq; | |
3790 | |
3791 typedef struct | |
3792 { | |
3793 PyObject_HEAD | |
3794 } TabListObject; | |
3795 | |
3796 static PyInt | |
3797 TabListLength(PyObject *self UNUSED) | |
3798 { | |
3799 tabpage_T *tp = first_tabpage; | |
3800 PyInt n = 0; | |
3801 | |
3802 while (tp != NULL) | |
3803 { | |
3804 ++n; | |
3805 tp = tp->tp_next; | |
3806 } | |
3807 | |
3808 return n; | |
3809 } | |
3810 | |
3811 static PyObject * | |
3812 TabListItem(PyObject *self UNUSED, PyInt n) | |
3813 { | |
3814 tabpage_T *tp; | |
3815 | |
3816 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, --n) | |
3817 if (n == 0) | |
3818 return TabPageNew(tp); | |
3819 | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3820 PyErr_SET_STRING(PyExc_IndexError, N_("no such tab page")); |
4401 | 3821 return NULL; |
3822 } | |
3823 | |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
3824 /* |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
3825 * Window object |
4385 | 3826 */ |
3827 | |
3828 typedef struct | |
3829 { | |
3830 PyObject_HEAD | |
3831 win_T *win; | |
4431 | 3832 TabPageObject *tabObject; |
4385 | 3833 } WindowObject; |
3834 | |
3835 static PyTypeObject WindowType; | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3836 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3837 static int |
4488 | 3838 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
|
3839 { |
4488 | 3840 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
|
3841 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3842 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
|
3843 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3844 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3845 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3846 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3847 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3848 |
4319 | 3849 static PyObject * |
4431 | 3850 WindowNew(win_T *win, tabpage_T *tab) |
4377 | 3851 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3852 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3853 * We need to handle deletion of windows underneath us. |
4377 | 3854 * If we add a "w_python*_ref" field to the win_T structure, |
3855 * then we can get at it in win_free() in vim. We then | |
3856 * need to create only ONE Python object per window - if | |
3857 * we try to create a second, just INCREF the existing one | |
3858 * and return it. The (single) Python object referring to | |
3859 * the window is stored in "w_python*_ref". | |
3860 * On a win_free() we set the Python object's win_T* field | |
3861 * to an invalid value. We trap all uses of a window | |
3862 * object, and reject them if the win_T* field is invalid. | |
3863 * | |
4385 | 3864 * Python2 and Python3 get different fields and different objects: |
4377 | 3865 * w_python_ref and w_python3_ref fields respectively. |
3866 */ | |
3867 | |
3868 WindowObject *self; | |
3869 | |
3870 if (WIN_PYTHON_REF(win)) | |
3871 { | |
3872 self = WIN_PYTHON_REF(win); | |
3873 Py_INCREF(self); | |
3874 } | |
3875 else | |
3876 { | |
4500 | 3877 self = PyObject_GC_New(WindowObject, &WindowType); |
4377 | 3878 if (self == NULL) |
3879 return NULL; | |
3880 self->win = win; | |
3881 WIN_PYTHON_REF(win) = self; | |
3882 } | |
3883 | |
4431 | 3884 self->tabObject = ((TabPageObject *)(TabPageNew(tab))); |
3885 | |
4377 | 3886 return (PyObject *)(self); |
3887 } | |
3888 | |
4385 | 3889 static void |
4488 | 3890 WindowDestructor(WindowObject *self) |
4385 | 3891 { |
4500 | 3892 PyObject_GC_UnTrack((void *)(self)); |
4488 | 3893 if (self->win && self->win != INVALID_WINDOW_VALUE) |
3894 WIN_PYTHON_REF(self->win) = NULL; | |
4500 | 3895 Py_XDECREF(((PyObject *)(self->tabObject))); |
3896 PyObject_GC_Del((void *)(self)); | |
3897 } | |
3898 | |
3899 static int | |
3900 WindowTraverse(WindowObject *self, visitproc visit, void *arg) | |
3901 { | |
3902 Py_VISIT(((PyObject *)(self->tabObject))); | |
3903 return 0; | |
3904 } | |
3905 | |
3906 static int | |
3907 WindowClear(WindowObject *self) | |
3908 { | |
3909 Py_CLEAR(self->tabObject); | |
3910 return 0; | |
4385 | 3911 } |
3912 | |
4431 | 3913 static win_T * |
3914 get_firstwin(TabPageObject *tabObject) | |
3915 { | |
3916 if (tabObject) | |
3917 { | |
3918 if (CheckTabPage(tabObject)) | |
3919 return NULL; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3920 // For current tab window.c does not bother to set or update tp_firstwin |
4431 | 3921 else if (tabObject->tab == curtab) |
3922 return firstwin; | |
3923 else | |
3924 return tabObject->tab->tp_firstwin; | |
3925 } | |
3926 else | |
3927 return firstwin; | |
3928 } | |
14047
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3929 |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3930 // 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
|
3931 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
|
3932 "buffer", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3933 "cursor", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3934 "height", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3935 "row", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3936 "width", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3937 "col", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3938 "vars", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3939 "options", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3940 "number", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3941 "tabpage", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3942 "valid", |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3943 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3944 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3945 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3946 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3947 WindowDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3948 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3949 return ObjectDir(self, WindowAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3950 } |
4431 | 3951 |
4377 | 3952 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3953 WindowAttrValid(WindowObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3954 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3955 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3956 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3957 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3958 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3959 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3960 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
|
3961 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3962 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3963 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3964 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3965 static PyObject * |
4488 | 3966 WindowAttr(WindowObject *self, char *name) |
4319 | 3967 { |
3968 if (strcmp(name, "buffer") == 0) | |
4488 | 3969 return (PyObject *)BufferNew(self->win->w_buffer); |
4319 | 3970 else if (strcmp(name, "cursor") == 0) |
3971 { | |
4488 | 3972 pos_T *pos = &self->win->w_cursor; |
4319 | 3973 |
3974 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col)); | |
3975 } | |
3976 else if (strcmp(name, "height") == 0) | |
4488 | 3977 return PyLong_FromLong((long)(self->win->w_height)); |
4383 | 3978 else if (strcmp(name, "row") == 0) |
4488 | 3979 return PyLong_FromLong((long)(self->win->w_winrow)); |
4319 | 3980 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
|
3981 return PyLong_FromLong((long)(self->win->w_width)); |
4383 | 3982 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
|
3983 return PyLong_FromLong((long)(self->win->w_wincol)); |
4323 | 3984 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3985 return NEW_DICTIONARY(self->win->w_vars); |
4350 | 3986 else if (strcmp(name, "options") == 0) |
4488 | 3987 return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow, |
3988 (PyObject *) self); | |
4379 | 3989 else if (strcmp(name, "number") == 0) |
4431 | 3990 { |
4488 | 3991 if (CheckTabPage(self->tabObject)) |
4431 | 3992 return NULL; |
3993 return PyLong_FromLong((long) | |
4488 | 3994 get_win_number(self->win, get_firstwin(self->tabObject))); |
4431 | 3995 } |
3996 else if (strcmp(name, "tabpage") == 0) | |
3997 { | |
4488 | 3998 Py_INCREF(self->tabObject); |
3999 return (PyObject *)(self->tabObject); | |
4431 | 4000 } |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4001 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4002 return ObjectDir(NULL, WindowAttrs); |
4319 | 4003 else |
4004 return NULL; | |
4005 } | |
4006 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4007 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4008 WindowSetattr(WindowObject *self, char *name, PyObject *valObject) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4009 { |
4488 | 4010 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
|
4011 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4012 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4013 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
|
4014 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4015 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
|
4016 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4017 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4018 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
|
4019 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4020 long lnum; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4021 long col; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4022 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4023 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
|
4024 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4025 |
4488 | 4026 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
|
4027 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4028 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
|
4029 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4030 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4031 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4032 // Check for keyboard interrupts |
4498 | 4033 if (VimCheckInterrupt()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4034 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4035 |
4488 | 4036 self->win->w_cursor.lnum = lnum; |
4037 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
|
4038 self->win->w_set_curswant = TRUE; |
4488 | 4039 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
|
4040 // When column is out of range silently correct it. |
4488 | 4041 check_cursor_col_win(self->win); |
2933 | 4042 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4043 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4044 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4045 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4046 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
|
4047 { |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4048 long height; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4049 win_T *savewin; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4050 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4051 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
|
4052 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4053 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4054 #ifdef FEAT_GUI |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4055 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
|
4056 #endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4057 savewin = curwin; |
4488 | 4058 curwin = self->win; |
4498 | 4059 |
4060 VimTryStart(); | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4061 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
|
4062 curwin = savewin; |
4498 | 4063 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4064 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4065 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4066 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4067 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4068 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
|
4069 { |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4070 long width; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4071 win_T *savewin; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4072 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4073 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
|
4074 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4075 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4076 #ifdef FEAT_GUI |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4077 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
|
4078 #endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4079 savewin = curwin; |
4488 | 4080 curwin = self->win; |
4498 | 4081 |
4082 VimTryStart(); | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4083 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
|
4084 curwin = savewin; |
4498 | 4085 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4086 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4087 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4088 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4089 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4090 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4091 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4092 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
|
4093 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4094 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4095 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4096 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4097 static PyObject * |
4488 | 4098 WindowRepr(WindowObject *self) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4099 { |
4488 | 4100 if (self->win == INVALID_WINDOW_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4101 return PyString_FromFormat("<window object (deleted) at %p>", (self)); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4102 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4103 { |
4488 | 4104 int w = get_win_number(self->win, firstwin); |
4379 | 4105 |
4106 if (w == 0) | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4107 return PyString_FromFormat("<window object (unknown) at %p>", |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4108 (self)); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4109 else |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4110 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
|
4111 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4112 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4113 |
4385 | 4114 static struct PyMethodDef WindowMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4115 // name, function, calling, documentation |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4116 {"__dir__", (PyCFunction)WindowDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4117 { NULL, NULL, 0, NULL} |
4385 | 4118 }; |
4119 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4120 /* |
4385 | 4121 * 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
|
4122 */ |
4319 | 4123 |
4385 | 4124 static PyTypeObject WinListType; |
4125 static PySequenceMethods WinListAsSeq; | |
4126 | |
4319 | 4127 typedef struct |
4128 { | |
4129 PyObject_HEAD | |
4401 | 4130 TabPageObject *tabObject; |
4319 | 4131 } WinListObject; |
4132 | |
4401 | 4133 static PyObject * |
4134 WinListNew(TabPageObject *tabObject) | |
4135 { | |
4136 WinListObject *self; | |
4137 | |
4138 self = PyObject_NEW(WinListObject, &WinListType); | |
4139 self->tabObject = tabObject; | |
4140 Py_INCREF(tabObject); | |
4141 | |
4142 return (PyObject *)(self); | |
4143 } | |
4144 | |
4145 static void | |
4488 | 4146 WinListDestructor(WinListObject *self) |
4401 | 4147 { |
4488 | 4148 TabPageObject *tabObject = self->tabObject; |
4401 | 4149 |
4150 if (tabObject) | |
4523
57393dc4b811
updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents:
4513
diff
changeset
|
4151 { |
4401 | 4152 Py_DECREF((PyObject *)(tabObject)); |
4523
57393dc4b811
updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents:
4513
diff
changeset
|
4153 } |
4401 | 4154 |
4155 DESTRUCTOR_FINISH(self); | |
4156 } | |
4157 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4158 static PyInt |
4488 | 4159 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
|
4160 { |
4401 | 4161 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
|
4162 PyInt n = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4163 |
4488 | 4164 if (!(w = get_firstwin(self->tabObject))) |
4401 | 4165 return -1; |
4166 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4167 while (w != NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4168 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4169 ++n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4170 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
|
4171 } |
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 return n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4174 } |
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 static PyObject * |
4488 | 4177 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
|
4178 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4179 win_T *w; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4180 |
4488 | 4181 if (!(w = get_firstwin(self->tabObject))) |
4401 | 4182 return NULL; |
4183 | |
4184 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
|
4185 if (n == 0) |
4488 | 4186 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
|
4187 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4188 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
|
4189 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4190 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4191 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4192 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4193 * 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
|
4194 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4195 * 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
|
4196 * 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
|
4197 * characters. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4198 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4199 * 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
|
4200 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4201 static char * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4202 StringToLine(PyObject *obj) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4203 { |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4204 char *str; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4205 char *save; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4206 PyObject *bytes = NULL; |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4207 Py_ssize_t len = 0; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4208 PyInt i; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4209 char *p; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4210 |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4211 if (PyBytes_Check(obj)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4212 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4213 if (PyBytes_AsStringAndSize(obj, &str, &len) == -1 |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4214 || str == NULL) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4215 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4216 } |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4217 else if (PyUnicode_Check(obj)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4218 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4219 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4220 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4221 |
4995
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4222 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1 |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4223 || str == NULL) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4224 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4225 Py_DECREF(bytes); |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4226 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4227 } |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4228 } |
4995
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4229 else |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4230 { |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4231 #if PY_MAJOR_VERSION < 3 |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4232 PyErr_FORMAT(PyExc_TypeError, |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4233 N_("expected str() or unicode() instance, but got %s"), |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4234 Py_TYPE_NAME(obj)); |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4235 #else |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4236 PyErr_FORMAT(PyExc_TypeError, |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4237 N_("expected bytes() or str() instance, but got %s"), |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4238 Py_TYPE_NAME(obj)); |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4239 #endif |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4240 return NULL; |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4241 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4242 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4243 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4244 * 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
|
4245 * 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
|
4246 * a single line. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4247 * 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
|
4248 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4249 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
|
4250 if (p != NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4251 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4252 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
|
4253 --len; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4254 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4255 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4256 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
|
4257 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
|
4258 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4259 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4260 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4261 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4262 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4263 * Create a copy of the string, with internal nulls replaced by |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4264 * newline characters, as is the vim convention. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4265 */ |
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
|
4266 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
|
4267 if (save == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4268 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4269 PyErr_NoMemory(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
4270 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
|
4271 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4272 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4273 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4274 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
|
4275 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4276 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
|
4277 save[i] = '\n'; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4278 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4279 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
|
4280 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4281 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4282 save[i] = '\0'; |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4283 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
|
4284 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4285 return save; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4286 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4287 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4288 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4289 * 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
|
4290 * 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
|
4291 * string object. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4292 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4293 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4294 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
|
4295 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4296 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
|
4297 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4298 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4299 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4300 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4301 * 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
|
4302 * 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
|
4303 * 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
|
4304 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4305 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4306 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
|
4307 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4308 PyInt i; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4309 PyInt n = hi - lo; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4310 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
|
4311 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4312 if (list == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4313 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4314 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4315 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
|
4316 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4317 PyObject *string = LineToString( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4318 (char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE)); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4319 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4320 // Error check - was the Python string creation OK? |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4321 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
|
4322 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4323 Py_DECREF(list); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4324 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4325 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4326 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4327 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
|
4328 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4329 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4330 // 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
|
4331 // 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
|
4332 // with it). |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4333 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4334 return list; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4335 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4336 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4337 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4338 * 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
|
4339 * 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
|
4340 * deleted). |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4341 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4342 static void |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4343 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
|
4344 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4345 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
|
4346 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4347 // 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
|
4348 // lines. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4349 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
|
4350 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4351 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
|
4352 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4353 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4354 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
|
4355 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4356 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
|
4357 check_cursor(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4358 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4359 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4360 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4361 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
|
4362 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4363 invalidate_botline(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4364 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4365 |
2894 | 4366 /* |
4367 * 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
|
4368 * 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
|
4369 * 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
|
4370 * 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
|
4371 * 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
|
4372 * 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
|
4373 * 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
|
4374 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4375 static int |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4376 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
|
4377 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4378 bufref_T save_curbuf = {NULL, 0, 0}; |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4379 win_T *save_curwin = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4380 tabpage_T *save_curtab = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4381 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4382 // 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
|
4383 // There are three cases: |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4384 // 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
|
4385 // 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
|
4386 // 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
|
4387 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
|
4388 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4389 PyErr_Clear(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4390 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4391 |
4498 | 4392 VimTryStart(); |
4393 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4394 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
|
4395 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
|
4396 else if (ml_delete((linenr_T)n, FALSE) == FAIL) |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4397 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
|
4398 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4399 { |
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
|
4400 if (buf == curbuf && (save_curwin != 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
|
4401 || 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
|
4402 // 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
|
4403 // position. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4404 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
|
4405 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
|
4406 // 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
|
4407 // 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
|
4408 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
|
4409 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4410 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4411 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4412 |
4498 | 4413 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4414 return FAIL; |
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 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4417 *len_change = -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4418 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4419 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4420 } |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4421 else if (PyBytes_Check(line) || PyUnicode_Check(line)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4422 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4423 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
|
4424 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4425 if (save == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4426 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4427 |
4498 | 4428 VimTryStart(); |
4429 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4430 // 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
|
4431 PyErr_Clear(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4432 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2447
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 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
|
4435 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
4436 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
|
4437 vim_free(save); |
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 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
|
4440 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4441 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
|
4442 vim_free(save); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4443 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4444 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4445 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
|
4446 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4447 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4448 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4449 // 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
|
4450 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
|
4451 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4452 |
4498 | 4453 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4454 return FAIL; |
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 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4457 *len_change = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4458 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4459 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4460 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4461 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4462 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4463 PyErr_BadArgument(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4464 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4465 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4466 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4467 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4468 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4469 * Replace a range of lines in the specified buffer. The line numbers are in |
2894 | 4470 * Vim format (1-based). The range is from lo up to, but not including, hi. |
4471 * The replacement lines are given as a Python list of string objects. The | |
4472 * list is checked for validity and correct format. Errors are returned as a | |
4473 * value of FAIL. The return value is OK on success. | |
4474 * If OK is returned and len_change is not NULL, *len_change | |
4475 * is set to the change in the buffer length. | |
4476 */ | |
4477 static int | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4478 SetBufferLineList( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4479 buf_T *buf, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4480 PyInt lo, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4481 PyInt hi, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4482 PyObject *list, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4483 PyInt *len_change) |
2894 | 4484 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4485 bufref_T save_curbuf = {NULL, 0, 0}; |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4486 win_T *save_curwin = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4487 tabpage_T *save_curtab = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4488 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4489 // 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
|
4490 // There are three cases: |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4491 // 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
|
4492 // 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
|
4493 // 3. Anything else - this is an error. |
2894 | 4494 if (list == Py_None || list == NULL) |
4495 { | |
4496 PyInt i; | |
4497 PyInt n = (int)(hi - lo); | |
4498 | |
4499 PyErr_Clear(); | |
4498 | 4500 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4501 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2894 | 4502 |
4503 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
|
4504 RAISE_UNDO_FAIL; |
2894 | 4505 else |
4506 { | |
4507 for (i = 0; i < n; ++i) | |
4508 { | |
4509 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
4510 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4511 RAISE_DELETE_LINE_FAIL; |
2894 | 4512 break; |
4513 } | |
4514 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4515 if (buf == curbuf && (save_curwin != NULL |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4516 || 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
|
4517 // 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
|
4518 // position. |
2894 | 4519 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
|
4520 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
|
4521 // 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
|
4522 // 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
|
4523 deleted_lines_mark((linenr_T)lo, (long)i); |
2894 | 4524 } |
4525 | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4526 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2894 | 4527 |
4498 | 4528 if (VimTryEnd()) |
2894 | 4529 return FAIL; |
4530 | |
4531 if (len_change) | |
4532 *len_change = -n; | |
4533 | |
4534 return OK; | |
4535 } | |
4536 else if (PyList_Check(list)) | |
4537 { | |
4538 PyInt i; | |
4539 PyInt new_len = PyList_Size(list); | |
4540 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
|
4541 PyInt extra = 0; // lines added to text, can be negative |
2894 | 4542 char **array; |
4543 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4544 if (new_len == 0) // avoid allocating zero bytes |
2894 | 4545 array = NULL; |
4546 else | |
4547 { | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4548 array = PyMem_New(char *, new_len); |
2894 | 4549 if (array == NULL) |
4550 { | |
4551 PyErr_NoMemory(); | |
4552 return FAIL; | |
4553 } | |
4554 } | |
4555 | |
4556 for (i = 0; i < new_len; ++i) | |
4557 { | |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4558 PyObject *line; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4559 |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4560 if (!(line = PyList_GetItem(list, i)) || |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4561 !(array[i] = StringToLine(line))) |
2894 | 4562 { |
4563 while (i) | |
4564 vim_free(array[--i]); | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4565 PyMem_Free(array); |
2894 | 4566 return FAIL; |
4567 } | |
4568 } | |
4569 | |
4498 | 4570 VimTryStart(); |
2894 | 4571 PyErr_Clear(); |
4429 | 4572 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4573 // START of region without "return". Must call restore_buffer()! |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4574 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2894 | 4575 |
4576 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
|
4577 RAISE_UNDO_FAIL; |
2894 | 4578 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4579 // 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
|
4580 // 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
|
4581 // repeatedly deleting line "lo". |
2894 | 4582 if (!PyErr_Occurred()) |
4583 { | |
4584 for (i = 0; i < old_len - new_len; ++i) | |
4585 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
4586 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4587 RAISE_DELETE_LINE_FAIL; |
2894 | 4588 break; |
4589 } | |
4590 extra -= i; | |
4591 } | |
4592 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4593 // 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
|
4594 // 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
|
4595 // less memory allocation and freeing. |
2894 | 4596 if (!PyErr_Occurred()) |
4597 { | |
4598 for (i = 0; i < old_len && i < new_len; ++i) | |
4599 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE) | |
4600 == FAIL) | |
4601 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4602 RAISE_REPLACE_LINE_FAIL; |
2894 | 4603 break; |
4604 } | |
4605 } | |
4606 else | |
4607 i = 0; | |
4608 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4609 // 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
|
4610 // must free the strings as we finish with them (we can't pass the |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4611 // responsibility to vim in this case). |
2894 | 4612 if (!PyErr_Occurred()) |
4613 { | |
4614 while (i < new_len) | |
4615 { | |
4616 if (ml_append((linenr_T)(lo + i - 1), | |
4617 (char_u *)array[i], 0, FALSE) == FAIL) | |
4618 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4619 RAISE_INSERT_LINE_FAIL; |
2894 | 4620 break; |
4621 } | |
4622 vim_free(array[i]); | |
4623 ++i; | |
4624 ++extra; | |
4625 } | |
4626 } | |
4627 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4628 // Free any left-over old_len, as a result of an error |
2894 | 4629 while (i < new_len) |
4630 { | |
4631 vim_free(array[i]); | |
4632 ++i; | |
4633 } | |
4634 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4635 // 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
|
4636 // 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
|
4637 // to vim. |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4638 PyMem_Free(array); |
2894 | 4639 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4640 // 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
|
4641 // 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
|
4642 // 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
|
4643 // 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
|
4644 if (save_curbuf.br_buf == NULL) |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4645 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), |
2894 | 4646 (long)MAXLNUM, (long)extra); |
4647 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); | |
4648 | |
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
|
4649 if (buf == curbuf && (save_curwin != 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
|
4650 || 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
|
4651 // 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
|
4652 // position. |
2894 | 4653 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra); |
4654 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4655 // END of region without "return". |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4656 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2894 | 4657 |
4498 | 4658 if (VimTryEnd()) |
2894 | 4659 return FAIL; |
4660 | |
4661 if (len_change) | |
4662 *len_change = new_len - old_len; | |
4663 | |
4664 return OK; | |
4665 } | |
4666 else | |
4667 { | |
4668 PyErr_BadArgument(); | |
4669 return FAIL; | |
4670 } | |
4671 } | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4672 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4673 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4674 * 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
|
4675 * 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
|
4676 * 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
|
4677 * 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
|
4678 * 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
|
4679 * 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
|
4680 * 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
|
4681 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4682 static int |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4683 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
|
4684 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4685 bufref_T save_curbuf = {NULL, 0, 0}; |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4686 win_T *save_curwin = NULL; |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4687 tabpage_T *save_curtab = NULL; |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4688 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4689 // 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
|
4690 // 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
|
4691 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
|
4692 { |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4693 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
|
4694 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4695 if (str == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4696 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4697 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4698 PyErr_Clear(); |
4498 | 4699 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4700 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4701 |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4702 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
|
4703 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
|
4704 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
|
4705 RAISE_INSERT_LINE_FAIL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4706 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
|
4707 // 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
|
4708 // 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
|
4709 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
|
4710 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4711 vim_free(str); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4712 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4713 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4714 |
4498 | 4715 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4716 return FAIL; |
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 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4719 *len_change = 1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4720 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4721 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4722 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4723 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
|
4724 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4725 PyInt i; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4726 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
|
4727 char **array; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4728 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4729 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
|
4730 if (array == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4731 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4732 PyErr_NoMemory(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4733 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4734 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4735 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4736 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
|
4737 { |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4738 PyObject *line; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4739 |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4740 if (!(line = PyList_GetItem(lines, i)) || |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4741 !(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
|
4742 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4743 while (i) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4744 vim_free(array[--i]); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4745 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
|
4746 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4747 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4748 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4749 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4750 PyErr_Clear(); |
4498 | 4751 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4752 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4753 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4754 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
|
4755 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
|
4756 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4757 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4758 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
|
4759 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4760 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
|
4761 (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
|
4762 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4763 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
|
4764 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4765 // 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
|
4766 while (i < size) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4767 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
|
4768 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4769 break; |
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 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
|
4772 } |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4773 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
|
4774 // 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
|
4775 // 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
|
4776 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
|
4777 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4778 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4779 // 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
|
4780 // been freed. |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4781 PyMem_Free(array); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4782 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4783 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4784 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4785 |
4498 | 4786 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4787 return FAIL; |
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 (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4790 *len_change = size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4791 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4792 return OK; |
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4795 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4796 PyErr_BadArgument(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4797 return FAIL; |
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 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4800 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4801 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4802 * 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
|
4803 * ------------------------------------------- |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4804 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4805 |
4385 | 4806 typedef struct |
4807 { | |
4808 PyObject_HEAD | |
4809 buf_T *buf; | |
4810 } BufferObject; | |
4811 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4812 static int |
4488 | 4813 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
|
4814 { |
4488 | 4815 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
|
4816 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4817 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
|
4818 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4819 } |
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 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4822 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4823 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4824 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4825 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
|
4826 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4827 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4828 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4829 |
4387 | 4830 if (end == -1) |
4831 end = self->buf->b_ml.ml_line_count; | |
4832 | |
4389 | 4833 if (n < 0) |
4834 n += end - start + 1; | |
4835 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4836 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
|
4837 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4838 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
|
4839 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4840 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4841 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4842 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
|
4843 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4844 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4845 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4846 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
|
4847 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4848 PyInt size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4849 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4850 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4851 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4852 |
4387 | 4853 if (end == -1) |
4854 end = self->buf->b_ml.ml_line_count; | |
4855 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4856 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
|
4857 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4858 if (lo < 0) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4859 lo = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4860 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
|
4861 lo = size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4862 if (hi < 0) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4863 hi = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4864 if (hi < lo) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4865 hi = lo; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4866 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
|
4867 hi = size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4868 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4869 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
|
4870 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4871 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4872 static PyInt |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4873 RBAsItem( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4874 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4875 PyInt n, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4876 PyObject *valObject, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4877 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4878 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4879 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
|
4880 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4881 PyInt len_change; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4882 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4883 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4884 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4885 |
4387 | 4886 if (end == -1) |
4887 end = self->buf->b_ml.ml_line_count; | |
4888 | |
4389 | 4889 if (n < 0) |
4890 n += end - start + 1; | |
4891 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4892 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
|
4893 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4894 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
|
4895 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4896 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4897 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4898 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
|
4899 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4900 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4901 if (new_end) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4902 *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
|
4903 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4904 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4905 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4906 |
2894 | 4907 static PyInt |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4908 RBAsSlice( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4909 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4910 PyInt lo, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4911 PyInt hi, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4912 PyObject *valObject, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4913 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4914 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4915 PyInt *new_end) |
2894 | 4916 { |
4917 PyInt size; | |
4918 PyInt len_change; | |
4919 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4920 // Self must be a valid buffer |
2894 | 4921 if (CheckBuffer(self)) |
4922 return -1; | |
4923 | |
4387 | 4924 if (end == -1) |
4925 end = self->buf->b_ml.ml_line_count; | |
4926 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4927 // Sort out the slice range |
2894 | 4928 size = end - start + 1; |
4929 | |
4930 if (lo < 0) | |
4931 lo = 0; | |
4932 else if (lo > size) | |
4933 lo = size; | |
4934 if (hi < 0) | |
4935 hi = 0; | |
4936 if (hi < lo) | |
4937 hi = lo; | |
4938 else if (hi > size) | |
4939 hi = size; | |
4940 | |
4941 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
|
4942 valObject, &len_change) == FAIL) |
2894 | 4943 return -1; |
4944 | |
4945 if (new_end) | |
4946 *new_end = end + len_change; | |
4947 | |
4948 return 0; | |
4949 } | |
4950 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4951 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4952 static PyObject * |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4953 RBAppend( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4954 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4955 PyObject *args, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4956 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4957 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4958 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
|
4959 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4960 PyObject *lines; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4961 PyInt len_change; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4962 PyInt max; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4963 PyInt n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4964 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4965 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4966 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4967 |
4387 | 4968 if (end == -1) |
4969 end = self->buf->b_ml.ml_line_count; | |
4970 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4971 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
|
4972 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4973 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
|
4974 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4975 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4976 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
|
4977 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4978 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
|
4979 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4980 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4981 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4982 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
|
4983 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4984 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4985 if (new_end) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4986 *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
|
4987 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4988 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
|
4989 return Py_None; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4990 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4991 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4992 // Range object |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4993 |
4319 | 4994 static PyTypeObject RangeType; |
4385 | 4995 static PySequenceMethods RangeAsSeq; |
4996 static PyMappingMethods RangeAsMapping; | |
4319 | 4997 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4998 typedef struct |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4999 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5000 PyObject_HEAD |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5001 BufferObject *buf; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5002 PyInt start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5003 PyInt end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5004 } RangeObject; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5005 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5006 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5007 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
|
5008 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5009 BufferObject *bufr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5010 RangeObject *self; |
4500 | 5011 self = PyObject_GC_New(RangeObject, &RangeType); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5012 if (self == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5013 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5014 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5015 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
|
5016 if (bufr == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5017 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5018 Py_DECREF(self); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5019 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5020 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5021 Py_INCREF(bufr); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5022 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5023 self->buf = bufr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5024 self->start = start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5025 self->end = end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5026 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5027 return (PyObject *)(self); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5028 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5029 |
4319 | 5030 static void |
4488 | 5031 RangeDestructor(RangeObject *self) |
4319 | 5032 { |
4500 | 5033 PyObject_GC_UnTrack((void *)(self)); |
4498 | 5034 Py_XDECREF(self->buf); |
4500 | 5035 PyObject_GC_Del((void *)(self)); |
5036 } | |
5037 | |
5038 static int | |
5039 RangeTraverse(RangeObject *self, visitproc visit, void *arg) | |
5040 { | |
5041 Py_VISIT(((PyObject *)(self->buf))); | |
5042 return 0; | |
5043 } | |
5044 | |
5045 static int | |
5046 RangeClear(RangeObject *self) | |
5047 { | |
5048 Py_CLEAR(self->buf); | |
5049 return 0; | |
4319 | 5050 } |
5051 | |
4385 | 5052 static PyInt |
4488 | 5053 RangeLength(RangeObject *self) |
4385 | 5054 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5055 // HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? |
4488 | 5056 if (CheckBuffer(self->buf)) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5057 return -1; // ??? |
4385 | 5058 |
4488 | 5059 return (self->end - self->start + 1); |
4385 | 5060 } |
5061 | |
5062 static PyObject * | |
4488 | 5063 RangeItem(RangeObject *self, PyInt n) |
4385 | 5064 { |
4488 | 5065 return RBItem(self->buf, n, self->start, self->end); |
4385 | 5066 } |
5067 | |
5068 static PyObject * | |
4488 | 5069 RangeSlice(RangeObject *self, PyInt lo, PyInt hi) |
4385 | 5070 { |
4488 | 5071 return RBSlice(self->buf, lo, hi, self->start, self->end); |
4385 | 5072 } |
5073 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5074 static char *RangeAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5075 "start", "end", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5076 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5077 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5078 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5079 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5080 RangeDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5081 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5082 return ObjectDir(self, RangeAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5083 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5084 |
4385 | 5085 static PyObject * |
4488 | 5086 RangeAppend(RangeObject *self, PyObject *args) |
4385 | 5087 { |
4488 | 5088 return RBAppend(self->buf, args, self->start, self->end, &self->end); |
4385 | 5089 } |
5090 | |
5091 static PyObject * | |
4488 | 5092 RangeRepr(RangeObject *self) |
4385 | 5093 { |
4488 | 5094 if (self->buf->buf == INVALID_BUFFER_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5095 return PyString_FromFormat("<range object (for deleted buffer) at %p>", |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5096 (self)); |
4385 | 5097 else |
5098 { | |
4488 | 5099 char *name = (char *)self->buf->buf->b_fname; |
4385 | 5100 |
5101 if (name == NULL) | |
5102 name = ""; | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5103 |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5104 return PyString_FromFormat("<range %s (%d:%d)>", |
4653
b943fd24c351
updated for version 7.3.1074
Bram Moolenaar <bram@vim.org>
parents:
4645
diff
changeset
|
5105 name, (int)self->start, (int)self->end); |
4385 | 5106 } |
5107 } | |
5108 | |
5109 static struct PyMethodDef RangeMethods[] = { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5110 // name, function, calling, documentation |
4492 | 5111 {"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
|
5112 {"__dir__", (PyCFunction)RangeDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5113 { NULL, NULL, 0, NULL} |
4385 | 5114 }; |
5115 | |
4319 | 5116 static PyTypeObject BufferType; |
5117 static PySequenceMethods BufferAsSeq; | |
5118 static PyMappingMethods BufferAsMapping; | |
5119 | |
5120 static PyObject * | |
4377 | 5121 BufferNew(buf_T *buf) |
5122 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5123 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5124 * We need to handle deletion of buffers underneath us. |
4377 | 5125 * If we add a "b_python*_ref" field to the buf_T structure, |
5126 * then we can get at it in buf_freeall() in vim. We then | |
5127 * need to create only ONE Python object per buffer - if | |
5128 * we try to create a second, just INCREF the existing one | |
5129 * and return it. The (single) Python object referring to | |
5130 * the buffer is stored in "b_python*_ref". | |
5131 * Question: what to do on a buf_freeall(). We'll probably | |
5132 * have to either delete the Python object (DECREF it to | |
5133 * zero - a bad idea, as it leaves dangling refs!) or | |
5134 * set the buf_T * value to an invalid value (-1?), which | |
5135 * means we need checks in all access functions... Bah. | |
5136 * | |
4385 | 5137 * Python2 and Python3 get different fields and different objects: |
4377 | 5138 * b_python_ref and b_python3_ref fields respectively. |
5139 */ | |
5140 | |
5141 BufferObject *self; | |
5142 | |
5143 if (BUF_PYTHON_REF(buf) != NULL) | |
5144 { | |
5145 self = BUF_PYTHON_REF(buf); | |
5146 Py_INCREF(self); | |
5147 } | |
5148 else | |
5149 { | |
5150 self = PyObject_NEW(BufferObject, &BufferType); | |
5151 if (self == NULL) | |
5152 return NULL; | |
5153 self->buf = buf; | |
5154 BUF_PYTHON_REF(buf) = self; | |
5155 } | |
5156 | |
5157 return (PyObject *)(self); | |
5158 } | |
5159 | |
4385 | 5160 static void |
4488 | 5161 BufferDestructor(BufferObject *self) |
4319 | 5162 { |
4488 | 5163 if (self->buf && self->buf != INVALID_BUFFER_VALUE) |
5164 BUF_PYTHON_REF(self->buf) = NULL; | |
4385 | 5165 |
5166 DESTRUCTOR_FINISH(self); | |
4319 | 5167 } |
5168 | |
4377 | 5169 static PyInt |
4488 | 5170 BufferLength(BufferObject *self) |
4377 | 5171 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5172 // HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? |
4488 | 5173 if (CheckBuffer(self)) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5174 return -1; // ??? |
4377 | 5175 |
4488 | 5176 return (PyInt)(self->buf->b_ml.ml_line_count); |
4377 | 5177 } |
5178 | |
5179 static PyObject * | |
4488 | 5180 BufferItem(BufferObject *self, PyInt n) |
4377 | 5181 { |
4488 | 5182 return RBItem(self, n, 1, -1); |
4377 | 5183 } |
5184 | |
5185 static PyObject * | |
4488 | 5186 BufferSlice(BufferObject *self, PyInt lo, PyInt hi) |
4377 | 5187 { |
4488 | 5188 return RBSlice(self, lo, hi, 1, -1); |
4377 | 5189 } |
5190 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5191 static char *BufferAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5192 "name", "number", "vars", "options", "valid", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5193 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5194 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5195 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5196 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5197 BufferDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5198 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5199 return ObjectDir(self, BufferAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5200 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5201 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5202 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5203 BufferAttrValid(BufferObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5204 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5205 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5206 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5207 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5208 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5209 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5210 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
|
5211 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5212 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5213 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5214 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5215 static PyObject * |
4488 | 5216 BufferAttr(BufferObject *self, char *name) |
4385 | 5217 { |
5218 if (strcmp(name, "name") == 0) | |
4597
00eecb2f8e3e
updated for version 7.3.1046
Bram Moolenaar <bram@vim.org>
parents:
4595
diff
changeset
|
5219 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
|
5220 ? "" : (char *)self->buf->b_ffname)); |
4385 | 5221 else if (strcmp(name, "number") == 0) |
4488 | 5222 return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum); |
4385 | 5223 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
5224 return NEW_DICTIONARY(self->buf->b_vars); |
4385 | 5225 else if (strcmp(name, "options") == 0) |
4488 | 5226 return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer, |
5227 (PyObject *) self); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5228 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5229 return ObjectDir(NULL, BufferAttrs); |
4385 | 5230 else |
5231 return NULL; | |
5232 } | |
5233 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5234 static int |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5235 BufferSetattr(BufferObject *self, char *name, PyObject *valObject) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5236 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5237 if (CheckBuffer(self)) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5238 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5239 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5240 if (strcmp(name, "name") == 0) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5241 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5242 char_u *val; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5243 aco_save_T aco; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5244 int ren_ret; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5245 PyObject *todecref; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5246 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5247 if (!(val = StringToChars(valObject, &todecref))) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5248 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5249 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5250 VimTryStart(); |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5251 // 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
|
5252 aucmd_prepbuf(&aco, self->buf); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5253 ren_ret = rename_buffer(val); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5254 aucmd_restbuf(&aco); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5255 Py_XDECREF(todecref); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5256 if (VimTryEnd()) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5257 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5258 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5259 if (ren_ret == FAIL) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5260 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5261 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
|
5262 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5263 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5264 return 0; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5265 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5266 else |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5267 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5268 PyErr_SetString(PyExc_AttributeError, name); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5269 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5270 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5271 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5272 |
4385 | 5273 static PyObject * |
4488 | 5274 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
|
5275 { |
4488 | 5276 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
|
5277 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5278 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5279 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5280 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
|
5281 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5282 pos_T *posp; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5283 char_u *pmark; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5284 char_u mark; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
5285 bufref_T savebuf; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5286 PyObject *todecref; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5287 |
4488 | 5288 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
|
5289 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5290 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5291 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
|
5292 return NULL; |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5293 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5294 if (pmark[0] == '\0' || pmark[1] != '\0') |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5295 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5296 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5297 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
|
5298 Py_XDECREF(todecref); |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5299 return NULL; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5300 } |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5301 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5302 mark = *pmark; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5303 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5304 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5305 |
4498 | 5306 VimTryStart(); |
4488 | 5307 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
|
5308 posp = getmark(mark, FALSE); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
5309 restore_buffer(&savebuf); |
4498 | 5310 if (VimTryEnd()) |
5311 return NULL; | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5312 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5313 if (posp == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5314 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5315 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
|
5316 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5317 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5318 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5319 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
|
5320 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5321 // 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
|
5322 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
|
5323 return Py_None; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5324 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5325 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5326 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
|
5327 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5328 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5329 static PyObject * |
4488 | 5330 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
|
5331 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5332 PyInt start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5333 PyInt end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5334 |
4488 | 5335 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
|
5336 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5337 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5338 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
|
5339 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5340 |
4488 | 5341 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
|
5342 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5343 |
4319 | 5344 static PyObject * |
4488 | 5345 BufferRepr(BufferObject *self) |
4319 | 5346 { |
4488 | 5347 if (self->buf == INVALID_BUFFER_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5348 return PyString_FromFormat("<buffer object (deleted) at %p>", self); |
4319 | 5349 else |
5350 { | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5351 char *name = (char *)self->buf->b_fname; |
4319 | 5352 |
5353 if (name == NULL) | |
5354 name = ""; | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5355 |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5356 return PyString_FromFormat("<buffer %s>", name); |
4319 | 5357 } |
5358 } | |
5359 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5360 static struct PyMethodDef BufferMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5361 // name, function, calling, documentation |
4492 | 5362 {"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
|
5363 {"mark", (PyCFunction)BufferMark, METH_O, "Return (row,col) representing position of named mark" }, |
4492 | 5364 {"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
|
5365 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5366 { 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
|
5367 }; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5368 |
4397 | 5369 /* |
5370 * Buffer list object - Implementation | |
5371 */ | |
5372 | |
5373 static PyTypeObject BufMapType; | |
5374 | |
5375 typedef struct | |
5376 { | |
5377 PyObject_HEAD | |
5378 } BufMapObject; | |
5379 | |
5380 static PyInt | |
5381 BufMapLength(PyObject *self UNUSED) | |
5382 { | |
5383 buf_T *b = firstbuf; | |
5384 PyInt n = 0; | |
5385 | |
5386 while (b) | |
5387 { | |
5388 ++n; | |
5389 b = b->b_next; | |
5390 } | |
5391 | |
5392 return n; | |
5393 } | |
5394 | |
5395 static PyObject * | |
5396 BufMapItem(PyObject *self UNUSED, PyObject *keyObject) | |
5397 { | |
5398 buf_T *b; | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5399 long bnr; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5400 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5401 if (NumberToLong(keyObject, &bnr, NUMBER_INT|NUMBER_NATURAL)) |
4397 | 5402 return NULL; |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5403 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5404 b = buflist_findnr((int) bnr); |
4397 | 5405 |
5406 if (b) | |
5407 return BufferNew(b); | |
5408 else | |
5409 { | |
4403 | 5410 PyErr_SetObject(PyExc_KeyError, keyObject); |
4397 | 5411 return NULL; |
5412 } | |
5413 } | |
5414 | |
5415 static void | |
5416 BufMapIterDestruct(PyObject *buffer) | |
5417 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5418 // Iteration was stopped before all buffers were processed |
4397 | 5419 if (buffer) |
5420 { | |
5421 Py_DECREF(buffer); | |
5422 } | |
5423 } | |
5424 | |
4433 | 5425 static int |
5426 BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg) | |
5427 { | |
4500 | 5428 if (buffer) |
5429 Py_VISIT(buffer); | |
4433 | 5430 return 0; |
5431 } | |
5432 | |
5433 static int | |
5434 BufMapIterClear(PyObject **buffer) | |
5435 { | |
4500 | 5436 if (*buffer) |
5437 Py_CLEAR(*buffer); | |
4433 | 5438 return 0; |
5439 } | |
5440 | |
4397 | 5441 static PyObject * |
5442 BufMapIterNext(PyObject **buffer) | |
5443 { | |
5444 PyObject *next; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5445 PyObject *ret; |
4397 | 5446 |
5447 if (!*buffer) | |
5448 return NULL; | |
5449 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5450 ret = *buffer; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5451 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5452 if (CheckBuffer((BufferObject *)(ret))) |
4397 | 5453 { |
5454 *buffer = NULL; | |
5455 return NULL; | |
5456 } | |
5457 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5458 if (!((BufferObject *)(ret))->buf->b_next) |
4397 | 5459 next = NULL; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5460 else if (!(next = BufferNew(((BufferObject *)(ret))->buf->b_next))) |
4397 | 5461 return NULL; |
5462 *buffer = next; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5463 // 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
|
5464 // 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
|
5465 return ret; |
4397 | 5466 } |
5467 | |
5468 static PyObject * | |
5469 BufMapIter(PyObject *self UNUSED) | |
5470 { | |
5471 PyObject *buffer; | |
5472 | |
5473 buffer = BufferNew(firstbuf); | |
5474 return IterNew(buffer, | |
4433 | 5475 (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext, |
5476 (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear); | |
4397 | 5477 } |
5478 | |
5479 static PyMappingMethods BufMapAsMapping = { | |
5480 (lenfunc) BufMapLength, | |
5481 (binaryfunc) BufMapItem, | |
5482 (objobjargproc) 0, | |
5483 }; | |
5484 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5485 // 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
|
5486 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5487 static char *CurrentAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5488 "buffer", "window", "line", "range", "tabpage", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5489 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5490 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5491 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5492 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5493 CurrentDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5494 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5495 return ObjectDir(self, CurrentAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5496 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5497 |
4319 | 5498 static PyObject * |
5499 CurrentGetattr(PyObject *self UNUSED, char *name) | |
5500 { | |
5501 if (strcmp(name, "buffer") == 0) | |
5502 return (PyObject *)BufferNew(curbuf); | |
5503 else if (strcmp(name, "window") == 0) | |
4431 | 5504 return (PyObject *)WindowNew(curwin, curtab); |
4401 | 5505 else if (strcmp(name, "tabpage") == 0) |
5506 return (PyObject *)TabPageNew(curtab); | |
4319 | 5507 else if (strcmp(name, "line") == 0) |
5508 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum); | |
5509 else if (strcmp(name, "range") == 0) | |
5510 return RangeNew(curbuf, RangeStart, RangeEnd); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5511 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5512 return ObjectDir(NULL, CurrentAttrs); |
4319 | 5513 else |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5514 #if PY_MAJOR_VERSION < 3 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5515 return Py_FindMethod(WindowMethods, self, name); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5516 #else |
4319 | 5517 return NULL; |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5518 #endif |
4319 | 5519 } |
5520 | |
5521 static int | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5522 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *valObject) |
4319 | 5523 { |
5524 if (strcmp(name, "line") == 0) | |
5525 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5526 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
|
5527 NULL) == FAIL) |
4319 | 5528 return -1; |
5529 | |
5530 return 0; | |
5531 } | |
4407 | 5532 else if (strcmp(name, "buffer") == 0) |
5533 { | |
5534 int count; | |
5535 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5536 if (valObject->ob_type != &BufferType) |
4407 | 5537 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5538 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5539 N_("expected vim.Buffer object, but got %s"), |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5540 Py_TYPE_NAME(valObject)); |
4407 | 5541 return -1; |
5542 } | |
5543 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5544 if (CheckBuffer((BufferObject *)(valObject))) |
4407 | 5545 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5546 count = ((BufferObject *)(valObject))->buf->b_fnum; |
4407 | 5547 |
4498 | 5548 VimTryStart(); |
4407 | 5549 if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL) |
5550 { | |
4498 | 5551 if (VimTryEnd()) |
5552 return -1; | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5553 PyErr_VIM_FORMAT(N_("failed to switch to buffer %d"), count); |
4407 | 5554 return -1; |
5555 } | |
5556 | |
4498 | 5557 return VimTryEnd(); |
4407 | 5558 } |
5559 else if (strcmp(name, "window") == 0) | |
5560 { | |
5561 int count; | |
5562 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5563 if (valObject->ob_type != &WindowType) |
4407 | 5564 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5565 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5566 N_("expected vim.Window object, but got %s"), |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5567 Py_TYPE_NAME(valObject)); |
4407 | 5568 return -1; |
5569 } | |
5570 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5571 if (CheckWindow((WindowObject *)(valObject))) |
4407 | 5572 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5573 count = get_win_number(((WindowObject *)(valObject))->win, firstwin); |
4407 | 5574 |
5575 if (!count) | |
5576 { | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5577 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5578 N_("failed to find window in the current tab page")); |
4407 | 5579 return -1; |
5580 } | |
5581 | |
4498 | 5582 VimTryStart(); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5583 win_goto(((WindowObject *)(valObject))->win); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5584 if (((WindowObject *)(valObject))->win != curwin) |
4407 | 5585 { |
4498 | 5586 if (VimTryEnd()) |
5587 return -1; | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5588 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5589 N_("did not switch to the specified window")); |
4407 | 5590 return -1; |
5591 } | |
5592 | |
4498 | 5593 return VimTryEnd(); |
4407 | 5594 } |
5595 else if (strcmp(name, "tabpage") == 0) | |
5596 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5597 if (valObject->ob_type != &TabPageType) |
4407 | 5598 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5599 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5600 N_("expected vim.TabPage object, but got %s"), |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5601 Py_TYPE_NAME(valObject)); |
4407 | 5602 return -1; |
5603 } | |
5604 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5605 if (CheckTabPage((TabPageObject *)(valObject))) |
4407 | 5606 return -1; |
5607 | |
4498 | 5608 VimTryStart(); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5609 goto_tabpage_tp(((TabPageObject *)(valObject))->tab, TRUE, TRUE); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5610 if (((TabPageObject *)(valObject))->tab != curtab) |
4407 | 5611 { |
4498 | 5612 if (VimTryEnd()) |
5613 return -1; | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5614 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5615 N_("did not switch to the specified tab page")); |
4407 | 5616 return -1; |
5617 } | |
5618 | |
4498 | 5619 return VimTryEnd(); |
4407 | 5620 } |
4319 | 5621 else |
5622 { | |
5623 PyErr_SetString(PyExc_AttributeError, name); | |
5624 return -1; | |
5625 } | |
5626 } | |
5627 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5628 static struct PyMethodDef CurrentMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5629 // name, function, calling, documentation |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5630 {"__dir__", (PyCFunction)CurrentDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5631 { NULL, NULL, 0, NULL} |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5632 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5633 |
3618 | 5634 static void |
4486 | 5635 init_range_cmd(exarg_T *eap) |
5636 { | |
5637 RangeStart = eap->line1; | |
5638 RangeEnd = eap->line2; | |
5639 } | |
5640 | |
5641 static void | |
5642 init_range_eval(typval_T *rettv UNUSED) | |
5643 { | |
5644 RangeStart = (PyInt) curwin->w_cursor.lnum; | |
5645 RangeEnd = RangeStart; | |
5646 } | |
5647 | |
5648 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5649 run_cmd(const char *cmd, void *arg UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5650 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5651 , PyGILState_STATE *pygilstate UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5652 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5653 ) |
4486 | 5654 { |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5655 PyObject *run_ret; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5656 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
|
5657 if (run_ret != NULL) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5658 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5659 Py_DECREF(run_ret); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5660 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5661 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5662 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5663 semsg(_(e_py_systemexit), "python"); |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5664 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5665 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5666 else |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5667 PyErr_PrintEx(1); |
4486 | 5668 } |
5669 | |
5670 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n "; | |
5671 static int code_hdr_len = 30; | |
5672 | |
5673 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5674 run_do(const char *cmd, void *arg UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5675 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5676 , PyGILState_STATE *pygilstate |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5677 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5678 ) |
4486 | 5679 { |
5680 PyInt lnum; | |
5681 size_t len; | |
5682 char *code; | |
5683 int status; | |
5684 PyObject *pyfunc, *pymain; | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5685 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
|
5686 buf_T *was_curbuf = curbuf; |
4486 | 5687 |
4575
626e9ccb7c48
updated for version 7.3.1035
Bram Moolenaar <bram@vim.org>
parents:
4523
diff
changeset
|
5688 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK) |
4486 | 5689 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5690 emsg(_("cannot save undo information")); |
4486 | 5691 return; |
5692 } | |
5693 | |
5694 len = code_hdr_len + STRLEN(cmd); | |
5695 code = PyMem_New(char, len + 1); | |
5696 memcpy(code, code_hdr, code_hdr_len); | |
5697 STRCPY(code + code_hdr_len, cmd); | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5698 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
|
5699 status = -1; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5700 if (run_ret != NULL) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5701 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5702 status = 0; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5703 Py_DECREF(run_ret); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5704 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5705 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5706 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5707 PyMem_Free(code); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5708 semsg(_(e_py_systemexit), "python"); |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5709 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5710 return; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5711 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5712 else |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5713 PyErr_PrintEx(1); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5714 |
4486 | 5715 PyMem_Free(code); |
5716 | |
5717 if (status) | |
5718 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5719 emsg(_("failed to run the code")); |
4486 | 5720 return; |
5721 } | |
5722 | |
5723 status = 0; | |
5724 pymain = PyImport_AddModule("__main__"); | |
5725 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5726 #ifdef PY_CAN_RECURSE |
4486 | 5727 PyGILState_Release(*pygilstate); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5728 #endif |
4486 | 5729 |
5730 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum) | |
5731 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5732 PyObject *line; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5733 PyObject *linenr; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5734 PyObject *ret; |
4486 | 5735 |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5736 #ifdef PY_CAN_RECURSE |
4486 | 5737 *pygilstate = PyGILState_Ensure(); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5738 #endif |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5739 // 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
|
5740 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
|
5741 || !(line = GetBufferLine(curbuf, lnum))) |
4486 | 5742 goto err; |
5743 if (!(linenr = PyInt_FromLong((long) lnum))) | |
5744 { | |
5745 Py_DECREF(line); | |
5746 goto err; | |
5747 } | |
5748 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL); | |
5749 Py_DECREF(line); | |
5750 Py_DECREF(linenr); | |
5751 if (!ret) | |
5752 goto err; | |
5753 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5754 // Check that the command didn't switch to another buffer. |
10751
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5755 if (curbuf != was_curbuf) |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5756 { |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5757 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
|
5758 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
|
5759 } |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5760 |
4486 | 5761 if (ret != Py_None) |
5762 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
|
5763 { |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5764 Py_XDECREF(ret); |
4486 | 5765 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
|
5766 } |
4486 | 5767 |
5768 Py_XDECREF(ret); | |
5769 PythonIO_Flush(); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5770 #ifdef PY_CAN_RECURSE |
4486 | 5771 PyGILState_Release(*pygilstate); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5772 #endif |
4486 | 5773 } |
5774 goto out; | |
5775 err: | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5776 #ifdef PY_CAN_RECURSE |
4486 | 5777 *pygilstate = PyGILState_Ensure(); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5778 #endif |
4486 | 5779 PyErr_PrintEx(0); |
5780 PythonIO_Flush(); | |
5781 status = 1; | |
5782 out: | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5783 #ifdef PY_CAN_RECURSE |
4486 | 5784 if (!status) |
5785 *pygilstate = PyGILState_Ensure(); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5786 #endif |
4486 | 5787 Py_DECREF(pyfunc); |
5788 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL); | |
5789 if (status) | |
5790 return; | |
5791 check_cursor(); | |
5792 update_curbuf(NOT_VALID); | |
5793 } | |
5794 | |
5795 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5796 run_eval(const char *cmd, typval_T *rettv |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5797 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5798 , PyGILState_STATE *pygilstate UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5799 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5800 ) |
4486 | 5801 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5802 PyObject *run_ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5803 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5804 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
|
5805 if (run_ret == NULL) |
4486 | 5806 { |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5807 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5808 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5809 semsg(_(e_py_systemexit), "python"); |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5810 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5811 } |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5812 else |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5813 { |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5814 if (PyErr_Occurred() && !msg_silent) |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5815 PyErr_PrintEx(0); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5816 emsg(_("E858: Eval did not return a valid python object")); |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5817 } |
4486 | 5818 } |
5819 else | |
5820 { | |
12806
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
5821 if (ConvertFromPyObject(run_ret, rettv) == -1) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5822 emsg(_("E859: 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
|
5823 Py_DECREF(run_ret); |
4486 | 5824 } |
5825 PyErr_Clear(); | |
5826 } | |
5827 | |
6565 | 5828 static int |
3618 | 5829 set_ref_in_py(const int copyID) |
5830 { | |
5831 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
|
5832 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
|
5833 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
|
5834 int abort = FALSE; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5835 FunctionObject *func; |
3618 | 5836 |
5837 if (lastdict != NULL) | |
6565 | 5838 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5839 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
|
5840 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
|
5841 copyID); |
6565 | 5842 } |
3618 | 5843 |
5844 if (lastlist != NULL) | |
6565 | 5845 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5846 for (cur = lastlist ; !abort && cur != NULL ; cur = cur->pll_prev) |
3618 | 5847 { |
5848 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
|
5849 abort = set_ref_in_list(ll, copyID); |
3618 | 5850 } |
6565 | 5851 } |
5852 | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5853 if (lastfunc != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5854 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5855 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
|
5856 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5857 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
|
5858 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
|
5859 if (func->argc) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5860 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
|
5861 abort = abort |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5862 || 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
|
5863 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5864 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5865 |
6565 | 5866 return abort; |
3618 | 5867 } |
5868 | |
5869 static int | |
5870 set_string_copy(char_u *str, typval_T *tv) | |
5871 { | |
5872 tv->vval.v_string = vim_strsave(str); | |
5873 if (tv->vval.v_string == NULL) | |
5874 { | |
5875 PyErr_NoMemory(); | |
5876 return -1; | |
5877 } | |
5878 return 0; | |
5879 } | |
5880 | |
4385 | 5881 static int |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5882 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 5883 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5884 dict_T *dict; |
4385 | 5885 char_u *key; |
5886 dictitem_T *di; | |
5887 PyObject *keyObject; | |
5888 PyObject *valObject; | |
5889 Py_ssize_t iter = 0; | |
5890 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5891 if (!(dict = py_dict_alloc())) |
4385 | 5892 return -1; |
5893 | |
5894 tv->v_type = VAR_DICT; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5895 tv->vval.v_dict = dict; |
4385 | 5896 |
5897 while (PyDict_Next(obj, &iter, &keyObject, &valObject)) | |
5898 { | |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5899 PyObject *todecref = NULL; |
4385 | 5900 |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
5901 if (keyObject == NULL || valObject == NULL) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5902 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5903 dict_unref(dict); |
4385 | 5904 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5905 } |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5906 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5907 if (!(key = StringToChars(keyObject, &todecref))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5908 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5909 dict_unref(dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5910 return -1; |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5911 } |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
5912 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5913 if (*key == NUL) |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5914 { |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5915 dict_unref(dict); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5916 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5917 RAISE_NO_EMPTY_KEYS; |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5918 return -1; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5919 } |
4385 | 5920 |
5921 di = dictitem_alloc(key); | |
5922 | |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5923 Py_XDECREF(todecref); |
4385 | 5924 |
5925 if (di == NULL) | |
5926 { | |
5927 PyErr_NoMemory(); | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5928 dict_unref(dict); |
4385 | 5929 return -1; |
5930 } | |
5931 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5932 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1) |
4385 | 5933 { |
5934 vim_free(di); | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5935 dict_unref(dict); |
4385 | 5936 return -1; |
5937 } | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5938 |
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5939 if (dict_add(dict, di) == FAIL) |
4385 | 5940 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5941 RAISE_KEY_ADD_FAIL(di->di_key); |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
5942 clear_tv(&di->di_tv); |
4385 | 5943 vim_free(di); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5944 dict_unref(dict); |
4385 | 5945 return -1; |
5946 } | |
5947 } | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5948 |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5949 --dict->dv_refcount; |
4385 | 5950 return 0; |
5951 } | |
5952 | |
5953 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5954 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 5955 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5956 dict_T *dict; |
4385 | 5957 char_u *key; |
5958 dictitem_T *di; | |
5959 PyObject *list; | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5960 PyObject *iterator; |
4385 | 5961 PyObject *keyObject; |
5962 PyObject *valObject; | |
5963 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5964 if (!(dict = py_dict_alloc())) |
4385 | 5965 return -1; |
5966 | |
5967 tv->v_type = VAR_DICT; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5968 tv->vval.v_dict = dict; |
4385 | 5969 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5970 if (!(list = PyMapping_Keys(obj))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5971 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5972 dict_unref(dict); |
4385 | 5973 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5974 } |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5975 |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5976 if (!(iterator = PyObject_GetIter(list))) |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5977 { |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5978 dict_unref(dict); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5979 Py_DECREF(list); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5980 return -1; |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5981 } |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5982 Py_DECREF(list); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5983 |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5984 while ((keyObject = PyIter_Next(iterator))) |
4385 | 5985 { |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5986 PyObject *todecref; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5987 |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5988 if (!(key = StringToChars(keyObject, &todecref))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5989 { |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5990 Py_DECREF(keyObject); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5991 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5992 dict_unref(dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5993 return -1; |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5994 } |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
5995 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5996 if (*key == NUL) |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5997 { |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5998 Py_DECREF(keyObject); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5999 Py_DECREF(iterator); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6000 Py_XDECREF(todecref); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6001 dict_unref(dict); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
6002 RAISE_NO_EMPTY_KEYS; |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6003 return -1; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6004 } |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6005 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6006 if (!(valObject = PyObject_GetItem(obj, keyObject))) |
4385 | 6007 { |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6008 Py_DECREF(keyObject); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6009 Py_DECREF(iterator); |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6010 Py_XDECREF(todecref); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6011 dict_unref(dict); |
4385 | 6012 return -1; |
6013 } | |
6014 | |
6015 di = dictitem_alloc(key); | |
6016 | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6017 Py_DECREF(keyObject); |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6018 Py_XDECREF(todecref); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6019 |
4385 | 6020 if (di == NULL) |
6021 { | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6022 Py_DECREF(iterator); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6023 Py_DECREF(valObject); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6024 dict_unref(dict); |
4385 | 6025 PyErr_NoMemory(); |
6026 return -1; | |
6027 } | |
6028 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6029 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1) |
4385 | 6030 { |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6031 Py_DECREF(iterator); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6032 Py_DECREF(valObject); |
4385 | 6033 vim_free(di); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6034 dict_unref(dict); |
4385 | 6035 return -1; |
6036 } | |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6037 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6038 Py_DECREF(valObject); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6039 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6040 if (dict_add(dict, di) == FAIL) |
4385 | 6041 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6042 RAISE_KEY_ADD_FAIL(di->di_key); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6043 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6044 dictitem_free(di); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6045 dict_unref(dict); |
4385 | 6046 return -1; |
6047 } | |
6048 } | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6049 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6050 --dict->dv_refcount; |
4385 | 6051 return 0; |
6052 } | |
6053 | |
6054 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6055 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 6056 { |
6057 list_T *l; | |
6058 | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6059 if (!(l = py_list_alloc())) |
4385 | 6060 return -1; |
6061 | |
6062 tv->v_type = VAR_LIST; | |
6063 tv->vval.v_list = l; | |
6064 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6065 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
|
6066 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6067 list_unref(l); |
4385 | 6068 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6069 } |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6070 |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6071 --l->lv_refcount; |
4385 | 6072 return 0; |
6073 } | |
6074 | |
3618 | 6075 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *); |
6076 | |
6077 static int | |
6078 convert_dl(PyObject *obj, typval_T *tv, | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6079 pytotvfunc py_to_tv, PyObject *lookup_dict) |
3618 | 6080 { |
6081 PyObject *capsule; | |
6082 char hexBuf[sizeof(void *) * 2 + 3]; | |
6083 | |
13353
8412df1479a3
patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents:
12812
diff
changeset
|
6084 sprintf(hexBuf, "%p", (void *)obj); |
3618 | 6085 |
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
|
6086 #ifdef PY_USE_CAPSULE |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6087 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
|
6088 #else |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6089 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
|
6090 #endif |
3618 | 6091 if (capsule == NULL) |
6092 { | |
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
|
6093 #ifdef PY_USE_CAPSULE |
3618 | 6094 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
|
6095 #else |
3648 | 6096 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
|
6097 #endif |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6098 if (PyDict_SetItemString(lookup_dict, hexBuf, capsule)) |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6099 { |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6100 Py_DECREF(capsule); |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6101 tv->v_type = VAR_UNKNOWN; |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6102 return -1; |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6103 } |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6104 |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6105 Py_DECREF(capsule); |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6106 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6107 if (py_to_tv(obj, tv, lookup_dict) == -1) |
3618 | 6108 { |
6109 tv->v_type = VAR_UNKNOWN; | |
6110 return -1; | |
6111 } | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
6112 // 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
|
6113 // do it ourself. |
7949
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6114 if (tv->v_type == VAR_DICT) |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6115 ++tv->vval.v_dict->dv_refcount; |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6116 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
|
6117 ++tv->vval.v_list->lv_refcount; |
3618 | 6118 } |
6119 else | |
6120 { | |
3638 | 6121 typval_T *v; |
6122 | |
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
|
6123 #ifdef PY_USE_CAPSULE |
3638 | 6124 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
|
6125 #else |
3648 | 6126 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
|
6127 #endif |
3618 | 6128 copy_tv(v, tv); |
6129 } | |
6130 return 0; | |
6131 } | |
6132 | |
6133 static int | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6134 ConvertFromPyMapping(PyObject *obj, typval_T *tv) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6135 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6136 PyObject *lookup_dict; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6137 int ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6138 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6139 if (!(lookup_dict = PyDict_New())) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6140 return -1; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6141 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6142 if (PyType_IsSubtype(obj->ob_type, &DictionaryType)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6143 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6144 tv->v_type = VAR_DICT; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6145 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6146 ++tv->vval.v_dict->dv_refcount; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6147 ret = 0; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6148 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6149 else if (PyDict_Check(obj)) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6150 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
|
6151 else if (PyMapping_Check(obj)) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6152 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
|
6153 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6154 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6155 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6156 N_("unable to convert %s to vim dictionary"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6157 Py_TYPE_NAME(obj)); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6158 ret = -1; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6159 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6160 Py_DECREF(lookup_dict); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6161 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6162 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6163 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6164 static int |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6165 ConvertFromPySequence(PyObject *obj, typval_T *tv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6166 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6167 PyObject *lookup_dict; |
8915
8cbf472483fa
commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents:
8913
diff
changeset
|
6168 int ret; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6169 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6170 if (!(lookup_dict = PyDict_New())) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6171 return -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6172 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6173 if (PyType_IsSubtype(obj->ob_type, &ListType)) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6174 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6175 tv->v_type = VAR_LIST; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6176 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
|
6177 ++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
|
6178 ret = 0; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6179 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6180 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
|
6181 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
|
6182 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6183 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6184 PyErr_FORMAT(PyExc_TypeError, |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6185 N_("unable to convert %s to vim list"), |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6186 Py_TYPE_NAME(obj)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6187 ret = -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6188 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6189 Py_DECREF(lookup_dict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6190 return ret; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6191 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6192 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6193 static int |
3618 | 6194 ConvertFromPyObject(PyObject *obj, typval_T *tv) |
6195 { | |
6196 PyObject *lookup_dict; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6197 int ret; |
3618 | 6198 |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6199 if (!(lookup_dict = PyDict_New())) |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6200 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6201 ret = _ConvertFromPyObject(obj, tv, lookup_dict); |
3618 | 6202 Py_DECREF(lookup_dict); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6203 return ret; |
3618 | 6204 } |
6205 | |
6206 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6207 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
3618 | 6208 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6209 if (PyType_IsSubtype(obj->ob_type, &DictionaryType)) |
3618 | 6210 { |
6211 tv->v_type = VAR_DICT; | |
6212 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict); | |
6213 ++tv->vval.v_dict->dv_refcount; | |
6214 } | |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6215 else if (PyType_IsSubtype(obj->ob_type, &ListType)) |
3618 | 6216 { |
6217 tv->v_type = VAR_LIST; | |
6218 tv->vval.v_list = (((ListObject *)(obj))->list); | |
6219 ++tv->vval.v_list->lv_refcount; | |
6220 } | |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6221 else if (PyType_IsSubtype(obj->ob_type, &FunctionType)) |
3618 | 6222 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6223 FunctionObject *func = (FunctionObject *) obj; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6224 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
|
6225 { |
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
|
6226 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
|
6227 |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6228 set_partial(func, pt, TRUE); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6229 tv->vval.v_partial = pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6230 tv->v_type = VAR_PARTIAL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6231 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6232 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6233 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6234 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
|
6235 return -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6236 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6237 tv->v_type = VAR_FUNC; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6238 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6239 func_ref(func->name); |
3618 | 6240 } |
6241 else if (PyBytes_Check(obj)) | |
6242 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6243 char_u *str; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6244 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6245 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1) |
3800 | 6246 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6247 if (str == NULL) |
3618 | 6248 return -1; |
6249 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6250 if (set_string_copy(str, tv) == -1) |
3618 | 6251 return -1; |
6252 | |
6253 tv->v_type = VAR_STRING; | |
6254 } | |
6255 else if (PyUnicode_Check(obj)) | |
6256 { | |
6257 PyObject *bytes; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6258 char_u *str; |
3618 | 6259 |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
6260 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL); |
3618 | 6261 if (bytes == NULL) |
6262 return -1; | |
6263 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6264 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1) |
3800 | 6265 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6266 if (str == NULL) |
3618 | 6267 return -1; |
6268 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6269 if (set_string_copy(str, tv)) |
3618 | 6270 { |
6271 Py_XDECREF(bytes); | |
6272 return -1; | |
6273 } | |
6274 Py_XDECREF(bytes); | |
6275 | |
6276 tv->v_type = VAR_STRING; | |
6277 } | |
4321 | 6278 #if PY_MAJOR_VERSION < 3 |
3618 | 6279 else if (PyInt_Check(obj)) |
6280 { | |
6281 tv->v_type = VAR_NUMBER; | |
6282 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
|
6283 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6284 return -1; |
3618 | 6285 } |
6286 #endif | |
6287 else if (PyLong_Check(obj)) | |
6288 { | |
6289 tv->v_type = VAR_NUMBER; | |
6290 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
|
6291 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6292 return -1; |
3618 | 6293 } |
6294 else if (PyDict_Check(obj)) | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6295 return convert_dl(obj, tv, pydict_to_tv, lookup_dict); |
3618 | 6296 #ifdef FEAT_FLOAT |
6297 else if (PyFloat_Check(obj)) | |
6298 { | |
6299 tv->v_type = VAR_FLOAT; | |
6300 tv->vval.v_float = (float_T) PyFloat_AsDouble(obj); | |
6301 } | |
6302 #endif | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6303 else if (PyObject_HasAttrString(obj, "keys")) |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6304 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
|
6305 // 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
|
6306 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
|
6307 return convert_dl(obj, tv, pyseq_to_tv, lookup_dict); |
3618 | 6308 else if (PyMapping_Check(obj)) |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6309 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
|
6310 else if (PyNumber_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6311 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6312 PyObject *num; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6313 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6314 if (!(num = PyNumber_Long(obj))) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6315 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6316 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6317 tv->v_type = VAR_NUMBER; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6318 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
|
6319 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6320 Py_DECREF(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6321 } |
12806
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6322 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
|
6323 { |
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6324 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
|
6325 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
|
6326 } |
3618 | 6327 else |
6328 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6329 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6330 N_("unable to convert %s to vim structure"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6331 Py_TYPE_NAME(obj)); |
3618 | 6332 return -1; |
6333 } | |
6334 return 0; | |
6335 } | |
6336 | |
6337 static PyObject * | |
6338 ConvertToPyObject(typval_T *tv) | |
6339 { | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6340 typval_T *argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6341 int i; |
3618 | 6342 if (tv == NULL) |
6343 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6344 PyErr_SET_VIM(N_("internal error: NULL reference passed")); |
3618 | 6345 return NULL; |
6346 } | |
6347 switch (tv->v_type) | |
6348 { | |
6349 case VAR_STRING: | |
3852 | 6350 return PyBytes_FromString(tv->vval.v_string == NULL |
6351 ? "" : (char *)tv->vval.v_string); | |
3618 | 6352 case VAR_NUMBER: |
6353 return PyLong_FromLong((long) tv->vval.v_number); | |
6354 #ifdef FEAT_FLOAT | |
6355 case VAR_FLOAT: | |
6356 return PyFloat_FromDouble((double) tv->vval.v_float); | |
6357 #endif | |
6358 case VAR_LIST: | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6359 return NEW_LIST(tv->vval.v_list); |
3618 | 6360 case VAR_DICT: |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6361 return NEW_DICTIONARY(tv->vval.v_dict); |
3618 | 6362 case VAR_FUNC: |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6363 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
|
6364 ? (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
|
6365 0, NULL, NULL, TRUE); |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6366 case VAR_PARTIAL: |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6367 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
|
6368 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6369 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
|
6370 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
|
6371 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
|
6372 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6373 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6374 argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6375 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
|
6376 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
|
6377 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
|
6378 ? (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
|
6379 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
|
6380 tv->vval.v_partial->pt_dict, |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
6381 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
|
6382 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
6383 return PyBytes_FromStringAndSize( |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
6384 (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
|
6385 (Py_ssize_t) tv->vval.v_blob->bv_ga.ga_len); |
3618 | 6386 case VAR_UNKNOWN: |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6387 case VAR_CHANNEL: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6388 case VAR_JOB: |
3618 | 6389 Py_INCREF(Py_None); |
6390 return Py_None; | |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6391 case VAR_SPECIAL: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6392 switch (tv->vval.v_number) |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6393 { |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6394 case VVAL_FALSE: return AlwaysFalse(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6395 case VVAL_TRUE: return AlwaysTrue(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6396 case VVAL_NONE: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6397 case VVAL_NULL: return AlwaysNone(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6398 } |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6399 PyErr_SET_VIM(N_("internal error: invalid value type")); |
3618 | 6400 return NULL; |
6401 } | |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6402 return NULL; |
3618 | 6403 } |
4319 | 6404 |
6405 typedef struct | |
6406 { | |
6407 PyObject_HEAD | |
6408 } CurrentObject; | |
6409 static PyTypeObject CurrentType; | |
6410 | |
6411 static void | |
6412 init_structs(void) | |
6413 { | |
6414 vim_memset(&OutputType, 0, sizeof(OutputType)); | |
6415 OutputType.tp_name = "vim.message"; | |
6416 OutputType.tp_basicsize = sizeof(OutputObject); | |
6417 OutputType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6418 OutputType.tp_doc = "vim message object"; | |
6419 OutputType.tp_methods = OutputMethods; | |
6420 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6421 OutputType.tp_getattro = (getattrofunc)OutputGetattro; |
6422 OutputType.tp_setattro = (setattrofunc)OutputSetattro; | |
4319 | 6423 OutputType.tp_alloc = call_PyType_GenericAlloc; |
6424 OutputType.tp_new = call_PyType_GenericNew; | |
6425 OutputType.tp_free = call_PyObject_Free; | |
13952
76a65058766f
patch 8.0.1846: Python interface is incompatible with lldb
Christian Brabandt <cb@256bit.org>
parents:
13353
diff
changeset
|
6426 OutputType.tp_base = &PyStdPrinter_Type; |
4319 | 6427 #else |
4488 | 6428 OutputType.tp_getattr = (getattrfunc)OutputGetattr; |
6429 OutputType.tp_setattr = (setattrfunc)OutputSetattr; | |
13952
76a65058766f
patch 8.0.1846: Python interface is incompatible with lldb
Christian Brabandt <cb@256bit.org>
parents:
13353
diff
changeset
|
6430 // 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
|
6431 // OutputType.tp_base = &PyFile_Type; |
4319 | 6432 #endif |
6433 | |
4397 | 6434 vim_memset(&IterType, 0, sizeof(IterType)); |
6435 IterType.tp_name = "vim.iter"; | |
6436 IterType.tp_basicsize = sizeof(IterObject); | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6437 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4397 | 6438 IterType.tp_doc = "generic iterator object"; |
4488 | 6439 IterType.tp_iter = (getiterfunc)IterIter; |
6440 IterType.tp_iternext = (iternextfunc)IterNext; | |
6441 IterType.tp_dealloc = (destructor)IterDestructor; | |
6442 IterType.tp_traverse = (traverseproc)IterTraverse; | |
6443 IterType.tp_clear = (inquiry)IterClear; | |
4397 | 6444 |
4319 | 6445 vim_memset(&BufferType, 0, sizeof(BufferType)); |
6446 BufferType.tp_name = "vim.buffer"; | |
6447 BufferType.tp_basicsize = sizeof(BufferType); | |
4488 | 6448 BufferType.tp_dealloc = (destructor)BufferDestructor; |
6449 BufferType.tp_repr = (reprfunc)BufferRepr; | |
4319 | 6450 BufferType.tp_as_sequence = &BufferAsSeq; |
6451 BufferType.tp_as_mapping = &BufferAsMapping; | |
6452 BufferType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6453 BufferType.tp_doc = "vim buffer object"; | |
6454 BufferType.tp_methods = BufferMethods; | |
6455 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6456 BufferType.tp_getattro = (getattrofunc)BufferGetattro; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
6457 BufferType.tp_setattro = (setattrofunc)BufferSetattro; |
4319 | 6458 BufferType.tp_alloc = call_PyType_GenericAlloc; |
6459 BufferType.tp_new = call_PyType_GenericNew; | |
6460 BufferType.tp_free = call_PyObject_Free; | |
6461 #else | |
4488 | 6462 BufferType.tp_getattr = (getattrfunc)BufferGetattr; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
6463 BufferType.tp_setattr = (setattrfunc)BufferSetattr; |
4319 | 6464 #endif |
6465 | |
6466 vim_memset(&WindowType, 0, sizeof(WindowType)); | |
6467 WindowType.tp_name = "vim.window"; | |
6468 WindowType.tp_basicsize = sizeof(WindowObject); | |
4488 | 6469 WindowType.tp_dealloc = (destructor)WindowDestructor; |
6470 WindowType.tp_repr = (reprfunc)WindowRepr; | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6471 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4319 | 6472 WindowType.tp_doc = "vim Window object"; |
6473 WindowType.tp_methods = WindowMethods; | |
4488 | 6474 WindowType.tp_traverse = (traverseproc)WindowTraverse; |
6475 WindowType.tp_clear = (inquiry)WindowClear; | |
4319 | 6476 #if PY_MAJOR_VERSION >= 3 |
4488 | 6477 WindowType.tp_getattro = (getattrofunc)WindowGetattro; |
6478 WindowType.tp_setattro = (setattrofunc)WindowSetattro; | |
4319 | 6479 WindowType.tp_alloc = call_PyType_GenericAlloc; |
6480 WindowType.tp_new = call_PyType_GenericNew; | |
6481 WindowType.tp_free = call_PyObject_Free; | |
6482 #else | |
4488 | 6483 WindowType.tp_getattr = (getattrfunc)WindowGetattr; |
6484 WindowType.tp_setattr = (setattrfunc)WindowSetattr; | |
4319 | 6485 #endif |
6486 | |
4401 | 6487 vim_memset(&TabPageType, 0, sizeof(TabPageType)); |
6488 TabPageType.tp_name = "vim.tabpage"; | |
6489 TabPageType.tp_basicsize = sizeof(TabPageObject); | |
4488 | 6490 TabPageType.tp_dealloc = (destructor)TabPageDestructor; |
6491 TabPageType.tp_repr = (reprfunc)TabPageRepr; | |
4401 | 6492 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT; |
6493 TabPageType.tp_doc = "vim tab page object"; | |
6494 TabPageType.tp_methods = TabPageMethods; | |
6495 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6496 TabPageType.tp_getattro = (getattrofunc)TabPageGetattro; |
4401 | 6497 TabPageType.tp_alloc = call_PyType_GenericAlloc; |
6498 TabPageType.tp_new = call_PyType_GenericNew; | |
6499 TabPageType.tp_free = call_PyObject_Free; | |
6500 #else | |
4488 | 6501 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr; |
4401 | 6502 #endif |
6503 | |
4393 | 6504 vim_memset(&BufMapType, 0, sizeof(BufMapType)); |
6505 BufMapType.tp_name = "vim.bufferlist"; | |
6506 BufMapType.tp_basicsize = sizeof(BufMapObject); | |
6507 BufMapType.tp_as_mapping = &BufMapAsMapping; | |
6508 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT; | |
4397 | 6509 BufMapType.tp_iter = BufMapIter; |
4319 | 6510 BufferType.tp_doc = "vim buffer list"; |
6511 | |
6512 vim_memset(&WinListType, 0, sizeof(WinListType)); | |
6513 WinListType.tp_name = "vim.windowlist"; | |
6514 WinListType.tp_basicsize = sizeof(WinListType); | |
6515 WinListType.tp_as_sequence = &WinListAsSeq; | |
6516 WinListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6517 WinListType.tp_doc = "vim window list"; | |
4488 | 6518 WinListType.tp_dealloc = (destructor)WinListDestructor; |
4401 | 6519 |
6520 vim_memset(&TabListType, 0, sizeof(TabListType)); | |
6521 TabListType.tp_name = "vim.tabpagelist"; | |
6522 TabListType.tp_basicsize = sizeof(TabListType); | |
6523 TabListType.tp_as_sequence = &TabListAsSeq; | |
6524 TabListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6525 TabListType.tp_doc = "vim tab page list"; | |
4319 | 6526 |
6527 vim_memset(&RangeType, 0, sizeof(RangeType)); | |
6528 RangeType.tp_name = "vim.range"; | |
6529 RangeType.tp_basicsize = sizeof(RangeObject); | |
4488 | 6530 RangeType.tp_dealloc = (destructor)RangeDestructor; |
6531 RangeType.tp_repr = (reprfunc)RangeRepr; | |
4319 | 6532 RangeType.tp_as_sequence = &RangeAsSeq; |
6533 RangeType.tp_as_mapping = &RangeAsMapping; | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6534 RangeType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4319 | 6535 RangeType.tp_doc = "vim Range object"; |
6536 RangeType.tp_methods = RangeMethods; | |
4500 | 6537 RangeType.tp_traverse = (traverseproc)RangeTraverse; |
6538 RangeType.tp_clear = (inquiry)RangeClear; | |
4319 | 6539 #if PY_MAJOR_VERSION >= 3 |
4488 | 6540 RangeType.tp_getattro = (getattrofunc)RangeGetattro; |
4319 | 6541 RangeType.tp_alloc = call_PyType_GenericAlloc; |
6542 RangeType.tp_new = call_PyType_GenericNew; | |
6543 RangeType.tp_free = call_PyObject_Free; | |
6544 #else | |
4488 | 6545 RangeType.tp_getattr = (getattrfunc)RangeGetattr; |
4319 | 6546 #endif |
6547 | |
6548 vim_memset(&CurrentType, 0, sizeof(CurrentType)); | |
6549 CurrentType.tp_name = "vim.currentdata"; | |
6550 CurrentType.tp_basicsize = sizeof(CurrentObject); | |
6551 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6552 CurrentType.tp_doc = "vim current object"; | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
6553 CurrentType.tp_methods = CurrentMethods; |
4319 | 6554 #if PY_MAJOR_VERSION >= 3 |
4488 | 6555 CurrentType.tp_getattro = (getattrofunc)CurrentGetattro; |
6556 CurrentType.tp_setattro = (setattrofunc)CurrentSetattro; | |
4319 | 6557 #else |
4488 | 6558 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr; |
6559 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr; | |
4319 | 6560 #endif |
6561 | |
6562 vim_memset(&DictionaryType, 0, sizeof(DictionaryType)); | |
6563 DictionaryType.tp_name = "vim.dictionary"; | |
6564 DictionaryType.tp_basicsize = sizeof(DictionaryObject); | |
4488 | 6565 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6566 DictionaryType.tp_as_sequence = &DictionaryAsSeq; |
4319 | 6567 DictionaryType.tp_as_mapping = &DictionaryAsMapping; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6568 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
4319 | 6569 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure"; |
6570 DictionaryType.tp_methods = DictionaryMethods; | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6571 DictionaryType.tp_iter = (getiterfunc)DictionaryIter; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6572 DictionaryType.tp_new = (newfunc)DictionaryConstructor; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6573 DictionaryType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6574 #if PY_MAJOR_VERSION >= 3 |
4488 | 6575 DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro; |
6576 DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro; | |
4319 | 6577 #else |
4488 | 6578 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr; |
6579 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr; | |
4319 | 6580 #endif |
6581 | |
6582 vim_memset(&ListType, 0, sizeof(ListType)); | |
6583 ListType.tp_name = "vim.list"; | |
4488 | 6584 ListType.tp_dealloc = (destructor)ListDestructor; |
4319 | 6585 ListType.tp_basicsize = sizeof(ListObject); |
6586 ListType.tp_as_sequence = &ListAsSeq; | |
6587 ListType.tp_as_mapping = &ListAsMapping; | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6588 ListType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
4319 | 6589 ListType.tp_doc = "list pushing modifications to vim structure"; |
6590 ListType.tp_methods = ListMethods; | |
4488 | 6591 ListType.tp_iter = (getiterfunc)ListIter; |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6592 ListType.tp_new = (newfunc)ListConstructor; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6593 ListType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6594 #if PY_MAJOR_VERSION >= 3 |
4488 | 6595 ListType.tp_getattro = (getattrofunc)ListGetattro; |
6596 ListType.tp_setattro = (setattrofunc)ListSetattro; | |
4319 | 6597 #else |
4488 | 6598 ListType.tp_getattr = (getattrfunc)ListGetattr; |
6599 ListType.tp_setattr = (setattrfunc)ListSetattr; | |
4319 | 6600 #endif |
6601 | |
6602 vim_memset(&FunctionType, 0, sizeof(FunctionType)); | |
4397 | 6603 FunctionType.tp_name = "vim.function"; |
4319 | 6604 FunctionType.tp_basicsize = sizeof(FunctionObject); |
4488 | 6605 FunctionType.tp_dealloc = (destructor)FunctionDestructor; |
6606 FunctionType.tp_call = (ternaryfunc)FunctionCall; | |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6607 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
4319 | 6608 FunctionType.tp_doc = "object that calls vim function"; |
6609 FunctionType.tp_methods = FunctionMethods; | |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
6610 FunctionType.tp_repr = (reprfunc)FunctionRepr; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6611 FunctionType.tp_new = (newfunc)FunctionConstructor; |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6612 FunctionType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6613 #if PY_MAJOR_VERSION >= 3 |
4488 | 6614 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro; |
4319 | 6615 #else |
4488 | 6616 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr; |
4319 | 6617 #endif |
6618 | |
4350 | 6619 vim_memset(&OptionsType, 0, sizeof(OptionsType)); |
6620 OptionsType.tp_name = "vim.options"; | |
6621 OptionsType.tp_basicsize = sizeof(OptionsObject); | |
5610 | 6622 OptionsType.tp_as_sequence = &OptionsAsSeq; |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6623 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4350 | 6624 OptionsType.tp_doc = "object for manipulating options"; |
5610 | 6625 OptionsType.tp_iter = (getiterfunc)OptionsIter; |
4350 | 6626 OptionsType.tp_as_mapping = &OptionsAsMapping; |
4488 | 6627 OptionsType.tp_dealloc = (destructor)OptionsDestructor; |
6628 OptionsType.tp_traverse = (traverseproc)OptionsTraverse; | |
6629 OptionsType.tp_clear = (inquiry)OptionsClear; | |
4350 | 6630 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6631 #if PY_VERSION_HEX < 0x030700f0 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6632 vim_memset(&LoaderType, 0, sizeof(LoaderType)); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6633 LoaderType.tp_name = "vim.Loader"; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6634 LoaderType.tp_basicsize = sizeof(LoaderObject); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6635 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6636 LoaderType.tp_doc = "vim message object"; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6637 LoaderType.tp_methods = LoaderMethods; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6638 LoaderType.tp_dealloc = (destructor)LoaderDestructor; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6639 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6640 |
4319 | 6641 #if PY_MAJOR_VERSION >= 3 |
6642 vim_memset(&vimmodule, 0, sizeof(vimmodule)); | |
6643 vimmodule.m_name = "vim"; | |
6644 vimmodule.m_doc = "Vim Python interface\n"; | |
6645 vimmodule.m_size = -1; | |
6646 vimmodule.m_methods = VimMethods; | |
6647 #endif | |
6648 } | |
4494 | 6649 |
6650 #define PYTYPE_READY(type) \ | |
6651 if (PyType_Ready(&type)) \ | |
6652 return -1; | |
6653 | |
6654 static int | |
5166
467efeee8f9e
updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents:
5139
diff
changeset
|
6655 init_types(void) |
4494 | 6656 { |
6657 PYTYPE_READY(IterType); | |
6658 PYTYPE_READY(BufferType); | |
6659 PYTYPE_READY(RangeType); | |
6660 PYTYPE_READY(WindowType); | |
6661 PYTYPE_READY(TabPageType); | |
6662 PYTYPE_READY(BufMapType); | |
6663 PYTYPE_READY(WinListType); | |
6664 PYTYPE_READY(TabListType); | |
6665 PYTYPE_READY(CurrentType); | |
6666 PYTYPE_READY(DictionaryType); | |
6667 PYTYPE_READY(ListType); | |
6668 PYTYPE_READY(FunctionType); | |
6669 PYTYPE_READY(OptionsType); | |
6670 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
|
6671 #if PY_VERSION_HEX < 0x030700f0 |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6672 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
|
6673 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6674 return 0; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6675 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6676 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6677 static int |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
6678 init_sys_path(void) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6679 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6680 PyObject *path; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6681 PyObject *path_hook; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6682 PyObject *path_hooks; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6683 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6684 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
|
6685 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6686 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6687 if (!(path_hooks = PySys_GetObject("path_hooks"))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6688 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6689 PyErr_Clear(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6690 path_hooks = PyList_New(1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6691 PyList_SET_ITEM(path_hooks, 0, path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6692 if (PySys_SetObject("path_hooks", path_hooks)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6693 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6694 Py_DECREF(path_hooks); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6695 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6696 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6697 Py_DECREF(path_hooks); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6698 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6699 else if (PyList_Check(path_hooks)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6700 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6701 if (PyList_Append(path_hooks, path_hook)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6702 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6703 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6704 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6705 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6706 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6707 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6708 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6709 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6710 VimTryStart(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
6711 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
|
6712 "You should now do the following:\n" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6713 "- 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
|
6714 "- 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
|
6715 VimTryEnd(); // Discard the error |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6716 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6717 return 0; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6718 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6719 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6720 if (!(path = PySys_GetObject("path"))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6721 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6722 PyErr_Clear(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6723 path = PyList_New(1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6724 Py_INCREF(vim_special_path_object); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6725 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
|
6726 if (PySys_SetObject("path", path)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6727 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6728 Py_DECREF(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6729 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6730 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6731 Py_DECREF(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6732 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6733 else if (PyList_Check(path)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6734 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6735 if (PyList_Append(path, vim_special_path_object)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6736 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6737 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6738 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6739 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6740 VimTryStart(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
6741 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
|
6742 "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
|
6743 VimTryEnd(); // Discard the error |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6744 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6745 |
4494 | 6746 return 0; |
6747 } | |
6748 | |
6749 static BufMapObject TheBufferMap = | |
6750 { | |
6751 PyObject_HEAD_INIT(&BufMapType) | |
6752 }; | |
6753 | |
6754 static WinListObject TheWindowList = | |
6755 { | |
6756 PyObject_HEAD_INIT(&WinListType) | |
6757 NULL | |
6758 }; | |
6759 | |
6760 static CurrentObject TheCurrent = | |
6761 { | |
6762 PyObject_HEAD_INIT(&CurrentType) | |
6763 }; | |
6764 | |
6765 static TabListObject TheTabPageList = | |
6766 { | |
6767 PyObject_HEAD_INIT(&TabListType) | |
6768 }; | |
6769 | |
6770 static struct numeric_constant { | |
6771 char *name; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6772 int val; |
4494 | 6773 } numeric_constants[] = { |
6774 {"VAR_LOCKED", VAR_LOCKED}, | |
6775 {"VAR_FIXED", VAR_FIXED}, | |
6776 {"VAR_SCOPE", VAR_SCOPE}, | |
6777 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE}, | |
6778 }; | |
6779 | |
6780 static struct object_constant { | |
6781 char *name; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6782 PyObject *valObject; |
4494 | 6783 } object_constants[] = { |
6784 {"buffers", (PyObject *)(void *)&TheBufferMap}, | |
6785 {"windows", (PyObject *)(void *)&TheWindowList}, | |
6786 {"tabpages", (PyObject *)(void *)&TheTabPageList}, | |
6787 {"current", (PyObject *)(void *)&TheCurrent}, | |
4496 | 6788 |
6789 {"Buffer", (PyObject *)&BufferType}, | |
6790 {"Range", (PyObject *)&RangeType}, | |
6791 {"Window", (PyObject *)&WindowType}, | |
6792 {"TabPage", (PyObject *)&TabPageType}, | |
6793 {"Dictionary", (PyObject *)&DictionaryType}, | |
6794 {"List", (PyObject *)&ListType}, | |
6795 {"Function", (PyObject *)&FunctionType}, | |
6796 {"Options", (PyObject *)&OptionsType}, | |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6797 #if PY_VERSION_HEX < 0x030700f0 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6798 {"_Loader", (PyObject *)&LoaderType}, |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6799 #endif |
4494 | 6800 }; |
6801 | |
6802 #define ADD_OBJECT(m, name, obj) \ | |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6803 if (PyModule_AddObject(m, name, obj)) \ |
4494 | 6804 return -1; |
6805 | |
6806 #define ADD_CHECKED_OBJECT(m, name, obj) \ | |
6807 { \ | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6808 PyObject *valObject = obj; \ |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6809 if (!valObject) \ |
4494 | 6810 return -1; \ |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6811 ADD_OBJECT(m, name, valObject); \ |
4494 | 6812 } |
6813 | |
6814 static int | |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6815 populate_module(PyObject *m) |
4494 | 6816 { |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6817 int i; |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6818 PyObject *other_module; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6819 PyObject *attr; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6820 PyObject *imp; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6821 #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
|
6822 PyObject *dict; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6823 PyObject *cls; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6824 #endif |
4494 | 6825 |
6826 for (i = 0; i < (int)(sizeof(numeric_constants) | |
6827 / sizeof(struct numeric_constant)); | |
6828 ++i) | |
6829 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
|
6830 PyInt_FromLong(numeric_constants[i].val)); |
4494 | 6831 |
6832 for (i = 0; i < (int)(sizeof(object_constants) | |
6833 / sizeof(struct object_constant)); | |
6834 ++i) | |
6835 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6836 PyObject *valObject; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6837 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6838 valObject = object_constants[i].valObject; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6839 Py_INCREF(valObject); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6840 ADD_OBJECT(m, object_constants[i].name, valObject); |
4494 | 6841 } |
6842 | |
6843 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL))) | |
6844 return -1; | |
6845 ADD_OBJECT(m, "error", VimError); | |
6846 | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17168
diff
changeset
|
6847 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
|
6848 ADD_CHECKED_OBJECT(m, "vvars", NEW_DICTIONARY(get_vimvar_dict())); |
4494 | 6849 ADD_CHECKED_OBJECT(m, "options", |
6850 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL)); | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6851 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6852 if (!(other_module = PyImport_ImportModule("os"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6853 return -1; |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6854 ADD_OBJECT(m, "os", other_module); |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6855 |
9161
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6856 #if PY_MAJOR_VERSION >= 3 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6857 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
|
6858 return -1; |
9161
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6859 #else |
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6860 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
|
6861 return -1; |
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6862 #endif |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6863 ADD_OBJECT(m, "_getcwd", py_getcwd) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6864 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6865 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
|
6866 return -1; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6867 ADD_OBJECT(m, "_chdir", py_chdir); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6868 if (!(attr = PyObject_GetAttrString(m, "chdir"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6869 return -1; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6870 if (PyObject_SetAttrString(other_module, "chdir", attr)) |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6871 { |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6872 Py_DECREF(attr); |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6873 return -1; |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6874 } |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6875 Py_DECREF(attr); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6876 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6877 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
|
6878 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6879 ADD_OBJECT(m, "_fchdir", py_fchdir); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6880 if (!(attr = PyObject_GetAttrString(m, "fchdir"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6881 return -1; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6882 if (PyObject_SetAttrString(other_module, "fchdir", attr)) |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6883 { |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6884 Py_DECREF(attr); |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6885 return -1; |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6886 } |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6887 Py_DECREF(attr); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6888 } |
4722
3534e9b4fa42
updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents:
4706
diff
changeset
|
6889 else |
3534e9b4fa42
updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents:
4706
diff
changeset
|
6890 PyErr_Clear(); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6891 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6892 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
|
6893 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6894 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6895 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
|
6896 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6897 #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
|
6898 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
|
6899 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6900 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6901 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
|
6902 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6903 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
|
6904 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6905 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6906 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6907 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6908 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6909 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
|
6910 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6911 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6912 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6913 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6914 |
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
|
6915 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
|
6916 { |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6917 // 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
|
6918 // version. |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6919 ADD_OBJECT(m, "_find_module", py_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
|
6920 } |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6921 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6922 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6923 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6924 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
|
6925 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6926 if (!(imp = PyImport_ImportModule("imp"))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6927 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6928 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6929 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
|
6930 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6931 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6932 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6933 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6934 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6935 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
|
6936 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6937 Py_DECREF(py_find_module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6938 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6939 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6940 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6941 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6942 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6943 |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6944 ADD_OBJECT(m, "_find_module", py_find_module); |
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6945 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
|
6946 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6947 |
4494 | 6948 return 0; |
6949 } |