Mercurial > vim
annotate src/if_py_both.h @ 15132:22e7834d286c v8.1.0576
patch 8.1.0576: indent script tests pick up installed scripts
commit https://github.com/vim/vim/commit/30700cd5ffa258f1d684ab6b34bd03e970450dba
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 10 21:36:56 2018 +0100
patch 8.1.0576: indent script tests pick up installed scripts
Problem: Indent script tests pick up installed scripts.
Solution: Use current runtime indent scripts.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 10 Dec 2018 21:45:07 +0100 |
parents | 16cccc953909 |
children | ee63f4fe3d45 |
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 |
5588 | 16 #ifdef __BORLANDC__ |
17 /* Disable Warning W8060: Possibly incorrect assignment in function ... */ | |
18 # pragma warn -8060 | |
19 #endif | |
20 | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
21 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
|
22 |
3734 | 23 #if PY_VERSION_HEX < 0x02050000 |
24 typedef int Py_ssize_t; /* Python 2.4 and earlier don't have this type. */ | |
25 #endif | |
26 | |
2919 | 27 #ifdef FEAT_MBYTE |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
28 # define ENC_OPT ((char *)p_enc) |
2919 | 29 #else |
30 # define ENC_OPT "latin1" | |
31 #endif | |
4435 | 32 #define DOPY_FUNC "_vim_pydo" |
2919 | 33 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
34 static const char *vim_special_path = "_vim_path_"; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
35 |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
36 #define PyErr_SET_STRING(exc, str) PyErr_SetString(exc, _(str)) |
4385 | 37 #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
|
38 #define PyErr_SET_VIM(str) PyErr_SET_STRING(VimError, str) |
5608 | 39 #define PyErr_FORMAT(exc, str, arg) PyErr_Format(exc, _(str), arg) |
40 #define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2) | |
41 #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
|
42 |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
43 #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
|
44 ? "(NULL)" \ |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
45 : obj->ob_type->tp_name) |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
46 |
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
47 #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
|
48 N_("empty keys are not allowed")) |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
49 #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
|
50 #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
|
51 #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
|
52 #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
|
53 #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
|
54 #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
|
55 #define RAISE_KEY_ADD_FAIL(key) \ |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
56 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
|
57 #define RAISE_INVALID_INDEX_TYPE(idx) \ |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
58 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
|
59 Py_TYPE_NAME(idx)); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
60 |
4385 | 61 #define INVALID_BUFFER_VALUE ((buf_T *)(-1)) |
62 #define INVALID_WINDOW_VALUE ((win_T *)(-1)) | |
4401 | 63 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1)) |
4385 | 64 |
4486 | 65 typedef void (*rangeinitializer)(void *); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
66 typedef void (*runner)(const char *, void * |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
67 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
68 , PyGILState_STATE * |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
69 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
70 ); |
4486 | 71 |
4385 | 72 static int ConvertFromPyObject(PyObject *, typval_T *); |
73 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
74 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
|
75 static int ConvertFromPySequence(PyObject *, typval_T *); |
4431 | 76 static PyObject *WindowNew(win_T *, tabpage_T *); |
77 static PyObject *BufferNew (buf_T *); | |
78 static PyObject *LineToString(const char *); | |
4385 | 79 |
80 static PyInt RangeStart; | |
81 static PyInt RangeEnd; | |
82 | |
4486 | 83 static PyObject *globals; |
84 | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
85 static PyObject *py_chdir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
86 static PyObject *py_fchdir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
87 static PyObject *py_getcwd; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
88 static PyObject *vim_module; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
89 static PyObject *vim_special_path_object; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
90 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
91 #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
|
92 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
|
93 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
94 static PyObject *py_find_module; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
95 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
|
96 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
97 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
98 static PyObject *VimError; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
99 |
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
|
100 /* |
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 * 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
|
102 */ |
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 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
|
104 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
|
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 } |
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
|
107 |
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
|
108 /* |
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
|
109 * 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
|
110 */ |
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
|
111 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
|
112 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
|
113 { |
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
|
114 } |
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
|
115 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
116 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
117 * 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
|
118 * 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
|
119 * was needed to generate returned value is object. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
120 * |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
121 * Use Py_XDECREF to decrement reference count. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
122 */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
123 static char_u * |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
124 StringToChars(PyObject *obj, PyObject **todecref) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
125 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
126 char_u *str; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
127 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
128 if (PyBytes_Check(obj)) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
129 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
130 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
131 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
132 || str == 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 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
135 *todecref = NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
136 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
137 else if (PyUnicode_Check(obj)) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
138 { |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
139 PyObject *bytes; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
140 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
141 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
|
142 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
143 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
144 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
145 || str == NULL) |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
146 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
147 Py_DECREF(bytes); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
148 return NULL; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
149 } |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
150 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
151 *todecref = bytes; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
152 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
153 else |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
154 { |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
155 #if PY_MAJOR_VERSION < 3 |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
156 PyErr_FORMAT(PyExc_TypeError, |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
157 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
|
158 Py_TYPE_NAME(obj)); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
159 #else |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
160 PyErr_FORMAT(PyExc_TypeError, |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
161 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
|
162 Py_TYPE_NAME(obj)); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
163 #endif |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
164 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
165 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
166 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
167 return (char_u *) str; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
168 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
169 |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
170 #define NUMBER_LONG 1 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
171 #define NUMBER_INT 2 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
172 #define NUMBER_NATURAL 4 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
173 #define NUMBER_UNSIGNED 8 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
174 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
175 static int |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
176 NumberToLong(PyObject *obj, long *result, int flags) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
177 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
178 #if PY_MAJOR_VERSION < 3 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
179 if (PyInt_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
180 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
181 *result = PyInt_AsLong(obj); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
182 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
183 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
184 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
185 else |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
186 #endif |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
187 if (PyLong_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
188 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
189 *result = PyLong_AsLong(obj); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
190 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
191 return -1; |
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 else if (PyNumber_Check(obj)) |
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 PyObject *num; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
196 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
197 if (!(num = PyNumber_Long(obj))) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
198 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
199 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
200 *result = PyLong_AsLong(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
201 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
202 Py_DECREF(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
203 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
204 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
205 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
206 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
207 else |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
208 { |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
209 #if PY_MAJOR_VERSION < 3 |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
210 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
211 N_("expected int(), long() or something supporting " |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
212 "coercing to long(), but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
213 Py_TYPE_NAME(obj)); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
214 #else |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
215 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
216 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
|
217 "but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
218 Py_TYPE_NAME(obj)); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
219 #endif |
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 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
223 if (flags & NUMBER_INT) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
224 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
225 if (*result > INT_MAX) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
226 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
227 PyErr_SET_STRING(PyExc_OverflowError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
228 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
|
229 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
230 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
231 else if (*result < INT_MIN) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
232 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
233 PyErr_SET_STRING(PyExc_OverflowError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
234 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
|
235 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
236 } |
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 if (flags & NUMBER_NATURAL) |
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, |
5695 | 244 N_("number must be greater than 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 else if (flags & NUMBER_UNSIGNED) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
249 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
250 if (*result < 0) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
251 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
252 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
253 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
|
254 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
255 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
256 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
257 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
258 return 0; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
259 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
260 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
261 static int |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
262 add_string(PyObject *list, char *s) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
263 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
264 PyObject *string; |
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 if (!(string = PyString_FromString(s))) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
267 return -1; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
268 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
269 if (PyList_Append(list, string)) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
270 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
271 Py_DECREF(string); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
272 return -1; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
273 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
274 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
275 Py_DECREF(string); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
276 return 0; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
277 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
278 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
279 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
280 ObjectDir(PyObject *self, char **attributes) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
281 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
282 PyMethodDef *method; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
283 char **attr; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
284 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
285 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
286 if (!(ret = PyList_New(0))) |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
287 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
288 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
289 if (self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
290 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
|
291 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
|
292 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
293 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
294 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
295 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
296 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
297 for (attr = attributes ; *attr ; ++attr) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
298 if (add_string(ret, *attr)) |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
299 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
300 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
301 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
302 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
303 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
304 #if PY_MAJOR_VERSION < 3 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
305 if (add_string(ret, "__members__")) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
306 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
307 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
308 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
309 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
310 #endif |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
311 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
312 return ret; |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
313 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
314 |
4385 | 315 /* Output buffer management |
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
|
316 */ |
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 |
2582 | 318 /* 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
|
319 typedef void (*writefn)(char_u *); |
4385 | 320 |
321 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
|
322 |
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
|
323 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
|
324 { |
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
|
325 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
|
326 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
|
327 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
|
328 } 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
|
329 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
330 static char *OutputAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
331 "softspace", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
332 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
333 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
334 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
335 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
336 OutputDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
337 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
338 return ObjectDir(self, OutputAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
339 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
340 |
3826 | 341 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
342 OutputSetattr(OutputObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
343 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
344 if (valObject == NULL) |
3826 | 345 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
346 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
347 N_("can't delete OutputObject attributes")); |
3826 | 348 return -1; |
349 } | |
350 | |
351 if (strcmp(name, "softspace") == 0) | |
352 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
353 if (NumberToLong(valObject, &(self->softspace), NUMBER_UNSIGNED)) |
3826 | 354 return -1; |
355 return 0; | |
356 } | |
357 | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
358 PyErr_FORMAT(PyExc_AttributeError, N_("invalid attribute: %s"), name); |
3826 | 359 return -1; |
360 } | |
361 | |
4385 | 362 /* Buffer IO, we write one whole line at a time. */ |
363 static garray_T io_ga = {0, 0, 1, 80, NULL}; | |
364 static writefn old_fn = NULL; | |
365 | |
366 static void | |
367 PythonIO_Flush(void) | |
368 { | |
369 if (old_fn != NULL && io_ga.ga_len > 0) | |
370 { | |
371 ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL; | |
372 old_fn((char_u *)io_ga.ga_data); | |
373 } | |
374 io_ga.ga_len = 0; | |
375 } | |
376 | |
377 static void | |
378 writer(writefn fn, char_u *str, PyInt n) | |
379 { | |
380 char_u *ptr; | |
381 | |
382 /* Flush when switching output function. */ | |
383 if (fn != old_fn) | |
384 PythonIO_Flush(); | |
385 old_fn = fn; | |
386 | |
387 /* Write each NL separated line. Text after the last NL is kept for | |
388 * writing later. */ | |
389 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL) | |
390 { | |
391 PyInt len = ptr - str; | |
392 | |
393 if (ga_grow(&io_ga, (int)(len + 1)) == FAIL) | |
394 break; | |
395 | |
396 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len); | |
397 ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL; | |
398 fn((char_u *)io_ga.ga_data); | |
399 str = ptr + 1; | |
400 n -= len + 1; | |
401 io_ga.ga_len = 0; | |
402 } | |
403 | |
404 /* Put the remaining text into io_ga for later printing. */ | |
405 if (n > 0 && ga_grow(&io_ga, (int)(n + 1)) == OK) | |
406 { | |
407 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n); | |
408 io_ga.ga_len += (int)n; | |
409 } | |
410 } | |
411 | |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
412 static int |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
413 write_output(OutputObject *self, PyObject *string) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
414 { |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
415 Py_ssize_t len = 0; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
416 char *str = NULL; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
417 int error = self->error; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
418 |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
419 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
|
420 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
|
421 |
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 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
|
423 Python_Lock_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
|
424 writer((writefn)(error ? emsg : msg), (char_u *)str, len); |
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 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
|
426 Py_END_ALLOW_THREADS |
2894 | 427 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
|
428 |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
429 return 0; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
430 } |
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 static PyObject * |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
433 OutputWrite(OutputObject *self, PyObject *string) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
434 { |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
435 if (write_output(self, string)) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
436 return NULL; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
437 |
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
|
438 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
|
439 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
|
440 } |
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
|
441 |
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
|
442 static PyObject * |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
443 OutputWritelines(OutputObject *self, PyObject *seq) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
444 { |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
445 PyObject *iterator; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
446 PyObject *item; |
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 if (!(iterator = PyObject_GetIter(seq))) |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
449 return NULL; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
450 |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
451 while ((item = PyIter_Next(iterator))) |
3618 | 452 { |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
453 if (write_output(self, item)) |
3618 | 454 { |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
455 Py_DECREF(iterator); |
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 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
|
458 } |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
459 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
|
460 } |
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
|
461 |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
462 Py_DECREF(iterator); |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
463 |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
464 /* Iterator may have finished due to an exception */ |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
465 if (PyErr_Occurred()) |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
466 return NULL; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
467 |
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
|
468 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
|
469 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
|
470 } |
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
|
471 |
2727 | 472 static PyObject * |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
473 AlwaysNone(PyObject *self UNUSED) |
2727 | 474 { |
475 /* do nothing */ | |
476 Py_INCREF(Py_None); | |
477 return Py_None; | |
478 } | |
479 | |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
480 static PyObject * |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
481 AlwaysFalse(PyObject *self UNUSED) |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
482 { |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
483 /* do nothing */ |
7202
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
484 PyObject *ret = Py_False; |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
485 Py_INCREF(ret); |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
486 return ret; |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
487 } |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
488 |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
489 static PyObject * |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
490 AlwaysTrue(PyObject *self UNUSED) |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
491 { |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
492 /* do nothing */ |
7202
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
493 PyObject *ret = Py_True; |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
494 Py_INCREF(ret); |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
495 return ret; |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
496 } |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
497 |
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
|
498 /***************/ |
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
|
499 |
4385 | 500 static struct PyMethodDef OutputMethods[] = { |
4492 | 501 /* name, function, calling, doc */ |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
502 {"write", (PyCFunction)OutputWrite, METH_O, ""}, |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
503 {"writelines", (PyCFunction)OutputWritelines, METH_O, ""}, |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
504 {"flush", (PyCFunction)AlwaysNone, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
505 {"close", (PyCFunction)AlwaysNone, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
506 {"isatty", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
507 {"readable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
508 {"seekable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
509 {"writable", (PyCFunction)AlwaysTrue, METH_NOARGS, ""}, |
8967
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8921
diff
changeset
|
510 {"closed", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
511 {"__dir__", (PyCFunction)OutputDir, METH_NOARGS, ""}, |
4492 | 512 { NULL, NULL, 0, NULL} |
4385 | 513 }; |
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
|
514 |
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 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
|
516 { |
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 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
|
518 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
|
519 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
|
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 |
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 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
|
523 { |
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 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
|
525 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
|
526 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
|
527 }; |
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 |
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
|
529 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
|
530 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
|
531 { |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
532 if (PySys_SetObject("stdout", (PyObject *)(void *)&Output)) |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
533 return -1; |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
534 if (PySys_SetObject("stderr", (PyObject *)(void *)&Error)) |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
535 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
|
536 |
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 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
|
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 EMSG(_("E264: Python: Error initialising I/O objects")); |
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 -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
|
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 |
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
|
543 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
|
544 } |
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
|
545 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
546 #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
|
547 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
|
548 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
549 typedef struct |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
550 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
551 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
|
552 char *fullname; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
553 PyObject *result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
554 } LoaderObject; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
555 static PyTypeObject LoaderType; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
556 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
557 static void |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
558 LoaderDestructor(LoaderObject *self) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
559 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
560 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
|
561 Py_XDECREF(self->result); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
562 DESTRUCTOR_FINISH(self); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
563 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
564 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
565 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
566 LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
567 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
568 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
|
569 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
|
570 PyObject *module; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
571 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
572 if (!fullname) |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
573 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
574 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
|
575 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
|
576 return module; |
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 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
579 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
|
580 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
581 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
|
582 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
|
583 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
584 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
|
585 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
|
586 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
587 if (!module) |
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 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
|
590 return NULL; |
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 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
|
593 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
|
594 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
595 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
596 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
|
597 return module; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
598 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
599 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
600 static struct PyMethodDef LoaderMethods[] = { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
601 /* name, function, calling, doc */ |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
602 {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""}, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
603 { NULL, NULL, 0, NULL} |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
604 }; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
605 #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
|
606 |
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 /* Check to see whether a Vim error has been reported, or a keyboard |
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
|
608 * 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
|
609 */ |
4498 | 610 |
611 static void | |
612 VimTryStart(void) | |
613 { | |
614 ++trylevel; | |
615 } | |
616 | |
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
|
617 static int |
4498 | 618 VimTryEnd(void) |
619 { | |
620 --trylevel; | |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10751
diff
changeset
|
621 /* Without this it stops processing all subsequent Vim script commands and |
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10751
diff
changeset
|
622 * generates strange error messages if I e.g. try calling Test() in a cycle |
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10751
diff
changeset
|
623 */ |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
624 did_emsg = FALSE; |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
625 /* Keyboard interrupt should be preferred over anything else */ |
4498 | 626 if (got_int) |
627 { | |
5629 | 628 if (did_throw) |
5469 | 629 discard_current_exception(); |
630 got_int = FALSE; | |
4498 | 631 PyErr_SetNone(PyExc_KeyboardInterrupt); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
632 return -1; |
4498 | 633 } |
5517 | 634 else if (msg_list != NULL && *msg_list != NULL) |
635 { | |
636 int should_free; | |
637 char_u *msg; | |
638 | |
639 msg = get_exception_string(*msg_list, ET_ERROR, NULL, &should_free); | |
640 | |
641 if (msg == NULL) | |
642 { | |
643 PyErr_NoMemory(); | |
644 return -1; | |
645 } | |
646 | |
647 PyErr_SetVim((char *) msg); | |
648 | |
649 free_global_msglist(); | |
650 | |
651 if (should_free) | |
652 vim_free(msg); | |
653 | |
654 return -1; | |
655 } | |
4498 | 656 else if (!did_throw) |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
657 return (PyErr_Occurred() ? -1 : 0); |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
658 /* Python exception is preferred over vim one; unlikely to occur though */ |
4498 | 659 else if (PyErr_Occurred()) |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
660 { |
5629 | 661 discard_current_exception(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
662 return -1; |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
663 } |
10942
e05695e59f6d
patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents:
10751
diff
changeset
|
664 /* Finally transform Vim script exception to python one */ |
4498 | 665 else |
666 { | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
667 PyErr_SetVim((char *)current_exception->value); |
4498 | 668 discard_current_exception(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
669 return -1; |
4498 | 670 } |
671 } | |
672 | |
673 static int | |
674 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
|
675 { |
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 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
|
677 { |
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 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
|
679 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
|
680 } |
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
|
681 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
|
682 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
683 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
684 /* Vim module - Implementation |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
685 */ |
4385 | 686 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
687 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
688 VimCommand(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
689 { |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
690 char_u *cmd; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
691 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
692 PyObject *todecref; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
693 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
694 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
|
695 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
696 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
697 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
|
698 Python_Lock_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
699 |
4498 | 700 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
701 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
|
702 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
703 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
704 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
705 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
|
706 |
4498 | 707 if (VimTryEnd()) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
708 ret = NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
709 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
710 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
711 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
712 Py_XINCREF(ret); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
713 Py_XDECREF(todecref); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
714 return ret; |
2447
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
717 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
718 * 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
|
719 * 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
|
720 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
721 * 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
|
722 * you call VimToPython. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
723 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
724 static PyObject * |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
725 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
|
726 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
727 PyObject *ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
728 PyObject *newObj; |
3618 | 729 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
|
730 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
731 /* Avoid infinite recursion */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
732 if (depth > 100) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
733 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
734 Py_INCREF(Py_None); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
735 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
736 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
737 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
738 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
739 /* Check if we run into a recursive loop. The item must be in lookup_dict |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
740 * then and we can use it again. */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
741 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
|
742 || (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
|
743 { |
3618 | 744 sprintf(ptrBuf, "%p", |
745 our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list | |
746 : (void *)our_tv->vval.v_dict); | |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
747 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
748 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
|
749 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
750 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
751 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
752 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
753 } |
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 if (our_tv->v_type == VAR_STRING) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
756 ret = PyString_FromString(our_tv->vval.v_string == NULL |
3852 | 757 ? "" : (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
|
758 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
|
759 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
760 char buf[NUMBUFLEN]; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
761 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
762 /* For backwards compatibility numbers are stored as strings. */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
763 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
|
764 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
|
765 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
766 # ifdef FEAT_FLOAT |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
767 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
|
768 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
769 char buf[NUMBUFLEN]; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
770 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
771 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
|
772 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
|
773 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
774 # endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
775 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
|
776 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
777 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
|
778 listitem_T *curr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
779 |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
780 if (list == NULL) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
781 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
782 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
783 if (!(ret = PyList_New(0))) |
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 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
786 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
|
787 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
788 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
789 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
790 } |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
791 |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
792 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
|
793 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
794 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
|
795 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
796 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
797 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
798 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
799 if (PyList_Append(ret, newObj)) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
800 { |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
801 Py_DECREF(newObj); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
802 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
803 return NULL; |
2447
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 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
|
806 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
807 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
808 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
|
809 { |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
810 |
6598 | 811 hashtab_T *ht; |
812 long_u todo; | |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
813 hashitem_T *hi; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
814 dictitem_T *di; |
6598 | 815 |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
816 if (our_tv->vval.v_dict == NULL) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
817 return NULL; |
6598 | 818 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
|
819 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
820 if (!(ret = PyDict_New())) |
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 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
823 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
|
824 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
825 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
826 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
827 } |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
828 |
6598 | 829 todo = ht->ht_used; |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
830 for (hi = ht->ht_array; todo > 0; ++hi) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
831 { |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
832 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
|
833 { |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
834 --todo; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
835 |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
836 di = dict_lookup(hi); |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
837 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
|
838 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
839 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
840 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
841 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
842 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
|
843 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
844 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
|
845 Py_DECREF(newObj); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
846 return NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
847 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
848 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
849 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
850 } |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
851 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
|
852 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
853 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
|
854 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
855 ret = Py_False; |
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 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
|
859 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
860 ret = Py_True; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
861 Py_INCREF(ret); |
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 else |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
864 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
865 Py_INCREF(Py_None); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
866 ret = Py_None; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
867 } |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
868 return ret; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
869 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
870 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
871 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
872 Py_INCREF(Py_None); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
873 ret = Py_None; |
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 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
876 return ret; |
2447
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
879 static PyObject * |
4500 | 880 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
|
881 { |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
882 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
|
883 typval_T *our_tv; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
884 PyObject *string; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
885 PyObject *todecref; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
886 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
887 PyObject *lookup_dict; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
888 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
889 if (!PyArg_ParseTuple(args, "O", &string)) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
890 return NULL; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
891 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
892 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
|
893 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
894 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
895 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
|
896 Python_Lock_Vim(); |
4498 | 897 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
898 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
|
899 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
900 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
|
901 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
902 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
903 |
4498 | 904 if (VimTryEnd()) |
905 return NULL; | |
906 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
907 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
|
908 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
909 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
|
910 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
911 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
912 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
913 /* Convert the Vim type into a Python type. Create a dictionary that's |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
914 * used to check for recursive loops. */ |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
915 if (!(lookup_dict = PyDict_New())) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
916 ret = NULL; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
917 else |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
918 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
919 ret = VimToPython(our_tv, 1, lookup_dict); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
920 Py_DECREF(lookup_dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
921 } |
2447
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
924 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
|
925 Python_Lock_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
926 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
|
927 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
928 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
|
929 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
930 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
931 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
932 |
3618 | 933 static PyObject *ConvertToPyObject(typval_T *); |
934 | |
935 static PyObject * | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
936 VimEvalPy(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
937 { |
3618 | 938 typval_T *our_tv; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
939 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
940 char_u *expr; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
941 PyObject *todecref; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
942 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
943 if (!(expr = StringToChars(string, &todecref))) |
3618 | 944 return NULL; |
945 | |
946 Py_BEGIN_ALLOW_THREADS | |
947 Python_Lock_Vim(); | |
4498 | 948 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
949 our_tv = eval_expr(expr, NULL); |
3618 | 950 Python_Release_Vim(); |
951 Py_END_ALLOW_THREADS | |
952 | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
953 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
954 |
4498 | 955 if (VimTryEnd()) |
956 return NULL; | |
957 | |
3618 | 958 if (our_tv == NULL) |
959 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
960 PyErr_SET_VIM(N_("invalid expression")); |
3618 | 961 return NULL; |
962 } | |
963 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
964 ret = ConvertToPyObject(our_tv); |
3618 | 965 Py_BEGIN_ALLOW_THREADS |
966 Python_Lock_Vim(); | |
967 free_tv(our_tv); | |
968 Python_Release_Vim(); | |
969 Py_END_ALLOW_THREADS | |
970 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
971 return ret; |
3618 | 972 } |
973 | |
974 static PyObject * | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
975 VimStrwidth(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
976 { |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
977 char_u *str; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
978 PyObject *todecref; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
979 int len; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
980 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
981 if (!(str = StringToChars(string, &todecref))) |
3618 | 982 return NULL; |
983 | |
3988 | 984 #ifdef FEAT_MBYTE |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
985 len = mb_string2cells(str, (int)STRLEN(str)); |
3988 | 986 #else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
987 len = STRLEN(str); |
3988 | 988 #endif |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
989 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
990 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
991 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
992 return PyLong_FromLong(len); |
3618 | 993 } |
994 | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
995 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
996 _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
997 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
998 PyObject *ret; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
999 PyObject *newwd; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1000 PyObject *todecref; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1001 char_u *new_dir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1002 |
4754
be1e4acb30ca
updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents:
4722
diff
changeset
|
1003 if (_chdir == NULL) |
be1e4acb30ca
updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents:
4722
diff
changeset
|
1004 return NULL; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1005 if (!(ret = PyObject_Call(_chdir, args, kwargs))) |
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 if (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL))) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1009 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1010 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1011 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1012 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1013 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1014 if (!(new_dir = StringToChars(newwd, &todecref))) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1015 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1016 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1017 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1018 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1019 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1020 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1021 VimTryStart(); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1022 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1023 if (vim_chdir(new_dir)) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1024 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1025 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1026 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1027 Py_XDECREF(todecref); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1028 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1029 if (VimTryEnd()) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1030 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1031 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1032 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
|
1033 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1034 } |
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 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1037 Py_XDECREF(todecref); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1038 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1039 post_chdir(FALSE); |
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 if (VimTryEnd()) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1042 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1043 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1044 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1045 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1046 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1047 return ret; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1048 } |
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 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1051 VimChdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1052 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1053 return _VimChdir(py_chdir, args, kwargs); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1054 } |
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 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1057 VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1058 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1059 return _VimChdir(py_fchdir, args, kwargs); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1060 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1061 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1062 typedef struct { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1063 PyObject *callable; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1064 PyObject *result; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1065 } map_rtp_data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1066 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1067 static void |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1068 map_rtp_callback(char_u *path, void *_data) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1069 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1070 void **data = (void **) _data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1071 PyObject *pathObject; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1072 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
|
1073 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1074 if (!(pathObject = PyString_FromString((char *)path))) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1075 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1076 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1077 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1078 } |
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 mr_data->result = PyObject_CallFunctionObjArgs(mr_data->callable, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1081 pathObject, NULL); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1082 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1083 Py_DECREF(pathObject); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1084 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1085 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
|
1086 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1087 else |
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 Py_DECREF(mr_data->result); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1090 mr_data->result = NULL; |
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 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1093 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1094 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1095 VimForeachRTP(PyObject *self UNUSED, PyObject *callable) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1096 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1097 map_rtp_data data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1098 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1099 data.callable = callable; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1100 data.result = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1101 |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7949
diff
changeset
|
1102 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
|
1103 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1104 if (data.result == NULL) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1105 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1106 if (PyErr_Occurred()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1107 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1108 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1109 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1110 Py_INCREF(Py_None); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1111 return Py_None; |
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 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1114 return data.result; |
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 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1117 /* |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1118 * _vim_runtimepath_ special path implementation. |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1119 */ |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1120 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1121 static void |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1122 map_finder_callback(char_u *path, void *_data) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1123 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1124 void **data = (void **) _data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1125 PyObject *list = *((PyObject **) data); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1126 PyObject *pathObject1, *pathObject2; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1127 char *pathbuf; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1128 size_t pathlen; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1129 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1130 pathlen = STRLEN(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1131 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1132 #if PY_MAJOR_VERSION < 3 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1133 # define PY_MAIN_DIR_STRING "python2" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1134 #else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1135 # define PY_MAIN_DIR_STRING "python3" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1136 #endif |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1137 #define PY_ALTERNATE_DIR_STRING "pythonx" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1138 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1139 #define PYTHONX_STRING_LENGTH 7 /* STRLEN("pythonx") */ |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1140 if (!(pathbuf = PyMem_New(char, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1141 pathlen + STRLEN(PATHSEPSTR) + PYTHONX_STRING_LENGTH + 1))) |
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 PyErr_NoMemory(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1144 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1145 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1146 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1147 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1148 mch_memmove(pathbuf, path, pathlen + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1149 add_pathsep((char_u *) pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1150 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1151 pathlen = STRLEN(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1152 mch_memmove(pathbuf + pathlen, PY_MAIN_DIR_STRING, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1153 PYTHONX_STRING_LENGTH + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1154 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1155 if (!(pathObject1 = PyString_FromString(pathbuf))) |
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 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1158 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1159 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1160 } |
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 mch_memmove(pathbuf + pathlen, PY_ALTERNATE_DIR_STRING, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1163 PYTHONX_STRING_LENGTH + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1164 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1165 if (!(pathObject2 = PyString_FromString(pathbuf))) |
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 Py_DECREF(pathObject1); |
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 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1170 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1171 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1172 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1173 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1174 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1175 if (PyList_Append(list, pathObject1) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1176 || PyList_Append(list, pathObject2)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1177 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1178 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1179 Py_DECREF(pathObject1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1180 Py_DECREF(pathObject2); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1181 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1182 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1183 static PyObject * |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1184 Vim_GetPaths(PyObject *self UNUSED) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1185 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1186 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1187 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1188 if (!(ret = PyList_New(0))) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1189 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1190 |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7949
diff
changeset
|
1191 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
|
1192 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1193 if (PyErr_Occurred()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1194 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1195 Py_DECREF(ret); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1196 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1197 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1198 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1199 return ret; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1200 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1201 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1202 #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
|
1203 static PyObject * |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1204 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
|
1205 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1206 char *fullname; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1207 PyObject *paths; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1208 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
|
1209 PyObject *spec; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1210 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1211 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
|
1212 return NULL; |
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 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
|
1215 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1216 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1217 spec = PyObject_CallFunction(py_find_spec, "sNN", fullname, paths, target); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1218 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1219 Py_DECREF(paths); |
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 if (!spec) |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1222 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1223 if (PyErr_Occurred()) |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1224 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1225 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1226 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
|
1227 return Py_None; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1228 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1229 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1230 return spec; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1231 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1232 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1233 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1234 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
|
1235 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1236 PyObject *fd, *pathname, *description; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1237 |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1238 if (!PyTuple_Check(find_module_result)) |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1239 { |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1240 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1241 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
|
1242 Py_TYPE_NAME(find_module_result)); |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1243 return NULL; |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1244 } |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1245 if (PyTuple_GET_SIZE(find_module_result) != 3) |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1246 { |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1247 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1248 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
|
1249 "tuple of size %d"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1250 (int) PyTuple_GET_SIZE(find_module_result)); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1251 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1252 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1253 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1254 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
|
1255 || !(pathname = PyTuple_GET_ITEM(find_module_result, 1)) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1256 || !(description = PyTuple_GET_ITEM(find_module_result, 2))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1257 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1258 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1259 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
|
1260 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1261 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1262 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1263 return PyObject_CallFunction(py_load_module, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1264 "s#OOO", name, len, fd, pathname, description); |
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 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1267 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1268 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
|
1269 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1270 PyObject *find_module_result; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1271 PyObject *module; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1272 char *dot; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1273 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1274 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
|
1275 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1276 /* |
4859
e48cabe98453
updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents:
4855
diff
changeset
|
1277 * 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
|
1278 * first component |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1279 */ |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1280 PyObject *newest_path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1281 int partlen = (int) (dot - 1 - tail); |
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 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
|
1284 "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
|
1285 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1286 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
|
1287 PyErr_Clear(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1288 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
|
1289 } |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1290 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1291 if (!(module = call_load_module( |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1292 fullname, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1293 ((int) (tail - fullname)) + partlen, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1294 find_module_result))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1295 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1296 Py_DECREF(find_module_result); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1297 return NULL; |
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 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1300 Py_DECREF(find_module_result); |
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 if (!(newest_path = PyObject_GetAttrString(module, "__path__"))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1303 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1304 Py_DECREF(module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1305 return NULL; |
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 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1308 Py_DECREF(module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1309 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1310 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
|
1311 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1312 Py_DECREF(newest_path); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1313 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1314 return find_module_result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1315 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1316 else |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1317 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1318 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
|
1319 "sO", tail, new_path))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1320 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1321 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
|
1322 PyErr_Clear(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1323 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1324 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1325 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1326 return find_module_result; |
4855
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 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1329 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1330 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1331 FinderFindModule(PyObject *self, PyObject *args) |
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 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
|
1334 PyObject *result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1335 PyObject *new_path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1336 LoaderObject *loader; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1337 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1338 if (!PyArg_ParseTuple(args, "s", &fullname)) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1339 return NULL; |
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 (!(new_path = Vim_GetPaths(self))) |
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 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1344 result = find_module(fullname, fullname, new_path); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1345 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1346 Py_DECREF(new_path); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1347 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1348 if (!result) |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1349 { |
4984
5b2c8f3b3906
updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
1350 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
|
1351 return NULL; |
4984
5b2c8f3b3906
updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
1352 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1353 Py_INCREF(Py_None); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1354 return Py_None; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1355 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1356 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1357 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
|
1358 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1359 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
|
1360 PyErr_NoMemory(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1361 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1362 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1363 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1364 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
|
1365 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1366 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
|
1367 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
|
1368 return NULL; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1369 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1370 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1371 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
|
1372 loader->result = result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1373 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1374 return (PyObject *) loader; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1375 } |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1376 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1377 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1378 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1379 VimPathHook(PyObject *self UNUSED, PyObject *args) |
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 char *path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1382 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1383 if (PyArg_ParseTuple(args, "s", &path) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1384 && STRCMP(path, vim_special_path) == 0) |
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 Py_INCREF(vim_module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1387 return vim_module; |
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 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1390 PyErr_Clear(); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1391 PyErr_SetNone(PyExc_ImportError); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1392 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1393 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1394 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1395 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1396 * Vim module - Definitions |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1397 */ |
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 static struct PyMethodDef VimMethods[] = { |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1400 /* name, function, calling, documentation */ |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1401 {"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
|
1402 {"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
|
1403 {"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
|
1404 {"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
|
1405 {"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
|
1406 {"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
|
1407 {"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
|
1408 #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
|
1409 {"find_spec", FinderFindSpec, METH_VARARGS, "Internal use only, returns spec object for any input it receives"}, |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1410 #else |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1411 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"}, |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1412 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1413 {"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
|
1414 {"_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
|
1415 { 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
|
1416 }; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1417 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1418 /* |
4397 | 1419 * 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
|
1420 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1421 |
4397 | 1422 static PyTypeObject IterType; |
1423 | |
1424 typedef PyObject *(*nextfun)(void **); | |
1425 typedef void (*destructorfun)(void *); | |
4433 | 1426 typedef int (*traversefun)(void *, visitproc, void *); |
1427 typedef int (*clearfun)(void **); | |
4397 | 1428 |
4438 | 1429 /* Main purpose of this object is removing the need for do python |
1430 * initialization (i.e. PyType_Ready and setting type attributes) for a big | |
1431 * bunch of objects. */ | |
4385 | 1432 |
4319 | 1433 typedef struct |
1434 { | |
1435 PyObject_HEAD | |
4397 | 1436 void *cur; |
1437 nextfun next; | |
1438 destructorfun destruct; | |
4433 | 1439 traversefun traverse; |
1440 clearfun clear; | |
4397 | 1441 } IterObject; |
1442 | |
1443 static PyObject * | |
4433 | 1444 IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse, |
1445 clearfun clear) | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1446 { |
4397 | 1447 IterObject *self; |
1448 | |
4500 | 1449 self = PyObject_GC_New(IterObject, &IterType); |
4397 | 1450 self->cur = start; |
1451 self->next = next; | |
1452 self->destruct = destruct; | |
4433 | 1453 self->traverse = traverse; |
1454 self->clear = clear; | |
4397 | 1455 |
1456 return (PyObject *)(self); | |
1457 } | |
1458 | |
1459 static void | |
4488 | 1460 IterDestructor(IterObject *self) |
4397 | 1461 { |
4500 | 1462 PyObject_GC_UnTrack((void *)(self)); |
4488 | 1463 self->destruct(self->cur); |
4500 | 1464 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
|
1465 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1466 |
4433 | 1467 static int |
4488 | 1468 IterTraverse(IterObject *self, visitproc visit, void *arg) |
4433 | 1469 { |
4488 | 1470 if (self->traverse != NULL) |
1471 return self->traverse(self->cur, visit, arg); | |
4433 | 1472 else |
1473 return 0; | |
1474 } | |
1475 | |
4438 | 1476 /* Mac OSX defines clear() somewhere. */ |
1477 #ifdef clear | |
1478 # undef clear | |
1479 #endif | |
1480 | |
4433 | 1481 static int |
4488 | 1482 IterClear(IterObject *self) |
4433 | 1483 { |
4488 | 1484 if (self->clear != NULL) |
1485 return self->clear(&self->cur); | |
4433 | 1486 else |
1487 return 0; | |
1488 } | |
1489 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1490 static PyObject * |
4488 | 1491 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
|
1492 { |
4488 | 1493 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
|
1494 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1495 |
4397 | 1496 static PyObject * |
1497 IterIter(PyObject *self) | |
1498 { | |
4609
12421d8a45d5
updated for version 7.3.1052
Bram Moolenaar <bram@vim.org>
parents:
4607
diff
changeset
|
1499 Py_INCREF(self); |
4397 | 1500 return self; |
1501 } | |
4393 | 1502 |
3618 | 1503 typedef struct pylinkedlist_S { |
1504 struct pylinkedlist_S *pll_next; | |
1505 struct pylinkedlist_S *pll_prev; | |
1506 PyObject *pll_obj; | |
1507 } pylinkedlist_T; | |
1508 | |
1509 static pylinkedlist_T *lastdict = NULL; | |
1510 static pylinkedlist_T *lastlist = NULL; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
1511 static pylinkedlist_T *lastfunc = NULL; |
3618 | 1512 |
1513 static void | |
1514 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last) | |
1515 { | |
1516 if (ref->pll_prev == NULL) | |
1517 { | |
1518 if (ref->pll_next == NULL) | |
1519 { | |
1520 *last = NULL; | |
1521 return; | |
1522 } | |
1523 } | |
1524 else | |
1525 ref->pll_prev->pll_next = ref->pll_next; | |
1526 | |
1527 if (ref->pll_next == NULL) | |
1528 *last = ref->pll_prev; | |
1529 else | |
1530 ref->pll_next->pll_prev = ref->pll_prev; | |
1531 } | |
1532 | |
1533 static void | |
1534 pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last) | |
1535 { | |
1536 if (*last == NULL) | |
1537 ref->pll_prev = NULL; | |
1538 else | |
1539 { | |
1540 (*last)->pll_next = ref; | |
1541 ref->pll_prev = *last; | |
1542 } | |
1543 ref->pll_next = NULL; | |
1544 ref->pll_obj = self; | |
1545 *last = ref; | |
1546 } | |
1547 | |
1548 static PyTypeObject DictionaryType; | |
1549 | |
1550 typedef struct | |
1551 { | |
1552 PyObject_HEAD | |
1553 dict_T *dict; | |
1554 pylinkedlist_T ref; | |
1555 } DictionaryObject; | |
1556 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1557 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1558 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1559 #define NEW_DICTIONARY(dict) DictionaryNew(&DictionaryType, dict) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1560 |
3618 | 1561 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1562 DictionaryNew(PyTypeObject *subtype, dict_T *dict) |
3618 | 1563 { |
1564 DictionaryObject *self; | |
1565 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1566 self = (DictionaryObject *) subtype->tp_alloc(subtype, 0); |
3618 | 1567 if (self == NULL) |
1568 return NULL; | |
1569 self->dict = dict; | |
1570 ++dict->dv_refcount; | |
1571 | |
1572 pyll_add((PyObject *)(self), &self->ref, &lastdict); | |
1573 | |
1574 return (PyObject *)(self); | |
1575 } | |
1576 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1577 static dict_T * |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1578 py_dict_alloc(void) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1579 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1580 dict_T *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1581 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1582 if (!(ret = dict_alloc())) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1583 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1584 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1585 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1586 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1587 ++ret->dv_refcount; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1588 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1589 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1590 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1593 DictionaryConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1594 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1595 DictionaryObject *self; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1596 dict_T *dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1597 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1598 if (!(dict = py_dict_alloc())) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1599 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1600 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1601 self = (DictionaryObject *) DictionaryNew(subtype, dict); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1602 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1603 --dict->dv_refcount; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1604 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1605 if (kwargs || PyTuple_Size(args)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1606 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1607 PyObject *tmp; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1608 if (!(tmp = DictionaryUpdate(self, args, kwargs))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1609 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1610 Py_DECREF(self); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1611 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1612 } |
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 Py_DECREF(tmp); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1615 } |
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 return (PyObject *)(self); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1618 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1619 |
4319 | 1620 static void |
4488 | 1621 DictionaryDestructor(DictionaryObject *self) |
4319 | 1622 { |
4488 | 1623 pyll_remove(&self->ref, &lastdict); |
1624 dict_unref(self->dict); | |
4319 | 1625 |
1626 DESTRUCTOR_FINISH(self); | |
1627 } | |
1628 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1629 static char *DictionaryAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1630 "locked", "scope", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1631 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1632 }; |
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 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1635 DictionaryDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1636 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1637 return ObjectDir(self, DictionaryAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1638 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1639 |
3618 | 1640 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1641 DictionarySetattr(DictionaryObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1642 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1643 if (valObject == NULL) |
3828 | 1644 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1645 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1646 N_("cannot delete vim.Dictionary attributes")); |
3828 | 1647 return -1; |
1648 } | |
1649 | |
1650 if (strcmp(name, "locked") == 0) | |
1651 { | |
4488 | 1652 if (self->dict->dv_lock == VAR_FIXED) |
3828 | 1653 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1654 PyErr_SET_STRING(PyExc_TypeError, |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1655 N_("cannot modify fixed dictionary")); |
3828 | 1656 return -1; |
1657 } | |
1658 else | |
1659 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1660 int istrue = PyObject_IsTrue(valObject); |
4411 | 1661 if (istrue == -1) |
1662 return -1; | |
1663 else if (istrue) | |
4488 | 1664 self->dict->dv_lock = VAR_LOCKED; |
3828 | 1665 else |
4488 | 1666 self->dict->dv_lock = 0; |
3828 | 1667 } |
1668 return 0; | |
1669 } | |
1670 else | |
1671 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1672 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name); |
3828 | 1673 return -1; |
1674 } | |
1675 } | |
1676 | |
1677 static PyInt | |
4488 | 1678 DictionaryLength(DictionaryObject *self) |
3618 | 1679 { |
4488 | 1680 return ((PyInt) (self->dict->dv_hashtab.ht_used)); |
3618 | 1681 } |
1682 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1683 #define DICT_FLAG_HAS_DEFAULT 0x01 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1684 #define DICT_FLAG_POP 0x02 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1685 #define DICT_FLAG_NONE_DEFAULT 0x04 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1686 #define DICT_FLAG_RETURN_BOOL 0x08 /* Incompatible with DICT_FLAG_POP */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1687 #define DICT_FLAG_RETURN_PAIR 0x10 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1688 |
3618 | 1689 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1690 _DictionaryItem(DictionaryObject *self, PyObject *args, int flags) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1691 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1692 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1693 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
|
1694 PyObject *ret; |
3618 | 1695 char_u *key; |
3792 | 1696 dictitem_T *di; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1697 dict_T *dict = self->dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1698 hashitem_T *hi; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1699 PyObject *todecref; |
3618 | 1700 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1701 if (flags & DICT_FLAG_HAS_DEFAULT) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1702 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1703 if (!PyArg_ParseTuple(args, "O|O", &keyObject, &defObject)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1704 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1705 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1706 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1707 keyObject = args; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1708 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1709 if (flags & DICT_FLAG_RETURN_BOOL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1710 defObject = Py_False; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1711 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1712 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1713 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1714 |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1715 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1716 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1717 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
1718 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1719 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1720 } |
3792 | 1721 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1722 hi = hash_find(&dict->dv_hashtab, key); |
3792 | 1723 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1724 Py_XDECREF(todecref); |
3824 | 1725 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1726 if (HASHITEM_EMPTY(hi)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1727 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1728 if (defObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1729 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1730 Py_INCREF(defObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1731 return defObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1732 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1733 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1734 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1735 PyErr_SetObject(PyExc_KeyError, keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1736 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1737 } |
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 else if (flags & DICT_FLAG_RETURN_BOOL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1740 { |
5666 | 1741 ret = Py_True; |
1742 Py_INCREF(ret); | |
1743 return ret; | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1744 } |
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 di = dict_lookup(hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1747 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1748 if (!(ret = ConvertToPyObject(&di->di_tv))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1749 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1750 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1751 if (flags & DICT_FLAG_POP) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1752 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1753 if (dict->dv_lock) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1754 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1755 RAISE_LOCKED_DICTIONARY; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1756 Py_DECREF(ret); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1757 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1758 } |
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 hash_remove(&dict->dv_hashtab, hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1761 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1762 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1763 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1764 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1765 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1768 DictionaryItem(DictionaryObject *self, PyObject *keyObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1769 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1770 return _DictionaryItem(self, keyObject, 0); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1771 } |
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 static int |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1774 DictionaryContains(DictionaryObject *self, PyObject *keyObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1775 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1776 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
|
1777 int ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1778 |
5426 | 1779 if (rObj == NULL) |
1780 return -1; | |
1781 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1782 ret = (rObj == Py_True); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1783 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
1784 Py_DECREF(rObj); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1785 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1786 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1787 } |
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 typedef struct |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1790 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1791 hashitem_T *ht_array; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1792 long_u ht_used; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1793 hashtab_T *ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1794 hashitem_T *hi; |
4667
9e7ef781d494
updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents:
4659
diff
changeset
|
1795 long_u todo; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1796 } dictiterinfo_T; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1797 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1798 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1799 DictionaryIterNext(dictiterinfo_T **dii) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1800 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1801 PyObject *ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1802 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1803 if (!(*dii)->todo) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1804 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1805 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1806 if ((*dii)->ht->ht_array != (*dii)->ht_array || |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1807 (*dii)->ht->ht_used != (*dii)->ht_used) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1808 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1809 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1810 N_("hashtab changed during iteration")); |
3792 | 1811 return NULL; |
1812 } | |
3618 | 1813 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1814 while (((*dii)->todo) && HASHITEM_EMPTY((*dii)->hi)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1815 ++((*dii)->hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1816 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1817 --((*dii)->todo); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1818 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1819 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
|
1820 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1821 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1822 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1823 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1826 DictionaryIter(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1827 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1828 dictiterinfo_T *dii; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1829 hashtab_T *ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1830 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1831 if (!(dii = PyMem_New(dictiterinfo_T, 1))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1832 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1833 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1834 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1835 } |
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 ht = &self->dict->dv_hashtab; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1838 dii->ht_array = ht->ht_array; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1839 dii->ht_used = ht->ht_used; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1840 dii->ht = ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1841 dii->hi = dii->ht_array; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1842 dii->todo = dii->ht_used; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1843 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1844 return IterNew(dii, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1845 (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1846 NULL, NULL); |
3618 | 1847 } |
1848 | |
1849 static PyInt | |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1850 DictionaryAssItem( |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1851 DictionaryObject *self, PyObject *keyObject, PyObject *valObject) |
3618 | 1852 { |
1853 char_u *key; | |
1854 typval_T tv; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1855 dict_T *dict = self->dict; |
3618 | 1856 dictitem_T *di; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1857 PyObject *todecref; |
3618 | 1858 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1859 if (dict->dv_lock) |
3618 | 1860 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1861 RAISE_LOCKED_DICTIONARY; |
3618 | 1862 return -1; |
1863 } | |
1864 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1865 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1866 return -1; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
1867 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1868 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1869 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1870 RAISE_NO_EMPTY_KEYS; |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1871 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1872 return -1; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1873 } |
3618 | 1874 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1875 di = dict_find(dict, key, -1); |
3618 | 1876 |
1877 if (valObject == NULL) | |
1878 { | |
3636 | 1879 hashitem_T *hi; |
1880 | |
3618 | 1881 if (di == NULL) |
1882 { | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1883 Py_XDECREF(todecref); |
4403 | 1884 PyErr_SetObject(PyExc_KeyError, keyObject); |
3618 | 1885 return -1; |
1886 } | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1887 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
|
1888 hash_remove(&dict->dv_hashtab, hi); |
3618 | 1889 dictitem_free(di); |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1890 Py_XDECREF(todecref); |
3618 | 1891 return 0; |
1892 } | |
1893 | |
1894 if (ConvertFromPyObject(valObject, &tv) == -1) | |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1895 { |
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1896 Py_XDECREF(todecref); |
3618 | 1897 return -1; |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1898 } |
3618 | 1899 |
1900 if (di == NULL) | |
1901 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1902 if (!(di = dictitem_alloc(key))) |
3618 | 1903 { |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1904 Py_XDECREF(todecref); |
3618 | 1905 PyErr_NoMemory(); |
1906 return -1; | |
1907 } | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1908 di->di_tv.v_type = VAR_UNKNOWN; |
3618 | 1909 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1910 if (dict_add(dict, di) == FAIL) |
3618 | 1911 { |
1912 vim_free(di); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1913 dictitem_free(di); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1914 RAISE_KEY_ADD_FAIL(key); |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1915 Py_XDECREF(todecref); |
3618 | 1916 return -1; |
1917 } | |
1918 } | |
1919 else | |
1920 clear_tv(&di->di_tv); | |
1921 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1922 Py_XDECREF(todecref); |
3618 | 1923 |
1924 copy_tv(&tv, &di->di_tv); | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1925 clear_tv(&tv); |
3618 | 1926 return 0; |
1927 } | |
1928 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1929 typedef PyObject *(*hi_to_py)(hashitem_T *); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1930 |
3618 | 1931 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1932 DictionaryListObjects(DictionaryObject *self, hi_to_py hiconvert) |
3618 | 1933 { |
4488 | 1934 dict_T *dict = self->dict; |
3618 | 1935 long_u todo = dict->dv_hashtab.ht_used; |
1936 Py_ssize_t i = 0; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1937 PyObject *ret; |
3618 | 1938 hashitem_T *hi; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1939 PyObject *newObj; |
3618 | 1940 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1941 ret = PyList_New(todo); |
3618 | 1942 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi) |
1943 { | |
1944 if (!HASHITEM_EMPTY(hi)) | |
1945 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1946 if (!(newObj = hiconvert(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1947 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1948 Py_DECREF(ret); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1949 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1950 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1951 PyList_SET_ITEM(ret, i, newObj); |
3618 | 1952 --todo; |
1953 ++i; | |
1954 } | |
1955 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1956 return ret; |
3618 | 1957 } |
1958 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1959 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1960 dict_key(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1961 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1962 return PyBytes_FromString((char *)(hi->hi_key)); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1963 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1966 DictionaryListKeys(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1967 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1968 return DictionaryListObjects(self, dict_key); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1969 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1972 dict_val(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1973 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1974 dictitem_T *di; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1975 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1976 di = dict_lookup(hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1977 return ConvertToPyObject(&di->di_tv); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1978 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1981 DictionaryListValues(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1982 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1983 return DictionaryListObjects(self, dict_val); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1984 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1987 dict_item(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1988 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1989 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1990 PyObject *valObject; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1991 PyObject *ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1992 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1993 if (!(keyObject = dict_key(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1994 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1995 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1996 if (!(valObject = dict_val(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1997 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1998 Py_DECREF(keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1999 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2000 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2001 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2002 ret = Py_BuildValue("(OO)", keyObject, valObject); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2003 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2004 Py_DECREF(keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2005 Py_DECREF(valObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2006 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2007 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2008 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2011 DictionaryListItems(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2012 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2013 return DictionaryListObjects(self, dict_item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2014 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2017 DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2018 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2019 dict_T *dict = self->dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2020 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2021 if (dict->dv_lock) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2022 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2023 RAISE_LOCKED_DICTIONARY; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2024 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2025 } |
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 if (kwargs) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2028 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2029 typval_T tv; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2030 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2031 if (ConvertFromPyMapping(kwargs, &tv) == -1) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2032 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2033 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2034 VimTryStart(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2035 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
|
2036 clear_tv(&tv); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2037 if (VimTryEnd()) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2038 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2039 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2040 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2041 { |
5659 | 2042 PyObject *obj = NULL; |
2043 | |
2044 if (!PyArg_ParseTuple(args, "|O", &obj)) | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2045 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2046 |
5659 | 2047 if (obj == NULL) |
2048 { | |
2049 Py_INCREF(Py_None); | |
2050 return Py_None; | |
2051 } | |
2052 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2053 if (PyObject_HasAttrString(obj, "keys")) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2054 return DictionaryUpdate(self, NULL, obj); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2055 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2056 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2057 PyObject *iterator; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2058 PyObject *item; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2059 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2060 if (!(iterator = PyObject_GetIter(obj))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2061 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2062 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2063 while ((item = PyIter_Next(iterator))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2064 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2065 PyObject *fast; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2066 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2067 PyObject *valObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2068 PyObject *todecref; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2069 char_u *key; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2070 dictitem_T *di; |
12812
381e67ccf02c
patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents:
12806
diff
changeset
|
2071 hashitem_T *hi; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2072 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2073 if (!(fast = PySequence_Fast(item, ""))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2074 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2075 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2076 Py_DECREF(item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2077 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2078 } |
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 Py_DECREF(item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2081 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2082 if (PySequence_Fast_GET_SIZE(fast) != 2) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2083 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2084 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2085 Py_DECREF(fast); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2086 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2087 N_("expected sequence element of size 2, " |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2088 "but got sequence of size %d"), |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
2089 (int) PySequence_Fast_GET_SIZE(fast)); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2090 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2091 } |
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 keyObject = PySequence_Fast_GET_ITEM(fast, 0); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2094 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2095 if (!(key = StringToChars(keyObject, &todecref))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2096 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2097 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2098 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2099 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2100 } |
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 di = dictitem_alloc(key); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2103 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2104 Py_XDECREF(todecref); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2105 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2106 if (di == NULL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2107 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2108 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2109 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2110 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2111 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2112 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2113 di->di_tv.v_type = VAR_UNKNOWN; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2114 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2115 valObject = PySequence_Fast_GET_ITEM(fast, 1); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2116 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2117 if (ConvertFromPyObject(valObject, &di->di_tv) == -1) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2118 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2119 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2120 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2121 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2122 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2123 } |
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 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2126 |
12812
381e67ccf02c
patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents:
12806
diff
changeset
|
2127 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
|
2128 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
|
2129 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2130 RAISE_KEY_ADD_FAIL(di->di_key); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2131 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2132 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2133 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2134 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2135 } |
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 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2138 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2139 /* Iterator may have finished due to an exception */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2140 if (PyErr_Occurred()) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2141 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2142 } |
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 Py_INCREF(Py_None); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2145 return Py_None; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2146 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2149 DictionaryGet(DictionaryObject *self, PyObject *args) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2150 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2151 return _DictionaryItem(self, args, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2152 DICT_FLAG_HAS_DEFAULT|DICT_FLAG_NONE_DEFAULT); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2153 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2156 DictionaryPop(DictionaryObject *self, PyObject *args) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2157 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2158 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
|
2159 } |
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 static PyObject * |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2162 DictionaryPopItem(DictionaryObject *self) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2163 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2164 hashitem_T *hi; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2165 PyObject *ret; |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2166 PyObject *valObject; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2167 dictitem_T *di; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2168 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2169 if (self->dict->dv_hashtab.ht_used == 0) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2170 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2171 PyErr_SetNone(PyExc_KeyError); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2172 return NULL; |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2173 } |
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 hi = self->dict->dv_hashtab.ht_array; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2176 while (HASHITEM_EMPTY(hi)) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2177 ++hi; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2178 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2179 di = dict_lookup(hi); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2180 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2181 if (!(valObject = ConvertToPyObject(&di->di_tv))) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2182 return NULL; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2183 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2184 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
|
2185 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2186 Py_DECREF(valObject); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2187 return NULL; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2188 } |
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 hash_remove(&self->dict->dv_hashtab, hi); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2191 dictitem_free(di); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2192 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2193 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2194 } |
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 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2197 DictionaryHasKey(DictionaryObject *self, PyObject *keyObject) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2198 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2199 return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2200 } |
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 static PySequenceMethods DictionaryAsSeq = { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2203 0, /* sq_length */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2204 0, /* sq_concat */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2205 0, /* sq_repeat */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2206 0, /* sq_item */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2207 0, /* sq_slice */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2208 0, /* sq_ass_item */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2209 0, /* sq_ass_slice */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2210 (objobjproc) DictionaryContains, /* sq_contains */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2211 0, /* sq_inplace_concat */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2212 0, /* sq_inplace_repeat */ |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2213 }; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2214 |
4385 | 2215 static PyMappingMethods DictionaryAsMapping = { |
2216 (lenfunc) DictionaryLength, | |
2217 (binaryfunc) DictionaryItem, | |
2218 (objobjargproc) DictionaryAssItem, | |
2219 }; | |
2220 | |
3618 | 2221 static struct PyMethodDef DictionaryMethods[] = { |
4492 | 2222 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""}, |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2223 {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2224 {"items", (PyCFunction)DictionaryListItems, METH_NOARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2225 {"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2226 {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2227 {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""}, |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2228 {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""}, |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2229 {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""}, |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2230 {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2231 { NULL, NULL, 0, NULL} |
3618 | 2232 }; |
2233 | |
2234 static PyTypeObject ListType; | |
2235 | |
2236 typedef struct | |
2237 { | |
2238 PyObject_HEAD | |
2239 list_T *list; | |
2240 pylinkedlist_T ref; | |
2241 } ListObject; | |
2242 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2243 #define NEW_LIST(list) ListNew(&ListType, list) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2244 |
3618 | 2245 static PyObject * |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2246 ListNew(PyTypeObject *subtype, list_T *list) |
3618 | 2247 { |
2248 ListObject *self; | |
2249 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2250 self = (ListObject *) subtype->tp_alloc(subtype, 0); |
3618 | 2251 if (self == NULL) |
2252 return NULL; | |
2253 self->list = list; | |
2254 ++list->lv_refcount; | |
2255 | |
2256 pyll_add((PyObject *)(self), &self->ref, &lastlist); | |
2257 | |
2258 return (PyObject *)(self); | |
2259 } | |
2260 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2261 static list_T * |
5166
467efeee8f9e
updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents:
5139
diff
changeset
|
2262 py_list_alloc(void) |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2263 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2264 list_T *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2265 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2266 if (!(ret = list_alloc())) |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2267 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2268 PyErr_NoMemory(); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2269 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2270 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2271 ++ret->lv_refcount; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2272 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2273 return ret; |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2274 } |
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 static int |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2277 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
|
2278 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2279 PyObject *iterator; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2280 PyObject *item; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2281 listitem_T *li; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2282 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2283 if (!(iterator = PyObject_GetIter(obj))) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2284 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2285 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2286 while ((item = PyIter_Next(iterator))) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2287 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2288 if (!(li = listitem_alloc())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2289 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2290 PyErr_NoMemory(); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2291 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2292 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2293 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2294 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2295 li->li_tv.v_lock = 0; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2296 li->li_tv.v_type = VAR_UNKNOWN; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2297 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2298 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
|
2299 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2300 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2301 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2302 listitem_free(li); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2303 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2304 } |
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 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2307 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2308 list_append(l, li); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2309 } |
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 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2312 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2313 /* Iterator may have finished due to an exception */ |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2314 if (PyErr_Occurred()) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2315 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2316 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2317 return 0; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2318 } |
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 static PyObject * |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2321 ListConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2322 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2323 list_T *list; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2324 PyObject *obj = NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2325 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2326 if (kwargs) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2327 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
2328 PyErr_SET_STRING(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2329 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
|
2330 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2331 } |
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 if (!PyArg_ParseTuple(args, "|O", &obj)) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2334 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2335 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2336 if (!(list = py_list_alloc())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2337 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2338 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2339 if (obj) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2340 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2341 PyObject *lookup_dict; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2342 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2343 if (!(lookup_dict = PyDict_New())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2344 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2345 list_unref(list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2346 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2347 } |
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 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
|
2350 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2351 Py_DECREF(lookup_dict); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2352 list_unref(list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2353 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2354 } |
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 Py_DECREF(lookup_dict); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2357 } |
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 return ListNew(subtype, list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2360 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2361 |
4319 | 2362 static void |
4488 | 2363 ListDestructor(ListObject *self) |
4319 | 2364 { |
4488 | 2365 pyll_remove(&self->ref, &lastlist); |
2366 list_unref(self->list); | |
4319 | 2367 |
2368 DESTRUCTOR_FINISH(self); | |
2369 } | |
2370 | |
3618 | 2371 static PyInt |
4488 | 2372 ListLength(ListObject *self) |
3618 | 2373 { |
4488 | 2374 return ((PyInt) (self->list->lv_len)); |
3618 | 2375 } |
2376 | |
2377 static PyObject * | |
5608 | 2378 ListIndex(ListObject *self, Py_ssize_t index) |
3618 | 2379 { |
2380 listitem_T *li; | |
2381 | |
4488 | 2382 if (index >= ListLength(self)) |
3618 | 2383 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2384 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range")); |
3618 | 2385 return NULL; |
2386 } | |
4488 | 2387 li = list_find(self->list, (long) index); |
3618 | 2388 if (li == NULL) |
2389 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2390 /* 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
|
2391 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
|
2392 (int) index); |
3618 | 2393 return NULL; |
2394 } | |
2395 return ConvertToPyObject(&li->li_tv); | |
2396 } | |
2397 | |
2398 static PyObject * | |
5608 | 2399 ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t step, |
2400 Py_ssize_t slicelen) | |
3618 | 2401 { |
2402 PyInt i; | |
2403 PyObject *list; | |
5608 | 2404 |
2405 if (step == 0) | |
2406 { | |
2407 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero")); | |
2408 return NULL; | |
2409 } | |
2410 | |
2411 list = PyList_New(slicelen); | |
3618 | 2412 if (list == NULL) |
2413 return NULL; | |
2414 | |
5608 | 2415 for (i = 0; i < slicelen; ++i) |
2416 { | |
2417 PyObject *item; | |
2418 | |
2419 item = ListIndex(self, first + i*step); | |
3618 | 2420 if (item == NULL) |
2421 { | |
2422 Py_DECREF(list); | |
2423 return NULL; | |
2424 } | |
2425 | |
5608 | 2426 PyList_SET_ITEM(list, i, item); |
3618 | 2427 } |
2428 | |
2429 return list; | |
2430 } | |
2431 | |
5608 | 2432 static PyObject * |
2433 ListItem(ListObject *self, PyObject* idx) | |
2434 { | |
2435 #if PY_MAJOR_VERSION < 3 | |
2436 if (PyInt_Check(idx)) | |
2437 { | |
2438 long _idx = PyInt_AsLong(idx); | |
2439 return ListIndex(self, _idx); | |
2440 } | |
2441 else | |
2442 #endif | |
2443 if (PyLong_Check(idx)) | |
2444 { | |
2445 long _idx = PyLong_AsLong(idx); | |
2446 return ListIndex(self, _idx); | |
2447 } | |
2448 else if (PySlice_Check(idx)) | |
2449 { | |
2450 Py_ssize_t start, stop, step, slicelen; | |
2451 | |
5768 | 2452 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), |
5608 | 2453 &start, &stop, &step, &slicelen) < 0) |
2454 return NULL; | |
2455 return ListSlice(self, start, step, slicelen); | |
2456 } | |
2457 else | |
2458 { | |
2459 RAISE_INVALID_INDEX_TYPE(idx); | |
2460 return NULL; | |
2461 } | |
2462 } | |
2463 | |
2464 static void | |
2465 list_restore(Py_ssize_t numadded, Py_ssize_t numreplaced, Py_ssize_t slicelen, | |
2466 list_T *l, listitem_T **lis, listitem_T *lastaddedli) | |
2467 { | |
2468 while (numreplaced--) | |
2469 { | |
2470 list_insert(l, lis[numreplaced], lis[slicelen + numreplaced]); | |
2471 listitem_remove(l, lis[slicelen + numreplaced]); | |
2472 } | |
2473 while (numadded--) | |
2474 { | |
2475 listitem_T *next; | |
2476 | |
2477 next = lastaddedli->li_prev; | |
2478 listitem_remove(l, lastaddedli); | |
2479 lastaddedli = next; | |
2480 } | |
2481 } | |
2482 | |
2483 static int | |
2484 ListAssSlice(ListObject *self, Py_ssize_t first, | |
2485 Py_ssize_t step, Py_ssize_t slicelen, PyObject *obj) | |
2486 { | |
2487 PyObject *iterator; | |
2488 PyObject *item; | |
2489 listitem_T *li; | |
2490 listitem_T *lastaddedli = NULL; | |
2491 listitem_T *next; | |
2492 typval_T v; | |
2493 list_T *l = self->list; | |
2494 PyInt i; | |
2495 PyInt j; | |
2496 PyInt numreplaced = 0; | |
2497 PyInt numadded = 0; | |
2498 PyInt size; | |
5655 | 2499 listitem_T **lis = NULL; |
5608 | 2500 |
2501 size = ListLength(self); | |
2502 | |
2503 if (l->lv_lock) | |
2504 { | |
2505 RAISE_LOCKED_LIST; | |
2506 return -1; | |
2507 } | |
2508 | |
2509 if (step == 0) | |
2510 { | |
2511 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero")); | |
2512 return -1; | |
2513 } | |
2514 | |
2515 if (step != 1 && slicelen == 0) | |
2516 { | |
2517 /* Nothing to do. Only error out if obj has some items. */ | |
2518 int ret = 0; | |
2519 | |
2520 if (obj == NULL) | |
2521 return 0; | |
2522 | |
2523 if (!(iterator = PyObject_GetIter(obj))) | |
2524 return -1; | |
2525 | |
2526 if ((item = PyIter_Next(iterator))) | |
2527 { | |
2528 PyErr_FORMAT(PyExc_ValueError, | |
5695 | 2529 N_("attempt to assign sequence of size greater than %d " |
5608 | 2530 "to extended slice"), 0); |
2531 Py_DECREF(item); | |
2532 ret = -1; | |
2533 } | |
2534 Py_DECREF(iterator); | |
2535 return ret; | |
2536 } | |
2537 | |
2538 if (obj != NULL) | |
2539 /* XXX May allocate zero bytes. */ | |
2540 if (!(lis = PyMem_New(listitem_T *, slicelen * 2))) | |
2541 { | |
2542 PyErr_NoMemory(); | |
2543 return -1; | |
2544 } | |
2545 | |
2546 if (first == size) | |
2547 li = NULL; | |
2548 else | |
2549 { | |
2550 li = list_find(l, (long) first); | |
2551 if (li == NULL) | |
2552 { | |
2553 PyErr_VIM_FORMAT(N_("internal error: no vim list item %d"), | |
2554 (int)first); | |
2555 if (obj != NULL) | |
2556 PyMem_Free(lis); | |
2557 return -1; | |
2558 } | |
2559 i = slicelen; | |
2560 while (i-- && li != NULL) | |
2561 { | |
2562 j = step; | |
2563 next = li; | |
2564 if (step > 0) | |
2565 while (next != NULL && ((next = next->li_next) != NULL) && --j); | |
2566 else | |
2567 while (next != NULL && ((next = next->li_prev) != NULL) && ++j); | |
2568 | |
2569 if (obj == NULL) | |
2570 listitem_remove(l, li); | |
2571 else | |
2572 lis[slicelen - i - 1] = li; | |
2573 | |
2574 li = next; | |
2575 } | |
2576 if (li == NULL && i != -1) | |
2577 { | |
2578 PyErr_SET_VIM(N_("internal error: not enough list items")); | |
2579 if (obj != NULL) | |
2580 PyMem_Free(lis); | |
2581 return -1; | |
2582 } | |
2583 } | |
2584 | |
2585 if (obj == NULL) | |
2586 return 0; | |
2587 | |
2588 if (!(iterator = PyObject_GetIter(obj))) | |
2589 { | |
2590 PyMem_Free(lis); | |
2591 return -1; | |
2592 } | |
2593 | |
2594 i = 0; | |
2595 while ((item = PyIter_Next(iterator))) | |
2596 { | |
2597 if (ConvertFromPyObject(item, &v) == -1) | |
2598 { | |
2599 Py_DECREF(iterator); | |
2600 Py_DECREF(item); | |
2601 PyMem_Free(lis); | |
2602 return -1; | |
2603 } | |
2604 Py_DECREF(item); | |
2605 if (list_insert_tv(l, &v, numreplaced < slicelen | |
2606 ? lis[numreplaced] | |
2607 : li) == FAIL) | |
2608 { | |
2609 clear_tv(&v); | |
2610 PyErr_SET_VIM(N_("internal error: failed to add item to list")); | |
2611 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); | |
2612 PyMem_Free(lis); | |
2613 return -1; | |
2614 } | |
2615 if (numreplaced < slicelen) | |
2616 { | |
2617 lis[slicelen + numreplaced] = lis[numreplaced]->li_prev; | |
5871 | 2618 vimlist_remove(l, lis[numreplaced], lis[numreplaced]); |
5608 | 2619 numreplaced++; |
2620 } | |
2621 else | |
2622 { | |
2623 if (li) | |
2624 lastaddedli = li->li_prev; | |
2625 else | |
2626 lastaddedli = l->lv_last; | |
2627 numadded++; | |
2628 } | |
2629 clear_tv(&v); | |
2630 if (step != 1 && i >= slicelen) | |
2631 { | |
2632 Py_DECREF(iterator); | |
2633 PyErr_FORMAT(PyExc_ValueError, | |
5695 | 2634 N_("attempt to assign sequence of size greater than %d " |
5668 | 2635 "to extended slice"), (int) slicelen); |
5608 | 2636 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); |
2637 PyMem_Free(lis); | |
2638 return -1; | |
2639 } | |
2640 ++i; | |
2641 } | |
2642 Py_DECREF(iterator); | |
2643 | |
2644 if (step != 1 && i != slicelen) | |
2645 { | |
2646 PyErr_FORMAT2(PyExc_ValueError, | |
5668 | 2647 N_("attempt to assign sequence of size %d to extended slice " |
2648 "of size %d"), (int) i, (int) slicelen); | |
5608 | 2649 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); |
2650 PyMem_Free(lis); | |
2651 return -1; | |
2652 } | |
2653 | |
2654 if (PyErr_Occurred()) | |
2655 { | |
2656 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); | |
2657 PyMem_Free(lis); | |
2658 return -1; | |
2659 } | |
2660 | |
2661 for (i = 0; i < numreplaced; i++) | |
2662 listitem_free(lis[i]); | |
2663 if (step == 1) | |
2664 for (i = numreplaced; i < slicelen; i++) | |
2665 listitem_remove(l, lis[i]); | |
2666 | |
2667 PyMem_Free(lis); | |
2668 | |
2669 return 0; | |
2670 } | |
2671 | |
2672 static int | |
2673 ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj) | |
2674 { | |
2675 typval_T tv; | |
2676 list_T *l = self->list; | |
2677 listitem_T *li; | |
2678 Py_ssize_t length = ListLength(self); | |
2679 | |
2680 if (l->lv_lock) | |
2681 { | |
2682 RAISE_LOCKED_LIST; | |
2683 return -1; | |
2684 } | |
2685 if (index > length || (index == length && obj == NULL)) | |
2686 { | |
2687 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range")); | |
2688 return -1; | |
2689 } | |
2690 | |
2691 if (obj == NULL) | |
2692 { | |
2693 li = list_find(l, (long) index); | |
5871 | 2694 vimlist_remove(l, li, li); |
5608 | 2695 clear_tv(&li->li_tv); |
2696 vim_free(li); | |
2697 return 0; | |
2698 } | |
2699 | |
2700 if (ConvertFromPyObject(obj, &tv) == -1) | |
2701 return -1; | |
2702 | |
2703 if (index == length) | |
2704 { | |
2705 if (list_append_tv(l, &tv) == FAIL) | |
2706 { | |
2707 clear_tv(&tv); | |
2708 PyErr_SET_VIM(N_("failed to add item to list")); | |
2709 return -1; | |
2710 } | |
2711 } | |
2712 else | |
2713 { | |
2714 li = list_find(l, (long) index); | |
2715 clear_tv(&li->li_tv); | |
2716 copy_tv(&tv, &li->li_tv); | |
2717 clear_tv(&tv); | |
2718 } | |
2719 return 0; | |
2720 } | |
2721 | |
2722 static Py_ssize_t | |
2723 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj) | |
2724 { | |
2725 #if PY_MAJOR_VERSION < 3 | |
2726 if (PyInt_Check(idx)) | |
2727 { | |
2728 long _idx = PyInt_AsLong(idx); | |
2729 return ListAssIndex(self, _idx, obj); | |
2730 } | |
2731 else | |
2732 #endif | |
2733 if (PyLong_Check(idx)) | |
2734 { | |
2735 long _idx = PyLong_AsLong(idx); | |
2736 return ListAssIndex(self, _idx, obj); | |
2737 } | |
2738 else if (PySlice_Check(idx)) | |
2739 { | |
2740 Py_ssize_t start, stop, step, slicelen; | |
2741 | |
5768 | 2742 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), |
5608 | 2743 &start, &stop, &step, &slicelen) < 0) |
2744 return -1; | |
2745 return ListAssSlice(self, start, step, slicelen, | |
2746 obj); | |
2747 } | |
2748 else | |
2749 { | |
2750 RAISE_INVALID_INDEX_TYPE(idx); | |
2751 return -1; | |
2752 } | |
2753 } | |
2754 | |
2755 static PyObject * | |
2756 ListConcatInPlace(ListObject *self, PyObject *obj) | |
2757 { | |
2758 list_T *l = self->list; | |
2759 PyObject *lookup_dict; | |
2760 | |
2761 if (l->lv_lock) | |
2762 { | |
2763 RAISE_LOCKED_LIST; | |
2764 return NULL; | |
2765 } | |
2766 | |
2767 if (!(lookup_dict = PyDict_New())) | |
2768 return NULL; | |
2769 | |
2770 if (list_py_concat(l, obj, lookup_dict) == -1) | |
2771 { | |
2772 Py_DECREF(lookup_dict); | |
2773 return NULL; | |
2774 } | |
2775 Py_DECREF(lookup_dict); | |
2776 | |
2777 Py_INCREF(self); | |
2778 return (PyObject *)(self); | |
2779 } | |
2780 | |
4397 | 2781 typedef struct |
2782 { | |
2783 listwatch_T lw; | |
2784 list_T *list; | |
2785 } listiterinfo_T; | |
2786 | |
2787 static void | |
2788 ListIterDestruct(listiterinfo_T *lii) | |
2789 { | |
2790 list_rem_watch(lii->list, &lii->lw); | |
2791 PyMem_Free(lii); | |
2792 } | |
2793 | |
2794 static PyObject * | |
2795 ListIterNext(listiterinfo_T **lii) | |
2796 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2797 PyObject *ret; |
4397 | 2798 |
2799 if (!((*lii)->lw.lw_item)) | |
2800 return NULL; | |
2801 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2802 if (!(ret = ConvertToPyObject(&((*lii)->lw.lw_item->li_tv)))) |
4397 | 2803 return NULL; |
2804 | |
2805 (*lii)->lw.lw_item = (*lii)->lw.lw_item->li_next; | |
2806 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2807 return ret; |
4397 | 2808 } |
2809 | |
2810 static PyObject * | |
4488 | 2811 ListIter(ListObject *self) |
4397 | 2812 { |
2813 listiterinfo_T *lii; | |
4488 | 2814 list_T *l = self->list; |
4397 | 2815 |
2816 if (!(lii = PyMem_New(listiterinfo_T, 1))) | |
2817 { | |
2818 PyErr_NoMemory(); | |
2819 return NULL; | |
2820 } | |
2821 | |
2822 list_add_watch(l, &lii->lw); | |
2823 lii->lw.lw_item = l->lv_first; | |
2824 lii->list = l; | |
2825 | |
2826 return IterNew(lii, | |
4433 | 2827 (destructorfun) ListIterDestruct, (nextfun) ListIterNext, |
2828 NULL, NULL); | |
4397 | 2829 } |
2830 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2831 static char *ListAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2832 "locked", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2833 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2834 }; |
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 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2837 ListDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2838 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2839 return ObjectDir(self, ListAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2840 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2841 |
3828 | 2842 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2843 ListSetattr(ListObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2844 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2845 if (valObject == NULL) |
3828 | 2846 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
2847 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2848 N_("cannot delete vim.List attributes")); |
3828 | 2849 return -1; |
2850 } | |
2851 | |
2852 if (strcmp(name, "locked") == 0) | |
2853 { | |
4488 | 2854 if (self->list->lv_lock == VAR_FIXED) |
3828 | 2855 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2856 PyErr_SET_STRING(PyExc_TypeError, N_("cannot modify fixed list")); |
3828 | 2857 return -1; |
2858 } | |
2859 else | |
2860 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2861 int istrue = PyObject_IsTrue(valObject); |
4411 | 2862 if (istrue == -1) |
2863 return -1; | |
2864 else if (istrue) | |
4488 | 2865 self->list->lv_lock = VAR_LOCKED; |
3828 | 2866 else |
4488 | 2867 self->list->lv_lock = 0; |
3828 | 2868 } |
2869 return 0; | |
2870 } | |
2871 else | |
2872 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2873 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name); |
3828 | 2874 return -1; |
2875 } | |
2876 } | |
2877 | |
5608 | 2878 static PySequenceMethods ListAsSeq = { |
2879 (lenfunc) ListLength, /* sq_length, len(x) */ | |
2880 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ | |
2881 0, /* RangeRepeat, sq_repeat, x*n */ | |
2882 (PyIntArgFunc) ListIndex, /* sq_item, x[i] */ | |
2883 0, /* was_sq_slice, x[i:j] */ | |
2884 (PyIntObjArgProc) ListAssIndex, /* sq_as_item, x[i]=v */ | |
2885 0, /* was_sq_ass_slice, x[i:j]=v */ | |
2886 0, /* sq_contains */ | |
2887 (binaryfunc) ListConcatInPlace,/* sq_inplace_concat */ | |
2888 0, /* sq_inplace_repeat */ | |
2889 }; | |
2890 | |
2891 static PyMappingMethods ListAsMapping = { | |
2892 /* mp_length */ (lenfunc) ListLength, | |
2893 /* mp_subscript */ (binaryfunc) ListItem, | |
2894 /* mp_ass_subscript */ (objobjargproc) ListAssItem, | |
2895 }; | |
2896 | |
3618 | 2897 static struct PyMethodDef ListMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2898 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2899 {"__dir__", (PyCFunction)ListDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2900 { NULL, NULL, 0, NULL} |
3618 | 2901 }; |
2902 | |
2903 typedef struct | |
2904 { | |
2905 PyObject_HEAD | |
2906 char_u *name; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2907 int argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2908 typval_T *argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2909 dict_T *self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2910 pylinkedlist_T ref; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2911 int auto_rebind; |
3618 | 2912 } FunctionObject; |
2913 | |
2914 static PyTypeObject FunctionType; | |
2915 | |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2916 #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
|
2917 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
|
2918 |
3618 | 2919 static PyObject * |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2920 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
|
2921 dict_T *selfdict, int auto_rebind) |
3618 | 2922 { |
2923 FunctionObject *self; | |
2924 | |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2925 self = (FunctionObject *) subtype->tp_alloc(subtype, 0); |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2926 |
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 |
4641
59e6c2bd68e3
updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
2941 if ((self->name = get_expanded_name(name, |
59e6c2bd68e3
updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
2942 vim_strchr(name, AUTOLOAD_CHAR) == NULL)) |
59e6c2bd68e3
updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
2943 == NULL) |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2944 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2945 PyErr_FORMAT(PyExc_ValueError, |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2946 N_("function %s does not exist"), name); |
4641
59e6c2bd68e3
updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
2947 return NULL; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2948 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2949 |
9725
4a4a71d67131
commit https://github.com/vim/vim/commit/2d3d60a7d4b410668dfc427120205ccf88789db4
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
2950 func_ref(self->name); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2951 self->argc = argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2952 self->argv = argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2953 self->self = selfdict; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2954 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
|
2955 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2956 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2957 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
|
2958 |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2959 return (PyObject *)(self); |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2960 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2961 |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2962 static PyObject * |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2963 FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2964 { |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2965 PyObject *self; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2966 PyObject *selfdictObject; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2967 PyObject *autoRebindObject; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2968 PyObject *argsObject = NULL; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2969 char_u *name; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2970 typval_T selfdicttv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2971 typval_T argstv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2972 list_T *argslist = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2973 dict_T *selfdict = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2974 int argc = 0; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2975 int auto_rebind = TRUE; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2976 typval_T *argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2977 typval_T *curtv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2978 listitem_T *li; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2979 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2980 if (kwargs != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2981 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2982 selfdictObject = PyDict_GetItemString(kwargs, "self"); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2983 if (selfdictObject != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2984 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2985 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2986 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2987 selfdict = selfdicttv.vval.v_dict; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2988 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2989 argsObject = PyDict_GetItemString(kwargs, "args"); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2990 if (argsObject != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2991 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2992 if (ConvertFromPySequence(argsObject, &argstv) == -1) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2993 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2994 dict_unref(selfdict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2995 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2996 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2997 argslist = argstv.vval.v_list; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2998 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2999 argc = argslist->lv_len; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3000 if (argc != 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3001 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3002 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
|
3003 if (argv == NULL) |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3004 { |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3005 PyErr_NoMemory(); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3006 dict_unref(selfdict); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3007 list_unref(argslist); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3008 return NULL; |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3009 } |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3010 curtv = argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3011 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
|
3012 copy_tv(&li->li_tv, curtv++); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3013 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3014 list_unref(argslist); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3015 } |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3016 if (selfdict != NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3017 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3018 auto_rebind = FALSE; |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3019 autoRebindObject = PyDict_GetItemString(kwargs, "auto_rebind"); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3020 if (autoRebindObject != NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3021 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3022 auto_rebind = PyObject_IsTrue(autoRebindObject); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3023 if (auto_rebind == -1) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3024 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3025 dict_unref(selfdict); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3026 list_unref(argslist); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3027 return NULL; |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3028 } |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3029 } |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3030 } |
3618 | 3031 } |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3032 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3033 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
|
3034 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3035 dict_unref(selfdict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3036 while (argc--) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3037 clear_tv(&argv[argc]); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3038 PyMem_Free(argv); |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3039 return NULL; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3040 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3041 |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3042 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
|
3043 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3044 PyMem_Free(name); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3045 |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3046 return self; |
3618 | 3047 } |
3048 | |
4319 | 3049 static void |
4488 | 3050 FunctionDestructor(FunctionObject *self) |
4319 | 3051 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3052 int i; |
4488 | 3053 func_unref(self->name); |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3054 vim_free(self->name); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3055 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
|
3056 clear_tv(&self->argv[i]); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3057 PyMem_Free(self->argv); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3058 dict_unref(self->self); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3059 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3060 pyll_remove(&self->ref, &lastfunc); |
4319 | 3061 |
3062 DESTRUCTOR_FINISH(self); | |
3063 } | |
3064 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3065 static char *FunctionAttrs[] = { |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3066 "softspace", "args", "self", "auto_rebind", |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3067 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3068 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3069 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3070 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3071 FunctionDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3072 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3073 return ObjectDir(self, FunctionAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3074 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3075 |
3618 | 3076 static PyObject * |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3077 FunctionAttr(FunctionObject *self, char *name) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3078 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3079 list_T *list; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3080 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3081 if (strcmp(name, "name") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3082 return PyString_FromString((char *)(self->name)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3083 else if (strcmp(name, "args") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3084 { |
9967
45098d7f72b6
commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents:
9725
diff
changeset
|
3085 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
|
3086 return AlwaysNone(NULL); |
9967
45098d7f72b6
commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents:
9725
diff
changeset
|
3087 |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3088 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
|
3089 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
|
3090 return NEW_LIST(list); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3091 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3092 else if (strcmp(name, "self") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3093 return self->self == NULL |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3094 ? AlwaysNone(NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3095 : NEW_DICTIONARY(self->self); |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3096 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
|
3097 return self->auto_rebind |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3098 ? AlwaysTrue(NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3099 : AlwaysFalse(NULL); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3100 else if (strcmp(name, "__members__") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3101 return ObjectDir(NULL, FunctionAttrs); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3102 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3103 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3104 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3105 /* Populate partial_T given function object. |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3106 * |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3107 * "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
|
3108 * 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
|
3109 */ |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3110 static void |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3111 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
|
3112 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3113 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3114 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3115 pt->pt_name = self->name; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3116 if (self->argv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3117 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3118 pt->pt_argc = self->argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3119 if (exported) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3120 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3121 pt->pt_argv = (typval_T *)alloc_clear( |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3122 sizeof(typval_T) * self->argc); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3123 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
|
3124 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
|
3125 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3126 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3127 pt->pt_argv = self->argv; |
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 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3130 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3131 pt->pt_argc = 0; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3132 pt->pt_argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3133 } |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3134 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
|
3135 pt->pt_dict = self->self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3136 if (exported && self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3137 ++pt->pt_dict->dv_refcount; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3138 if (exported) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3139 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
|
3140 pt->pt_refcount = 1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3141 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3142 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3143 static PyObject * |
4488 | 3144 FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs) |
3618 | 3145 { |
4488 | 3146 char_u *name = self->name; |
3618 | 3147 typval_T args; |
3148 typval_T selfdicttv; | |
3149 typval_T rettv; | |
3150 dict_T *selfdict = NULL; | |
3151 PyObject *selfdictObject; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3152 PyObject *ret; |
3618 | 3153 int error; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3154 partial_T pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3155 partial_T *pt_ptr = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3156 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3157 if (ConvertFromPySequence(argsObject, &args) == -1) |
3618 | 3158 return NULL; |
3159 | |
3160 if (kwargs != NULL) | |
3161 { | |
3162 selfdictObject = PyDict_GetItemString(kwargs, "self"); | |
3163 if (selfdictObject != NULL) | |
3164 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3165 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1) |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3166 { |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3167 clear_tv(&args); |
3618 | 3168 return NULL; |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3169 } |
3618 | 3170 selfdict = selfdicttv.vval.v_dict; |
3171 } | |
3172 } | |
3173 | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3174 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3175 { |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3176 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
|
3177 set_partial(self, &pt, FALSE); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3178 pt_ptr = &pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3179 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3180 |
4415 | 3181 Py_BEGIN_ALLOW_THREADS |
3182 Python_Lock_Vim(); | |
3183 | |
4498 | 3184 VimTryStart(); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3185 error = func_call(name, &args, pt_ptr, selfdict, &rettv); |
4415 | 3186 |
3187 Python_Release_Vim(); | |
3188 Py_END_ALLOW_THREADS | |
3189 | |
4498 | 3190 if (VimTryEnd()) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3191 ret = NULL; |
4498 | 3192 else if (error != OK) |
3618 | 3193 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3194 ret = NULL; |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3195 PyErr_VIM_FORMAT(N_("failed to run function %s"), (char *)name); |
3618 | 3196 } |
3197 else | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3198 ret = ConvertToPyObject(&rettv); |
3618 | 3199 |
3200 clear_tv(&args); | |
3201 clear_tv(&rettv); | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3202 if (selfdict != NULL) |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3203 clear_tv(&selfdicttv); |
3618 | 3204 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3205 return ret; |
3618 | 3206 } |
3207 | |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3208 static PyObject * |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3209 FunctionRepr(FunctionObject *self) |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3210 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3211 PyObject *ret; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3212 garray_T repr_ga; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3213 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3214 char_u *tofree = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3215 typval_T tv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3216 char_u numbuf[NUMBUFLEN]; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3217 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3218 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
|
3219 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
|
3220 if (self->name) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3221 ga_concat(&repr_ga, self->name); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3222 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3223 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
|
3224 ga_append(&repr_ga, '\''); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3225 if (self->argv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3226 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3227 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
|
3228 ++emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3229 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
|
3230 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3231 if (i != 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3232 ga_concat(&repr_ga, (char_u *)", "); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3233 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
|
3234 get_copyID())); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3235 vim_free(tofree); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3236 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3237 --emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3238 ga_append(&repr_ga, ']'); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3239 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3240 if (self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3241 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3242 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
|
3243 tv.v_type = VAR_DICT; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3244 tv.vval.v_dict = self->self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3245 ++emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3246 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
|
3247 --emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3248 vim_free(tofree); |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3249 if (self->auto_rebind) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3250 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
|
3251 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3252 ga_append(&repr_ga, '>'); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3253 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
|
3254 ga_clear(&repr_ga); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3255 return ret; |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3256 } |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3257 |
3618 | 3258 static struct PyMethodDef FunctionMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3259 {"__dir__", (PyCFunction)FunctionDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3260 { NULL, NULL, 0, NULL} |
3618 | 3261 }; |
3262 | |
4350 | 3263 /* |
3264 * Options object | |
3265 */ | |
3266 | |
3267 static PyTypeObject OptionsType; | |
3268 | |
3269 typedef int (*checkfun)(void *); | |
3270 | |
3271 typedef struct | |
3272 { | |
3273 PyObject_HEAD | |
5610 | 3274 int opt_type; |
3275 void *from; | |
3276 checkfun Check; | |
3277 PyObject *fromObj; | |
4350 | 3278 } OptionsObject; |
3279 | |
4433 | 3280 static int |
3281 dummy_check(void *arg UNUSED) | |
3282 { | |
3283 return 0; | |
3284 } | |
3285 | |
3286 static PyObject * | |
3287 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj) | |
3288 { | |
3289 OptionsObject *self; | |
3290 | |
4500 | 3291 self = PyObject_GC_New(OptionsObject, &OptionsType); |
4433 | 3292 if (self == NULL) |
3293 return NULL; | |
3294 | |
3295 self->opt_type = opt_type; | |
3296 self->from = from; | |
3297 self->Check = Check; | |
3298 self->fromObj = fromObj; | |
3299 if (fromObj) | |
3300 Py_INCREF(fromObj); | |
3301 | |
3302 return (PyObject *)(self); | |
3303 } | |
3304 | |
3305 static void | |
4488 | 3306 OptionsDestructor(OptionsObject *self) |
4433 | 3307 { |
4500 | 3308 PyObject_GC_UnTrack((void *)(self)); |
3309 Py_XDECREF(self->fromObj); | |
3310 PyObject_GC_Del((void *)(self)); | |
4433 | 3311 } |
3312 | |
3313 static int | |
4488 | 3314 OptionsTraverse(OptionsObject *self, visitproc visit, void *arg) |
4433 | 3315 { |
4488 | 3316 Py_VISIT(self->fromObj); |
4433 | 3317 return 0; |
3318 } | |
3319 | |
3320 static int | |
4488 | 3321 OptionsClear(OptionsObject *self) |
4433 | 3322 { |
4488 | 3323 Py_CLEAR(self->fromObj); |
4433 | 3324 return 0; |
3325 } | |
3326 | |
4350 | 3327 static PyObject * |
4488 | 3328 OptionsItem(OptionsObject *self, PyObject *keyObject) |
4350 | 3329 { |
3330 char_u *key; | |
3331 int flags; | |
3332 long numval; | |
3333 char_u *stringval; | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3334 PyObject *todecref; |
4350 | 3335 |
4488 | 3336 if (self->Check(self->from)) |
4350 | 3337 return NULL; |
3338 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3339 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3340 return NULL; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3341 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3342 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3343 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3344 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3345 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3346 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3347 } |
4350 | 3348 |
3349 flags = get_option_value_strict(key, &numval, &stringval, | |
4488 | 3350 self->opt_type, self->from); |
4350 | 3351 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3352 Py_XDECREF(todecref); |
4350 | 3353 |
3354 if (flags == 0) | |
3355 { | |
4403 | 3356 PyErr_SetObject(PyExc_KeyError, keyObject); |
4350 | 3357 return NULL; |
3358 } | |
3359 | |
3360 if (flags & SOPT_UNSET) | |
3361 { | |
3362 Py_INCREF(Py_None); | |
3363 return Py_None; | |
3364 } | |
3365 else if (flags & SOPT_BOOL) | |
3366 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3367 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3368 ret = numval ? Py_True : Py_False; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3369 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3370 return ret; |
4350 | 3371 } |
3372 else if (flags & SOPT_NUM) | |
3373 return PyInt_FromLong(numval); | |
3374 else if (flags & SOPT_STRING) | |
3375 { | |
3376 if (stringval) | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3377 { |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
3378 PyObject *ret = PyBytes_FromString((char *)stringval); |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3379 vim_free(stringval); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3380 return ret; |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3381 } |
4350 | 3382 else |
3383 { | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
3384 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3385 N_("unable to get option value")); |
4350 | 3386 return NULL; |
3387 } | |
3388 } | |
3389 else | |
3390 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3391 PyErr_SET_VIM(N_("internal error: unknown option type")); |
4350 | 3392 return NULL; |
3393 } | |
3394 } | |
3395 | |
3396 static int | |
5610 | 3397 OptionsContains(OptionsObject *self, PyObject *keyObject) |
3398 { | |
3399 char_u *key; | |
3400 PyObject *todecref; | |
3401 | |
3402 if (!(key = StringToChars(keyObject, &todecref))) | |
3403 return -1; | |
3404 | |
3405 if (*key == NUL) | |
3406 { | |
3407 Py_XDECREF(todecref); | |
3408 return 0; | |
3409 } | |
3410 | |
3411 if (get_option_value_strict(key, NULL, NULL, self->opt_type, NULL)) | |
3412 { | |
3413 Py_XDECREF(todecref); | |
3414 return 1; | |
3415 } | |
3416 else | |
3417 { | |
3418 Py_XDECREF(todecref); | |
3419 return 0; | |
3420 } | |
3421 } | |
3422 | |
3423 typedef struct | |
3424 { | |
3425 void *lastoption; | |
3426 int opt_type; | |
3427 } optiterinfo_T; | |
3428 | |
3429 static PyObject * | |
3430 OptionsIterNext(optiterinfo_T **oii) | |
3431 { | |
3432 char_u *name; | |
3433 | |
3434 if ((name = option_iter_next(&((*oii)->lastoption), (*oii)->opt_type))) | |
3435 return PyString_FromString((char *)name); | |
3436 | |
3437 return NULL; | |
3438 } | |
3439 | |
3440 static PyObject * | |
3441 OptionsIter(OptionsObject *self) | |
3442 { | |
3443 optiterinfo_T *oii; | |
3444 | |
3445 if (!(oii = PyMem_New(optiterinfo_T, 1))) | |
3446 { | |
3447 PyErr_NoMemory(); | |
3448 return NULL; | |
3449 } | |
3450 | |
3451 oii->opt_type = self->opt_type; | |
3452 oii->lastoption = NULL; | |
3453 | |
3454 return IterNew(oii, | |
3455 (destructorfun) PyMem_Free, (nextfun) OptionsIterNext, | |
3456 NULL, NULL); | |
3457 } | |
3458 | |
3459 static int | |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3460 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
|
3461 { |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3462 char_u *errmsg; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3463 |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3464 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
|
3465 { |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3466 if (VimTryEnd()) |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3467 return FAIL; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3468 PyErr_SetVim((char *)errmsg); |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3469 return FAIL; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3470 } |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3471 return OK; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3472 } |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3473 |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3474 static int |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3475 set_option_value_for( |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3476 char_u *key, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3477 int numval, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3478 char_u *stringval, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3479 int opt_flags, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3480 int opt_type, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3481 void *from) |
4350 | 3482 { |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3483 win_T *save_curwin = NULL; |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3484 tabpage_T *save_curtab = NULL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
3485 bufref_T save_curbuf; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3486 int set_ret = 0; |
4498 | 3487 |
3488 VimTryStart(); | |
4350 | 3489 switch (opt_type) |
3490 { | |
3491 case SREQ_WIN: | |
4429 | 3492 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
|
3493 win_find_tabpage((win_T *)from), FALSE) == FAIL) |
4350 | 3494 { |
6454 | 3495 restore_win(save_curwin, save_curtab, TRUE); |
4498 | 3496 if (VimTryEnd()) |
3497 return -1; | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3498 PyErr_SET_VIM(N_("problem while switching windows")); |
4350 | 3499 return -1; |
3500 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3501 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
|
3502 restore_win(save_curwin, save_curtab, TRUE); |
4350 | 3503 break; |
3504 case SREQ_BUF: | |
4429 | 3505 switch_buffer(&save_curbuf, (buf_T *)from); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3506 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
|
3507 restore_buffer(&save_curbuf); |
4350 | 3508 break; |
3509 case SREQ_GLOBAL: | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3510 set_ret = set_option_value_err(key, numval, stringval, opt_flags); |
4350 | 3511 break; |
3512 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3513 if (set_ret == FAIL) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3514 return -1; |
4498 | 3515 return VimTryEnd(); |
4350 | 3516 } |
3517 | |
3518 static int | |
4488 | 3519 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject) |
4350 | 3520 { |
3521 char_u *key; | |
3522 int flags; | |
3523 int opt_flags; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3524 int ret = 0; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3525 PyObject *todecref; |
4350 | 3526 |
4488 | 3527 if (self->Check(self->from)) |
4350 | 3528 return -1; |
3529 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3530 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3531 return -1; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3532 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3533 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3534 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3535 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3536 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3537 return -1; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3538 } |
4350 | 3539 |
3540 flags = get_option_value_strict(key, NULL, NULL, | |
4488 | 3541 self->opt_type, self->from); |
4350 | 3542 |
3543 if (flags == 0) | |
3544 { | |
4403 | 3545 PyErr_SetObject(PyExc_KeyError, keyObject); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3546 Py_XDECREF(todecref); |
4350 | 3547 return -1; |
3548 } | |
3549 | |
3550 if (valObject == NULL) | |
3551 { | |
4488 | 3552 if (self->opt_type == SREQ_GLOBAL) |
4350 | 3553 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
3554 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3555 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
|
3556 Py_XDECREF(todecref); |
4350 | 3557 return -1; |
3558 } | |
3559 else if (!(flags & SOPT_GLOBAL)) | |
3560 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
3561 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3562 N_("unable to unset option %s " |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3563 "which does not have global value"), key); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3564 Py_XDECREF(todecref); |
4350 | 3565 return -1; |
3566 } | |
3567 else | |
3568 { | |
4488 | 3569 unset_global_local_option(key, self->from); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3570 Py_XDECREF(todecref); |
4350 | 3571 return 0; |
3572 } | |
3573 } | |
3574 | |
4488 | 3575 opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL); |
4350 | 3576 |
3577 if (flags & SOPT_BOOL) | |
3578 { | |
4411 | 3579 int istrue = PyObject_IsTrue(valObject); |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3580 |
4411 | 3581 if (istrue == -1) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3582 ret = -1; |
4587
63c9b681c3db
updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents:
4575
diff
changeset
|
3583 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3584 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
|
3585 opt_flags, self->opt_type, self->from); |
4350 | 3586 } |
3587 else if (flags & SOPT_NUM) | |
3588 { | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3589 long val; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3590 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3591 if (NumberToLong(valObject, &val, NUMBER_INT)) |
4350 | 3592 { |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3593 Py_XDECREF(todecref); |
4350 | 3594 return -1; |
3595 } | |
3596 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3597 ret = set_option_value_for(key, (int) val, NULL, opt_flags, |
4488 | 3598 self->opt_type, self->from); |
4350 | 3599 } |
3600 else | |
3601 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3602 char_u *val; |
5525 | 3603 PyObject *todecref2; |
3604 | |
3605 if ((val = StringToChars(valObject, &todecref2))) | |
3606 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3607 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
|
3608 self->opt_type, self->from); |
5525 | 3609 Py_XDECREF(todecref2); |
3610 } | |
4350 | 3611 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3612 ret = -1; |
4350 | 3613 } |
3614 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3615 Py_XDECREF(todecref); |
4587
63c9b681c3db
updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents:
4575
diff
changeset
|
3616 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3617 return ret; |
4350 | 3618 } |
3619 | |
5610 | 3620 static PySequenceMethods OptionsAsSeq = { |
3621 0, /* sq_length */ | |
3622 0, /* sq_concat */ | |
3623 0, /* sq_repeat */ | |
3624 0, /* sq_item */ | |
3625 0, /* sq_slice */ | |
3626 0, /* sq_ass_item */ | |
3627 0, /* sq_ass_slice */ | |
3628 (objobjproc) OptionsContains, /* sq_contains */ | |
3629 0, /* sq_inplace_concat */ | |
3630 0, /* sq_inplace_repeat */ | |
3631 }; | |
3632 | |
4350 | 3633 static PyMappingMethods OptionsAsMapping = { |
3634 (lenfunc) NULL, | |
3635 (binaryfunc) OptionsItem, | |
3636 (objobjargproc) OptionsAssItem, | |
3637 }; | |
3638 | |
4401 | 3639 /* Tabpage object |
3640 */ | |
3641 | |
3642 typedef struct | |
3643 { | |
3644 PyObject_HEAD | |
3645 tabpage_T *tab; | |
3646 } TabPageObject; | |
3647 | |
3648 static PyObject *WinListNew(TabPageObject *tabObject); | |
3649 | |
3650 static PyTypeObject TabPageType; | |
3651 | |
3652 static int | |
4488 | 3653 CheckTabPage(TabPageObject *self) |
4401 | 3654 { |
4488 | 3655 if (self->tab == INVALID_TABPAGE_VALUE) |
4401 | 3656 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3657 PyErr_SET_VIM(N_("attempt to refer to deleted tab page")); |
4401 | 3658 return -1; |
3659 } | |
3660 | |
3661 return 0; | |
3662 } | |
3663 | |
3664 static PyObject * | |
3665 TabPageNew(tabpage_T *tab) | |
3666 { | |
3667 TabPageObject *self; | |
3668 | |
3669 if (TAB_PYTHON_REF(tab)) | |
3670 { | |
3671 self = TAB_PYTHON_REF(tab); | |
3672 Py_INCREF(self); | |
3673 } | |
3674 else | |
3675 { | |
3676 self = PyObject_NEW(TabPageObject, &TabPageType); | |
3677 if (self == NULL) | |
3678 return NULL; | |
3679 self->tab = tab; | |
3680 TAB_PYTHON_REF(tab) = self; | |
3681 } | |
3682 | |
3683 return (PyObject *)(self); | |
3684 } | |
3685 | |
3686 static void | |
4488 | 3687 TabPageDestructor(TabPageObject *self) |
4401 | 3688 { |
4488 | 3689 if (self->tab && self->tab != INVALID_TABPAGE_VALUE) |
3690 TAB_PYTHON_REF(self->tab) = NULL; | |
4401 | 3691 |
3692 DESTRUCTOR_FINISH(self); | |
3693 } | |
3694 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3695 static char *TabPageAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3696 "windows", "number", "vars", "window", "valid", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3697 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3698 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3699 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3700 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3701 TabPageDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3702 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3703 return ObjectDir(self, TabPageAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3704 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3705 |
4401 | 3706 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3707 TabPageAttrValid(TabPageObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3708 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3709 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3710 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3711 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3712 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3713 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3714 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
|
3715 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3716 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3717 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3718 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3719 static PyObject * |
4488 | 3720 TabPageAttr(TabPageObject *self, char *name) |
4401 | 3721 { |
3722 if (strcmp(name, "windows") == 0) | |
4488 | 3723 return WinListNew(self); |
4401 | 3724 else if (strcmp(name, "number") == 0) |
4488 | 3725 return PyLong_FromLong((long) get_tab_number(self->tab)); |
4401 | 3726 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3727 return NEW_DICTIONARY(self->tab->tp_vars); |
4401 | 3728 else if (strcmp(name, "window") == 0) |
3729 { | |
3730 /* For current tab window.c does not bother to set or update tp_curwin | |
3731 */ | |
4488 | 3732 if (self->tab == curtab) |
4431 | 3733 return WindowNew(curwin, curtab); |
4401 | 3734 else |
4488 | 3735 return WindowNew(self->tab->tp_curwin, self->tab); |
4401 | 3736 } |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3737 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3738 return ObjectDir(NULL, TabPageAttrs); |
4401 | 3739 return NULL; |
3740 } | |
3741 | |
3742 static PyObject * | |
4488 | 3743 TabPageRepr(TabPageObject *self) |
4401 | 3744 { |
4488 | 3745 if (self->tab == INVALID_TABPAGE_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3746 return PyString_FromFormat("<tabpage object (deleted) at %p>", (self)); |
4401 | 3747 else |
3748 { | |
4488 | 3749 int t = get_tab_number(self->tab); |
4401 | 3750 |
3751 if (t == 0) | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3752 return PyString_FromFormat("<tabpage object (unknown) at %p>", |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3753 (self)); |
4401 | 3754 else |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3755 return PyString_FromFormat("<tabpage %d>", t - 1); |
4401 | 3756 } |
3757 } | |
3758 | |
3759 static struct PyMethodDef TabPageMethods[] = { | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3760 /* name, function, calling, documentation */ |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3761 {"__dir__", (PyCFunction)TabPageDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3762 { NULL, NULL, 0, NULL} |
4401 | 3763 }; |
3764 | |
3765 /* | |
3766 * Window list object | |
3767 */ | |
3768 | |
3769 static PyTypeObject TabListType; | |
3770 static PySequenceMethods TabListAsSeq; | |
3771 | |
3772 typedef struct | |
3773 { | |
3774 PyObject_HEAD | |
3775 } TabListObject; | |
3776 | |
3777 static PyInt | |
3778 TabListLength(PyObject *self UNUSED) | |
3779 { | |
3780 tabpage_T *tp = first_tabpage; | |
3781 PyInt n = 0; | |
3782 | |
3783 while (tp != NULL) | |
3784 { | |
3785 ++n; | |
3786 tp = tp->tp_next; | |
3787 } | |
3788 | |
3789 return n; | |
3790 } | |
3791 | |
3792 static PyObject * | |
3793 TabListItem(PyObject *self UNUSED, PyInt n) | |
3794 { | |
3795 tabpage_T *tp; | |
3796 | |
3797 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, --n) | |
3798 if (n == 0) | |
3799 return TabPageNew(tp); | |
3800 | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3801 PyErr_SET_STRING(PyExc_IndexError, N_("no such tab page")); |
4401 | 3802 return NULL; |
3803 } | |
3804 | |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
3805 /* |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
3806 * Window object |
4385 | 3807 */ |
3808 | |
3809 typedef struct | |
3810 { | |
3811 PyObject_HEAD | |
3812 win_T *win; | |
4431 | 3813 TabPageObject *tabObject; |
4385 | 3814 } WindowObject; |
3815 | |
3816 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
|
3817 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3818 static int |
4488 | 3819 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
|
3820 { |
4488 | 3821 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
|
3822 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3823 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
|
3824 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3825 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3826 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3827 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3828 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3829 |
4319 | 3830 static PyObject * |
4431 | 3831 WindowNew(win_T *win, tabpage_T *tab) |
4377 | 3832 { |
3833 /* We need to handle deletion of windows underneath us. | |
3834 * If we add a "w_python*_ref" field to the win_T structure, | |
3835 * then we can get at it in win_free() in vim. We then | |
3836 * need to create only ONE Python object per window - if | |
3837 * we try to create a second, just INCREF the existing one | |
3838 * and return it. The (single) Python object referring to | |
3839 * the window is stored in "w_python*_ref". | |
3840 * On a win_free() we set the Python object's win_T* field | |
3841 * to an invalid value. We trap all uses of a window | |
3842 * object, and reject them if the win_T* field is invalid. | |
3843 * | |
4385 | 3844 * Python2 and Python3 get different fields and different objects: |
4377 | 3845 * w_python_ref and w_python3_ref fields respectively. |
3846 */ | |
3847 | |
3848 WindowObject *self; | |
3849 | |
3850 if (WIN_PYTHON_REF(win)) | |
3851 { | |
3852 self = WIN_PYTHON_REF(win); | |
3853 Py_INCREF(self); | |
3854 } | |
3855 else | |
3856 { | |
4500 | 3857 self = PyObject_GC_New(WindowObject, &WindowType); |
4377 | 3858 if (self == NULL) |
3859 return NULL; | |
3860 self->win = win; | |
3861 WIN_PYTHON_REF(win) = self; | |
3862 } | |
3863 | |
4431 | 3864 self->tabObject = ((TabPageObject *)(TabPageNew(tab))); |
3865 | |
4377 | 3866 return (PyObject *)(self); |
3867 } | |
3868 | |
4385 | 3869 static void |
4488 | 3870 WindowDestructor(WindowObject *self) |
4385 | 3871 { |
4500 | 3872 PyObject_GC_UnTrack((void *)(self)); |
4488 | 3873 if (self->win && self->win != INVALID_WINDOW_VALUE) |
3874 WIN_PYTHON_REF(self->win) = NULL; | |
4500 | 3875 Py_XDECREF(((PyObject *)(self->tabObject))); |
3876 PyObject_GC_Del((void *)(self)); | |
3877 } | |
3878 | |
3879 static int | |
3880 WindowTraverse(WindowObject *self, visitproc visit, void *arg) | |
3881 { | |
3882 Py_VISIT(((PyObject *)(self->tabObject))); | |
3883 return 0; | |
3884 } | |
3885 | |
3886 static int | |
3887 WindowClear(WindowObject *self) | |
3888 { | |
3889 Py_CLEAR(self->tabObject); | |
3890 return 0; | |
4385 | 3891 } |
3892 | |
4431 | 3893 static win_T * |
3894 get_firstwin(TabPageObject *tabObject) | |
3895 { | |
3896 if (tabObject) | |
3897 { | |
3898 if (CheckTabPage(tabObject)) | |
3899 return NULL; | |
3900 /* For current tab window.c does not bother to set or update tp_firstwin | |
3901 */ | |
3902 else if (tabObject->tab == curtab) | |
3903 return firstwin; | |
3904 else | |
3905 return tabObject->tab->tp_firstwin; | |
3906 } | |
3907 else | |
3908 return firstwin; | |
3909 } | |
14047
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3910 |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3911 // 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
|
3912 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
|
3913 "buffer", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3914 "cursor", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3915 "height", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3916 "row", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3917 "width", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3918 "col", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3919 "vars", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3920 "options", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3921 "number", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3922 "tabpage", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3923 "valid", |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3924 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3925 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3926 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3927 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3928 WindowDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3929 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3930 return ObjectDir(self, WindowAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3931 } |
4431 | 3932 |
4377 | 3933 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3934 WindowAttrValid(WindowObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3935 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3936 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3937 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3938 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3939 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3940 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3941 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
|
3942 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3943 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3944 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3945 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3946 static PyObject * |
4488 | 3947 WindowAttr(WindowObject *self, char *name) |
4319 | 3948 { |
3949 if (strcmp(name, "buffer") == 0) | |
4488 | 3950 return (PyObject *)BufferNew(self->win->w_buffer); |
4319 | 3951 else if (strcmp(name, "cursor") == 0) |
3952 { | |
4488 | 3953 pos_T *pos = &self->win->w_cursor; |
4319 | 3954 |
3955 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col)); | |
3956 } | |
3957 else if (strcmp(name, "height") == 0) | |
4488 | 3958 return PyLong_FromLong((long)(self->win->w_height)); |
4383 | 3959 else if (strcmp(name, "row") == 0) |
4488 | 3960 return PyLong_FromLong((long)(self->win->w_winrow)); |
4319 | 3961 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
|
3962 return PyLong_FromLong((long)(self->win->w_width)); |
4383 | 3963 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
|
3964 return PyLong_FromLong((long)(self->win->w_wincol)); |
4323 | 3965 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3966 return NEW_DICTIONARY(self->win->w_vars); |
4350 | 3967 else if (strcmp(name, "options") == 0) |
4488 | 3968 return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow, |
3969 (PyObject *) self); | |
4379 | 3970 else if (strcmp(name, "number") == 0) |
4431 | 3971 { |
4488 | 3972 if (CheckTabPage(self->tabObject)) |
4431 | 3973 return NULL; |
3974 return PyLong_FromLong((long) | |
4488 | 3975 get_win_number(self->win, get_firstwin(self->tabObject))); |
4431 | 3976 } |
3977 else if (strcmp(name, "tabpage") == 0) | |
3978 { | |
4488 | 3979 Py_INCREF(self->tabObject); |
3980 return (PyObject *)(self->tabObject); | |
4431 | 3981 } |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3982 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3983 return ObjectDir(NULL, WindowAttrs); |
4319 | 3984 else |
3985 return NULL; | |
3986 } | |
3987 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3988 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3989 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
|
3990 { |
4488 | 3991 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
|
3992 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3993 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3994 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
|
3995 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3996 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
|
3997 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3998 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3999 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
|
4000 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4001 long lnum; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4002 long col; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4003 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4004 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
|
4005 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4006 |
4488 | 4007 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
|
4008 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4009 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
|
4010 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4011 } |
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 /* Check for keyboard interrupts */ |
4498 | 4014 if (VimCheckInterrupt()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4015 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4016 |
4488 | 4017 self->win->w_cursor.lnum = lnum; |
4018 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
|
4019 self->win->w_set_curswant = TRUE; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4020 #ifdef FEAT_VIRTUALEDIT |
4488 | 4021 self->win->w_cursor.coladd = 0; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4022 #endif |
2933 | 4023 /* When column is out of range silently correct it. */ |
4488 | 4024 check_cursor_col_win(self->win); |
2933 | 4025 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4026 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4027 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4028 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4029 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
|
4030 { |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4031 long height; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4032 win_T *savewin; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4033 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4034 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
|
4035 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4036 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4037 #ifdef FEAT_GUI |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4038 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
|
4039 #endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4040 savewin = curwin; |
4488 | 4041 curwin = self->win; |
4498 | 4042 |
4043 VimTryStart(); | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4044 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
|
4045 curwin = savewin; |
4498 | 4046 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4047 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4048 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4049 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4050 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4051 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
|
4052 { |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4053 long width; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4054 win_T *savewin; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4055 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4056 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
|
4057 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4058 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4059 #ifdef FEAT_GUI |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4060 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
|
4061 #endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4062 savewin = curwin; |
4488 | 4063 curwin = self->win; |
4498 | 4064 |
4065 VimTryStart(); | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4066 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
|
4067 curwin = savewin; |
4498 | 4068 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4069 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4070 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4071 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4072 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4073 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4074 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4075 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
|
4076 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4077 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4078 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4079 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4080 static PyObject * |
4488 | 4081 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
|
4082 { |
4488 | 4083 if (self->win == INVALID_WINDOW_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4084 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
|
4085 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4086 { |
4488 | 4087 int w = get_win_number(self->win, firstwin); |
4379 | 4088 |
4089 if (w == 0) | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4090 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
|
4091 (self)); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4092 else |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4093 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
|
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 |
4385 | 4097 static struct PyMethodDef WindowMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4098 /* name, function, calling, documentation */ |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4099 {"__dir__", (PyCFunction)WindowDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4100 { NULL, NULL, 0, NULL} |
4385 | 4101 }; |
4102 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4103 /* |
4385 | 4104 * 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
|
4105 */ |
4319 | 4106 |
4385 | 4107 static PyTypeObject WinListType; |
4108 static PySequenceMethods WinListAsSeq; | |
4109 | |
4319 | 4110 typedef struct |
4111 { | |
4112 PyObject_HEAD | |
4401 | 4113 TabPageObject *tabObject; |
4319 | 4114 } WinListObject; |
4115 | |
4401 | 4116 static PyObject * |
4117 WinListNew(TabPageObject *tabObject) | |
4118 { | |
4119 WinListObject *self; | |
4120 | |
4121 self = PyObject_NEW(WinListObject, &WinListType); | |
4122 self->tabObject = tabObject; | |
4123 Py_INCREF(tabObject); | |
4124 | |
4125 return (PyObject *)(self); | |
4126 } | |
4127 | |
4128 static void | |
4488 | 4129 WinListDestructor(WinListObject *self) |
4401 | 4130 { |
4488 | 4131 TabPageObject *tabObject = self->tabObject; |
4401 | 4132 |
4133 if (tabObject) | |
4523
57393dc4b811
updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents:
4513
diff
changeset
|
4134 { |
4401 | 4135 Py_DECREF((PyObject *)(tabObject)); |
4523
57393dc4b811
updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents:
4513
diff
changeset
|
4136 } |
4401 | 4137 |
4138 DESTRUCTOR_FINISH(self); | |
4139 } | |
4140 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4141 static PyInt |
4488 | 4142 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
|
4143 { |
4401 | 4144 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
|
4145 PyInt n = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4146 |
4488 | 4147 if (!(w = get_firstwin(self->tabObject))) |
4401 | 4148 return -1; |
4149 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4150 while (w != NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4151 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4152 ++n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4153 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
|
4154 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4155 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4156 return n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4157 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4158 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4159 static PyObject * |
4488 | 4160 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
|
4161 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4162 win_T *w; |
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 NULL; |
4166 | |
4167 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
|
4168 if (n == 0) |
4488 | 4169 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
|
4170 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4171 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
|
4172 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4173 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4174 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4175 /* Convert a Python string into a Vim line. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4176 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4177 * 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
|
4178 * 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
|
4179 * characters. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4180 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4181 * 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
|
4182 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4183 static char * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4184 StringToLine(PyObject *obj) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4185 { |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4186 char *str; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4187 char *save; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4188 PyObject *bytes = NULL; |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4189 Py_ssize_t len = 0; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4190 PyInt i; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4191 char *p; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4192 |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4193 if (PyBytes_Check(obj)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4194 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4195 if (PyBytes_AsStringAndSize(obj, &str, &len) == -1 |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4196 || str == NULL) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4197 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4198 } |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4199 else if (PyUnicode_Check(obj)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4200 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4201 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4202 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4203 |
4995
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4204 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1 |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4205 || str == NULL) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4206 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4207 Py_DECREF(bytes); |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4208 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4209 } |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4210 } |
4995
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4211 else |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4212 { |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4213 #if PY_MAJOR_VERSION < 3 |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4214 PyErr_FORMAT(PyExc_TypeError, |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4215 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
|
4216 Py_TYPE_NAME(obj)); |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4217 #else |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4218 PyErr_FORMAT(PyExc_TypeError, |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4219 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
|
4220 Py_TYPE_NAME(obj)); |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4221 #endif |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4222 return NULL; |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4223 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4224 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4225 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4226 * 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
|
4227 * 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
|
4228 * a single line. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4229 * 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
|
4230 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4231 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
|
4232 if (p != NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4233 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4234 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
|
4235 --len; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4236 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4237 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4238 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
|
4239 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
|
4240 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4241 } |
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 /* Create a copy of the string, with internal nulls replaced by |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4245 * 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
|
4246 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4247 save = (char *)alloc((unsigned)(len+1)); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4248 if (save == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4249 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4250 PyErr_NoMemory(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
4251 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
|
4252 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4253 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4254 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4255 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
|
4256 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4257 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
|
4258 save[i] = '\n'; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4259 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4260 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
|
4261 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4262 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4263 save[i] = '\0'; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4264 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
|
4265 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4266 return save; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4267 } |
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 /* Get a line from the specified buffer. The line number is |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4270 * 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
|
4271 * string object. |
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 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4274 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
|
4275 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4276 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
|
4277 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4278 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4279 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4280 /* Get a list of lines from the specified buffer. The line numbers |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4281 * 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
|
4282 * 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
|
4283 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4284 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4285 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
|
4286 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4287 PyInt i; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4288 PyInt n = hi - lo; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4289 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
|
4290 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4291 if (list == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4292 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4293 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4294 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
|
4295 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4296 PyObject *string = LineToString( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4297 (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
|
4298 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4299 /* 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
|
4300 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
|
4301 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4302 Py_DECREF(list); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4303 return NULL; |
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 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4306 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
|
4307 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4308 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4309 /* The ownership of the Python list is passed to the caller (ie, |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4310 * the caller should Py_DECREF() the object when it is finished |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4311 * with it). |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4312 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4313 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4314 return list; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4315 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4316 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4317 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4318 * 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
|
4319 * 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
|
4320 * deleted). |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4321 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4322 static void |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4323 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
|
4324 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4325 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
|
4326 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4327 /* Adjust the cursor position if it's in/after the changed |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4328 * lines. */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4329 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
|
4330 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4331 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
|
4332 check_cursor_col(); |
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 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
|
4335 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4336 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
|
4337 check_cursor(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4338 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4339 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4340 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4341 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
|
4342 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4343 invalidate_botline(); |
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 |
2894 | 4346 /* |
4347 * 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
|
4348 * 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
|
4349 * 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
|
4350 * 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
|
4351 * 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
|
4352 * 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
|
4353 * 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
|
4354 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4355 static int |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4356 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
|
4357 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4358 bufref_T save_curbuf = {NULL, 0, 0}; |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4359 win_T *save_curwin = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4360 tabpage_T *save_curtab = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4361 |
4352 | 4362 /* First of all, we check the type of the supplied Python object. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4363 * There are three cases: |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4364 * 1. NULL, or None - this is a deletion. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4365 * 2. A string - this is a replacement. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4366 * 3. Anything else - this is an error. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4367 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4368 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
|
4369 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4370 PyErr_Clear(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4371 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
|
4372 |
4498 | 4373 VimTryStart(); |
4374 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4375 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
|
4376 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
|
4377 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
|
4378 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
|
4379 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4380 { |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4381 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
|
4382 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
|
4383 if (save_curbuf.br_buf == NULL) |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4384 /* Only adjust marks if we managed to switch to a window that |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4385 * holds the buffer, otherwise line numbers will be invalid. */ |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4386 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
|
4387 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4388 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4389 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
|
4390 |
4498 | 4391 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4392 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4393 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4394 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4395 *len_change = -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4396 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4397 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4398 } |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4399 else if (PyBytes_Check(line) || PyUnicode_Check(line)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4400 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4401 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
|
4402 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4403 if (save == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4404 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4405 |
4498 | 4406 VimTryStart(); |
4407 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4408 /* We do not need to free "save" if ml_replace() consumes it. */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4409 PyErr_Clear(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4410 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
|
4411 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4412 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
|
4413 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
4414 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
|
4415 vim_free(save); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4416 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4417 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
|
4418 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4419 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
|
4420 vim_free(save); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4421 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4422 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4423 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
|
4424 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4425 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
|
4426 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4427 /* 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
|
4428 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
|
4429 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4430 |
4498 | 4431 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4432 return FAIL; |
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 (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4435 *len_change = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4436 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4437 return OK; |
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4440 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4441 PyErr_BadArgument(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4442 return FAIL; |
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 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4445 |
2894 | 4446 /* Replace a range of lines in the specified buffer. The line numbers are in |
4447 * Vim format (1-based). The range is from lo up to, but not including, hi. | |
4448 * The replacement lines are given as a Python list of string objects. The | |
4449 * list is checked for validity and correct format. Errors are returned as a | |
4450 * value of FAIL. The return value is OK on success. | |
4451 * If OK is returned and len_change is not NULL, *len_change | |
4452 * is set to the change in the buffer length. | |
4453 */ | |
4454 static int | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4455 SetBufferLineList( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4456 buf_T *buf, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4457 PyInt lo, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4458 PyInt hi, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4459 PyObject *list, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4460 PyInt *len_change) |
2894 | 4461 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4462 bufref_T save_curbuf = {NULL, 0, 0}; |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4463 win_T *save_curwin = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4464 tabpage_T *save_curtab = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4465 |
4352 | 4466 /* First of all, we check the type of the supplied Python object. |
2894 | 4467 * There are three cases: |
4468 * 1. NULL, or None - this is a deletion. | |
4469 * 2. A list - this is a replacement. | |
4470 * 3. Anything else - this is an error. | |
4471 */ | |
4472 if (list == Py_None || list == NULL) | |
4473 { | |
4474 PyInt i; | |
4475 PyInt n = (int)(hi - lo); | |
4476 | |
4477 PyErr_Clear(); | |
4498 | 4478 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4479 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2894 | 4480 |
4481 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
|
4482 RAISE_UNDO_FAIL; |
2894 | 4483 else |
4484 { | |
4485 for (i = 0; i < n; ++i) | |
4486 { | |
4487 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
4488 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4489 RAISE_DELETE_LINE_FAIL; |
2894 | 4490 break; |
4491 } | |
4492 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4493 if (buf == curbuf && (save_curwin != NULL |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4494 || save_curbuf.br_buf == NULL)) |
6176 | 4495 /* Using an existing window for the buffer, adjust the cursor |
4496 * position. */ | |
2894 | 4497 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
|
4498 if (save_curbuf.br_buf == NULL) |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4499 /* Only adjust marks if we managed to switch to a window that |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4500 * holds the buffer, otherwise line numbers will be invalid. */ |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4501 deleted_lines_mark((linenr_T)lo, (long)i); |
2894 | 4502 } |
4503 | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4504 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2894 | 4505 |
4498 | 4506 if (VimTryEnd()) |
2894 | 4507 return FAIL; |
4508 | |
4509 if (len_change) | |
4510 *len_change = -n; | |
4511 | |
4512 return OK; | |
4513 } | |
4514 else if (PyList_Check(list)) | |
4515 { | |
4516 PyInt i; | |
4517 PyInt new_len = PyList_Size(list); | |
4518 PyInt old_len = hi - lo; | |
4519 PyInt extra = 0; /* lines added to text, can be negative */ | |
4520 char **array; | |
4521 | |
4522 if (new_len == 0) /* avoid allocating zero bytes */ | |
4523 array = NULL; | |
4524 else | |
4525 { | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4526 array = PyMem_New(char *, new_len); |
2894 | 4527 if (array == NULL) |
4528 { | |
4529 PyErr_NoMemory(); | |
4530 return FAIL; | |
4531 } | |
4532 } | |
4533 | |
4534 for (i = 0; i < new_len; ++i) | |
4535 { | |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4536 PyObject *line; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4537 |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4538 if (!(line = PyList_GetItem(list, i)) || |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4539 !(array[i] = StringToLine(line))) |
2894 | 4540 { |
4541 while (i) | |
4542 vim_free(array[--i]); | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4543 PyMem_Free(array); |
2894 | 4544 return FAIL; |
4545 } | |
4546 } | |
4547 | |
4498 | 4548 VimTryStart(); |
2894 | 4549 PyErr_Clear(); |
4429 | 4550 |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4551 /* 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
|
4552 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2894 | 4553 |
4554 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
|
4555 RAISE_UNDO_FAIL; |
2894 | 4556 |
4557 /* If the size of the range is reducing (ie, new_len < old_len) we | |
4558 * need to delete some old_len. We do this at the start, by | |
4559 * repeatedly deleting line "lo". | |
4560 */ | |
4561 if (!PyErr_Occurred()) | |
4562 { | |
4563 for (i = 0; i < old_len - new_len; ++i) | |
4564 if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
4565 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4566 RAISE_DELETE_LINE_FAIL; |
2894 | 4567 break; |
4568 } | |
4569 extra -= i; | |
4570 } | |
4571 | |
4572 /* For as long as possible, replace the existing old_len with the | |
4573 * new old_len. This is a more efficient operation, as it requires | |
4574 * less memory allocation and freeing. | |
4575 */ | |
4576 if (!PyErr_Occurred()) | |
4577 { | |
4578 for (i = 0; i < old_len && i < new_len; ++i) | |
4579 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE) | |
4580 == FAIL) | |
4581 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4582 RAISE_REPLACE_LINE_FAIL; |
2894 | 4583 break; |
4584 } | |
4585 } | |
4586 else | |
4587 i = 0; | |
4588 | |
4589 /* Now we may need to insert the remaining new old_len. If we do, we | |
4590 * must free the strings as we finish with them (we can't pass the | |
4591 * responsibility to vim in this case). | |
4592 */ | |
4593 if (!PyErr_Occurred()) | |
4594 { | |
4595 while (i < new_len) | |
4596 { | |
4597 if (ml_append((linenr_T)(lo + i - 1), | |
4598 (char_u *)array[i], 0, FALSE) == FAIL) | |
4599 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4600 RAISE_INSERT_LINE_FAIL; |
2894 | 4601 break; |
4602 } | |
4603 vim_free(array[i]); | |
4604 ++i; | |
4605 ++extra; | |
4606 } | |
4607 } | |
4608 | |
4609 /* Free any left-over old_len, as a result of an error */ | |
4610 while (i < new_len) | |
4611 { | |
4612 vim_free(array[i]); | |
4613 ++i; | |
4614 } | |
4615 | |
4616 /* Free the array of old_len. All of its contents have now | |
4617 * been dealt with (either freed, or the responsibility passed | |
4618 * to vim. | |
4619 */ | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4620 PyMem_Free(array); |
2894 | 4621 |
4622 /* Adjust marks. Invalidate any which lie in the | |
4623 * changed range, and move any in the remainder of the buffer. | |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4624 * Only adjust marks if we managed to switch to a window that holds |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4625 * 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
|
4626 if (save_curbuf.br_buf == NULL) |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4627 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), |
2894 | 4628 (long)MAXLNUM, (long)extra); |
4629 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); | |
4630 | |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4631 if (buf == curbuf) |
2894 | 4632 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra); |
4633 | |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4634 /* END of region without "return". */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4635 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2894 | 4636 |
4498 | 4637 if (VimTryEnd()) |
2894 | 4638 return FAIL; |
4639 | |
4640 if (len_change) | |
4641 *len_change = new_len - old_len; | |
4642 | |
4643 return OK; | |
4644 } | |
4645 else | |
4646 { | |
4647 PyErr_BadArgument(); | |
4648 return FAIL; | |
4649 } | |
4650 } | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4651 |
4352 | 4652 /* 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
|
4653 * 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
|
4654 * 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
|
4655 * 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
|
4656 * 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
|
4657 * 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
|
4658 * 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
|
4659 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4660 static int |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4661 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
|
4662 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4663 bufref_T save_curbuf = {NULL, 0, 0}; |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4664 win_T *save_curwin = NULL; |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4665 tabpage_T *save_curtab = NULL; |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4666 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4667 /* First of all, we check the type of the supplied Python object. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4668 * It must be a string or a list, or the call is in error. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4669 */ |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4670 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
|
4671 { |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4672 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
|
4673 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4674 if (str == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4675 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4676 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4677 PyErr_Clear(); |
4498 | 4678 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4679 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
|
4680 |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4681 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
|
4682 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
|
4683 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
|
4684 RAISE_INSERT_LINE_FAIL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4685 else if (save_curbuf.br_buf == NULL) |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4686 /* Only adjust marks if we managed to switch to a window that |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4687 * 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
|
4688 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
|
4689 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4690 vim_free(str); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4691 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
|
4692 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4693 |
4498 | 4694 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4695 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4696 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4697 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4698 *len_change = 1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4699 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4700 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4701 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4702 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
|
4703 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4704 PyInt i; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4705 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
|
4706 char **array; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4707 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4708 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
|
4709 if (array == NULL) |
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 PyErr_NoMemory(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4712 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4713 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4714 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4715 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
|
4716 { |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4717 PyObject *line; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4718 |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4719 if (!(line = PyList_GetItem(lines, i)) || |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4720 !(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
|
4721 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4722 while (i) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4723 vim_free(array[--i]); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4724 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
|
4725 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4726 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4727 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4728 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4729 PyErr_Clear(); |
4498 | 4730 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4731 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
|
4732 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4733 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
|
4734 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
|
4735 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4736 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4737 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
|
4738 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4739 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
|
4740 (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
|
4741 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4742 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
|
4743 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4744 /* Free the rest of the lines */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4745 while (i < size) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4746 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
|
4747 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4748 break; |
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 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
|
4751 } |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4752 if (i > 0 && save_curbuf.br_buf == NULL) |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4753 /* Only adjust marks if we managed to switch to a window that |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4754 * 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
|
4755 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
|
4756 } |
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 /* Free the array of lines. All of its contents have now |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4759 * been freed. */ |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4760 PyMem_Free(array); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4761 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
|
4762 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4763 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4764 |
4498 | 4765 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4766 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4767 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4768 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4769 *len_change = size; |
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 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4772 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4773 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4774 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4775 PyErr_BadArgument(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4776 return FAIL; |
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 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4779 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4780 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4781 * 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
|
4782 * ------------------------------------------- |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4783 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4784 |
4385 | 4785 typedef struct |
4786 { | |
4787 PyObject_HEAD | |
4788 buf_T *buf; | |
4789 } BufferObject; | |
4790 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4791 static int |
4488 | 4792 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
|
4793 { |
4488 | 4794 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
|
4795 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4796 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
|
4797 return -1; |
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 return 0; |
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4803 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4804 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
|
4805 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4806 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4807 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4808 |
4387 | 4809 if (end == -1) |
4810 end = self->buf->b_ml.ml_line_count; | |
4811 | |
4389 | 4812 if (n < 0) |
4813 n += end - start + 1; | |
4814 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4815 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
|
4816 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4817 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
|
4818 return NULL; |
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 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
|
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 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
|
4826 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4827 PyInt size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4828 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4829 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4830 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4831 |
4387 | 4832 if (end == -1) |
4833 end = self->buf->b_ml.ml_line_count; | |
4834 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4835 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
|
4836 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4837 if (lo < 0) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4838 lo = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4839 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
|
4840 lo = size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4841 if (hi < 0) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4842 hi = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4843 if (hi < lo) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4844 hi = lo; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4845 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
|
4846 hi = size; |
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 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
|
4849 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4850 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4851 static PyInt |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4852 RBAsItem( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4853 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4854 PyInt n, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4855 PyObject *valObject, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4856 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4857 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4858 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
|
4859 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4860 PyInt len_change; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4861 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4862 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4863 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4864 |
4387 | 4865 if (end == -1) |
4866 end = self->buf->b_ml.ml_line_count; | |
4867 | |
4389 | 4868 if (n < 0) |
4869 n += end - start + 1; | |
4870 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4871 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
|
4872 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4873 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
|
4874 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4875 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4876 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4877 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
|
4878 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4879 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4880 if (new_end) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4881 *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
|
4882 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4883 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4884 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4885 |
2894 | 4886 static PyInt |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4887 RBAsSlice( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4888 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4889 PyInt lo, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4890 PyInt hi, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4891 PyObject *valObject, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4892 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4893 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4894 PyInt *new_end) |
2894 | 4895 { |
4896 PyInt size; | |
4897 PyInt len_change; | |
4898 | |
4899 /* Self must be a valid buffer */ | |
4900 if (CheckBuffer(self)) | |
4901 return -1; | |
4902 | |
4387 | 4903 if (end == -1) |
4904 end = self->buf->b_ml.ml_line_count; | |
4905 | |
2894 | 4906 /* Sort out the slice range */ |
4907 size = end - start + 1; | |
4908 | |
4909 if (lo < 0) | |
4910 lo = 0; | |
4911 else if (lo > size) | |
4912 lo = size; | |
4913 if (hi < 0) | |
4914 hi = 0; | |
4915 if (hi < lo) | |
4916 hi = lo; | |
4917 else if (hi > size) | |
4918 hi = size; | |
4919 | |
4920 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
|
4921 valObject, &len_change) == FAIL) |
2894 | 4922 return -1; |
4923 | |
4924 if (new_end) | |
4925 *new_end = end + len_change; | |
4926 | |
4927 return 0; | |
4928 } | |
4929 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4930 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4931 static PyObject * |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4932 RBAppend( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4933 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4934 PyObject *args, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4935 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4936 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4937 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
|
4938 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4939 PyObject *lines; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4940 PyInt len_change; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4941 PyInt max; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4942 PyInt n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4943 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4944 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4945 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4946 |
4387 | 4947 if (end == -1) |
4948 end = self->buf->b_ml.ml_line_count; | |
4949 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4950 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
|
4951 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4952 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
|
4953 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4954 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4955 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
|
4956 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4957 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
|
4958 return NULL; |
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4961 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
|
4962 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4963 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4964 if (new_end) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4965 *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
|
4966 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4967 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
|
4968 return Py_None; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4969 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4970 |
4385 | 4971 /* Range object |
2447
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 |
4319 | 4974 static PyTypeObject RangeType; |
4385 | 4975 static PySequenceMethods RangeAsSeq; |
4976 static PyMappingMethods RangeAsMapping; | |
4319 | 4977 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4978 typedef struct |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4979 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4980 PyObject_HEAD |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4981 BufferObject *buf; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4982 PyInt start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4983 PyInt end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4984 } RangeObject; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4985 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4986 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4987 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
|
4988 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4989 BufferObject *bufr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4990 RangeObject *self; |
4500 | 4991 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
|
4992 if (self == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4993 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4994 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4995 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
|
4996 if (bufr == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4997 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4998 Py_DECREF(self); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4999 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5000 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5001 Py_INCREF(bufr); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5002 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5003 self->buf = bufr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5004 self->start = start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5005 self->end = end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5006 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5007 return (PyObject *)(self); |
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 |
4319 | 5010 static void |
4488 | 5011 RangeDestructor(RangeObject *self) |
4319 | 5012 { |
4500 | 5013 PyObject_GC_UnTrack((void *)(self)); |
4498 | 5014 Py_XDECREF(self->buf); |
4500 | 5015 PyObject_GC_Del((void *)(self)); |
5016 } | |
5017 | |
5018 static int | |
5019 RangeTraverse(RangeObject *self, visitproc visit, void *arg) | |
5020 { | |
5021 Py_VISIT(((PyObject *)(self->buf))); | |
5022 return 0; | |
5023 } | |
5024 | |
5025 static int | |
5026 RangeClear(RangeObject *self) | |
5027 { | |
5028 Py_CLEAR(self->buf); | |
5029 return 0; | |
4319 | 5030 } |
5031 | |
4385 | 5032 static PyInt |
4488 | 5033 RangeLength(RangeObject *self) |
4385 | 5034 { |
5035 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */ | |
4488 | 5036 if (CheckBuffer(self->buf)) |
4385 | 5037 return -1; /* ??? */ |
5038 | |
4488 | 5039 return (self->end - self->start + 1); |
4385 | 5040 } |
5041 | |
5042 static PyObject * | |
4488 | 5043 RangeItem(RangeObject *self, PyInt n) |
4385 | 5044 { |
4488 | 5045 return RBItem(self->buf, n, self->start, self->end); |
4385 | 5046 } |
5047 | |
5048 static PyObject * | |
4488 | 5049 RangeSlice(RangeObject *self, PyInt lo, PyInt hi) |
4385 | 5050 { |
4488 | 5051 return RBSlice(self->buf, lo, hi, self->start, self->end); |
4385 | 5052 } |
5053 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5054 static char *RangeAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5055 "start", "end", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5056 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5057 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5058 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5059 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5060 RangeDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5061 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5062 return ObjectDir(self, RangeAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5063 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5064 |
4385 | 5065 static PyObject * |
4488 | 5066 RangeAppend(RangeObject *self, PyObject *args) |
4385 | 5067 { |
4488 | 5068 return RBAppend(self->buf, args, self->start, self->end, &self->end); |
4385 | 5069 } |
5070 | |
5071 static PyObject * | |
4488 | 5072 RangeRepr(RangeObject *self) |
4385 | 5073 { |
4488 | 5074 if (self->buf->buf == INVALID_BUFFER_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5075 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
|
5076 (self)); |
4385 | 5077 else |
5078 { | |
4488 | 5079 char *name = (char *)self->buf->buf->b_fname; |
4385 | 5080 |
5081 if (name == NULL) | |
5082 name = ""; | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5083 |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5084 return PyString_FromFormat("<range %s (%d:%d)>", |
4653
b943fd24c351
updated for version 7.3.1074
Bram Moolenaar <bram@vim.org>
parents:
4645
diff
changeset
|
5085 name, (int)self->start, (int)self->end); |
4385 | 5086 } |
5087 } | |
5088 | |
5089 static struct PyMethodDef RangeMethods[] = { | |
4492 | 5090 /* name, function, calling, documentation */ |
5091 {"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
|
5092 {"__dir__", (PyCFunction)RangeDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5093 { NULL, NULL, 0, NULL} |
4385 | 5094 }; |
5095 | |
4319 | 5096 static PyTypeObject BufferType; |
5097 static PySequenceMethods BufferAsSeq; | |
5098 static PyMappingMethods BufferAsMapping; | |
5099 | |
5100 static PyObject * | |
4377 | 5101 BufferNew(buf_T *buf) |
5102 { | |
5103 /* We need to handle deletion of buffers underneath us. | |
5104 * If we add a "b_python*_ref" field to the buf_T structure, | |
5105 * then we can get at it in buf_freeall() in vim. We then | |
5106 * need to create only ONE Python object per buffer - if | |
5107 * we try to create a second, just INCREF the existing one | |
5108 * and return it. The (single) Python object referring to | |
5109 * the buffer is stored in "b_python*_ref". | |
5110 * Question: what to do on a buf_freeall(). We'll probably | |
5111 * have to either delete the Python object (DECREF it to | |
5112 * zero - a bad idea, as it leaves dangling refs!) or | |
5113 * set the buf_T * value to an invalid value (-1?), which | |
5114 * means we need checks in all access functions... Bah. | |
5115 * | |
4385 | 5116 * Python2 and Python3 get different fields and different objects: |
4377 | 5117 * b_python_ref and b_python3_ref fields respectively. |
5118 */ | |
5119 | |
5120 BufferObject *self; | |
5121 | |
5122 if (BUF_PYTHON_REF(buf) != NULL) | |
5123 { | |
5124 self = BUF_PYTHON_REF(buf); | |
5125 Py_INCREF(self); | |
5126 } | |
5127 else | |
5128 { | |
5129 self = PyObject_NEW(BufferObject, &BufferType); | |
5130 if (self == NULL) | |
5131 return NULL; | |
5132 self->buf = buf; | |
5133 BUF_PYTHON_REF(buf) = self; | |
5134 } | |
5135 | |
5136 return (PyObject *)(self); | |
5137 } | |
5138 | |
4385 | 5139 static void |
4488 | 5140 BufferDestructor(BufferObject *self) |
4319 | 5141 { |
4488 | 5142 if (self->buf && self->buf != INVALID_BUFFER_VALUE) |
5143 BUF_PYTHON_REF(self->buf) = NULL; | |
4385 | 5144 |
5145 DESTRUCTOR_FINISH(self); | |
4319 | 5146 } |
5147 | |
4377 | 5148 static PyInt |
4488 | 5149 BufferLength(BufferObject *self) |
4377 | 5150 { |
5151 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */ | |
4488 | 5152 if (CheckBuffer(self)) |
4377 | 5153 return -1; /* ??? */ |
5154 | |
4488 | 5155 return (PyInt)(self->buf->b_ml.ml_line_count); |
4377 | 5156 } |
5157 | |
5158 static PyObject * | |
4488 | 5159 BufferItem(BufferObject *self, PyInt n) |
4377 | 5160 { |
4488 | 5161 return RBItem(self, n, 1, -1); |
4377 | 5162 } |
5163 | |
5164 static PyObject * | |
4488 | 5165 BufferSlice(BufferObject *self, PyInt lo, PyInt hi) |
4377 | 5166 { |
4488 | 5167 return RBSlice(self, lo, hi, 1, -1); |
4377 | 5168 } |
5169 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5170 static char *BufferAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5171 "name", "number", "vars", "options", "valid", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5172 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5173 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5174 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5175 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5176 BufferDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5177 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5178 return ObjectDir(self, BufferAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5179 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5180 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5181 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5182 BufferAttrValid(BufferObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5183 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5184 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5185 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5186 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5187 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5188 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5189 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
|
5190 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5191 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5192 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5193 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5194 static PyObject * |
4488 | 5195 BufferAttr(BufferObject *self, char *name) |
4385 | 5196 { |
5197 if (strcmp(name, "name") == 0) | |
4597
00eecb2f8e3e
updated for version 7.3.1046
Bram Moolenaar <bram@vim.org>
parents:
4595
diff
changeset
|
5198 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
|
5199 ? "" : (char *)self->buf->b_ffname)); |
4385 | 5200 else if (strcmp(name, "number") == 0) |
4488 | 5201 return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum); |
4385 | 5202 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
5203 return NEW_DICTIONARY(self->buf->b_vars); |
4385 | 5204 else if (strcmp(name, "options") == 0) |
4488 | 5205 return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer, |
5206 (PyObject *) self); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5207 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5208 return ObjectDir(NULL, BufferAttrs); |
4385 | 5209 else |
5210 return NULL; | |
5211 } | |
5212 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5213 static int |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5214 BufferSetattr(BufferObject *self, char *name, PyObject *valObject) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5215 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5216 if (CheckBuffer(self)) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5217 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5218 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5219 if (strcmp(name, "name") == 0) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5220 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5221 char_u *val; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5222 aco_save_T aco; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5223 int ren_ret; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5224 PyObject *todecref; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5225 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5226 if (!(val = StringToChars(valObject, &todecref))) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5227 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5228 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5229 VimTryStart(); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5230 /* Using aucmd_*: autocommands will be executed by rename_buffer */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5231 aucmd_prepbuf(&aco, self->buf); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5232 ren_ret = rename_buffer(val); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5233 aucmd_restbuf(&aco); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5234 Py_XDECREF(todecref); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5235 if (VimTryEnd()) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5236 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5237 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5238 if (ren_ret == FAIL) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5239 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5240 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
|
5241 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5242 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5243 return 0; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5244 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5245 else |
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 PyErr_SetString(PyExc_AttributeError, name); |
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 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5251 |
4385 | 5252 static PyObject * |
4488 | 5253 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
|
5254 { |
4488 | 5255 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
|
5256 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5257 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5258 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5259 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
|
5260 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5261 pos_T *posp; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5262 char_u *pmark; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5263 char_u mark; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
5264 bufref_T savebuf; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5265 PyObject *todecref; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5266 |
4488 | 5267 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
|
5268 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5269 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5270 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
|
5271 return NULL; |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5272 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5273 if (pmark[0] == '\0' || pmark[1] != '\0') |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5274 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5275 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5276 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
|
5277 Py_XDECREF(todecref); |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5278 return NULL; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5279 } |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5280 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5281 mark = *pmark; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5282 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5283 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5284 |
4498 | 5285 VimTryStart(); |
4488 | 5286 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
|
5287 posp = getmark(mark, FALSE); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
5288 restore_buffer(&savebuf); |
4498 | 5289 if (VimTryEnd()) |
5290 return NULL; | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5291 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5292 if (posp == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5293 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5294 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
|
5295 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5296 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5297 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5298 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
|
5299 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5300 /* Or raise an error? */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5301 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
|
5302 return Py_None; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5303 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5304 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5305 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
|
5306 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5307 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5308 static PyObject * |
4488 | 5309 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
|
5310 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5311 PyInt start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5312 PyInt end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5313 |
4488 | 5314 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
|
5315 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5316 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5317 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
|
5318 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5319 |
4488 | 5320 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
|
5321 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5322 |
4319 | 5323 static PyObject * |
4488 | 5324 BufferRepr(BufferObject *self) |
4319 | 5325 { |
4488 | 5326 if (self->buf == INVALID_BUFFER_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5327 return PyString_FromFormat("<buffer object (deleted) at %p>", self); |
4319 | 5328 else |
5329 { | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5330 char *name = (char *)self->buf->b_fname; |
4319 | 5331 |
5332 if (name == NULL) | |
5333 name = ""; | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5334 |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5335 return PyString_FromFormat("<buffer %s>", name); |
4319 | 5336 } |
5337 } | |
5338 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5339 static struct PyMethodDef BufferMethods[] = { |
4492 | 5340 /* name, function, calling, documentation */ |
5341 {"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
|
5342 {"mark", (PyCFunction)BufferMark, METH_O, "Return (row,col) representing position of named mark" }, |
4492 | 5343 {"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
|
5344 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5345 { 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
|
5346 }; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5347 |
4397 | 5348 /* |
5349 * Buffer list object - Implementation | |
5350 */ | |
5351 | |
5352 static PyTypeObject BufMapType; | |
5353 | |
5354 typedef struct | |
5355 { | |
5356 PyObject_HEAD | |
5357 } BufMapObject; | |
5358 | |
5359 static PyInt | |
5360 BufMapLength(PyObject *self UNUSED) | |
5361 { | |
5362 buf_T *b = firstbuf; | |
5363 PyInt n = 0; | |
5364 | |
5365 while (b) | |
5366 { | |
5367 ++n; | |
5368 b = b->b_next; | |
5369 } | |
5370 | |
5371 return n; | |
5372 } | |
5373 | |
5374 static PyObject * | |
5375 BufMapItem(PyObject *self UNUSED, PyObject *keyObject) | |
5376 { | |
5377 buf_T *b; | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5378 long bnr; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5379 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5380 if (NumberToLong(keyObject, &bnr, NUMBER_INT|NUMBER_NATURAL)) |
4397 | 5381 return NULL; |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5382 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5383 b = buflist_findnr((int) bnr); |
4397 | 5384 |
5385 if (b) | |
5386 return BufferNew(b); | |
5387 else | |
5388 { | |
4403 | 5389 PyErr_SetObject(PyExc_KeyError, keyObject); |
4397 | 5390 return NULL; |
5391 } | |
5392 } | |
5393 | |
5394 static void | |
5395 BufMapIterDestruct(PyObject *buffer) | |
5396 { | |
5397 /* Iteration was stopped before all buffers were processed */ | |
5398 if (buffer) | |
5399 { | |
5400 Py_DECREF(buffer); | |
5401 } | |
5402 } | |
5403 | |
4433 | 5404 static int |
5405 BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg) | |
5406 { | |
4500 | 5407 if (buffer) |
5408 Py_VISIT(buffer); | |
4433 | 5409 return 0; |
5410 } | |
5411 | |
5412 static int | |
5413 BufMapIterClear(PyObject **buffer) | |
5414 { | |
4500 | 5415 if (*buffer) |
5416 Py_CLEAR(*buffer); | |
4433 | 5417 return 0; |
5418 } | |
5419 | |
4397 | 5420 static PyObject * |
5421 BufMapIterNext(PyObject **buffer) | |
5422 { | |
5423 PyObject *next; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5424 PyObject *ret; |
4397 | 5425 |
5426 if (!*buffer) | |
5427 return NULL; | |
5428 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5429 ret = *buffer; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5430 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5431 if (CheckBuffer((BufferObject *)(ret))) |
4397 | 5432 { |
5433 *buffer = NULL; | |
5434 return NULL; | |
5435 } | |
5436 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5437 if (!((BufferObject *)(ret))->buf->b_next) |
4397 | 5438 next = NULL; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5439 else if (!(next = BufferNew(((BufferObject *)(ret))->buf->b_next))) |
4397 | 5440 return NULL; |
5441 *buffer = next; | |
4438 | 5442 /* Do not increment reference: we no longer hold it (decref), but whoever |
5443 * 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
|
5444 return ret; |
4397 | 5445 } |
5446 | |
5447 static PyObject * | |
5448 BufMapIter(PyObject *self UNUSED) | |
5449 { | |
5450 PyObject *buffer; | |
5451 | |
5452 buffer = BufferNew(firstbuf); | |
5453 return IterNew(buffer, | |
4433 | 5454 (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext, |
5455 (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear); | |
4397 | 5456 } |
5457 | |
5458 static PyMappingMethods BufMapAsMapping = { | |
5459 (lenfunc) BufMapLength, | |
5460 (binaryfunc) BufMapItem, | |
5461 (objobjargproc) 0, | |
5462 }; | |
5463 | |
4385 | 5464 /* 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
|
5465 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5466 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5467 static char *CurrentAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5468 "buffer", "window", "line", "range", "tabpage", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5469 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5470 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5471 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5472 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5473 CurrentDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5474 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5475 return ObjectDir(self, CurrentAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5476 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5477 |
4319 | 5478 static PyObject * |
5479 CurrentGetattr(PyObject *self UNUSED, char *name) | |
5480 { | |
5481 if (strcmp(name, "buffer") == 0) | |
5482 return (PyObject *)BufferNew(curbuf); | |
5483 else if (strcmp(name, "window") == 0) | |
4431 | 5484 return (PyObject *)WindowNew(curwin, curtab); |
4401 | 5485 else if (strcmp(name, "tabpage") == 0) |
5486 return (PyObject *)TabPageNew(curtab); | |
4319 | 5487 else if (strcmp(name, "line") == 0) |
5488 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum); | |
5489 else if (strcmp(name, "range") == 0) | |
5490 return RangeNew(curbuf, RangeStart, RangeEnd); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5491 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5492 return ObjectDir(NULL, CurrentAttrs); |
4319 | 5493 else |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5494 #if PY_MAJOR_VERSION < 3 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5495 return Py_FindMethod(WindowMethods, self, name); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5496 #else |
4319 | 5497 return NULL; |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5498 #endif |
4319 | 5499 } |
5500 | |
5501 static int | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5502 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *valObject) |
4319 | 5503 { |
5504 if (strcmp(name, "line") == 0) | |
5505 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5506 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
|
5507 NULL) == FAIL) |
4319 | 5508 return -1; |
5509 | |
5510 return 0; | |
5511 } | |
4407 | 5512 else if (strcmp(name, "buffer") == 0) |
5513 { | |
5514 int count; | |
5515 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5516 if (valObject->ob_type != &BufferType) |
4407 | 5517 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5518 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5519 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
|
5520 Py_TYPE_NAME(valObject)); |
4407 | 5521 return -1; |
5522 } | |
5523 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5524 if (CheckBuffer((BufferObject *)(valObject))) |
4407 | 5525 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5526 count = ((BufferObject *)(valObject))->buf->b_fnum; |
4407 | 5527 |
4498 | 5528 VimTryStart(); |
4407 | 5529 if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL) |
5530 { | |
4498 | 5531 if (VimTryEnd()) |
5532 return -1; | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5533 PyErr_VIM_FORMAT(N_("failed to switch to buffer %d"), count); |
4407 | 5534 return -1; |
5535 } | |
5536 | |
4498 | 5537 return VimTryEnd(); |
4407 | 5538 } |
5539 else if (strcmp(name, "window") == 0) | |
5540 { | |
5541 int count; | |
5542 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5543 if (valObject->ob_type != &WindowType) |
4407 | 5544 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5545 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5546 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
|
5547 Py_TYPE_NAME(valObject)); |
4407 | 5548 return -1; |
5549 } | |
5550 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5551 if (CheckWindow((WindowObject *)(valObject))) |
4407 | 5552 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5553 count = get_win_number(((WindowObject *)(valObject))->win, firstwin); |
4407 | 5554 |
5555 if (!count) | |
5556 { | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5557 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5558 N_("failed to find window in the current tab page")); |
4407 | 5559 return -1; |
5560 } | |
5561 | |
4498 | 5562 VimTryStart(); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5563 win_goto(((WindowObject *)(valObject))->win); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5564 if (((WindowObject *)(valObject))->win != curwin) |
4407 | 5565 { |
4498 | 5566 if (VimTryEnd()) |
5567 return -1; | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5568 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5569 N_("did not switch to the specified window")); |
4407 | 5570 return -1; |
5571 } | |
5572 | |
4498 | 5573 return VimTryEnd(); |
4407 | 5574 } |
5575 else if (strcmp(name, "tabpage") == 0) | |
5576 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5577 if (valObject->ob_type != &TabPageType) |
4407 | 5578 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5579 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5580 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
|
5581 Py_TYPE_NAME(valObject)); |
4407 | 5582 return -1; |
5583 } | |
5584 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5585 if (CheckTabPage((TabPageObject *)(valObject))) |
4407 | 5586 return -1; |
5587 | |
4498 | 5588 VimTryStart(); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5589 goto_tabpage_tp(((TabPageObject *)(valObject))->tab, TRUE, TRUE); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5590 if (((TabPageObject *)(valObject))->tab != curtab) |
4407 | 5591 { |
4498 | 5592 if (VimTryEnd()) |
5593 return -1; | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5594 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5595 N_("did not switch to the specified tab page")); |
4407 | 5596 return -1; |
5597 } | |
5598 | |
4498 | 5599 return VimTryEnd(); |
4407 | 5600 } |
4319 | 5601 else |
5602 { | |
5603 PyErr_SetString(PyExc_AttributeError, name); | |
5604 return -1; | |
5605 } | |
5606 } | |
5607 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5608 static struct PyMethodDef CurrentMethods[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5609 /* name, function, calling, documentation */ |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5610 {"__dir__", (PyCFunction)CurrentDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5611 { NULL, NULL, 0, NULL} |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5612 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5613 |
3618 | 5614 static void |
4486 | 5615 init_range_cmd(exarg_T *eap) |
5616 { | |
5617 RangeStart = eap->line1; | |
5618 RangeEnd = eap->line2; | |
5619 } | |
5620 | |
5621 static void | |
5622 init_range_eval(typval_T *rettv UNUSED) | |
5623 { | |
5624 RangeStart = (PyInt) curwin->w_cursor.lnum; | |
5625 RangeEnd = RangeStart; | |
5626 } | |
5627 | |
5628 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5629 run_cmd(const char *cmd, void *arg UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5630 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5631 , PyGILState_STATE *pygilstate UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5632 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5633 ) |
4486 | 5634 { |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5635 PyObject *run_ret; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5636 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
|
5637 if (run_ret != NULL) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5638 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5639 Py_DECREF(run_ret); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5640 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5641 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5642 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5643 EMSG2(_(e_py_systemexit), "python"); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5644 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5645 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5646 else |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5647 PyErr_PrintEx(1); |
4486 | 5648 } |
5649 | |
5650 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n "; | |
5651 static int code_hdr_len = 30; | |
5652 | |
5653 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5654 run_do(const char *cmd, void *arg UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5655 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5656 , PyGILState_STATE *pygilstate |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5657 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5658 ) |
4486 | 5659 { |
5660 PyInt lnum; | |
5661 size_t len; | |
5662 char *code; | |
5663 int status; | |
5664 PyObject *pyfunc, *pymain; | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5665 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
|
5666 buf_T *was_curbuf = curbuf; |
4486 | 5667 |
4575
626e9ccb7c48
updated for version 7.3.1035
Bram Moolenaar <bram@vim.org>
parents:
4523
diff
changeset
|
5668 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK) |
4486 | 5669 { |
5670 EMSG(_("cannot save undo information")); | |
5671 return; | |
5672 } | |
5673 | |
5674 len = code_hdr_len + STRLEN(cmd); | |
5675 code = PyMem_New(char, len + 1); | |
5676 memcpy(code, code_hdr, code_hdr_len); | |
5677 STRCPY(code + code_hdr_len, cmd); | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5678 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
|
5679 status = -1; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5680 if (run_ret != NULL) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5681 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5682 status = 0; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5683 Py_DECREF(run_ret); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5684 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5685 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5686 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5687 PyMem_Free(code); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5688 EMSG2(_(e_py_systemexit), "python"); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5689 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5690 return; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5691 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5692 else |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5693 PyErr_PrintEx(1); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5694 |
4486 | 5695 PyMem_Free(code); |
5696 | |
5697 if (status) | |
5698 { | |
5699 EMSG(_("failed to run the code")); | |
5700 return; | |
5701 } | |
5702 | |
5703 status = 0; | |
5704 pymain = PyImport_AddModule("__main__"); | |
5705 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5706 #ifdef PY_CAN_RECURSE |
4486 | 5707 PyGILState_Release(*pygilstate); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5708 #endif |
4486 | 5709 |
5710 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum) | |
5711 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5712 PyObject *line; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5713 PyObject *linenr; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5714 PyObject *ret; |
4486 | 5715 |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5716 #ifdef PY_CAN_RECURSE |
4486 | 5717 *pygilstate = PyGILState_Ensure(); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5718 #endif |
10751
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5719 /* Check the line number, the command my have deleted lines. */ |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5720 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
|
5721 || !(line = GetBufferLine(curbuf, lnum))) |
4486 | 5722 goto err; |
5723 if (!(linenr = PyInt_FromLong((long) lnum))) | |
5724 { | |
5725 Py_DECREF(line); | |
5726 goto err; | |
5727 } | |
5728 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL); | |
5729 Py_DECREF(line); | |
5730 Py_DECREF(linenr); | |
5731 if (!ret) | |
5732 goto err; | |
5733 | |
10751
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5734 /* Check that the command didn't switch to another buffer. */ |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5735 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
|
5736 { |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5737 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
|
5738 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
|
5739 } |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5740 |
4486 | 5741 if (ret != Py_None) |
5742 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
|
5743 { |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5744 Py_XDECREF(ret); |
4486 | 5745 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
|
5746 } |
4486 | 5747 |
5748 Py_XDECREF(ret); | |
5749 PythonIO_Flush(); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5750 #ifdef PY_CAN_RECURSE |
4486 | 5751 PyGILState_Release(*pygilstate); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5752 #endif |
4486 | 5753 } |
5754 goto out; | |
5755 err: | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5756 #ifdef PY_CAN_RECURSE |
4486 | 5757 *pygilstate = PyGILState_Ensure(); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5758 #endif |
4486 | 5759 PyErr_PrintEx(0); |
5760 PythonIO_Flush(); | |
5761 status = 1; | |
5762 out: | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5763 #ifdef PY_CAN_RECURSE |
4486 | 5764 if (!status) |
5765 *pygilstate = PyGILState_Ensure(); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5766 #endif |
4486 | 5767 Py_DECREF(pyfunc); |
5768 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL); | |
5769 if (status) | |
5770 return; | |
5771 check_cursor(); | |
5772 update_curbuf(NOT_VALID); | |
5773 } | |
5774 | |
5775 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5776 run_eval(const char *cmd, typval_T *rettv |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5777 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5778 , PyGILState_STATE *pygilstate UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5779 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5780 ) |
4486 | 5781 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5782 PyObject *run_ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5783 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5784 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
|
5785 if (run_ret == NULL) |
4486 | 5786 { |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5787 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5788 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5789 EMSG2(_(e_py_systemexit), "python"); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5790 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5791 } |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5792 else |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5793 { |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5794 if (PyErr_Occurred() && !msg_silent) |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5795 PyErr_PrintEx(0); |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5796 EMSG(_("E858: Eval did not return a valid python object")); |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5797 } |
4486 | 5798 } |
5799 else | |
5800 { | |
12806
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
5801 if (ConvertFromPyObject(run_ret, rettv) == -1) |
4486 | 5802 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
|
5803 Py_DECREF(run_ret); |
4486 | 5804 } |
5805 PyErr_Clear(); | |
5806 } | |
5807 | |
6565 | 5808 static int |
3618 | 5809 set_ref_in_py(const int copyID) |
5810 { | |
5811 pylinkedlist_T *cur; | |
5812 dict_T *dd; | |
5813 list_T *ll; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5814 int i; |
6565 | 5815 int abort = FALSE; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5816 FunctionObject *func; |
3618 | 5817 |
5818 if (lastdict != NULL) | |
6565 | 5819 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5820 for (cur = lastdict ; !abort && cur != NULL ; cur = cur->pll_prev) |
3618 | 5821 { |
5822 dd = ((DictionaryObject *) (cur->pll_obj))->dict; | |
5823 if (dd->dv_copyID != copyID) | |
5824 { | |
5825 dd->dv_copyID = copyID; | |
6565 | 5826 abort = abort || set_ref_in_ht(&dd->dv_hashtab, copyID, NULL); |
3618 | 5827 } |
5828 } | |
6565 | 5829 } |
3618 | 5830 |
5831 if (lastlist != NULL) | |
6565 | 5832 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5833 for (cur = lastlist ; !abort && cur != NULL ; cur = cur->pll_prev) |
3618 | 5834 { |
5835 ll = ((ListObject *) (cur->pll_obj))->list; | |
5836 if (ll->lv_copyID != copyID) | |
5837 { | |
5838 ll->lv_copyID = copyID; | |
6565 | 5839 abort = abort || set_ref_in_list(ll, copyID, NULL); |
3618 | 5840 } |
5841 } | |
6565 | 5842 } |
5843 | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5844 if (lastfunc != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5845 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5846 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
|
5847 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5848 func = (FunctionObject *) cur->pll_obj; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5849 if (func->self != NULL && func->self->dv_copyID != copyID) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5850 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5851 func->self->dv_copyID = copyID; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5852 abort = abort || set_ref_in_ht( |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5853 &func->self->dv_hashtab, copyID, 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 if (func->argc) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5856 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
|
5857 abort = abort |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5858 || 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
|
5859 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5860 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5861 |
6565 | 5862 return abort; |
3618 | 5863 } |
5864 | |
5865 static int | |
5866 set_string_copy(char_u *str, typval_T *tv) | |
5867 { | |
5868 tv->vval.v_string = vim_strsave(str); | |
5869 if (tv->vval.v_string == NULL) | |
5870 { | |
5871 PyErr_NoMemory(); | |
5872 return -1; | |
5873 } | |
5874 return 0; | |
5875 } | |
5876 | |
4385 | 5877 static int |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5878 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 5879 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5880 dict_T *dict; |
4385 | 5881 char_u *key; |
5882 dictitem_T *di; | |
5883 PyObject *keyObject; | |
5884 PyObject *valObject; | |
5885 Py_ssize_t iter = 0; | |
5886 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5887 if (!(dict = py_dict_alloc())) |
4385 | 5888 return -1; |
5889 | |
5890 tv->v_type = VAR_DICT; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5891 tv->vval.v_dict = dict; |
4385 | 5892 |
5893 while (PyDict_Next(obj, &iter, &keyObject, &valObject)) | |
5894 { | |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5895 PyObject *todecref = NULL; |
4385 | 5896 |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
5897 if (keyObject == NULL || valObject == NULL) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5898 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5899 dict_unref(dict); |
4385 | 5900 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5901 } |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5902 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5903 if (!(key = StringToChars(keyObject, &todecref))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5904 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5905 dict_unref(dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5906 return -1; |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5907 } |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
5908 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5909 if (*key == NUL) |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5910 { |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5911 dict_unref(dict); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5912 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5913 RAISE_NO_EMPTY_KEYS; |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5914 return -1; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5915 } |
4385 | 5916 |
5917 di = dictitem_alloc(key); | |
5918 | |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5919 Py_XDECREF(todecref); |
4385 | 5920 |
5921 if (di == NULL) | |
5922 { | |
5923 PyErr_NoMemory(); | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5924 dict_unref(dict); |
4385 | 5925 return -1; |
5926 } | |
5927 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5928 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1) |
4385 | 5929 { |
5930 vim_free(di); | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5931 dict_unref(dict); |
4385 | 5932 return -1; |
5933 } | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5934 |
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5935 if (dict_add(dict, di) == FAIL) |
4385 | 5936 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5937 RAISE_KEY_ADD_FAIL(di->di_key); |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
5938 clear_tv(&di->di_tv); |
4385 | 5939 vim_free(di); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5940 dict_unref(dict); |
4385 | 5941 return -1; |
5942 } | |
5943 } | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5944 |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5945 --dict->dv_refcount; |
4385 | 5946 return 0; |
5947 } | |
5948 | |
5949 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5950 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 5951 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5952 dict_T *dict; |
4385 | 5953 char_u *key; |
5954 dictitem_T *di; | |
5955 PyObject *list; | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5956 PyObject *iterator; |
4385 | 5957 PyObject *keyObject; |
5958 PyObject *valObject; | |
5959 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5960 if (!(dict = py_dict_alloc())) |
4385 | 5961 return -1; |
5962 | |
5963 tv->v_type = VAR_DICT; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5964 tv->vval.v_dict = dict; |
4385 | 5965 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5966 if (!(list = PyMapping_Keys(obj))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5967 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5968 dict_unref(dict); |
4385 | 5969 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5970 } |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5971 |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5972 if (!(iterator = PyObject_GetIter(list))) |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5973 { |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5974 dict_unref(dict); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5975 Py_DECREF(list); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5976 return -1; |
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 Py_DECREF(list); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5979 |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5980 while ((keyObject = PyIter_Next(iterator))) |
4385 | 5981 { |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5982 PyObject *todecref; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5983 |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5984 if (!(key = StringToChars(keyObject, &todecref))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5985 { |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5986 Py_DECREF(keyObject); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5987 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5988 dict_unref(dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5989 return -1; |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5990 } |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
5991 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5992 if (*key == NUL) |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5993 { |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5994 Py_DECREF(keyObject); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5995 Py_DECREF(iterator); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5996 Py_XDECREF(todecref); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5997 dict_unref(dict); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5998 RAISE_NO_EMPTY_KEYS; |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5999 return -1; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6000 } |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6001 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6002 if (!(valObject = PyObject_GetItem(obj, keyObject))) |
4385 | 6003 { |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6004 Py_DECREF(keyObject); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6005 Py_DECREF(iterator); |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6006 Py_XDECREF(todecref); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6007 dict_unref(dict); |
4385 | 6008 return -1; |
6009 } | |
6010 | |
6011 di = dictitem_alloc(key); | |
6012 | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6013 Py_DECREF(keyObject); |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6014 Py_XDECREF(todecref); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6015 |
4385 | 6016 if (di == NULL) |
6017 { | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6018 Py_DECREF(iterator); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6019 Py_DECREF(valObject); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6020 dict_unref(dict); |
4385 | 6021 PyErr_NoMemory(); |
6022 return -1; | |
6023 } | |
6024 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6025 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1) |
4385 | 6026 { |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6027 Py_DECREF(iterator); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6028 Py_DECREF(valObject); |
4385 | 6029 vim_free(di); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6030 dict_unref(dict); |
4385 | 6031 return -1; |
6032 } | |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6033 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6034 Py_DECREF(valObject); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6035 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6036 if (dict_add(dict, di) == FAIL) |
4385 | 6037 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6038 RAISE_KEY_ADD_FAIL(di->di_key); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6039 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6040 dictitem_free(di); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6041 dict_unref(dict); |
4385 | 6042 return -1; |
6043 } | |
6044 } | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6045 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6046 --dict->dv_refcount; |
4385 | 6047 return 0; |
6048 } | |
6049 | |
6050 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6051 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 6052 { |
6053 list_T *l; | |
6054 | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6055 if (!(l = py_list_alloc())) |
4385 | 6056 return -1; |
6057 | |
6058 tv->v_type = VAR_LIST; | |
6059 tv->vval.v_list = l; | |
6060 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6061 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
|
6062 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6063 list_unref(l); |
4385 | 6064 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6065 } |
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 --l->lv_refcount; |
4385 | 6068 return 0; |
6069 } | |
6070 | |
3618 | 6071 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *); |
6072 | |
6073 static int | |
6074 convert_dl(PyObject *obj, typval_T *tv, | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6075 pytotvfunc py_to_tv, PyObject *lookup_dict) |
3618 | 6076 { |
6077 PyObject *capsule; | |
6078 char hexBuf[sizeof(void *) * 2 + 3]; | |
6079 | |
13353
8412df1479a3
patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents:
12812
diff
changeset
|
6080 sprintf(hexBuf, "%p", (void *)obj); |
3618 | 6081 |
3638 | 6082 # ifdef PY_USE_CAPSULE |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6083 capsule = PyDict_GetItemString(lookup_dict, hexBuf); |
3648 | 6084 # else |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6085 capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf); |
3648 | 6086 # endif |
3618 | 6087 if (capsule == NULL) |
6088 { | |
3638 | 6089 # ifdef PY_USE_CAPSULE |
3618 | 6090 capsule = PyCapsule_New(tv, NULL, NULL); |
3648 | 6091 # else |
6092 capsule = PyCObject_FromVoidPtr(tv, NULL); | |
6093 # endif | |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6094 if (PyDict_SetItemString(lookup_dict, hexBuf, capsule)) |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6095 { |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6096 Py_DECREF(capsule); |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6097 tv->v_type = VAR_UNKNOWN; |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6098 return -1; |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6099 } |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6100 |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6101 Py_DECREF(capsule); |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6102 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6103 if (py_to_tv(obj, tv, lookup_dict) == -1) |
3618 | 6104 { |
6105 tv->v_type = VAR_UNKNOWN; | |
6106 return -1; | |
6107 } | |
6108 /* As we are not using copy_tv which increments reference count we must | |
6109 * do it ourself. */ | |
7949
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6110 if (tv->v_type == VAR_DICT) |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6111 ++tv->vval.v_dict->dv_refcount; |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6112 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
|
6113 ++tv->vval.v_list->lv_refcount; |
3618 | 6114 } |
6115 else | |
6116 { | |
3638 | 6117 typval_T *v; |
6118 | |
6119 # ifdef PY_USE_CAPSULE | |
6120 v = PyCapsule_GetPointer(capsule, NULL); | |
6121 # else | |
3648 | 6122 v = PyCObject_AsVoidPtr(capsule); |
3638 | 6123 # endif |
3618 | 6124 copy_tv(v, tv); |
6125 } | |
6126 return 0; | |
6127 } | |
6128 | |
6129 static int | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6130 ConvertFromPyMapping(PyObject *obj, typval_T *tv) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6131 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6132 PyObject *lookup_dict; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6133 int ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6134 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6135 if (!(lookup_dict = PyDict_New())) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6136 return -1; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6137 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6138 if (PyType_IsSubtype(obj->ob_type, &DictionaryType)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6139 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6140 tv->v_type = VAR_DICT; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6141 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6142 ++tv->vval.v_dict->dv_refcount; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6143 ret = 0; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6144 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6145 else if (PyDict_Check(obj)) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6146 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
|
6147 else if (PyMapping_Check(obj)) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6148 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
|
6149 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6150 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6151 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6152 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
|
6153 Py_TYPE_NAME(obj)); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6154 ret = -1; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6155 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6156 Py_DECREF(lookup_dict); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6157 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6158 } |
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 static int |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6161 ConvertFromPySequence(PyObject *obj, typval_T *tv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6162 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6163 PyObject *lookup_dict; |
8915
8cbf472483fa
commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents:
8913
diff
changeset
|
6164 int ret; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6165 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6166 if (!(lookup_dict = PyDict_New())) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6167 return -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6168 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6169 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
|
6170 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6171 tv->v_type = VAR_LIST; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6172 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
|
6173 ++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
|
6174 ret = 0; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6175 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6176 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
|
6177 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
|
6178 else |
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 PyErr_FORMAT(PyExc_TypeError, |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6181 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
|
6182 Py_TYPE_NAME(obj)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6183 ret = -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6184 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6185 Py_DECREF(lookup_dict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6186 return ret; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6187 } |
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 static int |
3618 | 6190 ConvertFromPyObject(PyObject *obj, typval_T *tv) |
6191 { | |
6192 PyObject *lookup_dict; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6193 int ret; |
3618 | 6194 |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6195 if (!(lookup_dict = PyDict_New())) |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6196 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6197 ret = _ConvertFromPyObject(obj, tv, lookup_dict); |
3618 | 6198 Py_DECREF(lookup_dict); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6199 return ret; |
3618 | 6200 } |
6201 | |
6202 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6203 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
3618 | 6204 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6205 if (PyType_IsSubtype(obj->ob_type, &DictionaryType)) |
3618 | 6206 { |
6207 tv->v_type = VAR_DICT; | |
6208 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict); | |
6209 ++tv->vval.v_dict->dv_refcount; | |
6210 } | |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6211 else if (PyType_IsSubtype(obj->ob_type, &ListType)) |
3618 | 6212 { |
6213 tv->v_type = VAR_LIST; | |
6214 tv->vval.v_list = (((ListObject *)(obj))->list); | |
6215 ++tv->vval.v_list->lv_refcount; | |
6216 } | |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6217 else if (PyType_IsSubtype(obj->ob_type, &FunctionType)) |
3618 | 6218 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6219 FunctionObject *func = (FunctionObject *) obj; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6220 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
|
6221 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6222 partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6223 set_partial(func, pt, TRUE); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6224 tv->vval.v_partial = pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6225 tv->v_type = VAR_PARTIAL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6226 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6227 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6228 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6229 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
|
6230 return -1; |
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 tv->v_type = VAR_FUNC; |
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 func_ref(func->name); |
3618 | 6235 } |
6236 else if (PyBytes_Check(obj)) | |
6237 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6238 char_u *str; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6239 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6240 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1) |
3800 | 6241 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6242 if (str == NULL) |
3618 | 6243 return -1; |
6244 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6245 if (set_string_copy(str, tv) == -1) |
3618 | 6246 return -1; |
6247 | |
6248 tv->v_type = VAR_STRING; | |
6249 } | |
6250 else if (PyUnicode_Check(obj)) | |
6251 { | |
6252 PyObject *bytes; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6253 char_u *str; |
3618 | 6254 |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
6255 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL); |
3618 | 6256 if (bytes == NULL) |
6257 return -1; | |
6258 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6259 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1) |
3800 | 6260 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6261 if (str == NULL) |
3618 | 6262 return -1; |
6263 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6264 if (set_string_copy(str, tv)) |
3618 | 6265 { |
6266 Py_XDECREF(bytes); | |
6267 return -1; | |
6268 } | |
6269 Py_XDECREF(bytes); | |
6270 | |
6271 tv->v_type = VAR_STRING; | |
6272 } | |
4321 | 6273 #if PY_MAJOR_VERSION < 3 |
3618 | 6274 else if (PyInt_Check(obj)) |
6275 { | |
6276 tv->v_type = VAR_NUMBER; | |
6277 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
|
6278 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6279 return -1; |
3618 | 6280 } |
6281 #endif | |
6282 else if (PyLong_Check(obj)) | |
6283 { | |
6284 tv->v_type = VAR_NUMBER; | |
6285 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
|
6286 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6287 return -1; |
3618 | 6288 } |
6289 else if (PyDict_Check(obj)) | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6290 return convert_dl(obj, tv, pydict_to_tv, lookup_dict); |
3618 | 6291 #ifdef FEAT_FLOAT |
6292 else if (PyFloat_Check(obj)) | |
6293 { | |
6294 tv->v_type = VAR_FLOAT; | |
6295 tv->vval.v_float = (float_T) PyFloat_AsDouble(obj); | |
6296 } | |
6297 #endif | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6298 else if (PyObject_HasAttrString(obj, "keys")) |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6299 return convert_dl(obj, tv, pymap_to_tv, lookup_dict); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6300 /* 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
|
6301 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
|
6302 return convert_dl(obj, tv, pyseq_to_tv, lookup_dict); |
3618 | 6303 else if (PyMapping_Check(obj)) |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6304 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
|
6305 else if (PyNumber_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6306 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6307 PyObject *num; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6308 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6309 if (!(num = PyNumber_Long(obj))) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6310 return -1; |
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 tv->v_type = VAR_NUMBER; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6313 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
|
6314 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6315 Py_DECREF(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6316 } |
12806
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6317 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
|
6318 { |
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6319 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
|
6320 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
|
6321 } |
3618 | 6322 else |
6323 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6324 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6325 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
|
6326 Py_TYPE_NAME(obj)); |
3618 | 6327 return -1; |
6328 } | |
6329 return 0; | |
6330 } | |
6331 | |
6332 static PyObject * | |
6333 ConvertToPyObject(typval_T *tv) | |
6334 { | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6335 typval_T *argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6336 int i; |
3618 | 6337 if (tv == NULL) |
6338 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6339 PyErr_SET_VIM(N_("internal error: NULL reference passed")); |
3618 | 6340 return NULL; |
6341 } | |
6342 switch (tv->v_type) | |
6343 { | |
6344 case VAR_STRING: | |
3852 | 6345 return PyBytes_FromString(tv->vval.v_string == NULL |
6346 ? "" : (char *)tv->vval.v_string); | |
3618 | 6347 case VAR_NUMBER: |
6348 return PyLong_FromLong((long) tv->vval.v_number); | |
6349 #ifdef FEAT_FLOAT | |
6350 case VAR_FLOAT: | |
6351 return PyFloat_FromDouble((double) tv->vval.v_float); | |
6352 #endif | |
6353 case VAR_LIST: | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6354 return NEW_LIST(tv->vval.v_list); |
3618 | 6355 case VAR_DICT: |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6356 return NEW_DICTIONARY(tv->vval.v_dict); |
3618 | 6357 case VAR_FUNC: |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6358 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
|
6359 ? (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
|
6360 0, NULL, NULL, TRUE); |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6361 case VAR_PARTIAL: |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6362 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
|
6363 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6364 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
|
6365 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
|
6366 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
|
6367 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6368 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6369 argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6370 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
|
6371 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
|
6372 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
|
6373 ? (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
|
6374 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
|
6375 tv->vval.v_partial->pt_dict, |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
6376 tv->vval.v_partial->pt_auto); |
3618 | 6377 case VAR_UNKNOWN: |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6378 case VAR_CHANNEL: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6379 case VAR_JOB: |
3618 | 6380 Py_INCREF(Py_None); |
6381 return Py_None; | |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6382 case VAR_SPECIAL: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6383 switch (tv->vval.v_number) |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6384 { |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6385 case VVAL_FALSE: return AlwaysFalse(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6386 case VVAL_TRUE: return AlwaysTrue(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6387 case VVAL_NONE: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6388 case VVAL_NULL: return AlwaysNone(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6389 } |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6390 PyErr_SET_VIM(N_("internal error: invalid value type")); |
3618 | 6391 return NULL; |
6392 } | |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6393 return NULL; |
3618 | 6394 } |
4319 | 6395 |
6396 typedef struct | |
6397 { | |
6398 PyObject_HEAD | |
6399 } CurrentObject; | |
6400 static PyTypeObject CurrentType; | |
6401 | |
6402 static void | |
6403 init_structs(void) | |
6404 { | |
6405 vim_memset(&OutputType, 0, sizeof(OutputType)); | |
6406 OutputType.tp_name = "vim.message"; | |
6407 OutputType.tp_basicsize = sizeof(OutputObject); | |
6408 OutputType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6409 OutputType.tp_doc = "vim message object"; | |
6410 OutputType.tp_methods = OutputMethods; | |
6411 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6412 OutputType.tp_getattro = (getattrofunc)OutputGetattro; |
6413 OutputType.tp_setattro = (setattrofunc)OutputSetattro; | |
4319 | 6414 OutputType.tp_alloc = call_PyType_GenericAlloc; |
6415 OutputType.tp_new = call_PyType_GenericNew; | |
6416 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
|
6417 OutputType.tp_base = &PyStdPrinter_Type; |
4319 | 6418 #else |
4488 | 6419 OutputType.tp_getattr = (getattrfunc)OutputGetattr; |
6420 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
|
6421 // 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
|
6422 // OutputType.tp_base = &PyFile_Type; |
4319 | 6423 #endif |
6424 | |
4397 | 6425 vim_memset(&IterType, 0, sizeof(IterType)); |
6426 IterType.tp_name = "vim.iter"; | |
6427 IterType.tp_basicsize = sizeof(IterObject); | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6428 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4397 | 6429 IterType.tp_doc = "generic iterator object"; |
4488 | 6430 IterType.tp_iter = (getiterfunc)IterIter; |
6431 IterType.tp_iternext = (iternextfunc)IterNext; | |
6432 IterType.tp_dealloc = (destructor)IterDestructor; | |
6433 IterType.tp_traverse = (traverseproc)IterTraverse; | |
6434 IterType.tp_clear = (inquiry)IterClear; | |
4397 | 6435 |
4319 | 6436 vim_memset(&BufferType, 0, sizeof(BufferType)); |
6437 BufferType.tp_name = "vim.buffer"; | |
6438 BufferType.tp_basicsize = sizeof(BufferType); | |
4488 | 6439 BufferType.tp_dealloc = (destructor)BufferDestructor; |
6440 BufferType.tp_repr = (reprfunc)BufferRepr; | |
4319 | 6441 BufferType.tp_as_sequence = &BufferAsSeq; |
6442 BufferType.tp_as_mapping = &BufferAsMapping; | |
6443 BufferType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6444 BufferType.tp_doc = "vim buffer object"; | |
6445 BufferType.tp_methods = BufferMethods; | |
6446 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6447 BufferType.tp_getattro = (getattrofunc)BufferGetattro; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
6448 BufferType.tp_setattro = (setattrofunc)BufferSetattro; |
4319 | 6449 BufferType.tp_alloc = call_PyType_GenericAlloc; |
6450 BufferType.tp_new = call_PyType_GenericNew; | |
6451 BufferType.tp_free = call_PyObject_Free; | |
6452 #else | |
4488 | 6453 BufferType.tp_getattr = (getattrfunc)BufferGetattr; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
6454 BufferType.tp_setattr = (setattrfunc)BufferSetattr; |
4319 | 6455 #endif |
6456 | |
6457 vim_memset(&WindowType, 0, sizeof(WindowType)); | |
6458 WindowType.tp_name = "vim.window"; | |
6459 WindowType.tp_basicsize = sizeof(WindowObject); | |
4488 | 6460 WindowType.tp_dealloc = (destructor)WindowDestructor; |
6461 WindowType.tp_repr = (reprfunc)WindowRepr; | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6462 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4319 | 6463 WindowType.tp_doc = "vim Window object"; |
6464 WindowType.tp_methods = WindowMethods; | |
4488 | 6465 WindowType.tp_traverse = (traverseproc)WindowTraverse; |
6466 WindowType.tp_clear = (inquiry)WindowClear; | |
4319 | 6467 #if PY_MAJOR_VERSION >= 3 |
4488 | 6468 WindowType.tp_getattro = (getattrofunc)WindowGetattro; |
6469 WindowType.tp_setattro = (setattrofunc)WindowSetattro; | |
4319 | 6470 WindowType.tp_alloc = call_PyType_GenericAlloc; |
6471 WindowType.tp_new = call_PyType_GenericNew; | |
6472 WindowType.tp_free = call_PyObject_Free; | |
6473 #else | |
4488 | 6474 WindowType.tp_getattr = (getattrfunc)WindowGetattr; |
6475 WindowType.tp_setattr = (setattrfunc)WindowSetattr; | |
4319 | 6476 #endif |
6477 | |
4401 | 6478 vim_memset(&TabPageType, 0, sizeof(TabPageType)); |
6479 TabPageType.tp_name = "vim.tabpage"; | |
6480 TabPageType.tp_basicsize = sizeof(TabPageObject); | |
4488 | 6481 TabPageType.tp_dealloc = (destructor)TabPageDestructor; |
6482 TabPageType.tp_repr = (reprfunc)TabPageRepr; | |
4401 | 6483 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT; |
6484 TabPageType.tp_doc = "vim tab page object"; | |
6485 TabPageType.tp_methods = TabPageMethods; | |
6486 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6487 TabPageType.tp_getattro = (getattrofunc)TabPageGetattro; |
4401 | 6488 TabPageType.tp_alloc = call_PyType_GenericAlloc; |
6489 TabPageType.tp_new = call_PyType_GenericNew; | |
6490 TabPageType.tp_free = call_PyObject_Free; | |
6491 #else | |
4488 | 6492 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr; |
4401 | 6493 #endif |
6494 | |
4393 | 6495 vim_memset(&BufMapType, 0, sizeof(BufMapType)); |
6496 BufMapType.tp_name = "vim.bufferlist"; | |
6497 BufMapType.tp_basicsize = sizeof(BufMapObject); | |
6498 BufMapType.tp_as_mapping = &BufMapAsMapping; | |
6499 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT; | |
4397 | 6500 BufMapType.tp_iter = BufMapIter; |
4319 | 6501 BufferType.tp_doc = "vim buffer list"; |
6502 | |
6503 vim_memset(&WinListType, 0, sizeof(WinListType)); | |
6504 WinListType.tp_name = "vim.windowlist"; | |
6505 WinListType.tp_basicsize = sizeof(WinListType); | |
6506 WinListType.tp_as_sequence = &WinListAsSeq; | |
6507 WinListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6508 WinListType.tp_doc = "vim window list"; | |
4488 | 6509 WinListType.tp_dealloc = (destructor)WinListDestructor; |
4401 | 6510 |
6511 vim_memset(&TabListType, 0, sizeof(TabListType)); | |
6512 TabListType.tp_name = "vim.tabpagelist"; | |
6513 TabListType.tp_basicsize = sizeof(TabListType); | |
6514 TabListType.tp_as_sequence = &TabListAsSeq; | |
6515 TabListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6516 TabListType.tp_doc = "vim tab page list"; | |
4319 | 6517 |
6518 vim_memset(&RangeType, 0, sizeof(RangeType)); | |
6519 RangeType.tp_name = "vim.range"; | |
6520 RangeType.tp_basicsize = sizeof(RangeObject); | |
4488 | 6521 RangeType.tp_dealloc = (destructor)RangeDestructor; |
6522 RangeType.tp_repr = (reprfunc)RangeRepr; | |
4319 | 6523 RangeType.tp_as_sequence = &RangeAsSeq; |
6524 RangeType.tp_as_mapping = &RangeAsMapping; | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6525 RangeType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4319 | 6526 RangeType.tp_doc = "vim Range object"; |
6527 RangeType.tp_methods = RangeMethods; | |
4500 | 6528 RangeType.tp_traverse = (traverseproc)RangeTraverse; |
6529 RangeType.tp_clear = (inquiry)RangeClear; | |
4319 | 6530 #if PY_MAJOR_VERSION >= 3 |
4488 | 6531 RangeType.tp_getattro = (getattrofunc)RangeGetattro; |
4319 | 6532 RangeType.tp_alloc = call_PyType_GenericAlloc; |
6533 RangeType.tp_new = call_PyType_GenericNew; | |
6534 RangeType.tp_free = call_PyObject_Free; | |
6535 #else | |
4488 | 6536 RangeType.tp_getattr = (getattrfunc)RangeGetattr; |
4319 | 6537 #endif |
6538 | |
6539 vim_memset(&CurrentType, 0, sizeof(CurrentType)); | |
6540 CurrentType.tp_name = "vim.currentdata"; | |
6541 CurrentType.tp_basicsize = sizeof(CurrentObject); | |
6542 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6543 CurrentType.tp_doc = "vim current object"; | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
6544 CurrentType.tp_methods = CurrentMethods; |
4319 | 6545 #if PY_MAJOR_VERSION >= 3 |
4488 | 6546 CurrentType.tp_getattro = (getattrofunc)CurrentGetattro; |
6547 CurrentType.tp_setattro = (setattrofunc)CurrentSetattro; | |
4319 | 6548 #else |
4488 | 6549 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr; |
6550 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr; | |
4319 | 6551 #endif |
6552 | |
6553 vim_memset(&DictionaryType, 0, sizeof(DictionaryType)); | |
6554 DictionaryType.tp_name = "vim.dictionary"; | |
6555 DictionaryType.tp_basicsize = sizeof(DictionaryObject); | |
4488 | 6556 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6557 DictionaryType.tp_as_sequence = &DictionaryAsSeq; |
4319 | 6558 DictionaryType.tp_as_mapping = &DictionaryAsMapping; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6559 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
4319 | 6560 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure"; |
6561 DictionaryType.tp_methods = DictionaryMethods; | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6562 DictionaryType.tp_iter = (getiterfunc)DictionaryIter; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6563 DictionaryType.tp_new = (newfunc)DictionaryConstructor; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6564 DictionaryType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6565 #if PY_MAJOR_VERSION >= 3 |
4488 | 6566 DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro; |
6567 DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro; | |
4319 | 6568 #else |
4488 | 6569 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr; |
6570 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr; | |
4319 | 6571 #endif |
6572 | |
6573 vim_memset(&ListType, 0, sizeof(ListType)); | |
6574 ListType.tp_name = "vim.list"; | |
4488 | 6575 ListType.tp_dealloc = (destructor)ListDestructor; |
4319 | 6576 ListType.tp_basicsize = sizeof(ListObject); |
6577 ListType.tp_as_sequence = &ListAsSeq; | |
6578 ListType.tp_as_mapping = &ListAsMapping; | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6579 ListType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
4319 | 6580 ListType.tp_doc = "list pushing modifications to vim structure"; |
6581 ListType.tp_methods = ListMethods; | |
4488 | 6582 ListType.tp_iter = (getiterfunc)ListIter; |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6583 ListType.tp_new = (newfunc)ListConstructor; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6584 ListType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6585 #if PY_MAJOR_VERSION >= 3 |
4488 | 6586 ListType.tp_getattro = (getattrofunc)ListGetattro; |
6587 ListType.tp_setattro = (setattrofunc)ListSetattro; | |
4319 | 6588 #else |
4488 | 6589 ListType.tp_getattr = (getattrfunc)ListGetattr; |
6590 ListType.tp_setattr = (setattrfunc)ListSetattr; | |
4319 | 6591 #endif |
6592 | |
6593 vim_memset(&FunctionType, 0, sizeof(FunctionType)); | |
4397 | 6594 FunctionType.tp_name = "vim.function"; |
4319 | 6595 FunctionType.tp_basicsize = sizeof(FunctionObject); |
4488 | 6596 FunctionType.tp_dealloc = (destructor)FunctionDestructor; |
6597 FunctionType.tp_call = (ternaryfunc)FunctionCall; | |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6598 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
4319 | 6599 FunctionType.tp_doc = "object that calls vim function"; |
6600 FunctionType.tp_methods = FunctionMethods; | |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
6601 FunctionType.tp_repr = (reprfunc)FunctionRepr; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6602 FunctionType.tp_new = (newfunc)FunctionConstructor; |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6603 FunctionType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6604 #if PY_MAJOR_VERSION >= 3 |
4488 | 6605 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro; |
4319 | 6606 #else |
4488 | 6607 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr; |
4319 | 6608 #endif |
6609 | |
4350 | 6610 vim_memset(&OptionsType, 0, sizeof(OptionsType)); |
6611 OptionsType.tp_name = "vim.options"; | |
6612 OptionsType.tp_basicsize = sizeof(OptionsObject); | |
5610 | 6613 OptionsType.tp_as_sequence = &OptionsAsSeq; |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6614 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4350 | 6615 OptionsType.tp_doc = "object for manipulating options"; |
5610 | 6616 OptionsType.tp_iter = (getiterfunc)OptionsIter; |
4350 | 6617 OptionsType.tp_as_mapping = &OptionsAsMapping; |
4488 | 6618 OptionsType.tp_dealloc = (destructor)OptionsDestructor; |
6619 OptionsType.tp_traverse = (traverseproc)OptionsTraverse; | |
6620 OptionsType.tp_clear = (inquiry)OptionsClear; | |
4350 | 6621 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6622 #if PY_VERSION_HEX < 0x030700f0 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6623 vim_memset(&LoaderType, 0, sizeof(LoaderType)); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6624 LoaderType.tp_name = "vim.Loader"; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6625 LoaderType.tp_basicsize = sizeof(LoaderObject); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6626 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6627 LoaderType.tp_doc = "vim message object"; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6628 LoaderType.tp_methods = LoaderMethods; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6629 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
|
6630 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6631 |
4319 | 6632 #if PY_MAJOR_VERSION >= 3 |
6633 vim_memset(&vimmodule, 0, sizeof(vimmodule)); | |
6634 vimmodule.m_name = "vim"; | |
6635 vimmodule.m_doc = "Vim Python interface\n"; | |
6636 vimmodule.m_size = -1; | |
6637 vimmodule.m_methods = VimMethods; | |
6638 #endif | |
6639 } | |
4494 | 6640 |
6641 #define PYTYPE_READY(type) \ | |
6642 if (PyType_Ready(&type)) \ | |
6643 return -1; | |
6644 | |
6645 static int | |
5166
467efeee8f9e
updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents:
5139
diff
changeset
|
6646 init_types(void) |
4494 | 6647 { |
6648 PYTYPE_READY(IterType); | |
6649 PYTYPE_READY(BufferType); | |
6650 PYTYPE_READY(RangeType); | |
6651 PYTYPE_READY(WindowType); | |
6652 PYTYPE_READY(TabPageType); | |
6653 PYTYPE_READY(BufMapType); | |
6654 PYTYPE_READY(WinListType); | |
6655 PYTYPE_READY(TabListType); | |
6656 PYTYPE_READY(CurrentType); | |
6657 PYTYPE_READY(DictionaryType); | |
6658 PYTYPE_READY(ListType); | |
6659 PYTYPE_READY(FunctionType); | |
6660 PYTYPE_READY(OptionsType); | |
6661 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
|
6662 #if PY_VERSION_HEX < 0x030700f0 |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6663 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
|
6664 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6665 return 0; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6666 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6667 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6668 static int |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
6669 init_sys_path(void) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6670 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6671 PyObject *path; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6672 PyObject *path_hook; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6673 PyObject *path_hooks; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6674 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6675 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
|
6676 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6677 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6678 if (!(path_hooks = PySys_GetObject("path_hooks"))) |
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 PyErr_Clear(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6681 path_hooks = PyList_New(1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6682 PyList_SET_ITEM(path_hooks, 0, path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6683 if (PySys_SetObject("path_hooks", path_hooks)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6684 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6685 Py_DECREF(path_hooks); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6686 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6687 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6688 Py_DECREF(path_hooks); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6689 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6690 else if (PyList_Check(path_hooks)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6691 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6692 if (PyList_Append(path_hooks, path_hook)) |
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_hook); |
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_hook); |
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 |
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 VimTryStart(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6702 EMSG(_("Failed to set path hook: sys.path_hooks is not a list\n" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6703 "You should now do the following:\n" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6704 "- 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
|
6705 "- append vim.VIM_SPECIAL_PATH to sys.path\n")); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6706 VimTryEnd(); /* Discard the error */ |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6707 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6708 return 0; |
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 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6711 if (!(path = PySys_GetObject("path"))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6712 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6713 PyErr_Clear(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6714 path = PyList_New(1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6715 Py_INCREF(vim_special_path_object); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6716 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
|
6717 if (PySys_SetObject("path", path)) |
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 Py_DECREF(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6720 return -1; |
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 Py_DECREF(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6723 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6724 else if (PyList_Check(path)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6725 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6726 if (PyList_Append(path, vim_special_path_object)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6727 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6728 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6729 else |
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 VimTryStart(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6732 EMSG(_("Failed to set path: sys.path is not a list\n" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6733 "You should now append vim.VIM_SPECIAL_PATH to sys.path")); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6734 VimTryEnd(); /* Discard the error */ |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6735 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6736 |
4494 | 6737 return 0; |
6738 } | |
6739 | |
6740 static BufMapObject TheBufferMap = | |
6741 { | |
6742 PyObject_HEAD_INIT(&BufMapType) | |
6743 }; | |
6744 | |
6745 static WinListObject TheWindowList = | |
6746 { | |
6747 PyObject_HEAD_INIT(&WinListType) | |
6748 NULL | |
6749 }; | |
6750 | |
6751 static CurrentObject TheCurrent = | |
6752 { | |
6753 PyObject_HEAD_INIT(&CurrentType) | |
6754 }; | |
6755 | |
6756 static TabListObject TheTabPageList = | |
6757 { | |
6758 PyObject_HEAD_INIT(&TabListType) | |
6759 }; | |
6760 | |
6761 static struct numeric_constant { | |
6762 char *name; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6763 int val; |
4494 | 6764 } numeric_constants[] = { |
6765 {"VAR_LOCKED", VAR_LOCKED}, | |
6766 {"VAR_FIXED", VAR_FIXED}, | |
6767 {"VAR_SCOPE", VAR_SCOPE}, | |
6768 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE}, | |
6769 }; | |
6770 | |
6771 static struct object_constant { | |
6772 char *name; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6773 PyObject *valObject; |
4494 | 6774 } object_constants[] = { |
6775 {"buffers", (PyObject *)(void *)&TheBufferMap}, | |
6776 {"windows", (PyObject *)(void *)&TheWindowList}, | |
6777 {"tabpages", (PyObject *)(void *)&TheTabPageList}, | |
6778 {"current", (PyObject *)(void *)&TheCurrent}, | |
4496 | 6779 |
6780 {"Buffer", (PyObject *)&BufferType}, | |
6781 {"Range", (PyObject *)&RangeType}, | |
6782 {"Window", (PyObject *)&WindowType}, | |
6783 {"TabPage", (PyObject *)&TabPageType}, | |
6784 {"Dictionary", (PyObject *)&DictionaryType}, | |
6785 {"List", (PyObject *)&ListType}, | |
6786 {"Function", (PyObject *)&FunctionType}, | |
6787 {"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
|
6788 #if PY_VERSION_HEX < 0x030700f0 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6789 {"_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
|
6790 #endif |
4494 | 6791 }; |
6792 | |
6793 #define ADD_OBJECT(m, name, obj) \ | |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6794 if (PyModule_AddObject(m, name, obj)) \ |
4494 | 6795 return -1; |
6796 | |
6797 #define ADD_CHECKED_OBJECT(m, name, obj) \ | |
6798 { \ | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6799 PyObject *valObject = obj; \ |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6800 if (!valObject) \ |
4494 | 6801 return -1; \ |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6802 ADD_OBJECT(m, name, valObject); \ |
4494 | 6803 } |
6804 | |
6805 static int | |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6806 populate_module(PyObject *m) |
4494 | 6807 { |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6808 int i; |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6809 PyObject *other_module; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6810 PyObject *attr; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6811 PyObject *imp; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6812 #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
|
6813 PyObject *dict; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6814 PyObject *cls; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6815 #endif |
4494 | 6816 |
6817 for (i = 0; i < (int)(sizeof(numeric_constants) | |
6818 / sizeof(struct numeric_constant)); | |
6819 ++i) | |
6820 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
|
6821 PyInt_FromLong(numeric_constants[i].val)); |
4494 | 6822 |
6823 for (i = 0; i < (int)(sizeof(object_constants) | |
6824 / sizeof(struct object_constant)); | |
6825 ++i) | |
6826 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6827 PyObject *valObject; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6828 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6829 valObject = object_constants[i].valObject; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6830 Py_INCREF(valObject); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6831 ADD_OBJECT(m, object_constants[i].name, valObject); |
4494 | 6832 } |
6833 | |
6834 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL))) | |
6835 return -1; | |
6836 ADD_OBJECT(m, "error", VimError); | |
6837 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6838 ADD_CHECKED_OBJECT(m, "vars", NEW_DICTIONARY(&globvardict)); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6839 ADD_CHECKED_OBJECT(m, "vvars", NEW_DICTIONARY(&vimvardict)); |
4494 | 6840 ADD_CHECKED_OBJECT(m, "options", |
6841 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL)); | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6842 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6843 if (!(other_module = PyImport_ImportModule("os"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6844 return -1; |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6845 ADD_OBJECT(m, "os", other_module); |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6846 |
9161
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6847 #if PY_MAJOR_VERSION >= 3 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6848 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
|
6849 return -1; |
9161
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6850 #else |
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6851 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
|
6852 return -1; |
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6853 #endif |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6854 ADD_OBJECT(m, "_getcwd", py_getcwd) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6855 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6856 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
|
6857 return -1; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6858 ADD_OBJECT(m, "_chdir", py_chdir); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6859 if (!(attr = PyObject_GetAttrString(m, "chdir"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6860 return -1; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6861 if (PyObject_SetAttrString(other_module, "chdir", attr)) |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6862 { |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6863 Py_DECREF(attr); |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6864 return -1; |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6865 } |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6866 Py_DECREF(attr); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6867 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6868 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
|
6869 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6870 ADD_OBJECT(m, "_fchdir", py_fchdir); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6871 if (!(attr = PyObject_GetAttrString(m, "fchdir"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6872 return -1; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6873 if (PyObject_SetAttrString(other_module, "fchdir", attr)) |
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); |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6876 return -1; |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6877 } |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6878 Py_DECREF(attr); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6879 } |
4722
3534e9b4fa42
updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents:
4706
diff
changeset
|
6880 else |
3534e9b4fa42
updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents:
4706
diff
changeset
|
6881 PyErr_Clear(); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6882 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6883 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
|
6884 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6885 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6886 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
|
6887 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6888 #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
|
6889 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
|
6890 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6891 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6892 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
|
6893 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6894 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
|
6895 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6896 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6897 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6898 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6899 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6900 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
|
6901 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6902 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6903 return -1; |
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 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6906 Py_DECREF(imp); |
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 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
|
6909 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6910 if (!(imp = PyImport_ImportModule("imp"))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6911 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6912 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6913 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
|
6914 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6915 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6916 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6917 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6918 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6919 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
|
6920 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6921 Py_DECREF(py_find_module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6922 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6923 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6924 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6925 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6926 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6927 |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6928 ADD_OBJECT(m, "_find_module", py_find_module); |
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6929 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
|
6930 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6931 |
4494 | 6932 return 0; |
6933 } |