Mercurial > vim
annotate src/if_py_both.h @ 22476:b3751f4d3b26 v8.2.1786
patch 8.2.1786: various Normal mode commands not fully tested
Commit: https://github.com/vim/vim/commit/8a9bc95eaec53f4e0c951ff8f2686ae5113a5709
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Oct 2 18:48:07 2020 +0200
patch 8.2.1786: various Normal mode commands not fully tested
Problem: Various Normal mode commands not fully tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/7059)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 02 Oct 2020 19:00:05 +0200 |
parents | d1a7088c6efe |
children | 0fd4d7548b07 |
rev | line source |
---|---|
3618 | 1 /* vi:set ts=8 sts=4 sw=4 noet: |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2 * |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
4 * |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
8 */ |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
9 /* |
4385 | 10 * Python extensions by Paul Moore, David Leonard, Roland Puntaier, Nikolay |
11 * Pavlov. | |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
12 * |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
13 * Common code for if_python.c and if_python3.c. |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
14 */ |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
15 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
16 static char_u e_py_systemexit[] = "E880: Can't handle SystemExit of %s exception in vim"; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
17 |
3734 | 18 #if PY_VERSION_HEX < 0x02050000 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
19 typedef int Py_ssize_t; // Python 2.4 and earlier don't have this type. |
3734 | 20 #endif |
21 | |
19019
75562beba71c
patch 8.2.0070: crash when using Python 3 with "debug" encoding
Bram Moolenaar <Bram@vim.org>
parents:
19015
diff
changeset
|
22 // Use values that are known to work, others may make Vim crash. |
75562beba71c
patch 8.2.0070: crash when using Python 3 with "debug" encoding
Bram Moolenaar <Bram@vim.org>
parents:
19015
diff
changeset
|
23 #define ENC_OPT (enc_utf8 ? "utf-8" : enc_dbcs ? "euc-jp" : (char *)p_enc) |
4435 | 24 #define DOPY_FUNC "_vim_pydo" |
2919 | 25 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
26 static const char *vim_special_path = "_vim_path_"; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
27 |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
28 #define PyErr_SET_STRING(exc, str) PyErr_SetString(exc, _(str)) |
4385 | 29 #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
|
30 #define PyErr_SET_VIM(str) PyErr_SET_STRING(VimError, str) |
5608 | 31 #define PyErr_FORMAT(exc, str, arg) PyErr_Format(exc, _(str), arg) |
32 #define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2) | |
33 #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
|
34 |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
35 #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
|
36 ? "(NULL)" \ |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
37 : obj->ob_type->tp_name) |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
38 |
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
39 #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
|
40 N_("empty keys are not allowed")) |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
41 #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
|
42 #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
|
43 #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
|
44 #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
|
45 #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
|
46 #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
|
47 #define RAISE_KEY_ADD_FAIL(key) \ |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
48 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
|
49 #define RAISE_INVALID_INDEX_TYPE(idx) \ |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
50 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
|
51 Py_TYPE_NAME(idx)); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
52 |
4385 | 53 #define INVALID_BUFFER_VALUE ((buf_T *)(-1)) |
54 #define INVALID_WINDOW_VALUE ((win_T *)(-1)) | |
4401 | 55 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1)) |
4385 | 56 |
4486 | 57 typedef void (*rangeinitializer)(void *); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
58 typedef void (*runner)(const char *, void * |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
59 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
60 , PyGILState_STATE * |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
61 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
62 ); |
4486 | 63 |
4385 | 64 static int ConvertFromPyObject(PyObject *, typval_T *); |
65 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *); | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
66 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
|
67 static int ConvertFromPySequence(PyObject *, typval_T *); |
4431 | 68 static PyObject *WindowNew(win_T *, tabpage_T *); |
69 static PyObject *BufferNew (buf_T *); | |
70 static PyObject *LineToString(const char *); | |
4385 | 71 |
72 static PyInt RangeStart; | |
73 static PyInt RangeEnd; | |
74 | |
4486 | 75 static PyObject *globals; |
76 | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
77 static PyObject *py_chdir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
78 static PyObject *py_fchdir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
79 static PyObject *py_getcwd; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
80 static PyObject *vim_module; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
81 static PyObject *vim_special_path_object; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
82 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
83 #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
|
84 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
|
85 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
86 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
|
87 #endif |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
88 static PyObject *py_find_module; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
89 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
90 static PyObject *VimError; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
91 |
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
|
92 /* |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
93 * 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
|
94 */ |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
95 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
|
96 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
|
97 { |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
98 } |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
99 |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
100 /* |
76f0c4918f5c
Move 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 * 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
|
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_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
|
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 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
108 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
109 * 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
|
110 * 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
|
111 * was needed to generate returned value is object. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
112 * |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
113 * Use Py_XDECREF to decrement reference count. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
114 */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
115 static char_u * |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
116 StringToChars(PyObject *obj, PyObject **todecref) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
117 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
118 char_u *str; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
119 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
120 if (PyBytes_Check(obj)) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
121 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
122 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
123 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
124 || str == NULL) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
125 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
126 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
127 *todecref = NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
128 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
129 else if (PyUnicode_Check(obj)) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
130 { |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
131 PyObject *bytes; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
132 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
133 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
|
134 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
135 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
136 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
137 || str == NULL) |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
138 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
139 Py_DECREF(bytes); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
140 return NULL; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
141 } |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
142 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
143 *todecref = bytes; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
144 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
145 else |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
146 { |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
147 #if PY_MAJOR_VERSION < 3 |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
148 PyErr_FORMAT(PyExc_TypeError, |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
149 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
|
150 Py_TYPE_NAME(obj)); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
151 #else |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
152 PyErr_FORMAT(PyExc_TypeError, |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
153 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
|
154 Py_TYPE_NAME(obj)); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
155 #endif |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
156 return NULL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
157 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
158 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
159 return (char_u *) str; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
160 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
161 |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
162 #define NUMBER_LONG 1 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
163 #define NUMBER_INT 2 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
164 #define NUMBER_NATURAL 4 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
165 #define NUMBER_UNSIGNED 8 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
166 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
167 static int |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
168 NumberToLong(PyObject *obj, long *result, int flags) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
169 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
170 #if PY_MAJOR_VERSION < 3 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
171 if (PyInt_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
172 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
173 *result = PyInt_AsLong(obj); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
174 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
175 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
176 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
177 else |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
178 #endif |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
179 if (PyLong_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 = PyLong_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 if (PyNumber_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
186 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
187 PyObject *num; |
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 if (!(num = PyNumber_Long(obj))) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
190 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
191 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
192 *result = PyLong_AsLong(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
193 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
194 Py_DECREF(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
195 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
196 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
197 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
198 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
199 else |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
200 { |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
201 #if PY_MAJOR_VERSION < 3 |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
202 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
203 N_("expected int(), long() or something supporting " |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
204 "coercing to long(), but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
205 Py_TYPE_NAME(obj)); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
206 #else |
4988
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
207 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
208 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
|
209 "but got %s"), |
e130cc3d17af
updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents:
4984
diff
changeset
|
210 Py_TYPE_NAME(obj)); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
211 #endif |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
212 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
213 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
214 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
215 if (flags & NUMBER_INT) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
216 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
217 if (*result > INT_MAX) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
218 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
219 PyErr_SET_STRING(PyExc_OverflowError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
220 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
|
221 return -1; |
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 else if (*result < INT_MIN) |
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 PyErr_SET_STRING(PyExc_OverflowError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
226 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
|
227 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
228 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
229 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
230 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
231 if (flags & NUMBER_NATURAL) |
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 if (*result <= 0) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
234 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
235 PyErr_SET_STRING(PyExc_ValueError, |
5695 | 236 N_("number must be greater than zero")); |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
237 return -1; |
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 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
240 else if (flags & NUMBER_UNSIGNED) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
241 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
242 if (*result < 0) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
243 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
244 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
245 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
|
246 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
247 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
248 } |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
249 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
250 return 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 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
253 static int |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
254 add_string(PyObject *list, char *s) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
255 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
256 PyObject *string; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
257 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
258 if (!(string = PyString_FromString(s))) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
259 return -1; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
260 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
261 if (PyList_Append(list, string)) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
262 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
263 Py_DECREF(string); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
264 return -1; |
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 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
267 Py_DECREF(string); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
268 return 0; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
269 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
270 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
271 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
272 ObjectDir(PyObject *self, char **attributes) |
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 PyMethodDef *method; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
275 char **attr; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
276 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
277 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
278 if (!(ret = PyList_New(0))) |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
279 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
280 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
281 if (self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
282 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
|
283 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
|
284 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
285 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
286 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
287 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
288 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
289 for (attr = attributes ; *attr ; ++attr) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
290 if (add_string(ret, *attr)) |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
291 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
292 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
293 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
294 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
295 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
296 #if PY_MAJOR_VERSION < 3 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
297 if (add_string(ret, "__members__")) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
298 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
299 Py_DECREF(ret); |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
300 return NULL; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
301 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
302 #endif |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
303 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
304 return ret; |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
305 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
306 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
307 // Output buffer management |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
308 |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
309 // 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
|
310 typedef void (*writefn)(char_u *); |
4385 | 311 |
312 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
|
313 |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
314 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
|
315 { |
76f0c4918f5c
Move 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 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
|
317 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
|
318 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
|
319 } 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
|
320 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
321 static char *OutputAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
322 "softspace", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
323 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
324 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
325 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
326 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
327 OutputDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
328 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
329 return ObjectDir(self, OutputAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
330 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
331 |
3826 | 332 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
333 OutputSetattr(OutputObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
334 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
335 if (valObject == NULL) |
3826 | 336 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
337 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
338 N_("can't delete OutputObject attributes")); |
3826 | 339 return -1; |
340 } | |
341 | |
342 if (strcmp(name, "softspace") == 0) | |
343 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
344 if (NumberToLong(valObject, &(self->softspace), NUMBER_UNSIGNED)) |
3826 | 345 return -1; |
346 return 0; | |
347 } | |
348 | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
349 PyErr_FORMAT(PyExc_AttributeError, N_("invalid attribute: %s"), name); |
3826 | 350 return -1; |
351 } | |
352 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
353 // Buffer IO, we write one whole line at a time. |
4385 | 354 static garray_T io_ga = {0, 0, 1, 80, NULL}; |
355 static writefn old_fn = NULL; | |
356 | |
357 static void | |
358 PythonIO_Flush(void) | |
359 { | |
360 if (old_fn != NULL && io_ga.ga_len > 0) | |
361 { | |
362 ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL; | |
363 old_fn((char_u *)io_ga.ga_data); | |
364 } | |
365 io_ga.ga_len = 0; | |
366 } | |
367 | |
368 static void | |
369 writer(writefn fn, char_u *str, PyInt n) | |
370 { | |
371 char_u *ptr; | |
372 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
373 // Flush when switching output function. |
4385 | 374 if (fn != old_fn) |
375 PythonIO_Flush(); | |
376 old_fn = fn; | |
377 | |
18370
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
378 // Write each NL separated line. Text after the last NL is kept for |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
379 // writing later. |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
380 // For normal messages: Do not output when "got_int" was set. This avoids |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
381 // a loop gone crazy flooding the terminal with messages. Also for when |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
382 // "q" is pressed at the more-prompt. |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
383 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
384 && (fn == (writefn)emsg || !got_int)) |
4385 | 385 { |
386 PyInt len = ptr - str; | |
387 | |
388 if (ga_grow(&io_ga, (int)(len + 1)) == FAIL) | |
389 break; | |
390 | |
391 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len); | |
392 ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL; | |
393 fn((char_u *)io_ga.ga_data); | |
394 str = ptr + 1; | |
395 n -= len + 1; | |
396 io_ga.ga_len = 0; | |
397 } | |
398 | |
18370
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
399 // Put the remaining text into io_ga for later printing. |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
400 if (n > 0 && (fn == (writefn)emsg || !got_int) |
026034963159
patch 8.1.2179: pressing "q" at the more prompt doesn't stop Python output
Bram Moolenaar <Bram@vim.org>
parents:
17922
diff
changeset
|
401 && ga_grow(&io_ga, (int)(n + 1)) == OK) |
4385 | 402 { |
403 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n); | |
404 io_ga.ga_len += (int)n; | |
405 } | |
406 } | |
407 | |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
408 static int |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
409 write_output(OutputObject *self, PyObject *string) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
410 { |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
411 Py_ssize_t len = 0; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
412 char *str = NULL; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
413 int error = self->error; |
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 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
|
416 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
|
417 |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
418 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
|
419 Python_Lock_Vim(); |
16688
e791f29affae
patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
420 if (error) |
e791f29affae
patch 8.1.1346: error for Python exception does not show useful info
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
421 emsg_severe = TRUE; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15472
diff
changeset
|
422 writer((writefn)(error ? emsg : msg), (char_u *)str, len); |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
423 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
|
424 Py_END_ALLOW_THREADS |
2894 | 425 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
|
426 |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
427 return 0; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
428 } |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
429 |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
430 static PyObject * |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
431 OutputWrite(OutputObject *self, PyObject *string) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
432 { |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
433 if (write_output(self, string)) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
434 return NULL; |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
435 |
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
|
436 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
|
437 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
|
438 } |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
439 |
76f0c4918f5c
Move 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 static PyObject * |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
441 OutputWritelines(OutputObject *self, PyObject *seq) |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
442 { |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
443 PyObject *iterator; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
444 PyObject *item; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
445 |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
446 if (!(iterator = PyObject_GetIter(seq))) |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
447 return NULL; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
448 |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
449 while ((item = PyIter_Next(iterator))) |
3618 | 450 { |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
451 if (write_output(self, item)) |
3618 | 452 { |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
453 Py_DECREF(iterator); |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
454 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
|
455 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
|
456 } |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
457 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
|
458 } |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
459 |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
460 Py_DECREF(iterator); |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
461 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
462 // Iterator may have finished due to an exception |
4619
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
463 if (PyErr_Occurred()) |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
464 return NULL; |
90beab957ba9
updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents:
4617
diff
changeset
|
465 |
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
|
466 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
|
467 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
|
468 } |
76f0c4918f5c
Move 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 |
2727 | 470 static PyObject * |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
471 AlwaysNone(PyObject *self UNUSED) |
2727 | 472 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
473 // do nothing |
2727 | 474 Py_INCREF(Py_None); |
475 return Py_None; | |
476 } | |
477 | |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
478 static PyObject * |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
479 AlwaysFalse(PyObject *self UNUSED) |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
480 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
481 // do nothing |
7202
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
482 PyObject *ret = Py_False; |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
483 Py_INCREF(ret); |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
484 return ret; |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
485 } |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
486 |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
487 static PyObject * |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
488 AlwaysTrue(PyObject *self UNUSED) |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
489 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
490 // do nothing |
7202
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
491 PyObject *ret = Py_True; |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
492 Py_INCREF(ret); |
de43f10a3850
commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents:
7191
diff
changeset
|
493 return ret; |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
494 } |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
495 |
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
|
496 /***************/ |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
497 |
4385 | 498 static struct PyMethodDef OutputMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
499 // name, function, calling, doc |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
500 {"write", (PyCFunction)OutputWrite, METH_O, ""}, |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
501 {"writelines", (PyCFunction)OutputWritelines, METH_O, ""}, |
7191
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
502 {"flush", (PyCFunction)AlwaysNone, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
503 {"close", (PyCFunction)AlwaysNone, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
504 {"isatty", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
505 {"readable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
506 {"seekable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
692dac7183de
commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents:
6598
diff
changeset
|
507 {"writable", (PyCFunction)AlwaysTrue, METH_NOARGS, ""}, |
8967
df5f9284fcba
commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents:
8921
diff
changeset
|
508 {"closed", (PyCFunction)AlwaysFalse, METH_NOARGS, ""}, |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
509 {"__dir__", (PyCFunction)OutputDir, METH_NOARGS, ""}, |
4492 | 510 { NULL, NULL, 0, NULL} |
4385 | 511 }; |
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
|
512 |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
513 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
|
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 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
|
516 0, |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
517 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
|
518 }; |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
519 |
76f0c4918f5c
Move 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 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
|
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 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
|
523 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
|
524 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
|
525 }; |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
526 |
76f0c4918f5c
Move 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 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
|
528 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
|
529 { |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
530 if (PySys_SetObject("stdout", (PyObject *)(void *)&Output)) |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
531 return -1; |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
532 if (PySys_SetObject("stderr", (PyObject *)(void *)&Error)) |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
533 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
|
534 |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
535 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
|
536 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
537 emsg(_("E264: Python: Error initialising I/O objects")); |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
538 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
|
539 } |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
540 |
76f0c4918f5c
Move 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 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
|
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 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
544 #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
|
545 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
|
546 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
547 typedef struct |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
548 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
549 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
|
550 char *fullname; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
551 PyObject *result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
552 } LoaderObject; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
553 static PyTypeObject LoaderType; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
554 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
555 static void |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
556 LoaderDestructor(LoaderObject *self) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
557 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
558 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
|
559 Py_XDECREF(self->result); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
560 DESTRUCTOR_FINISH(self); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
561 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
562 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
563 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
564 LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
565 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
566 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
|
567 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
|
568 PyObject *module; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
569 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
570 if (!fullname) |
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 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
|
573 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
|
574 return module; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
575 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
576 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
577 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
|
578 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
579 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
|
580 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
|
581 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
582 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
|
583 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
|
584 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
585 if (!module) |
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 (PyErr_Occurred()) |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
588 return NULL; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
589 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
590 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
|
591 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
|
592 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
593 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
594 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
|
595 return module; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
596 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
597 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
598 static struct PyMethodDef LoaderMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
599 // name, function, calling, doc |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
600 {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""}, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
601 { NULL, NULL, 0, NULL} |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
602 }; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
603 #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
|
604 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
605 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
606 * Check to see whether a Vim error has been reported, or a keyboard |
2399
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
607 * 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
|
608 */ |
4498 | 609 static void |
610 VimTryStart(void) | |
611 { | |
612 ++trylevel; | |
613 } | |
614 | |
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
|
615 static int |
4498 | 616 VimTryEnd(void) |
617 { | |
618 --trylevel; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
619 // Without this it stops processing all subsequent Vim script commands and |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
620 // generates strange error messages if I e.g. try calling Test() in a cycle |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
621 did_emsg = FALSE; |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
622 // Keyboard interrupt should be preferred over anything else |
4498 | 623 if (got_int) |
624 { | |
5629 | 625 if (did_throw) |
5469 | 626 discard_current_exception(); |
627 got_int = FALSE; | |
4498 | 628 PyErr_SetNone(PyExc_KeyboardInterrupt); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
629 return -1; |
4498 | 630 } |
5517 | 631 else if (msg_list != NULL && *msg_list != NULL) |
632 { | |
633 int should_free; | |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
634 char *msg; |
5517 | 635 |
636 msg = get_exception_string(*msg_list, ET_ERROR, NULL, &should_free); | |
637 | |
638 if (msg == NULL) | |
639 { | |
640 PyErr_NoMemory(); | |
641 return -1; | |
642 } | |
643 | |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
644 PyErr_SetVim(msg); |
5517 | 645 |
646 free_global_msglist(); | |
647 | |
648 if (should_free) | |
649 vim_free(msg); | |
650 | |
651 return -1; | |
652 } | |
4498 | 653 else if (!did_throw) |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
654 return (PyErr_Occurred() ? -1 : 0); |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
655 // Python exception is preferred over Vim one; unlikely to occur though |
4498 | 656 else if (PyErr_Occurred()) |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
657 { |
5629 | 658 discard_current_exception(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
659 return -1; |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
660 } |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
661 // Finally transform Vim script exception to python one |
4498 | 662 else |
663 { | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
664 PyErr_SetVim((char *)current_exception->value); |
4498 | 665 discard_current_exception(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
666 return -1; |
4498 | 667 } |
668 } | |
669 | |
670 static int | |
671 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
|
672 { |
76f0c4918f5c
Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
673 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
|
674 { |
76f0c4918f5c
Move 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 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
|
676 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
|
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 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
|
679 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
680 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
681 // Vim module - Implementation |
4385 | 682 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
683 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
684 VimCommand(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
685 { |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
686 char_u *cmd; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
687 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
688 PyObject *todecref; |
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 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
|
691 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
692 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
693 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
|
694 Python_Lock_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
695 |
4498 | 696 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
697 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
|
698 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
699 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
700 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
701 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
|
702 |
4498 | 703 if (VimTryEnd()) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
704 ret = NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
705 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
706 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
707 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
708 Py_XINCREF(ret); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
709 Py_XDECREF(todecref); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
710 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
711 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
712 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
713 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
714 * 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
|
715 * 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
|
716 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
717 * 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
|
718 * you call VimToPython. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
719 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
720 static PyObject * |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
721 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
|
722 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
723 PyObject *ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
724 PyObject *newObj; |
3618 | 725 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
|
726 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
727 // Avoid infinite recursion |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
728 if (depth > 100) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
729 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
730 Py_INCREF(Py_None); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
731 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
732 return ret; |
2447
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 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
735 // Check if we run into a recursive loop. The item must be in lookup_dict |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
736 // then and we can use it again. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
737 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
|
738 || (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
|
739 { |
3618 | 740 sprintf(ptrBuf, "%p", |
741 our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list | |
742 : (void *)our_tv->vval.v_dict); | |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
743 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
744 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
|
745 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
746 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
747 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
748 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
749 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
750 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
751 if (our_tv->v_type == VAR_STRING) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
752 ret = PyString_FromString(our_tv->vval.v_string == NULL |
3852 | 753 ? "" : (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
|
754 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
|
755 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
756 char buf[NUMBUFLEN]; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
757 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
758 // For backwards compatibility numbers are stored as strings. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
759 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
|
760 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
|
761 } |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
762 #ifdef FEAT_FLOAT |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
763 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
|
764 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
765 char buf[NUMBUFLEN]; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
766 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
767 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
|
768 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
|
769 } |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
770 #endif |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
771 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
|
772 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
773 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
|
774 listitem_T *curr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
775 |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
776 if (list == NULL) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
777 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
778 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
779 if (!(ret = PyList_New(0))) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
780 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
781 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
782 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
|
783 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
784 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
785 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
786 } |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
787 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20369
diff
changeset
|
788 CHECK_LIST_MATERIALIZE(list); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
789 FOR_ALL_LIST_ITEMS(list, curr) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
790 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
791 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
|
792 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
793 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
794 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
795 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
796 if (PyList_Append(ret, newObj)) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
797 { |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
798 Py_DECREF(newObj); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
799 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
800 return NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
801 } |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
802 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
|
803 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
804 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
805 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
|
806 { |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
807 |
6598 | 808 hashtab_T *ht; |
809 long_u todo; | |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
810 hashitem_T *hi; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
811 dictitem_T *di; |
6598 | 812 |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
813 if (our_tv->vval.v_dict == NULL) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
814 return NULL; |
6598 | 815 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
|
816 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
817 if (!(ret = PyDict_New())) |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
818 return NULL; |
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 (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
|
821 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
822 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
823 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
824 } |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
825 |
6598 | 826 todo = ht->ht_used; |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
827 for (hi = ht->ht_array; todo > 0; ++hi) |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
828 { |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
829 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
|
830 { |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
831 --todo; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
832 |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
833 di = dict_lookup(hi); |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
834 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
|
835 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
836 Py_DECREF(ret); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
837 return NULL; |
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
838 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
839 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
|
840 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
841 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
|
842 Py_DECREF(newObj); |
4595
29b2be2bba0d
updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents:
4593
diff
changeset
|
843 return NULL; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
844 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
845 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
846 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
847 } |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
848 else if (our_tv->v_type == VAR_BOOL) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
849 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
850 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
|
851 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
852 ret = Py_False; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
853 Py_INCREF(ret); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
854 } |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
855 else |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
856 { |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
857 ret = Py_True; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
858 Py_INCREF(ret); |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
859 } |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
860 return ret; |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
861 } |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
862 else if (our_tv->v_type == VAR_SPECIAL) |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
863 { |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
864 Py_INCREF(Py_None); |
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
865 ret = Py_None; |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
866 return ret; |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
7660
diff
changeset
|
867 } |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
868 else if (our_tv->v_type == VAR_BLOB) |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
869 ret = PyBytes_FromStringAndSize( |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
870 (char*) our_tv->vval.v_blob->bv_ga.ga_data, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
871 (Py_ssize_t) our_tv->vval.v_blob->bv_ga.ga_len); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
872 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
873 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
874 Py_INCREF(Py_None); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
875 ret = Py_None; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
876 } |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
877 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
878 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
879 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
880 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
881 static PyObject * |
4500 | 882 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
|
883 { |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
884 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
|
885 typval_T *our_tv; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
886 PyObject *string; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
887 PyObject *todecref; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
888 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
889 PyObject *lookup_dict; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
890 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
891 if (!PyArg_ParseTuple(args, "O", &string)) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
892 return NULL; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
893 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
894 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
|
895 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
896 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
897 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
|
898 Python_Lock_Vim(); |
4498 | 899 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
900 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
|
901 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
902 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
|
903 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
904 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
905 |
4498 | 906 if (VimTryEnd()) |
907 return NULL; | |
908 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
909 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
|
910 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
911 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
|
912 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
913 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
914 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
915 // Convert the Vim type into a Python type. Create a dictionary that's |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
916 // used to check for recursive loops. |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
917 if (!(lookup_dict = PyDict_New())) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
918 ret = NULL; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
919 else |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
920 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
921 ret = VimToPython(our_tv, 1, lookup_dict); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
922 Py_DECREF(lookup_dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
923 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
924 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
925 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
926 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
|
927 Python_Lock_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
928 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
|
929 Python_Release_Vim(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
930 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
|
931 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
932 return ret; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
933 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
934 |
3618 | 935 static PyObject *ConvertToPyObject(typval_T *); |
936 | |
937 static PyObject * | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
938 VimEvalPy(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
939 { |
3618 | 940 typval_T *our_tv; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
941 PyObject *ret; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
942 char_u *expr; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
943 PyObject *todecref; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
944 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
945 if (!(expr = StringToChars(string, &todecref))) |
3618 | 946 return NULL; |
947 | |
948 Py_BEGIN_ALLOW_THREADS | |
949 Python_Lock_Vim(); | |
4498 | 950 VimTryStart(); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
951 our_tv = eval_expr(expr, NULL); |
3618 | 952 Python_Release_Vim(); |
953 Py_END_ALLOW_THREADS | |
954 | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
955 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
956 |
4498 | 957 if (VimTryEnd()) |
958 return NULL; | |
959 | |
3618 | 960 if (our_tv == NULL) |
961 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
962 PyErr_SET_VIM(N_("invalid expression")); |
3618 | 963 return NULL; |
964 } | |
965 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
966 ret = ConvertToPyObject(our_tv); |
3618 | 967 Py_BEGIN_ALLOW_THREADS |
968 Python_Lock_Vim(); | |
969 free_tv(our_tv); | |
970 Python_Release_Vim(); | |
971 Py_END_ALLOW_THREADS | |
972 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
973 return ret; |
3618 | 974 } |
975 | |
976 static PyObject * | |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
977 VimStrwidth(PyObject *self UNUSED, PyObject *string) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
978 { |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
979 char_u *str; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
980 PyObject *todecref; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
981 int len; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
982 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
983 if (!(str = StringToChars(string, &todecref))) |
3618 | 984 return NULL; |
985 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
986 len = mb_string2cells(str, (int)STRLEN(str)); |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
987 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
988 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
989 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
990 return PyLong_FromLong(len); |
3618 | 991 } |
992 | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
993 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
994 _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
995 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
996 PyObject *ret; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
997 PyObject *newwd; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
998 PyObject *todecref; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
999 char_u *new_dir; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1000 |
4754
be1e4acb30ca
updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents:
4722
diff
changeset
|
1001 if (_chdir == NULL) |
be1e4acb30ca
updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents:
4722
diff
changeset
|
1002 return NULL; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1003 if (!(ret = PyObject_Call(_chdir, args, kwargs))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1004 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1005 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1006 if (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL))) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1007 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1008 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1009 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1010 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1011 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1012 if (!(new_dir = StringToChars(newwd, &todecref))) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1013 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1014 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1015 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1016 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1017 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1018 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1019 VimTryStart(); |
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 if (vim_chdir(new_dir)) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1022 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1023 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1024 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1025 Py_XDECREF(todecref); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1026 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1027 if (VimTryEnd()) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1028 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1029 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1030 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
|
1031 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1032 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1033 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1034 Py_DECREF(newwd); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1035 Py_XDECREF(todecref); |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1036 |
16576
bcc343175103
patch 8.1.1291: not easy to change directory and restore
Bram Moolenaar <Bram@vim.org>
parents:
16427
diff
changeset
|
1037 post_chdir(CDSCOPE_GLOBAL); |
4704
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 if (VimTryEnd()) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1040 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1041 Py_DECREF(ret); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1042 return NULL; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1043 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1044 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1045 return ret; |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1046 } |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1047 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1048 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1049 VimChdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1050 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1051 return _VimChdir(py_chdir, args, 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 |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1054 static PyObject * |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1055 VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1056 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
1057 return _VimChdir(py_fchdir, args, 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 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1060 typedef struct { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1061 PyObject *callable; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1062 PyObject *result; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1063 } map_rtp_data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1064 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1065 static void |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1066 map_rtp_callback(char_u *path, void *_data) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1067 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1068 void **data = (void **) _data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1069 PyObject *pathObject; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1070 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
|
1071 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1072 if (!(pathObject = PyString_FromString((char *)path))) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1073 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1074 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1075 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1076 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1077 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1078 mr_data->result = PyObject_CallFunctionObjArgs(mr_data->callable, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1079 pathObject, NULL); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1080 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1081 Py_DECREF(pathObject); |
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 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
|
1084 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1085 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1086 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1087 Py_DECREF(mr_data->result); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1088 mr_data->result = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1089 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1090 } |
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 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1093 VimForeachRTP(PyObject *self UNUSED, PyObject *callable) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1094 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1095 map_rtp_data data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1096 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1097 data.callable = callable; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1098 data.result = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1099 |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7949
diff
changeset
|
1100 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
|
1101 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1102 if (data.result == NULL) |
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 (PyErr_Occurred()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1105 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1106 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1107 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1108 Py_INCREF(Py_None); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1109 return Py_None; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1110 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1111 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1112 return data.result; |
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 |
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 * _vim_runtimepath_ special path implementation. |
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 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1119 static void |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1120 map_finder_callback(char_u *path, void *_data) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1121 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1122 void **data = (void **) _data; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1123 PyObject *list = *((PyObject **) data); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1124 PyObject *pathObject1, *pathObject2; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1125 char *pathbuf; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1126 size_t pathlen; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1127 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1128 pathlen = STRLEN(path); |
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 #if PY_MAJOR_VERSION < 3 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1131 # define PY_MAIN_DIR_STRING "python2" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1132 #else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1133 # define PY_MAIN_DIR_STRING "python3" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1134 #endif |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1135 #define PY_ALTERNATE_DIR_STRING "pythonx" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1136 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1137 #define PYTHONX_STRING_LENGTH 7 // STRLEN("pythonx") |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1138 if (!(pathbuf = PyMem_New(char, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1139 pathlen + STRLEN(PATHSEPSTR) + PYTHONX_STRING_LENGTH + 1))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1140 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1141 PyErr_NoMemory(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1142 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1143 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1144 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1145 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1146 mch_memmove(pathbuf, path, pathlen + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1147 add_pathsep((char_u *) pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1148 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1149 pathlen = STRLEN(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1150 mch_memmove(pathbuf + pathlen, PY_MAIN_DIR_STRING, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1151 PYTHONX_STRING_LENGTH + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1152 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1153 if (!(pathObject1 = PyString_FromString(pathbuf))) |
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 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1156 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1157 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1158 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1159 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1160 mch_memmove(pathbuf + pathlen, PY_ALTERNATE_DIR_STRING, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1161 PYTHONX_STRING_LENGTH + 1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1162 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1163 if (!(pathObject2 = PyString_FromString(pathbuf))) |
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 Py_DECREF(pathObject1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1166 PyMem_Free(pathbuf); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1167 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1168 return; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1169 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1170 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1171 PyMem_Free(pathbuf); |
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 if (PyList_Append(list, pathObject1) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1174 || PyList_Append(list, pathObject2)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1175 *data = NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1176 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1177 Py_DECREF(pathObject1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1178 Py_DECREF(pathObject2); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1179 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1180 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1181 static PyObject * |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1182 Vim_GetPaths(PyObject *self UNUSED) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1183 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1184 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1185 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1186 if (!(ret = PyList_New(0))) |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1187 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1188 |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7949
diff
changeset
|
1189 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
|
1190 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1191 if (PyErr_Occurred()) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1192 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1193 Py_DECREF(ret); |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1194 return NULL; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1195 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1196 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1197 return ret; |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1198 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1199 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1200 #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
|
1201 static PyObject * |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1202 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
|
1203 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1204 char *fullname; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1205 PyObject *paths; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1206 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
|
1207 PyObject *spec; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1208 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1209 if (!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
|
1210 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1211 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1212 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
|
1213 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1214 |
16140
ab815ed87969
patch 8.1.1075: function reference count wrong in Python code
Bram Moolenaar <Bram@vim.org>
parents:
16080
diff
changeset
|
1215 spec = PyObject_CallFunction(py_find_spec, "sOO", fullname, paths, target); |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1216 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1217 Py_DECREF(paths); |
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 if (!spec) |
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 (PyErr_Occurred()) |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1222 return NULL; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1223 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1224 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
|
1225 return Py_None; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1226 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1227 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1228 return spec; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1229 } |
16718
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1230 |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1231 static PyObject * |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1232 FinderFindModule(PyObject* self UNUSED, PyObject* args UNUSED) |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1233 { |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1234 // Apparently returning None works. |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1235 Py_INCREF(Py_None); |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1236 return Py_None; |
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1237 } |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1238 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1239 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1240 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
|
1241 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1242 PyObject *fd, *pathname, *description; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1243 |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1244 if (!PyTuple_Check(find_module_result)) |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1245 { |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1246 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1247 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
|
1248 Py_TYPE_NAME(find_module_result)); |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1249 return NULL; |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1250 } |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1251 if (PyTuple_GET_SIZE(find_module_result) != 3) |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1252 { |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1253 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1254 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
|
1255 "tuple of size %d"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1256 (int) PyTuple_GET_SIZE(find_module_result)); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1257 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1258 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1259 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1260 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
|
1261 || !(pathname = PyTuple_GET_ITEM(find_module_result, 1)) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1262 || !(description = PyTuple_GET_ITEM(find_module_result, 2))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1263 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1264 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1265 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
|
1266 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1267 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1268 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1269 return PyObject_CallFunction(py_load_module, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1270 "s#OOO", name, len, fd, pathname, description); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1271 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1272 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1273 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1274 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
|
1275 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1276 PyObject *find_module_result; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1277 PyObject *module; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1278 char *dot; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1279 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
1280 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
|
1281 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1282 /* |
4859
e48cabe98453
updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents:
4855
diff
changeset
|
1283 * 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
|
1284 * first component |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1285 */ |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1286 PyObject *newest_path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1287 int partlen = (int) (dot - 1 - tail); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1288 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1289 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
|
1290 "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
|
1291 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1292 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
|
1293 PyErr_Clear(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1294 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
|
1295 } |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1296 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1297 if (!(module = call_load_module( |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1298 fullname, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1299 ((int) (tail - fullname)) + partlen, |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1300 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 Py_DECREF(find_module_result); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1303 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1304 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1305 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1306 Py_DECREF(find_module_result); |
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 if (!(newest_path = PyObject_GetAttrString(module, "__path__"))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1309 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1310 Py_DECREF(module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1311 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1312 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1313 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1314 Py_DECREF(module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1315 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1316 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
|
1317 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1318 Py_DECREF(newest_path); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1319 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1320 return find_module_result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1321 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1322 else |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1323 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1324 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
|
1325 "sO", tail, new_path))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1326 { |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1327 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
|
1328 PyErr_Clear(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1329 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1330 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1331 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1332 return find_module_result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1333 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1334 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1335 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1336 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1337 FinderFindModule(PyObject *self, PyObject *args) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1338 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1339 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
|
1340 PyObject *result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1341 PyObject *new_path; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1342 LoaderObject *loader; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1343 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1344 if (!PyArg_ParseTuple(args, "s", &fullname)) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1345 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1346 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1347 if (!(new_path = Vim_GetPaths(self))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1348 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1349 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1350 result = find_module(fullname, fullname, new_path); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1351 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1352 Py_DECREF(new_path); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1353 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1354 if (!result) |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1355 { |
4984
5b2c8f3b3906
updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
1356 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
|
1357 return NULL; |
4984
5b2c8f3b3906
updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents:
4982
diff
changeset
|
1358 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1359 Py_INCREF(Py_None); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1360 return Py_None; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1361 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1362 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1363 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
|
1364 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1365 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
|
1366 PyErr_NoMemory(); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1367 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1368 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1369 |
14467
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1370 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
|
1371 { |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1372 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
|
1373 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
|
1374 return NULL; |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1375 } |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1376 |
16cccc953909
patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents:
14395
diff
changeset
|
1377 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
|
1378 loader->result = result; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1379 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1380 return (PyObject *) loader; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1381 } |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1382 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1383 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1384 static PyObject * |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1385 VimPathHook(PyObject *self UNUSED, PyObject *args) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1386 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1387 char *path; |
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 if (PyArg_ParseTuple(args, "s", &path) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1390 && STRCMP(path, vim_special_path) == 0) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1391 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1392 Py_INCREF(vim_module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1393 return vim_module; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1394 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1395 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1396 PyErr_Clear(); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1397 PyErr_SetNone(PyExc_ImportError); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1398 return NULL; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1399 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
1400 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1401 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1402 * Vim module - Definitions |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1403 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1404 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1405 static struct PyMethodDef VimMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1406 // name, function, calling, documentation |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1407 {"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
|
1408 {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" }, |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
1409 {"bindeval", VimEvalPy, METH_O, "Like eval(), but returns objects attached to Vim ones"}, |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
1410 {"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
|
1411 {"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
|
1412 {"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
|
1413 {"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
|
1414 #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
|
1415 {"find_spec", FinderFindSpec, METH_VARARGS, "Internal use only, returns spec object for any input it receives"}, |
16718
9aa87f5aab55
patch 8.1.1361: Python setuptools don't work with Python 3
Bram Moolenaar <Bram@vim.org>
parents:
16688
diff
changeset
|
1416 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1417 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"}, |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
1418 {"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
|
1419 {"_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
|
1420 { 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
|
1421 }; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1422 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1423 /* |
4397 | 1424 * 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
|
1425 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1426 |
4397 | 1427 static PyTypeObject IterType; |
1428 | |
1429 typedef PyObject *(*nextfun)(void **); | |
1430 typedef void (*destructorfun)(void *); | |
4433 | 1431 typedef int (*traversefun)(void *, visitproc, void *); |
1432 typedef int (*clearfun)(void **); | |
4397 | 1433 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1434 // Main purpose of this object is removing the need for do python |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1435 // initialization (i.e. PyType_Ready and setting type attributes) for a big |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1436 // bunch of objects. |
4319 | 1437 typedef struct |
1438 { | |
1439 PyObject_HEAD | |
4397 | 1440 void *cur; |
1441 nextfun next; | |
1442 destructorfun destruct; | |
4433 | 1443 traversefun traverse; |
1444 clearfun clear; | |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1445 PyObject *iter_object; |
4397 | 1446 } IterObject; |
1447 | |
1448 static PyObject * | |
4433 | 1449 IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse, |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1450 clearfun clear, PyObject *iter_object) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1451 { |
4397 | 1452 IterObject *self; |
1453 | |
4500 | 1454 self = PyObject_GC_New(IterObject, &IterType); |
4397 | 1455 self->cur = start; |
1456 self->next = next; | |
1457 self->destruct = destruct; | |
4433 | 1458 self->traverse = traverse; |
1459 self->clear = clear; | |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1460 self->iter_object = iter_object; |
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1461 |
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1462 if (iter_object) |
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1463 Py_INCREF(iter_object); |
4397 | 1464 |
1465 return (PyObject *)(self); | |
1466 } | |
1467 | |
1468 static void | |
4488 | 1469 IterDestructor(IterObject *self) |
4397 | 1470 { |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1471 if (self->iter_object) |
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1472 Py_DECREF(self->iter_object); |
4500 | 1473 PyObject_GC_UnTrack((void *)(self)); |
4488 | 1474 self->destruct(self->cur); |
4500 | 1475 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
|
1476 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1477 |
4433 | 1478 static int |
4488 | 1479 IterTraverse(IterObject *self, visitproc visit, void *arg) |
4433 | 1480 { |
4488 | 1481 if (self->traverse != NULL) |
1482 return self->traverse(self->cur, visit, arg); | |
4433 | 1483 else |
1484 return 0; | |
1485 } | |
1486 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1487 // Mac OSX defines clear() somewhere. |
4438 | 1488 #ifdef clear |
1489 # undef clear | |
1490 #endif | |
1491 | |
4433 | 1492 static int |
4488 | 1493 IterClear(IterObject *self) |
4433 | 1494 { |
4488 | 1495 if (self->clear != NULL) |
1496 return self->clear(&self->cur); | |
4433 | 1497 else |
1498 return 0; | |
1499 } | |
1500 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1501 static PyObject * |
4488 | 1502 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
|
1503 { |
4488 | 1504 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
|
1505 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
1506 |
4397 | 1507 static PyObject * |
1508 IterIter(PyObject *self) | |
1509 { | |
4609
12421d8a45d5
updated for version 7.3.1052
Bram Moolenaar <bram@vim.org>
parents:
4607
diff
changeset
|
1510 Py_INCREF(self); |
4397 | 1511 return self; |
1512 } | |
4393 | 1513 |
3618 | 1514 typedef struct pylinkedlist_S { |
1515 struct pylinkedlist_S *pll_next; | |
1516 struct pylinkedlist_S *pll_prev; | |
1517 PyObject *pll_obj; | |
1518 } pylinkedlist_T; | |
1519 | |
1520 static pylinkedlist_T *lastdict = NULL; | |
1521 static pylinkedlist_T *lastlist = NULL; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
1522 static pylinkedlist_T *lastfunc = NULL; |
3618 | 1523 |
1524 static void | |
1525 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last) | |
1526 { | |
1527 if (ref->pll_prev == NULL) | |
1528 { | |
1529 if (ref->pll_next == NULL) | |
1530 { | |
1531 *last = NULL; | |
1532 return; | |
1533 } | |
1534 } | |
1535 else | |
1536 ref->pll_prev->pll_next = ref->pll_next; | |
1537 | |
1538 if (ref->pll_next == NULL) | |
1539 *last = ref->pll_prev; | |
1540 else | |
1541 ref->pll_next->pll_prev = ref->pll_prev; | |
1542 } | |
1543 | |
1544 static void | |
1545 pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last) | |
1546 { | |
1547 if (*last == NULL) | |
1548 ref->pll_prev = NULL; | |
1549 else | |
1550 { | |
1551 (*last)->pll_next = ref; | |
1552 ref->pll_prev = *last; | |
1553 } | |
1554 ref->pll_next = NULL; | |
1555 ref->pll_obj = self; | |
1556 *last = ref; | |
1557 } | |
1558 | |
1559 static PyTypeObject DictionaryType; | |
1560 | |
1561 typedef struct | |
1562 { | |
1563 PyObject_HEAD | |
1564 dict_T *dict; | |
1565 pylinkedlist_T ref; | |
1566 } DictionaryObject; | |
1567 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1568 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1569 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1570 #define NEW_DICTIONARY(dict) DictionaryNew(&DictionaryType, dict) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1571 |
3618 | 1572 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1573 DictionaryNew(PyTypeObject *subtype, dict_T *dict) |
3618 | 1574 { |
1575 DictionaryObject *self; | |
1576 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1577 self = (DictionaryObject *) subtype->tp_alloc(subtype, 0); |
3618 | 1578 if (self == NULL) |
1579 return NULL; | |
1580 self->dict = dict; | |
1581 ++dict->dv_refcount; | |
1582 | |
1583 pyll_add((PyObject *)(self), &self->ref, &lastdict); | |
1584 | |
1585 return (PyObject *)(self); | |
1586 } | |
1587 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1588 static dict_T * |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1589 py_dict_alloc(void) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1590 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1591 dict_T *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1592 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1593 if (!(ret = dict_alloc())) |
4627
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 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1596 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1597 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1598 ++ret->dv_refcount; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1599 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1600 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1601 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1602 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1603 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1604 DictionaryConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1605 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1606 DictionaryObject *self; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1607 dict_T *dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1608 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1609 if (!(dict = py_dict_alloc())) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1610 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1611 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1612 self = (DictionaryObject *) DictionaryNew(subtype, dict); |
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 --dict->dv_refcount; |
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 if (kwargs || PyTuple_Size(args)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1617 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1618 PyObject *tmp; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1619 if (!(tmp = DictionaryUpdate(self, args, kwargs))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1620 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1621 Py_DECREF(self); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1622 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1623 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1624 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1625 Py_DECREF(tmp); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1626 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1627 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1628 return (PyObject *)(self); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1629 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1630 |
4319 | 1631 static void |
4488 | 1632 DictionaryDestructor(DictionaryObject *self) |
4319 | 1633 { |
4488 | 1634 pyll_remove(&self->ref, &lastdict); |
1635 dict_unref(self->dict); | |
4319 | 1636 |
1637 DESTRUCTOR_FINISH(self); | |
1638 } | |
1639 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1640 static char *DictionaryAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1641 "locked", "scope", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1642 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1643 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1644 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1645 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1646 DictionaryDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1647 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1648 return ObjectDir(self, DictionaryAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1649 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
1650 |
3618 | 1651 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1652 DictionarySetattr(DictionaryObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1653 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1654 if (valObject == NULL) |
3828 | 1655 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1656 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1657 N_("cannot delete vim.Dictionary attributes")); |
3828 | 1658 return -1; |
1659 } | |
1660 | |
1661 if (strcmp(name, "locked") == 0) | |
1662 { | |
4488 | 1663 if (self->dict->dv_lock == VAR_FIXED) |
3828 | 1664 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1665 PyErr_SET_STRING(PyExc_TypeError, |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1666 N_("cannot modify fixed dictionary")); |
3828 | 1667 return -1; |
1668 } | |
1669 else | |
1670 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1671 int istrue = PyObject_IsTrue(valObject); |
4411 | 1672 if (istrue == -1) |
1673 return -1; | |
1674 else if (istrue) | |
4488 | 1675 self->dict->dv_lock = VAR_LOCKED; |
3828 | 1676 else |
4488 | 1677 self->dict->dv_lock = 0; |
3828 | 1678 } |
1679 return 0; | |
1680 } | |
1681 else | |
1682 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1683 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name); |
3828 | 1684 return -1; |
1685 } | |
1686 } | |
1687 | |
1688 static PyInt | |
4488 | 1689 DictionaryLength(DictionaryObject *self) |
3618 | 1690 { |
4488 | 1691 return ((PyInt) (self->dict->dv_hashtab.ht_used)); |
3618 | 1692 } |
1693 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1694 #define DICT_FLAG_HAS_DEFAULT 0x01 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1695 #define DICT_FLAG_POP 0x02 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1696 #define DICT_FLAG_NONE_DEFAULT 0x04 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
1697 #define DICT_FLAG_RETURN_BOOL 0x08 // Incompatible with DICT_FLAG_POP |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1698 #define DICT_FLAG_RETURN_PAIR 0x10 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1699 |
3618 | 1700 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1701 _DictionaryItem(DictionaryObject *self, PyObject *args, int flags) |
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 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1704 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
|
1705 PyObject *ret; |
3618 | 1706 char_u *key; |
3792 | 1707 dictitem_T *di; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1708 dict_T *dict = self->dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1709 hashitem_T *hi; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1710 PyObject *todecref; |
3618 | 1711 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1712 if (flags & DICT_FLAG_HAS_DEFAULT) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1713 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1714 if (!PyArg_ParseTuple(args, "O|O", &keyObject, &defObject)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1715 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1716 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1717 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1718 keyObject = args; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1719 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1720 if (flags & DICT_FLAG_RETURN_BOOL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1721 defObject = Py_False; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1722 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1723 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1724 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1725 |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1726 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1727 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1728 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
1729 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1730 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1731 } |
3792 | 1732 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1733 hi = hash_find(&dict->dv_hashtab, key); |
3792 | 1734 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1735 Py_XDECREF(todecref); |
3824 | 1736 |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1737 if (HASHITEM_EMPTY(hi)) |
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 if (defObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1740 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1741 Py_INCREF(defObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1742 return defObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1743 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1744 else |
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 PyErr_SetObject(PyExc_KeyError, keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1747 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1748 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1749 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1750 else if (flags & DICT_FLAG_RETURN_BOOL) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1751 { |
5666 | 1752 ret = Py_True; |
1753 Py_INCREF(ret); | |
1754 return ret; | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1755 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1756 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1757 di = dict_lookup(hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1758 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1759 if (!(ret = ConvertToPyObject(&di->di_tv))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1760 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1761 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1762 if (flags & DICT_FLAG_POP) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1763 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1764 if (dict->dv_lock) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1765 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1766 RAISE_LOCKED_DICTIONARY; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1767 Py_DECREF(ret); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1768 return NULL; |
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 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1771 hash_remove(&dict->dv_hashtab, hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1772 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1773 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1774 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1775 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1776 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1777 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1778 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1779 DictionaryItem(DictionaryObject *self, PyObject *keyObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1780 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1781 return _DictionaryItem(self, keyObject, 0); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1782 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1783 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1784 static int |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1785 DictionaryContains(DictionaryObject *self, PyObject *keyObject) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1786 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1787 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
|
1788 int ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1789 |
5426 | 1790 if (rObj == NULL) |
1791 return -1; | |
1792 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1793 ret = (rObj == Py_True); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1794 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
1795 Py_DECREF(rObj); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1796 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1797 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1798 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1799 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1800 typedef struct |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1801 { |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1802 int dii_changed; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1803 hashtab_T *dii_ht; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1804 hashitem_T *dii_hi; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1805 long_u dii_todo; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1806 } dictiterinfo_T; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1807 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1808 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1809 DictionaryIterNext(dictiterinfo_T **dii) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1810 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1811 PyObject *ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1812 |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1813 if (!(*dii)->dii_todo) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1814 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1815 |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1816 if ((*dii)->dii_ht->ht_changed != (*dii)->dii_changed) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1817 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
1818 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
1819 N_("hashtab changed during iteration")); |
3792 | 1820 return NULL; |
1821 } | |
3618 | 1822 |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1823 while (((*dii)->dii_todo) && HASHITEM_EMPTY((*dii)->dii_hi)) |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1824 ++((*dii)->dii_hi); |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1825 |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1826 --((*dii)->dii_todo); |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1827 |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1828 if (!(ret = PyBytes_FromString((char *)(*dii)->dii_hi->hi_key))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1829 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1830 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1831 return ret; |
4627
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 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1834 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1835 DictionaryIter(DictionaryObject *self) |
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 dictiterinfo_T *dii; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1838 hashtab_T *ht; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1839 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1840 if (!(dii = PyMem_New(dictiterinfo_T, 1))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1841 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1842 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1843 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1844 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1845 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1846 ht = &self->dict->dv_hashtab; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1847 dii->dii_changed = ht->ht_changed; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1848 dii->dii_ht = ht; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1849 dii->dii_hi = ht->ht_array; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21198
diff
changeset
|
1850 dii->dii_todo = ht->ht_used; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1851 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1852 return IterNew(dii, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1853 (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext, |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
1854 NULL, NULL, (PyObject *)self); |
3618 | 1855 } |
1856 | |
1857 static PyInt | |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1858 DictionaryAssItem( |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
1859 DictionaryObject *self, PyObject *keyObject, PyObject *valObject) |
3618 | 1860 { |
1861 char_u *key; | |
1862 typval_T tv; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1863 dict_T *dict = self->dict; |
3618 | 1864 dictitem_T *di; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1865 PyObject *todecref; |
3618 | 1866 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1867 if (dict->dv_lock) |
3618 | 1868 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1869 RAISE_LOCKED_DICTIONARY; |
3618 | 1870 return -1; |
1871 } | |
1872 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1873 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1874 return -1; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
1875 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1876 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1877 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1878 RAISE_NO_EMPTY_KEYS; |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1879 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1880 return -1; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1881 } |
3618 | 1882 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1883 di = dict_find(dict, key, -1); |
3618 | 1884 |
1885 if (valObject == NULL) | |
1886 { | |
3636 | 1887 hashitem_T *hi; |
1888 | |
3618 | 1889 if (di == NULL) |
1890 { | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1891 Py_XDECREF(todecref); |
4403 | 1892 PyErr_SetObject(PyExc_KeyError, keyObject); |
3618 | 1893 return -1; |
1894 } | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1895 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
|
1896 hash_remove(&dict->dv_hashtab, hi); |
3618 | 1897 dictitem_free(di); |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1898 Py_XDECREF(todecref); |
3618 | 1899 return 0; |
1900 } | |
1901 | |
1902 if (ConvertFromPyObject(valObject, &tv) == -1) | |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1903 { |
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1904 Py_XDECREF(todecref); |
3618 | 1905 return -1; |
4706
bf917ee1fad2
updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents:
4704
diff
changeset
|
1906 } |
3618 | 1907 |
1908 if (di == NULL) | |
1909 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1910 if (!(di = dictitem_alloc(key))) |
3618 | 1911 { |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1912 Py_XDECREF(todecref); |
3618 | 1913 PyErr_NoMemory(); |
1914 return -1; | |
1915 } | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1916 di->di_tv.v_type = VAR_UNKNOWN; |
3618 | 1917 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
1918 if (dict_add(dict, di) == FAIL) |
3618 | 1919 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1920 dictitem_free(di); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1921 RAISE_KEY_ADD_FAIL(key); |
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
1922 Py_XDECREF(todecref); |
3618 | 1923 return -1; |
1924 } | |
1925 } | |
1926 else | |
1927 clear_tv(&di->di_tv); | |
1928 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
1929 Py_XDECREF(todecref); |
3618 | 1930 |
1931 copy_tv(&tv, &di->di_tv); | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
1932 clear_tv(&tv); |
3618 | 1933 return 0; |
1934 } | |
1935 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1936 typedef PyObject *(*hi_to_py)(hashitem_T *); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1937 |
3618 | 1938 static PyObject * |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1939 DictionaryListObjects(DictionaryObject *self, hi_to_py hiconvert) |
3618 | 1940 { |
4488 | 1941 dict_T *dict = self->dict; |
3618 | 1942 long_u todo = dict->dv_hashtab.ht_used; |
1943 Py_ssize_t i = 0; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1944 PyObject *ret; |
3618 | 1945 hashitem_T *hi; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1946 PyObject *newObj; |
3618 | 1947 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1948 ret = PyList_New(todo); |
3618 | 1949 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi) |
1950 { | |
1951 if (!HASHITEM_EMPTY(hi)) | |
1952 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1953 if (!(newObj = hiconvert(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1954 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1955 Py_DECREF(ret); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1956 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1957 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1958 PyList_SET_ITEM(ret, i, newObj); |
3618 | 1959 --todo; |
1960 ++i; | |
1961 } | |
1962 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1963 return ret; |
3618 | 1964 } |
1965 | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1966 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1967 dict_key(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1968 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1969 return PyBytes_FromString((char *)(hi->hi_key)); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1970 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1971 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1972 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1973 DictionaryListKeys(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1974 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1975 return DictionaryListObjects(self, dict_key); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1976 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1977 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1978 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1979 dict_val(hashitem_T *hi) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1980 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1981 dictitem_T *di; |
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 di = dict_lookup(hi); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1984 return ConvertToPyObject(&di->di_tv); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1985 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1986 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1987 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1988 DictionaryListValues(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1989 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1990 return DictionaryListObjects(self, dict_val); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1991 } |
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 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1994 dict_item(hashitem_T *hi) |
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 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1997 PyObject *valObject; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
1998 PyObject *ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
1999 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2000 if (!(keyObject = dict_key(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2001 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2002 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2003 if (!(valObject = dict_val(hi))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2004 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2005 Py_DECREF(keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2006 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2007 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2008 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2009 ret = Py_BuildValue("(OO)", keyObject, valObject); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2010 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2011 Py_DECREF(keyObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2012 Py_DECREF(valObject); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2013 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2014 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2015 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2016 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2017 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2018 DictionaryListItems(DictionaryObject *self) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2019 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2020 return DictionaryListObjects(self, dict_item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2021 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2022 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2023 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2024 DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs) |
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 dict_T *dict = self->dict; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2027 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2028 if (dict->dv_lock) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2029 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2030 RAISE_LOCKED_DICTIONARY; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2031 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2032 } |
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 if (kwargs) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2035 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2036 typval_T tv; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2037 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2038 if (ConvertFromPyMapping(kwargs, &tv) == -1) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2039 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2040 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2041 VimTryStart(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2042 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
|
2043 clear_tv(&tv); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2044 if (VimTryEnd()) |
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 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2047 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2048 { |
5659 | 2049 PyObject *obj = NULL; |
2050 | |
2051 if (!PyArg_ParseTuple(args, "|O", &obj)) | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2052 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2053 |
5659 | 2054 if (obj == NULL) |
2055 { | |
2056 Py_INCREF(Py_None); | |
2057 return Py_None; | |
2058 } | |
2059 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2060 if (PyObject_HasAttrString(obj, "keys")) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2061 return DictionaryUpdate(self, NULL, obj); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2062 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2063 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2064 PyObject *iterator; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2065 PyObject *item; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2066 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2067 if (!(iterator = PyObject_GetIter(obj))) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2068 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2069 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2070 while ((item = PyIter_Next(iterator))) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2071 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2072 PyObject *fast; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2073 PyObject *keyObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2074 PyObject *valObject; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2075 PyObject *todecref; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2076 char_u *key; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2077 dictitem_T *di; |
12812
381e67ccf02c
patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents:
12806
diff
changeset
|
2078 hashitem_T *hi; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2079 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2080 if (!(fast = PySequence_Fast(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 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2083 Py_DECREF(item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2084 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2085 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2086 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2087 Py_DECREF(item); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2088 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2089 if (PySequence_Fast_GET_SIZE(fast) != 2) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2090 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2091 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2092 Py_DECREF(fast); |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2093 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2094 N_("expected sequence element of size 2, " |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2095 "but got sequence of size %d"), |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
2096 (int) PySequence_Fast_GET_SIZE(fast)); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2097 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2098 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2099 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2100 keyObject = PySequence_Fast_GET_ITEM(fast, 0); |
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 if (!(key = StringToChars(keyObject, &todecref))) |
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_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2105 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2106 return 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 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2109 di = dictitem_alloc(key); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2110 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2111 Py_XDECREF(todecref); |
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 if (di == NULL) |
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 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2116 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2117 PyErr_NoMemory(); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2118 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2119 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2120 di->di_tv.v_type = VAR_UNKNOWN; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2121 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2122 valObject = PySequence_Fast_GET_ITEM(fast, 1); |
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 if (ConvertFromPyObject(valObject, &di->di_tv) == -1) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2125 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2126 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2127 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2128 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2129 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2130 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2131 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2132 Py_DECREF(fast); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2133 |
12812
381e67ccf02c
patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents:
12806
diff
changeset
|
2134 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
|
2135 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
|
2136 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2137 RAISE_KEY_ADD_FAIL(di->di_key); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2138 Py_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2139 dictitem_free(di); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2140 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2141 } |
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_DECREF(iterator); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2145 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2146 // Iterator may have finished due to an exception |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2147 if (PyErr_Occurred()) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2148 return NULL; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2149 } |
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 Py_INCREF(Py_None); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2152 return Py_None; |
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 DictionaryGet(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, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2159 DICT_FLAG_HAS_DEFAULT|DICT_FLAG_NONE_DEFAULT); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2160 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2161 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2162 static PyObject * |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2163 DictionaryPop(DictionaryObject *self, PyObject *args) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2164 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2165 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
|
2166 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2167 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2168 static PyObject * |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2169 DictionaryPopItem(DictionaryObject *self) |
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 hashitem_T *hi; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2172 PyObject *ret; |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2173 PyObject *valObject; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2174 dictitem_T *di; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2175 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2176 if (self->dict->dv_hashtab.ht_used == 0) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2177 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2178 PyErr_SetNone(PyExc_KeyError); |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2179 return NULL; |
4698
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 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2182 hi = self->dict->dv_hashtab.ht_array; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2183 while (HASHITEM_EMPTY(hi)) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2184 ++hi; |
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 di = dict_lookup(hi); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2187 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2188 if (!(valObject = ConvertToPyObject(&di->di_tv))) |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2189 return NULL; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2190 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2191 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
|
2192 { |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2193 Py_DECREF(valObject); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2194 return NULL; |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2195 } |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2196 |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2197 hash_remove(&self->dict->dv_hashtab, hi); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2198 dictitem_free(di); |
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2199 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2200 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2201 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2202 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2203 static PyObject * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2204 DictionaryHasKey(DictionaryObject *self, PyObject *keyObject) |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2205 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2206 return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2207 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2208 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2209 static PySequenceMethods DictionaryAsSeq = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2210 0, // sq_length |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2211 0, // sq_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2212 0, // sq_repeat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2213 0, // sq_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2214 0, // sq_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2215 0, // sq_ass_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2216 0, // sq_ass_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2217 (objobjproc) DictionaryContains, // sq_contains |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2218 0, // sq_inplace_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2219 0, // sq_inplace_repeat |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2220 }; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2221 |
4385 | 2222 static PyMappingMethods DictionaryAsMapping = { |
2223 (lenfunc) DictionaryLength, | |
2224 (binaryfunc) DictionaryItem, | |
2225 (objobjargproc) DictionaryAssItem, | |
2226 }; | |
2227 | |
3618 | 2228 static struct PyMethodDef DictionaryMethods[] = { |
4492 | 2229 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""}, |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2230 {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2231 {"items", (PyCFunction)DictionaryListItems, METH_NOARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2232 {"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2233 {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""}, |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
2234 {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""}, |
4698
2db005052371
updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents:
4667
diff
changeset
|
2235 {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""}, |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
2236 {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""}, |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2237 {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2238 { NULL, NULL, 0, NULL} |
3618 | 2239 }; |
2240 | |
2241 static PyTypeObject ListType; | |
2242 | |
2243 typedef struct | |
2244 { | |
2245 PyObject_HEAD | |
2246 list_T *list; | |
2247 pylinkedlist_T ref; | |
2248 } ListObject; | |
2249 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2250 #define NEW_LIST(list) ListNew(&ListType, list) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2251 |
3618 | 2252 static PyObject * |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2253 ListNew(PyTypeObject *subtype, list_T *list) |
3618 | 2254 { |
2255 ListObject *self; | |
2256 | |
21190
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2257 if (list == NULL) |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2258 return NULL; |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2259 |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2260 self = (ListObject *) subtype->tp_alloc(subtype, 0); |
3618 | 2261 if (self == NULL) |
2262 return NULL; | |
2263 self->list = list; | |
2264 ++list->lv_refcount; | |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20369
diff
changeset
|
2265 CHECK_LIST_MATERIALIZE(list); |
3618 | 2266 |
2267 pyll_add((PyObject *)(self), &self->ref, &lastlist); | |
2268 | |
2269 return (PyObject *)(self); | |
2270 } | |
2271 | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2272 static list_T * |
5166
467efeee8f9e
updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents:
5139
diff
changeset
|
2273 py_list_alloc(void) |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2274 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2275 list_T *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2276 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2277 if (!(ret = list_alloc())) |
4629
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 PyErr_NoMemory(); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2280 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2281 } |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2282 ++ret->lv_refcount; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2283 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2284 return ret; |
4629
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 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2287 static int |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2288 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
|
2289 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2290 PyObject *iterator; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2291 PyObject *item; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2292 listitem_T *li; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2293 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2294 if (!(iterator = PyObject_GetIter(obj))) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2295 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2296 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2297 while ((item = PyIter_Next(iterator))) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2298 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2299 if (!(li = listitem_alloc())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2300 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2301 PyErr_NoMemory(); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2302 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2303 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2304 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2305 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2306 li->li_tv.v_lock = 0; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2307 li->li_tv.v_type = VAR_UNKNOWN; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2308 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2309 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
|
2310 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2311 Py_DECREF(item); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2312 Py_DECREF(iterator); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
2313 listitem_free(l, li); |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2314 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2315 } |
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 Py_DECREF(item); |
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 list_append(l, li); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2320 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2321 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2322 Py_DECREF(iterator); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2323 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2324 // Iterator may have finished due to an exception |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2325 if (PyErr_Occurred()) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2326 return -1; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2327 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2328 return 0; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2329 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2330 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2331 static PyObject * |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2332 ListConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2333 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2334 list_T *list; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2335 PyObject *obj = NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2336 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2337 if (kwargs) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2338 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
2339 PyErr_SET_STRING(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2340 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
|
2341 return NULL; |
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 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2344 if (!PyArg_ParseTuple(args, "|O", &obj)) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2345 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2346 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2347 if (!(list = py_list_alloc())) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2348 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2349 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2350 if (obj) |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2351 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2352 PyObject *lookup_dict; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2353 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2354 if (!(lookup_dict = PyDict_New())) |
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 list_unref(list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2357 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2358 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2359 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2360 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
|
2361 { |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2362 Py_DECREF(lookup_dict); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2363 list_unref(list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2364 return NULL; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2365 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2366 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2367 Py_DECREF(lookup_dict); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2368 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2369 |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2370 return ListNew(subtype, list); |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2371 } |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
2372 |
4319 | 2373 static void |
4488 | 2374 ListDestructor(ListObject *self) |
4319 | 2375 { |
4488 | 2376 pyll_remove(&self->ref, &lastlist); |
2377 list_unref(self->list); | |
4319 | 2378 |
2379 DESTRUCTOR_FINISH(self); | |
2380 } | |
2381 | |
3618 | 2382 static PyInt |
4488 | 2383 ListLength(ListObject *self) |
3618 | 2384 { |
4488 | 2385 return ((PyInt) (self->list->lv_len)); |
3618 | 2386 } |
2387 | |
2388 static PyObject * | |
5608 | 2389 ListIndex(ListObject *self, Py_ssize_t index) |
3618 | 2390 { |
2391 listitem_T *li; | |
2392 | |
4488 | 2393 if (index >= ListLength(self)) |
3618 | 2394 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2395 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range")); |
3618 | 2396 return NULL; |
2397 } | |
4488 | 2398 li = list_find(self->list, (long) index); |
3618 | 2399 if (li == NULL) |
2400 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2401 // No more suitable format specifications in python-2.3 |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
2402 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
|
2403 (int) index); |
3618 | 2404 return NULL; |
2405 } | |
2406 return ConvertToPyObject(&li->li_tv); | |
2407 } | |
2408 | |
2409 static PyObject * | |
5608 | 2410 ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t step, |
2411 Py_ssize_t slicelen) | |
3618 | 2412 { |
2413 PyInt i; | |
2414 PyObject *list; | |
5608 | 2415 |
2416 if (step == 0) | |
2417 { | |
2418 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero")); | |
2419 return NULL; | |
2420 } | |
2421 | |
2422 list = PyList_New(slicelen); | |
3618 | 2423 if (list == NULL) |
2424 return NULL; | |
2425 | |
5608 | 2426 for (i = 0; i < slicelen; ++i) |
2427 { | |
2428 PyObject *item; | |
2429 | |
2430 item = ListIndex(self, first + i*step); | |
3618 | 2431 if (item == NULL) |
2432 { | |
2433 Py_DECREF(list); | |
2434 return NULL; | |
2435 } | |
2436 | |
5608 | 2437 PyList_SET_ITEM(list, i, item); |
3618 | 2438 } |
2439 | |
2440 return list; | |
2441 } | |
2442 | |
5608 | 2443 static PyObject * |
2444 ListItem(ListObject *self, PyObject* idx) | |
2445 { | |
2446 #if PY_MAJOR_VERSION < 3 | |
2447 if (PyInt_Check(idx)) | |
2448 { | |
2449 long _idx = PyInt_AsLong(idx); | |
2450 return ListIndex(self, _idx); | |
2451 } | |
2452 else | |
2453 #endif | |
2454 if (PyLong_Check(idx)) | |
2455 { | |
2456 long _idx = PyLong_AsLong(idx); | |
2457 return ListIndex(self, _idx); | |
2458 } | |
2459 else if (PySlice_Check(idx)) | |
2460 { | |
2461 Py_ssize_t start, stop, step, slicelen; | |
2462 | |
5768 | 2463 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), |
5608 | 2464 &start, &stop, &step, &slicelen) < 0) |
2465 return NULL; | |
2466 return ListSlice(self, start, step, slicelen); | |
2467 } | |
2468 else | |
2469 { | |
2470 RAISE_INVALID_INDEX_TYPE(idx); | |
2471 return NULL; | |
2472 } | |
2473 } | |
2474 | |
2475 static void | |
2476 list_restore(Py_ssize_t numadded, Py_ssize_t numreplaced, Py_ssize_t slicelen, | |
2477 list_T *l, listitem_T **lis, listitem_T *lastaddedli) | |
2478 { | |
2479 while (numreplaced--) | |
2480 { | |
2481 list_insert(l, lis[numreplaced], lis[slicelen + numreplaced]); | |
2482 listitem_remove(l, lis[slicelen + numreplaced]); | |
2483 } | |
2484 while (numadded--) | |
2485 { | |
2486 listitem_T *next; | |
2487 | |
2488 next = lastaddedli->li_prev; | |
2489 listitem_remove(l, lastaddedli); | |
2490 lastaddedli = next; | |
2491 } | |
2492 } | |
2493 | |
2494 static int | |
2495 ListAssSlice(ListObject *self, Py_ssize_t first, | |
2496 Py_ssize_t step, Py_ssize_t slicelen, PyObject *obj) | |
2497 { | |
2498 PyObject *iterator; | |
2499 PyObject *item; | |
2500 listitem_T *li; | |
2501 listitem_T *lastaddedli = NULL; | |
2502 listitem_T *next; | |
2503 typval_T v; | |
2504 list_T *l = self->list; | |
2505 PyInt i; | |
2506 PyInt j; | |
2507 PyInt numreplaced = 0; | |
2508 PyInt numadded = 0; | |
2509 PyInt size; | |
5655 | 2510 listitem_T **lis = NULL; |
5608 | 2511 |
2512 size = ListLength(self); | |
2513 | |
2514 if (l->lv_lock) | |
2515 { | |
2516 RAISE_LOCKED_LIST; | |
2517 return -1; | |
2518 } | |
2519 | |
2520 if (step == 0) | |
2521 { | |
2522 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero")); | |
2523 return -1; | |
2524 } | |
2525 | |
2526 if (step != 1 && slicelen == 0) | |
2527 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2528 // Nothing to do. Only error out if obj has some items. |
5608 | 2529 int ret = 0; |
2530 | |
2531 if (obj == NULL) | |
2532 return 0; | |
2533 | |
2534 if (!(iterator = PyObject_GetIter(obj))) | |
2535 return -1; | |
2536 | |
2537 if ((item = PyIter_Next(iterator))) | |
2538 { | |
2539 PyErr_FORMAT(PyExc_ValueError, | |
5695 | 2540 N_("attempt to assign sequence of size greater than %d " |
5608 | 2541 "to extended slice"), 0); |
2542 Py_DECREF(item); | |
2543 ret = -1; | |
2544 } | |
2545 Py_DECREF(iterator); | |
2546 return ret; | |
2547 } | |
2548 | |
2549 if (obj != NULL) | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2550 // XXX May allocate zero bytes. |
5608 | 2551 if (!(lis = PyMem_New(listitem_T *, slicelen * 2))) |
2552 { | |
2553 PyErr_NoMemory(); | |
2554 return -1; | |
2555 } | |
2556 | |
2557 if (first == size) | |
2558 li = NULL; | |
2559 else | |
2560 { | |
2561 li = list_find(l, (long) first); | |
2562 if (li == NULL) | |
2563 { | |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
2564 PyErr_VIM_FORMAT(N_("internal error: no Vim list item %d"), |
5608 | 2565 (int)first); |
2566 if (obj != NULL) | |
2567 PyMem_Free(lis); | |
2568 return -1; | |
2569 } | |
2570 i = slicelen; | |
2571 while (i-- && li != NULL) | |
2572 { | |
2573 j = step; | |
2574 next = li; | |
2575 if (step > 0) | |
2576 while (next != NULL && ((next = next->li_next) != NULL) && --j); | |
2577 else | |
2578 while (next != NULL && ((next = next->li_prev) != NULL) && ++j); | |
2579 | |
2580 if (obj == NULL) | |
2581 listitem_remove(l, li); | |
2582 else | |
2583 lis[slicelen - i - 1] = li; | |
2584 | |
2585 li = next; | |
2586 } | |
2587 if (li == NULL && i != -1) | |
2588 { | |
2589 PyErr_SET_VIM(N_("internal error: not enough list items")); | |
2590 if (obj != NULL) | |
2591 PyMem_Free(lis); | |
2592 return -1; | |
2593 } | |
2594 } | |
2595 | |
2596 if (obj == NULL) | |
2597 return 0; | |
2598 | |
2599 if (!(iterator = PyObject_GetIter(obj))) | |
2600 { | |
2601 PyMem_Free(lis); | |
2602 return -1; | |
2603 } | |
2604 | |
2605 i = 0; | |
2606 while ((item = PyIter_Next(iterator))) | |
2607 { | |
2608 if (ConvertFromPyObject(item, &v) == -1) | |
2609 { | |
2610 Py_DECREF(iterator); | |
2611 Py_DECREF(item); | |
2612 PyMem_Free(lis); | |
2613 return -1; | |
2614 } | |
2615 Py_DECREF(item); | |
2616 if (list_insert_tv(l, &v, numreplaced < slicelen | |
2617 ? lis[numreplaced] | |
2618 : li) == FAIL) | |
2619 { | |
2620 clear_tv(&v); | |
2621 PyErr_SET_VIM(N_("internal error: failed to add item to list")); | |
2622 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); | |
2623 PyMem_Free(lis); | |
2624 return -1; | |
2625 } | |
2626 if (numreplaced < slicelen) | |
2627 { | |
2628 lis[slicelen + numreplaced] = lis[numreplaced]->li_prev; | |
5871 | 2629 vimlist_remove(l, lis[numreplaced], lis[numreplaced]); |
5608 | 2630 numreplaced++; |
2631 } | |
2632 else | |
2633 { | |
2634 if (li) | |
2635 lastaddedli = li->li_prev; | |
2636 else | |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19193
diff
changeset
|
2637 lastaddedli = l->lv_u.mat.lv_last; |
5608 | 2638 numadded++; |
2639 } | |
2640 clear_tv(&v); | |
2641 if (step != 1 && i >= slicelen) | |
2642 { | |
2643 Py_DECREF(iterator); | |
2644 PyErr_FORMAT(PyExc_ValueError, | |
5695 | 2645 N_("attempt to assign sequence of size greater than %d " |
5668 | 2646 "to extended slice"), (int) slicelen); |
5608 | 2647 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); |
2648 PyMem_Free(lis); | |
2649 return -1; | |
2650 } | |
2651 ++i; | |
2652 } | |
2653 Py_DECREF(iterator); | |
2654 | |
2655 if (step != 1 && i != slicelen) | |
2656 { | |
2657 PyErr_FORMAT2(PyExc_ValueError, | |
5668 | 2658 N_("attempt to assign sequence of size %d to extended slice " |
2659 "of size %d"), (int) i, (int) slicelen); | |
5608 | 2660 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); |
2661 PyMem_Free(lis); | |
2662 return -1; | |
2663 } | |
2664 | |
2665 if (PyErr_Occurred()) | |
2666 { | |
2667 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli); | |
2668 PyMem_Free(lis); | |
2669 return -1; | |
2670 } | |
2671 | |
2672 for (i = 0; i < numreplaced; i++) | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
2673 listitem_free(l, lis[i]); |
5608 | 2674 if (step == 1) |
2675 for (i = numreplaced; i < slicelen; i++) | |
2676 listitem_remove(l, lis[i]); | |
2677 | |
2678 PyMem_Free(lis); | |
2679 | |
2680 return 0; | |
2681 } | |
2682 | |
2683 static int | |
2684 ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj) | |
2685 { | |
2686 typval_T tv; | |
2687 list_T *l = self->list; | |
2688 listitem_T *li; | |
2689 Py_ssize_t length = ListLength(self); | |
2690 | |
2691 if (l->lv_lock) | |
2692 { | |
2693 RAISE_LOCKED_LIST; | |
2694 return -1; | |
2695 } | |
2696 if (index > length || (index == length && obj == NULL)) | |
2697 { | |
2698 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range")); | |
2699 return -1; | |
2700 } | |
2701 | |
2702 if (obj == NULL) | |
2703 { | |
2704 li = list_find(l, (long) index); | |
21190
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2705 if (li == NULL) |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2706 { |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2707 PyErr_VIM_FORMAT(N_("internal error: failed to get Vim " |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2708 "list item %d"), (int) index); |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2709 return -1; |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2710 } |
5871 | 2711 vimlist_remove(l, li, li); |
5608 | 2712 clear_tv(&li->li_tv); |
2713 vim_free(li); | |
2714 return 0; | |
2715 } | |
2716 | |
2717 if (ConvertFromPyObject(obj, &tv) == -1) | |
2718 return -1; | |
2719 | |
2720 if (index == length) | |
2721 { | |
2722 if (list_append_tv(l, &tv) == FAIL) | |
2723 { | |
2724 clear_tv(&tv); | |
2725 PyErr_SET_VIM(N_("failed to add item to list")); | |
2726 return -1; | |
2727 } | |
2728 } | |
2729 else | |
2730 { | |
2731 li = list_find(l, (long) index); | |
21190
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2732 if (li == NULL) |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2733 { |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2734 PyErr_VIM_FORMAT(N_("internal error: failed to get Vim " |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2735 "list item %d"), (int) index); |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2736 return -1; |
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
2737 } |
5608 | 2738 clear_tv(&li->li_tv); |
2739 copy_tv(&tv, &li->li_tv); | |
2740 clear_tv(&tv); | |
2741 } | |
2742 return 0; | |
2743 } | |
2744 | |
2745 static Py_ssize_t | |
2746 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj) | |
2747 { | |
2748 #if PY_MAJOR_VERSION < 3 | |
2749 if (PyInt_Check(idx)) | |
2750 { | |
2751 long _idx = PyInt_AsLong(idx); | |
2752 return ListAssIndex(self, _idx, obj); | |
2753 } | |
2754 else | |
2755 #endif | |
2756 if (PyLong_Check(idx)) | |
2757 { | |
2758 long _idx = PyLong_AsLong(idx); | |
2759 return ListAssIndex(self, _idx, obj); | |
2760 } | |
2761 else if (PySlice_Check(idx)) | |
2762 { | |
2763 Py_ssize_t start, stop, step, slicelen; | |
2764 | |
5768 | 2765 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self), |
5608 | 2766 &start, &stop, &step, &slicelen) < 0) |
2767 return -1; | |
2768 return ListAssSlice(self, start, step, slicelen, | |
2769 obj); | |
2770 } | |
2771 else | |
2772 { | |
2773 RAISE_INVALID_INDEX_TYPE(idx); | |
2774 return -1; | |
2775 } | |
2776 } | |
2777 | |
2778 static PyObject * | |
2779 ListConcatInPlace(ListObject *self, PyObject *obj) | |
2780 { | |
2781 list_T *l = self->list; | |
2782 PyObject *lookup_dict; | |
2783 | |
2784 if (l->lv_lock) | |
2785 { | |
2786 RAISE_LOCKED_LIST; | |
2787 return NULL; | |
2788 } | |
2789 | |
2790 if (!(lookup_dict = PyDict_New())) | |
2791 return NULL; | |
2792 | |
2793 if (list_py_concat(l, obj, lookup_dict) == -1) | |
2794 { | |
2795 Py_DECREF(lookup_dict); | |
2796 return NULL; | |
2797 } | |
2798 Py_DECREF(lookup_dict); | |
2799 | |
2800 Py_INCREF(self); | |
2801 return (PyObject *)(self); | |
2802 } | |
2803 | |
4397 | 2804 typedef struct |
2805 { | |
2806 listwatch_T lw; | |
2807 list_T *list; | |
2808 } listiterinfo_T; | |
2809 | |
2810 static void | |
2811 ListIterDestruct(listiterinfo_T *lii) | |
2812 { | |
2813 list_rem_watch(lii->list, &lii->lw); | |
2814 PyMem_Free(lii); | |
2815 } | |
2816 | |
2817 static PyObject * | |
2818 ListIterNext(listiterinfo_T **lii) | |
2819 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2820 PyObject *ret; |
4397 | 2821 |
2822 if (!((*lii)->lw.lw_item)) | |
2823 return NULL; | |
2824 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2825 if (!(ret = ConvertToPyObject(&((*lii)->lw.lw_item->li_tv)))) |
4397 | 2826 return NULL; |
2827 | |
2828 (*lii)->lw.lw_item = (*lii)->lw.lw_item->li_next; | |
2829 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2830 return ret; |
4397 | 2831 } |
2832 | |
2833 static PyObject * | |
4488 | 2834 ListIter(ListObject *self) |
4397 | 2835 { |
2836 listiterinfo_T *lii; | |
4488 | 2837 list_T *l = self->list; |
4397 | 2838 |
2839 if (!(lii = PyMem_New(listiterinfo_T, 1))) | |
2840 { | |
2841 PyErr_NoMemory(); | |
2842 return NULL; | |
2843 } | |
2844 | |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20369
diff
changeset
|
2845 CHECK_LIST_MATERIALIZE(l); |
4397 | 2846 list_add_watch(l, &lii->lw); |
2847 lii->lw.lw_item = l->lv_first; | |
2848 lii->list = l; | |
2849 | |
2850 return IterNew(lii, | |
4433 | 2851 (destructorfun) ListIterDestruct, (nextfun) ListIterNext, |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
2852 NULL, NULL, (PyObject *)self); |
4397 | 2853 } |
2854 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2855 static char *ListAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2856 "locked", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2857 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2858 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2859 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2860 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2861 ListDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2862 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2863 return ObjectDir(self, ListAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2864 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2865 |
3828 | 2866 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2867 ListSetattr(ListObject *self, char *name, PyObject *valObject) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2868 { |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2869 if (valObject == NULL) |
3828 | 2870 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
2871 PyErr_SET_STRING(PyExc_AttributeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2872 N_("cannot delete vim.List attributes")); |
3828 | 2873 return -1; |
2874 } | |
2875 | |
2876 if (strcmp(name, "locked") == 0) | |
2877 { | |
4488 | 2878 if (self->list->lv_lock == VAR_FIXED) |
3828 | 2879 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2880 PyErr_SET_STRING(PyExc_TypeError, N_("cannot modify fixed list")); |
3828 | 2881 return -1; |
2882 } | |
2883 else | |
2884 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
2885 int istrue = PyObject_IsTrue(valObject); |
4411 | 2886 if (istrue == -1) |
2887 return -1; | |
2888 else if (istrue) | |
4488 | 2889 self->list->lv_lock = VAR_LOCKED; |
3828 | 2890 else |
4488 | 2891 self->list->lv_lock = 0; |
3828 | 2892 } |
2893 return 0; | |
2894 } | |
2895 else | |
2896 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2897 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name); |
3828 | 2898 return -1; |
2899 } | |
2900 } | |
2901 | |
5608 | 2902 static PySequenceMethods ListAsSeq = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2903 (lenfunc) ListLength, // sq_length, len(x) |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2904 (binaryfunc) 0, // RangeConcat, sq_concat, x+y |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2905 0, // RangeRepeat, sq_repeat, x*n |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2906 (PyIntArgFunc) ListIndex, // sq_item, x[i] |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2907 0, // was_sq_slice, x[i:j] |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2908 (PyIntObjArgProc) ListAssIndex, // sq_as_item, x[i]=v |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2909 0, // was_sq_ass_slice, x[i:j]=v |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2910 0, // sq_contains |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2911 (binaryfunc) ListConcatInPlace,// sq_inplace_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
2912 0, // sq_inplace_repeat |
5608 | 2913 }; |
2914 | |
2915 static PyMappingMethods ListAsMapping = { | |
2916 /* mp_length */ (lenfunc) ListLength, | |
2917 /* mp_subscript */ (binaryfunc) ListItem, | |
2918 /* mp_ass_subscript */ (objobjargproc) ListAssItem, | |
2919 }; | |
2920 | |
3618 | 2921 static struct PyMethodDef ListMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2922 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2923 {"__dir__", (PyCFunction)ListDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
2924 { NULL, NULL, 0, NULL} |
3618 | 2925 }; |
2926 | |
2927 typedef struct | |
2928 { | |
2929 PyObject_HEAD | |
2930 char_u *name; | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2931 int argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2932 typval_T *argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2933 dict_T *self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2934 pylinkedlist_T ref; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2935 int auto_rebind; |
3618 | 2936 } FunctionObject; |
2937 | |
2938 static PyTypeObject FunctionType; | |
2939 | |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2940 #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
|
2941 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
|
2942 |
3618 | 2943 static PyObject * |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2944 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
|
2945 dict_T *selfdict, int auto_rebind) |
3618 | 2946 { |
2947 FunctionObject *self; | |
2948 | |
15234
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2949 self = (FunctionObject *)subtype->tp_alloc(subtype, 0); |
3618 | 2950 if (self == NULL) |
2951 return NULL; | |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2952 |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2953 if (isdigit(*name)) |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2954 { |
20197
7e84afe0831e
patch 8.2.0654: building with Python fails
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2955 if (!translated_function_exists(name, FALSE)) |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2956 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
2957 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2958 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
|
2959 return NULL; |
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 self->name = vim_strsave(name); |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2962 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2963 else |
15234
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2964 { |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2965 char_u *p; |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2966 |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2967 if ((p = get_expanded_name(name, |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2968 vim_strchr(name, AUTOLOAD_CHAR) == NULL)) == NULL) |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2969 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2970 PyErr_FORMAT(PyExc_ValueError, |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
2971 N_("function %s does not exist"), name); |
4641
59e6c2bd68e3
updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents:
4635
diff
changeset
|
2972 return NULL; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2973 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
2974 |
15234
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2975 if (p[0] == K_SPECIAL && p[1] == KS_EXTRA && p[2] == (int)KE_SNR) |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2976 { |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2977 char_u *np; |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2978 size_t len = STRLEN(p) + 1; |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2979 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16718
diff
changeset
|
2980 if ((np = alloc(len + 2)) == NULL) |
15234
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2981 { |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2982 vim_free(p); |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2983 return NULL; |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2984 } |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2985 mch_memmove(np, "<SNR>", 5); |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2986 mch_memmove(np + 5, p + 3, len - 3); |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2987 vim_free(p); |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2988 self->name = np; |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2989 } |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2990 else |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2991 self->name = p; |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2992 } |
ee63f4fe3d45
patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents:
14467
diff
changeset
|
2993 |
9725
4a4a71d67131
commit https://github.com/vim/vim/commit/2d3d60a7d4b410668dfc427120205ccf88789db4
Christian Brabandt <cb@256bit.org>
parents:
9723
diff
changeset
|
2994 func_ref(self->name); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2995 self->argc = argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2996 self->argv = argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
2997 self->self = selfdict; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
2998 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
|
2999 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3000 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3001 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
|
3002 |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3003 return (PyObject *)(self); |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3004 } |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3005 |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3006 static PyObject * |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3007 FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3008 { |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3009 PyObject *self; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3010 PyObject *selfdictObject; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3011 PyObject *autoRebindObject; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3012 PyObject *argsObject = NULL; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3013 char_u *name; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3014 typval_T selfdicttv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3015 typval_T argstv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3016 list_T *argslist = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3017 dict_T *selfdict = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3018 int argc = 0; |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3019 int auto_rebind = TRUE; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3020 typval_T *argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3021 typval_T *curtv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3022 listitem_T *li; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3023 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3024 if (kwargs != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3025 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3026 selfdictObject = PyDict_GetItemString(kwargs, "self"); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3027 if (selfdictObject != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3028 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3029 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3030 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3031 selfdict = selfdicttv.vval.v_dict; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3032 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3033 argsObject = PyDict_GetItemString(kwargs, "args"); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3034 if (argsObject != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3035 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3036 if (ConvertFromPySequence(argsObject, &argstv) == -1) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3037 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3038 dict_unref(selfdict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3039 return NULL; |
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 argslist = argstv.vval.v_list; |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20369
diff
changeset
|
3042 CHECK_LIST_MATERIALIZE(argslist); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3043 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3044 argc = argslist->lv_len; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3045 if (argc != 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3046 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3047 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
|
3048 if (argv == NULL) |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3049 { |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3050 PyErr_NoMemory(); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3051 dict_unref(selfdict); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3052 list_unref(argslist); |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3053 return NULL; |
c3e7cc135754
commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents:
8915
diff
changeset
|
3054 } |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3055 curtv = argv; |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
3056 FOR_ALL_LIST_ITEMS(argslist, li) |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3057 copy_tv(&li->li_tv, curtv++); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3058 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3059 list_unref(argslist); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3060 } |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3061 if (selfdict != NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3062 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3063 auto_rebind = FALSE; |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3064 autoRebindObject = PyDict_GetItemString(kwargs, "auto_rebind"); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3065 if (autoRebindObject != NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3066 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3067 auto_rebind = PyObject_IsTrue(autoRebindObject); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3068 if (auto_rebind == -1) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3069 { |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3070 dict_unref(selfdict); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3071 list_unref(argslist); |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3072 return NULL; |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3073 } |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3074 } |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3075 } |
3618 | 3076 } |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3077 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3078 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
|
3079 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3080 dict_unref(selfdict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3081 while (argc--) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3082 clear_tv(&argv[argc]); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3083 PyMem_Free(argv); |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3084 return NULL; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3085 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3086 |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3087 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
|
3088 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3089 PyMem_Free(name); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
3090 |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3091 return self; |
3618 | 3092 } |
3093 | |
4319 | 3094 static void |
4488 | 3095 FunctionDestructor(FunctionObject *self) |
4319 | 3096 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3097 int i; |
4488 | 3098 func_unref(self->name); |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
3099 vim_free(self->name); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3100 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
|
3101 clear_tv(&self->argv[i]); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3102 PyMem_Free(self->argv); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3103 dict_unref(self->self); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3104 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3105 pyll_remove(&self->ref, &lastfunc); |
4319 | 3106 |
3107 DESTRUCTOR_FINISH(self); | |
3108 } | |
3109 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3110 static char *FunctionAttrs[] = { |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3111 "softspace", "args", "self", "auto_rebind", |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3112 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3113 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3114 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3115 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3116 FunctionDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3117 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3118 return ObjectDir(self, FunctionAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3119 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3120 |
3618 | 3121 static PyObject * |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3122 FunctionAttr(FunctionObject *self, char *name) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3123 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3124 list_T *list; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3125 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3126 if (strcmp(name, "name") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3127 return PyString_FromString((char *)(self->name)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3128 else if (strcmp(name, "args") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3129 { |
9967
45098d7f72b6
commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents:
9725
diff
changeset
|
3130 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
|
3131 return AlwaysNone(NULL); |
9967
45098d7f72b6
commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents:
9725
diff
changeset
|
3132 |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3133 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
|
3134 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
|
3135 return NEW_LIST(list); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3136 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3137 else if (strcmp(name, "self") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3138 return self->self == NULL |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3139 ? AlwaysNone(NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3140 : NEW_DICTIONARY(self->self); |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3141 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
|
3142 return self->auto_rebind |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3143 ? AlwaysTrue(NULL) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3144 : AlwaysFalse(NULL); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3145 else if (strcmp(name, "__members__") == 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3146 return ObjectDir(NULL, FunctionAttrs); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3147 return NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3148 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3149 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3150 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3151 * Populate partial_T given function object. |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3152 * |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3153 * "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
|
3154 * 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
|
3155 */ |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3156 static void |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3157 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
|
3158 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3159 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3160 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3161 pt->pt_name = self->name; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3162 if (self->argv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3163 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3164 pt->pt_argc = self->argc; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3165 if (exported) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3166 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3167 pt->pt_argv = ALLOC_CLEAR_MULT(typval_T, self->argc); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3168 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
|
3169 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
|
3170 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3171 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3172 pt->pt_argv = self->argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3173 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3174 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3175 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3176 pt->pt_argc = 0; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3177 pt->pt_argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3178 } |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3179 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
|
3180 pt->pt_dict = self->self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3181 if (exported && self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3182 ++pt->pt_dict->dv_refcount; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3183 if (exported) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3184 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
|
3185 pt->pt_refcount = 1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3186 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3187 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3188 static PyObject * |
4488 | 3189 FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs) |
3618 | 3190 { |
4488 | 3191 char_u *name = self->name; |
3618 | 3192 typval_T args; |
3193 typval_T selfdicttv; | |
3194 typval_T rettv; | |
3195 dict_T *selfdict = NULL; | |
3196 PyObject *selfdictObject; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3197 PyObject *ret; |
3618 | 3198 int error; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3199 partial_T pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3200 partial_T *pt_ptr = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3201 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3202 if (ConvertFromPySequence(argsObject, &args) == -1) |
3618 | 3203 return NULL; |
3204 | |
3205 if (kwargs != NULL) | |
3206 { | |
3207 selfdictObject = PyDict_GetItemString(kwargs, "self"); | |
3208 if (selfdictObject != NULL) | |
3209 { | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3210 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1) |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3211 { |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3212 clear_tv(&args); |
3618 | 3213 return NULL; |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3214 } |
3618 | 3215 selfdict = selfdicttv.vval.v_dict; |
3216 } | |
3217 } | |
3218 | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3219 if (self->argv || self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3220 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
3221 CLEAR_FIELD(pt); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3222 set_partial(self, &pt, FALSE); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3223 pt_ptr = &pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3224 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3225 |
4415 | 3226 Py_BEGIN_ALLOW_THREADS |
3227 Python_Lock_Vim(); | |
3228 | |
4498 | 3229 VimTryStart(); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3230 error = func_call(name, &args, pt_ptr, selfdict, &rettv); |
4415 | 3231 |
3232 Python_Release_Vim(); | |
3233 Py_END_ALLOW_THREADS | |
3234 | |
4498 | 3235 if (VimTryEnd()) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3236 ret = NULL; |
4498 | 3237 else if (error != OK) |
3618 | 3238 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3239 ret = NULL; |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3240 PyErr_VIM_FORMAT(N_("failed to run function %s"), (char *)name); |
3618 | 3241 } |
3242 else | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3243 ret = ConvertToPyObject(&rettv); |
3618 | 3244 |
3245 clear_tv(&args); | |
3246 clear_tv(&rettv); | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3247 if (selfdict != NULL) |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3248 clear_tv(&selfdicttv); |
3618 | 3249 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3250 return ret; |
3618 | 3251 } |
3252 | |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3253 static PyObject * |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3254 FunctionRepr(FunctionObject *self) |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3255 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3256 PyObject *ret; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3257 garray_T repr_ga; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3258 int i; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3259 char_u *tofree = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3260 typval_T tv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3261 char_u numbuf[NUMBUFLEN]; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3262 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3263 ga_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
|
3264 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
|
3265 if (self->name) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3266 ga_concat(&repr_ga, self->name); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3267 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3268 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
|
3269 ga_append(&repr_ga, '\''); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3270 if (self->argv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3271 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3272 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
|
3273 ++emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3274 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
|
3275 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3276 if (i != 0) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3277 ga_concat(&repr_ga, (char_u *)", "); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3278 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
|
3279 get_copyID())); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3280 vim_free(tofree); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3281 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3282 --emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3283 ga_append(&repr_ga, ']'); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3284 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3285 if (self->self) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3286 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3287 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
|
3288 tv.v_type = VAR_DICT; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3289 tv.vval.v_dict = self->self; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3290 ++emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3291 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
|
3292 --emsg_silent; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3293 vim_free(tofree); |
9119
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3294 if (self->auto_rebind) |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
3295 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
|
3296 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3297 ga_append(&repr_ga, '>'); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3298 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
|
3299 ga_clear(&repr_ga); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
3300 return ret; |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3301 } |
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
3302 |
3618 | 3303 static struct PyMethodDef FunctionMethods[] = { |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3304 {"__dir__", (PyCFunction)FunctionDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3305 { NULL, NULL, 0, NULL} |
3618 | 3306 }; |
3307 | |
4350 | 3308 /* |
3309 * Options object | |
3310 */ | |
3311 | |
3312 static PyTypeObject OptionsType; | |
3313 | |
3314 typedef int (*checkfun)(void *); | |
3315 | |
3316 typedef struct | |
3317 { | |
3318 PyObject_HEAD | |
5610 | 3319 int opt_type; |
3320 void *from; | |
3321 checkfun Check; | |
3322 PyObject *fromObj; | |
4350 | 3323 } OptionsObject; |
3324 | |
4433 | 3325 static int |
3326 dummy_check(void *arg UNUSED) | |
3327 { | |
3328 return 0; | |
3329 } | |
3330 | |
3331 static PyObject * | |
3332 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj) | |
3333 { | |
3334 OptionsObject *self; | |
3335 | |
4500 | 3336 self = PyObject_GC_New(OptionsObject, &OptionsType); |
4433 | 3337 if (self == NULL) |
3338 return NULL; | |
3339 | |
3340 self->opt_type = opt_type; | |
3341 self->from = from; | |
3342 self->Check = Check; | |
3343 self->fromObj = fromObj; | |
3344 if (fromObj) | |
3345 Py_INCREF(fromObj); | |
3346 | |
3347 return (PyObject *)(self); | |
3348 } | |
3349 | |
3350 static void | |
4488 | 3351 OptionsDestructor(OptionsObject *self) |
4433 | 3352 { |
4500 | 3353 PyObject_GC_UnTrack((void *)(self)); |
3354 Py_XDECREF(self->fromObj); | |
3355 PyObject_GC_Del((void *)(self)); | |
4433 | 3356 } |
3357 | |
3358 static int | |
4488 | 3359 OptionsTraverse(OptionsObject *self, visitproc visit, void *arg) |
4433 | 3360 { |
4488 | 3361 Py_VISIT(self->fromObj); |
4433 | 3362 return 0; |
3363 } | |
3364 | |
3365 static int | |
4488 | 3366 OptionsClear(OptionsObject *self) |
4433 | 3367 { |
4488 | 3368 Py_CLEAR(self->fromObj); |
4433 | 3369 return 0; |
3370 } | |
3371 | |
4350 | 3372 static PyObject * |
4488 | 3373 OptionsItem(OptionsObject *self, PyObject *keyObject) |
4350 | 3374 { |
3375 char_u *key; | |
3376 int flags; | |
3377 long numval; | |
3378 char_u *stringval; | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3379 PyObject *todecref; |
4350 | 3380 |
21198
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
3381 if (self->Check(self->fromObj)) |
4350 | 3382 return NULL; |
3383 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3384 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3385 return NULL; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3386 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3387 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3388 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3389 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3390 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3391 return NULL; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3392 } |
4350 | 3393 |
3394 flags = get_option_value_strict(key, &numval, &stringval, | |
4488 | 3395 self->opt_type, self->from); |
4350 | 3396 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3397 Py_XDECREF(todecref); |
4350 | 3398 |
3399 if (flags == 0) | |
3400 { | |
4403 | 3401 PyErr_SetObject(PyExc_KeyError, keyObject); |
4350 | 3402 return NULL; |
3403 } | |
3404 | |
3405 if (flags & SOPT_UNSET) | |
3406 { | |
3407 Py_INCREF(Py_None); | |
3408 return Py_None; | |
3409 } | |
3410 else if (flags & SOPT_BOOL) | |
3411 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3412 PyObject *ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3413 ret = numval ? Py_True : Py_False; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3414 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3415 return ret; |
4350 | 3416 } |
3417 else if (flags & SOPT_NUM) | |
3418 return PyInt_FromLong(numval); | |
3419 else if (flags & SOPT_STRING) | |
3420 { | |
3421 if (stringval) | |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3422 { |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
3423 PyObject *ret = PyBytes_FromString((char *)stringval); |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3424 vim_free(stringval); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3425 return ret; |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3426 } |
4350 | 3427 else |
3428 { | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
3429 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3430 N_("unable to get option value")); |
4350 | 3431 return NULL; |
3432 } | |
3433 } | |
3434 else | |
3435 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3436 PyErr_SET_VIM(N_("internal error: unknown option type")); |
4350 | 3437 return NULL; |
3438 } | |
3439 } | |
3440 | |
3441 static int | |
5610 | 3442 OptionsContains(OptionsObject *self, PyObject *keyObject) |
3443 { | |
3444 char_u *key; | |
3445 PyObject *todecref; | |
3446 | |
3447 if (!(key = StringToChars(keyObject, &todecref))) | |
3448 return -1; | |
3449 | |
3450 if (*key == NUL) | |
3451 { | |
3452 Py_XDECREF(todecref); | |
3453 return 0; | |
3454 } | |
3455 | |
3456 if (get_option_value_strict(key, NULL, NULL, self->opt_type, NULL)) | |
3457 { | |
3458 Py_XDECREF(todecref); | |
3459 return 1; | |
3460 } | |
3461 else | |
3462 { | |
3463 Py_XDECREF(todecref); | |
3464 return 0; | |
3465 } | |
3466 } | |
3467 | |
3468 typedef struct | |
3469 { | |
3470 void *lastoption; | |
3471 int opt_type; | |
3472 } optiterinfo_T; | |
3473 | |
3474 static PyObject * | |
3475 OptionsIterNext(optiterinfo_T **oii) | |
3476 { | |
3477 char_u *name; | |
3478 | |
3479 if ((name = option_iter_next(&((*oii)->lastoption), (*oii)->opt_type))) | |
3480 return PyString_FromString((char *)name); | |
3481 | |
3482 return NULL; | |
3483 } | |
3484 | |
3485 static PyObject * | |
3486 OptionsIter(OptionsObject *self) | |
3487 { | |
3488 optiterinfo_T *oii; | |
3489 | |
3490 if (!(oii = PyMem_New(optiterinfo_T, 1))) | |
3491 { | |
3492 PyErr_NoMemory(); | |
3493 return NULL; | |
3494 } | |
3495 | |
3496 oii->opt_type = self->opt_type; | |
3497 oii->lastoption = NULL; | |
3498 | |
3499 return IterNew(oii, | |
3500 (destructorfun) PyMem_Free, (nextfun) OptionsIterNext, | |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
3501 NULL, NULL, (PyObject *)self); |
5610 | 3502 } |
3503 | |
3504 static int | |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3505 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
|
3506 { |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3507 char *errmsg; |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3508 |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3509 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
|
3510 { |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3511 if (VimTryEnd()) |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3512 return FAIL; |
15472
0fcc1315c061
patch 8.1.0744: compiler warnings for signed/unsigned strings
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3513 PyErr_SetVim(errmsg); |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3514 return FAIL; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3515 } |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3516 return OK; |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3517 } |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3518 |
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3519 static int |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3520 set_option_value_for( |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3521 char_u *key, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3522 int numval, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3523 char_u *stringval, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3524 int opt_flags, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3525 int opt_type, |
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
3526 void *from) |
4350 | 3527 { |
4509
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3528 win_T *save_curwin = NULL; |
b498224f5b41
updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents:
4500
diff
changeset
|
3529 tabpage_T *save_curtab = NULL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
3530 bufref_T save_curbuf; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3531 int set_ret = 0; |
4498 | 3532 |
3533 VimTryStart(); | |
4350 | 3534 switch (opt_type) |
3535 { | |
3536 case SREQ_WIN: | |
4429 | 3537 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
|
3538 win_find_tabpage((win_T *)from), FALSE) == FAIL) |
4350 | 3539 { |
6454 | 3540 restore_win(save_curwin, save_curtab, TRUE); |
4498 | 3541 if (VimTryEnd()) |
3542 return -1; | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3543 PyErr_SET_VIM(N_("problem while switching windows")); |
4350 | 3544 return -1; |
3545 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3546 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
|
3547 restore_win(save_curwin, save_curtab, TRUE); |
4350 | 3548 break; |
3549 case SREQ_BUF: | |
4429 | 3550 switch_buffer(&save_curbuf, (buf_T *)from); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3551 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
|
3552 restore_buffer(&save_curbuf); |
4350 | 3553 break; |
3554 case SREQ_GLOBAL: | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3555 set_ret = set_option_value_err(key, numval, stringval, opt_flags); |
4350 | 3556 break; |
3557 } | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3558 if (set_ret == FAIL) |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3559 return -1; |
4498 | 3560 return VimTryEnd(); |
4350 | 3561 } |
3562 | |
3563 static int | |
4488 | 3564 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject) |
4350 | 3565 { |
3566 char_u *key; | |
3567 int flags; | |
3568 int opt_flags; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3569 int ret = 0; |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3570 PyObject *todecref; |
4350 | 3571 |
21198
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
3572 if (self->Check(self->fromObj)) |
4350 | 3573 return -1; |
3574 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3575 if (!(key = StringToChars(keyObject, &todecref))) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3576 return -1; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3577 |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3578 if (*key == NUL) |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3579 { |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3580 RAISE_NO_EMPTY_KEYS; |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
3581 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3582 return -1; |
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3583 } |
4350 | 3584 |
3585 flags = get_option_value_strict(key, NULL, NULL, | |
4488 | 3586 self->opt_type, self->from); |
4350 | 3587 |
3588 if (flags == 0) | |
3589 { | |
4403 | 3590 PyErr_SetObject(PyExc_KeyError, keyObject); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3591 Py_XDECREF(todecref); |
4350 | 3592 return -1; |
3593 } | |
3594 | |
3595 if (valObject == NULL) | |
3596 { | |
4488 | 3597 if (self->opt_type == SREQ_GLOBAL) |
4350 | 3598 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
3599 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3600 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
|
3601 Py_XDECREF(todecref); |
4350 | 3602 return -1; |
3603 } | |
3604 else if (!(flags & SOPT_GLOBAL)) | |
3605 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
3606 PyErr_FORMAT(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3607 N_("unable to unset option %s " |
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3608 "which does not have global value"), key); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3609 Py_XDECREF(todecref); |
4350 | 3610 return -1; |
3611 } | |
3612 else | |
3613 { | |
4488 | 3614 unset_global_local_option(key, self->from); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3615 Py_XDECREF(todecref); |
4350 | 3616 return 0; |
3617 } | |
3618 } | |
3619 | |
4488 | 3620 opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL); |
4350 | 3621 |
3622 if (flags & SOPT_BOOL) | |
3623 { | |
4411 | 3624 int istrue = PyObject_IsTrue(valObject); |
4513
cadb57fbb781
updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents:
4511
diff
changeset
|
3625 |
4411 | 3626 if (istrue == -1) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3627 ret = -1; |
4587
63c9b681c3db
updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents:
4575
diff
changeset
|
3628 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3629 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
|
3630 opt_flags, self->opt_type, self->from); |
4350 | 3631 } |
3632 else if (flags & SOPT_NUM) | |
3633 { | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3634 long val; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3635 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
3636 if (NumberToLong(valObject, &val, NUMBER_INT)) |
4350 | 3637 { |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3638 Py_XDECREF(todecref); |
4350 | 3639 return -1; |
3640 } | |
3641 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3642 ret = set_option_value_for(key, (int) val, NULL, opt_flags, |
4488 | 3643 self->opt_type, self->from); |
4350 | 3644 } |
3645 else | |
3646 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3647 char_u *val; |
5525 | 3648 PyObject *todecref2; |
3649 | |
3650 if ((val = StringToChars(valObject, &todecref2))) | |
3651 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3652 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
|
3653 self->opt_type, self->from); |
5525 | 3654 Py_XDECREF(todecref2); |
3655 } | |
4350 | 3656 else |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3657 ret = -1; |
4350 | 3658 } |
3659 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
3660 Py_XDECREF(todecref); |
4587
63c9b681c3db
updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents:
4575
diff
changeset
|
3661 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3662 return ret; |
4350 | 3663 } |
3664 | |
5610 | 3665 static PySequenceMethods OptionsAsSeq = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3666 0, // sq_length |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3667 0, // sq_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3668 0, // sq_repeat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3669 0, // sq_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3670 0, // sq_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3671 0, // sq_ass_item |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3672 0, // sq_ass_slice |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3673 (objobjproc) OptionsContains, // sq_contains |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3674 0, // sq_inplace_concat |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3675 0, // sq_inplace_repeat |
5610 | 3676 }; |
3677 | |
4350 | 3678 static PyMappingMethods OptionsAsMapping = { |
3679 (lenfunc) NULL, | |
3680 (binaryfunc) OptionsItem, | |
3681 (objobjargproc) OptionsAssItem, | |
3682 }; | |
3683 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3684 // Tabpage object |
4401 | 3685 |
3686 typedef struct | |
3687 { | |
3688 PyObject_HEAD | |
3689 tabpage_T *tab; | |
3690 } TabPageObject; | |
3691 | |
3692 static PyObject *WinListNew(TabPageObject *tabObject); | |
3693 | |
3694 static PyTypeObject TabPageType; | |
3695 | |
3696 static int | |
4488 | 3697 CheckTabPage(TabPageObject *self) |
4401 | 3698 { |
4488 | 3699 if (self->tab == INVALID_TABPAGE_VALUE) |
4401 | 3700 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3701 PyErr_SET_VIM(N_("attempt to refer to deleted tab page")); |
4401 | 3702 return -1; |
3703 } | |
3704 | |
3705 return 0; | |
3706 } | |
3707 | |
3708 static PyObject * | |
3709 TabPageNew(tabpage_T *tab) | |
3710 { | |
3711 TabPageObject *self; | |
3712 | |
3713 if (TAB_PYTHON_REF(tab)) | |
3714 { | |
3715 self = TAB_PYTHON_REF(tab); | |
3716 Py_INCREF(self); | |
3717 } | |
3718 else | |
3719 { | |
3720 self = PyObject_NEW(TabPageObject, &TabPageType); | |
3721 if (self == NULL) | |
3722 return NULL; | |
3723 self->tab = tab; | |
3724 TAB_PYTHON_REF(tab) = self; | |
3725 } | |
3726 | |
3727 return (PyObject *)(self); | |
3728 } | |
3729 | |
3730 static void | |
4488 | 3731 TabPageDestructor(TabPageObject *self) |
4401 | 3732 { |
4488 | 3733 if (self->tab && self->tab != INVALID_TABPAGE_VALUE) |
3734 TAB_PYTHON_REF(self->tab) = NULL; | |
4401 | 3735 |
3736 DESTRUCTOR_FINISH(self); | |
3737 } | |
3738 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3739 static char *TabPageAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3740 "windows", "number", "vars", "window", "valid", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3741 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3742 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3743 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3744 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3745 TabPageDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3746 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3747 return ObjectDir(self, TabPageAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3748 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3749 |
4401 | 3750 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3751 TabPageAttrValid(TabPageObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3752 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3753 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3754 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3755 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3756 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3757 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3758 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
|
3759 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3760 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3761 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3762 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3763 static PyObject * |
4488 | 3764 TabPageAttr(TabPageObject *self, char *name) |
4401 | 3765 { |
3766 if (strcmp(name, "windows") == 0) | |
4488 | 3767 return WinListNew(self); |
4401 | 3768 else if (strcmp(name, "number") == 0) |
4488 | 3769 return PyLong_FromLong((long) get_tab_number(self->tab)); |
4401 | 3770 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
3771 return NEW_DICTIONARY(self->tab->tp_vars); |
4401 | 3772 else if (strcmp(name, "window") == 0) |
3773 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3774 // For current tab window.c does not bother to set or update tp_curwin |
4488 | 3775 if (self->tab == curtab) |
4431 | 3776 return WindowNew(curwin, curtab); |
4401 | 3777 else |
4488 | 3778 return WindowNew(self->tab->tp_curwin, self->tab); |
4401 | 3779 } |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3780 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3781 return ObjectDir(NULL, TabPageAttrs); |
4401 | 3782 return NULL; |
3783 } | |
3784 | |
3785 static PyObject * | |
4488 | 3786 TabPageRepr(TabPageObject *self) |
4401 | 3787 { |
4488 | 3788 if (self->tab == INVALID_TABPAGE_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3789 return PyString_FromFormat("<tabpage object (deleted) at %p>", (self)); |
4401 | 3790 else |
3791 { | |
4488 | 3792 int t = get_tab_number(self->tab); |
4401 | 3793 |
3794 if (t == 0) | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3795 return PyString_FromFormat("<tabpage object (unknown) at %p>", |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3796 (self)); |
4401 | 3797 else |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
3798 return PyString_FromFormat("<tabpage %d>", t - 1); |
4401 | 3799 } |
3800 } | |
3801 | |
3802 static struct PyMethodDef TabPageMethods[] = { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3803 // name, function, calling, documentation |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3804 {"__dir__", (PyCFunction)TabPageDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3805 { NULL, NULL, 0, NULL} |
4401 | 3806 }; |
3807 | |
3808 /* | |
3809 * Window list object | |
3810 */ | |
3811 | |
3812 static PyTypeObject TabListType; | |
3813 static PySequenceMethods TabListAsSeq; | |
3814 | |
3815 typedef struct | |
3816 { | |
3817 PyObject_HEAD | |
3818 } TabListObject; | |
3819 | |
3820 static PyInt | |
3821 TabListLength(PyObject *self UNUSED) | |
3822 { | |
3823 tabpage_T *tp = first_tabpage; | |
3824 PyInt n = 0; | |
3825 | |
3826 while (tp != NULL) | |
3827 { | |
3828 ++n; | |
3829 tp = tp->tp_next; | |
3830 } | |
3831 | |
3832 return n; | |
3833 } | |
3834 | |
3835 static PyObject * | |
3836 TabListItem(PyObject *self UNUSED, PyInt n) | |
3837 { | |
3838 tabpage_T *tp; | |
3839 | |
3840 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, --n) | |
3841 if (n == 0) | |
3842 return TabPageNew(tp); | |
3843 | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3844 PyErr_SET_STRING(PyExc_IndexError, N_("no such tab page")); |
4401 | 3845 return NULL; |
3846 } | |
3847 | |
4962
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
3848 /* |
b34d719b13cd
updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents:
4922
diff
changeset
|
3849 * Window object |
4385 | 3850 */ |
3851 | |
3852 typedef struct | |
3853 { | |
3854 PyObject_HEAD | |
3855 win_T *win; | |
4431 | 3856 TabPageObject *tabObject; |
4385 | 3857 } WindowObject; |
3858 | |
3859 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
|
3860 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3861 static int |
4488 | 3862 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
|
3863 { |
4488 | 3864 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
|
3865 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
3866 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
|
3867 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3868 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3869 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3870 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3871 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
3872 |
4319 | 3873 static PyObject * |
4431 | 3874 WindowNew(win_T *win, tabpage_T *tab) |
4377 | 3875 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3876 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3877 * We need to handle deletion of windows underneath us. |
4377 | 3878 * If we add a "w_python*_ref" field to the win_T structure, |
3879 * then we can get at it in win_free() in vim. We then | |
3880 * need to create only ONE Python object per window - if | |
3881 * we try to create a second, just INCREF the existing one | |
3882 * and return it. The (single) Python object referring to | |
3883 * the window is stored in "w_python*_ref". | |
3884 * On a win_free() we set the Python object's win_T* field | |
3885 * to an invalid value. We trap all uses of a window | |
3886 * object, and reject them if the win_T* field is invalid. | |
3887 * | |
4385 | 3888 * Python2 and Python3 get different fields and different objects: |
4377 | 3889 * w_python_ref and w_python3_ref fields respectively. |
3890 */ | |
3891 | |
3892 WindowObject *self; | |
3893 | |
3894 if (WIN_PYTHON_REF(win)) | |
3895 { | |
3896 self = WIN_PYTHON_REF(win); | |
3897 Py_INCREF(self); | |
3898 } | |
3899 else | |
3900 { | |
4500 | 3901 self = PyObject_GC_New(WindowObject, &WindowType); |
4377 | 3902 if (self == NULL) |
3903 return NULL; | |
3904 self->win = win; | |
3905 WIN_PYTHON_REF(win) = self; | |
3906 } | |
3907 | |
4431 | 3908 self->tabObject = ((TabPageObject *)(TabPageNew(tab))); |
3909 | |
4377 | 3910 return (PyObject *)(self); |
3911 } | |
3912 | |
4385 | 3913 static void |
4488 | 3914 WindowDestructor(WindowObject *self) |
4385 | 3915 { |
4500 | 3916 PyObject_GC_UnTrack((void *)(self)); |
4488 | 3917 if (self->win && self->win != INVALID_WINDOW_VALUE) |
3918 WIN_PYTHON_REF(self->win) = NULL; | |
21190
10eb6c38938c
patch 8.2.1146: not enough testing for Python
Bram Moolenaar <Bram@vim.org>
parents:
21083
diff
changeset
|
3919 Py_XDECREF(((PyObject *)(self->tabObject))); |
4500 | 3920 PyObject_GC_Del((void *)(self)); |
3921 } | |
3922 | |
3923 static int | |
3924 WindowTraverse(WindowObject *self, visitproc visit, void *arg) | |
3925 { | |
3926 Py_VISIT(((PyObject *)(self->tabObject))); | |
3927 return 0; | |
3928 } | |
3929 | |
3930 static int | |
3931 WindowClear(WindowObject *self) | |
3932 { | |
3933 Py_CLEAR(self->tabObject); | |
3934 return 0; | |
4385 | 3935 } |
3936 | |
4431 | 3937 static win_T * |
3938 get_firstwin(TabPageObject *tabObject) | |
3939 { | |
3940 if (tabObject) | |
3941 { | |
3942 if (CheckTabPage(tabObject)) | |
3943 return NULL; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
3944 // For current tab window.c does not bother to set or update tp_firstwin |
4431 | 3945 else if (tabObject->tab == curtab) |
3946 return firstwin; | |
3947 else | |
3948 return tabObject->tab->tp_firstwin; | |
3949 } | |
3950 else | |
3951 return firstwin; | |
3952 } | |
14047
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3953 |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3954 // 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
|
3955 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
|
3956 "buffer", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3957 "cursor", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3958 "height", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3959 "row", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3960 "width", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3961 "col", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3962 "vars", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3963 "options", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3964 "number", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3965 "tabpage", |
30a0068f6167
patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents:
13952
diff
changeset
|
3966 "valid", |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3967 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3968 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3969 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3970 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3971 WindowDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3972 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3973 return ObjectDir(self, WindowAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
3974 } |
4431 | 3975 |
4377 | 3976 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3977 WindowAttrValid(WindowObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3978 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3979 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3980 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3981 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3982 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3983 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3984 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
|
3985 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
3986 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3987 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3988 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3989 static PyObject * |
4488 | 3990 WindowAttr(WindowObject *self, char *name) |
4319 | 3991 { |
3992 if (strcmp(name, "buffer") == 0) | |
4488 | 3993 return (PyObject *)BufferNew(self->win->w_buffer); |
4319 | 3994 else if (strcmp(name, "cursor") == 0) |
3995 { | |
4488 | 3996 pos_T *pos = &self->win->w_cursor; |
4319 | 3997 |
3998 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col)); | |
3999 } | |
4000 else if (strcmp(name, "height") == 0) | |
4488 | 4001 return PyLong_FromLong((long)(self->win->w_height)); |
4383 | 4002 else if (strcmp(name, "row") == 0) |
4488 | 4003 return PyLong_FromLong((long)(self->win->w_winrow)); |
4319 | 4004 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
|
4005 return PyLong_FromLong((long)(self->win->w_width)); |
4383 | 4006 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
|
4007 return PyLong_FromLong((long)(self->win->w_wincol)); |
4323 | 4008 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
4009 return NEW_DICTIONARY(self->win->w_vars); |
4350 | 4010 else if (strcmp(name, "options") == 0) |
4488 | 4011 return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow, |
4012 (PyObject *) self); | |
4379 | 4013 else if (strcmp(name, "number") == 0) |
4431 | 4014 { |
4488 | 4015 if (CheckTabPage(self->tabObject)) |
4431 | 4016 return NULL; |
4017 return PyLong_FromLong((long) | |
4488 | 4018 get_win_number(self->win, get_firstwin(self->tabObject))); |
4431 | 4019 } |
4020 else if (strcmp(name, "tabpage") == 0) | |
4021 { | |
4488 | 4022 Py_INCREF(self->tabObject); |
4023 return (PyObject *)(self->tabObject); | |
4431 | 4024 } |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4025 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4026 return ObjectDir(NULL, WindowAttrs); |
4319 | 4027 else |
4028 return NULL; | |
4029 } | |
4030 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4031 static int |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4032 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
|
4033 { |
4488 | 4034 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
|
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 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
|
4038 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4039 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
|
4040 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4041 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4042 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
|
4043 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4044 long lnum; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4045 long col; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4046 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4047 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
|
4048 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4049 |
4488 | 4050 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
|
4051 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4052 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
|
4053 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4054 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4055 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4056 // Check for keyboard interrupts |
4498 | 4057 if (VimCheckInterrupt()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4058 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4059 |
4488 | 4060 self->win->w_cursor.lnum = lnum; |
4061 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
|
4062 self->win->w_set_curswant = TRUE; |
4488 | 4063 self->win->w_cursor.coladd = 0; |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4064 // When column is out of range silently correct it. |
4488 | 4065 check_cursor_col_win(self->win); |
2933 | 4066 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4067 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4068 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4069 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4070 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
|
4071 { |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4072 long height; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4073 win_T *savewin; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4074 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4075 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
|
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 #ifdef FEAT_GUI |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4079 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
|
4080 #endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4081 savewin = curwin; |
4488 | 4082 curwin = self->win; |
4498 | 4083 |
4084 VimTryStart(); | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4085 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
|
4086 curwin = savewin; |
4498 | 4087 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4088 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4089 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4090 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4091 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4092 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
|
4093 { |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4094 long width; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4095 win_T *savewin; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4096 |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4097 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
|
4098 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4099 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4100 #ifdef FEAT_GUI |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4101 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
|
4102 #endif |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4103 savewin = curwin; |
4488 | 4104 curwin = self->win; |
4498 | 4105 |
4106 VimTryStart(); | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
4107 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
|
4108 curwin = savewin; |
4498 | 4109 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4110 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4111 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4112 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4113 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4114 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4115 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4116 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
|
4117 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4118 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4119 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4120 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4121 static PyObject * |
4488 | 4122 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
|
4123 { |
4488 | 4124 if (self->win == INVALID_WINDOW_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4125 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
|
4126 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4127 { |
4488 | 4128 int w = get_win_number(self->win, firstwin); |
4379 | 4129 |
4130 if (w == 0) | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4131 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
|
4132 (self)); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4133 else |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
4134 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
|
4135 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4136 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4137 |
4385 | 4138 static struct PyMethodDef WindowMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4139 // name, function, calling, documentation |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4140 {"__dir__", (PyCFunction)WindowDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
4141 { NULL, NULL, 0, NULL} |
4385 | 4142 }; |
4143 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4144 /* |
4385 | 4145 * 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
|
4146 */ |
4319 | 4147 |
4385 | 4148 static PyTypeObject WinListType; |
4149 static PySequenceMethods WinListAsSeq; | |
4150 | |
4319 | 4151 typedef struct |
4152 { | |
4153 PyObject_HEAD | |
4401 | 4154 TabPageObject *tabObject; |
4319 | 4155 } WinListObject; |
4156 | |
4401 | 4157 static PyObject * |
4158 WinListNew(TabPageObject *tabObject) | |
4159 { | |
4160 WinListObject *self; | |
4161 | |
4162 self = PyObject_NEW(WinListObject, &WinListType); | |
4163 self->tabObject = tabObject; | |
4164 Py_INCREF(tabObject); | |
4165 | |
4166 return (PyObject *)(self); | |
4167 } | |
4168 | |
4169 static void | |
4488 | 4170 WinListDestructor(WinListObject *self) |
4401 | 4171 { |
4488 | 4172 TabPageObject *tabObject = self->tabObject; |
4401 | 4173 |
4174 if (tabObject) | |
4523
57393dc4b811
updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents:
4513
diff
changeset
|
4175 { |
4401 | 4176 Py_DECREF((PyObject *)(tabObject)); |
4523
57393dc4b811
updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents:
4513
diff
changeset
|
4177 } |
4401 | 4178 |
4179 DESTRUCTOR_FINISH(self); | |
4180 } | |
4181 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4182 static PyInt |
4488 | 4183 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
|
4184 { |
4401 | 4185 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
|
4186 PyInt n = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4187 |
4488 | 4188 if (!(w = get_firstwin(self->tabObject))) |
4401 | 4189 return -1; |
4190 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4191 while (w != NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4192 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4193 ++n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4194 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
|
4195 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4196 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4197 return n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4198 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4199 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4200 static PyObject * |
4488 | 4201 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
|
4202 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4203 win_T *w; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4204 |
4488 | 4205 if (!(w = get_firstwin(self->tabObject))) |
4401 | 4206 return NULL; |
4207 | |
4208 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
|
4209 if (n == 0) |
4488 | 4210 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
|
4211 |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4212 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
|
4213 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4214 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4215 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4216 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4217 * Convert a Python string into a Vim line. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4218 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4219 * 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
|
4220 * 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
|
4221 * characters. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4222 * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4223 * 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
|
4224 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4225 static char * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4226 StringToLine(PyObject *obj) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4227 { |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4228 char *str; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4229 char *save; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4230 PyObject *bytes = NULL; |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
4231 Py_ssize_t len = 0; |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4232 PyInt i; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4233 char *p; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4234 |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4235 if (PyBytes_Check(obj)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4236 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4237 if (PyBytes_AsStringAndSize(obj, &str, &len) == -1 |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4238 || str == NULL) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4239 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4240 } |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4241 else if (PyUnicode_Check(obj)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4242 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4243 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4244 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4245 |
4995
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4246 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1 |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4247 || str == NULL) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4248 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4249 Py_DECREF(bytes); |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4250 return NULL; |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4251 } |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4252 } |
4995
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4253 else |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4254 { |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4255 #if PY_MAJOR_VERSION < 3 |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4256 PyErr_FORMAT(PyExc_TypeError, |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4257 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
|
4258 Py_TYPE_NAME(obj)); |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4259 #else |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4260 PyErr_FORMAT(PyExc_TypeError, |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4261 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
|
4262 Py_TYPE_NAME(obj)); |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4263 #endif |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4264 return NULL; |
b4a2eaf28b51
updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents:
4988
diff
changeset
|
4265 } |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4266 |
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 * 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
|
4269 * 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
|
4270 * a single line. |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4271 * 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
|
4272 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4273 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
|
4274 if (p != NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4275 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4276 if (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
|
4277 --len; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4278 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4279 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4280 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
|
4281 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
|
4282 return NULL; |
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 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4285 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4286 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4287 * Create a copy of the string, with internal nulls replaced by |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
4288 * newline characters, as is the Vim convention. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4289 */ |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4290 save = alloc(len+1); |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4291 if (save == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4292 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4293 PyErr_NoMemory(); |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
4294 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
|
4295 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4296 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4297 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4298 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
|
4299 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4300 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
|
4301 save[i] = '\n'; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4302 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4303 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
|
4304 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4305 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4306 save[i] = '\0'; |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4307 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
|
4308 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4309 return save; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4310 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4311 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4312 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4313 * Get a line from the specified buffer. The line number is |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4314 * 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
|
4315 * string object. |
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 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4318 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
|
4319 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4320 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
|
4321 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4322 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4323 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4324 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4325 * Get a list of lines from the specified buffer. The line numbers |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4326 * 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
|
4327 * 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
|
4328 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4329 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4330 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
|
4331 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4332 PyInt i; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4333 PyInt n = hi - lo; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4334 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
|
4335 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4336 if (list == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4337 return NULL; |
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 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
|
4340 { |
21198
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4341 linenr_T lnum = (linenr_T)(lo + i); |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4342 char *text; |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4343 PyObject *string; |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4344 |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4345 if (lnum > buf->b_ml.ml_line_count) |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4346 text = ""; |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4347 else |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4348 text = (char *)ml_get_buf(buf, lnum, FALSE); |
8531ddd7dd63
patch 8.2.1150: ml_get error when using Python
Bram Moolenaar <Bram@vim.org>
parents:
21190
diff
changeset
|
4349 string = LineToString(text); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4350 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
|
4351 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4352 Py_DECREF(list); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4353 return NULL; |
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 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4356 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
|
4357 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4358 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4359 // The ownership of the Python list is passed to the caller (ie, |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4360 // the caller should Py_DECREF() the object when it is finished |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4361 // with it). |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4362 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4363 return list; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4364 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4365 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4366 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4367 * 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
|
4368 * 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
|
4369 * deleted). |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4370 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4371 static void |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4372 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
|
4373 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4374 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
|
4375 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4376 // Adjust the cursor position if it's in/after the changed |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4377 // lines. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4378 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
|
4379 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4380 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
|
4381 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4382 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4383 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
|
4384 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4385 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
|
4386 check_cursor(); |
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 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4389 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4390 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
|
4391 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4392 invalidate_botline(); |
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 |
2894 | 4395 /* |
4396 * 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
|
4397 * 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
|
4398 * 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
|
4399 * 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
|
4400 * 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
|
4401 * 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
|
4402 * 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
|
4403 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4404 static int |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4405 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
|
4406 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4407 bufref_T save_curbuf = {NULL, 0, 0}; |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4408 win_T *save_curwin = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4409 tabpage_T *save_curtab = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4410 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4411 // First of all, we check the type of the supplied Python object. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4412 // There are three cases: |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4413 // 1. NULL, or None - this is a deletion. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4414 // 2. A string - this is a replacement. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4415 // 3. Anything else - this is an error. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4416 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
|
4417 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4418 PyErr_Clear(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4419 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
|
4420 |
4498 | 4421 VimTryStart(); |
4422 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4423 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
|
4424 RAISE_UNDO_FAIL; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
4425 else if (ml_delete((linenr_T)n) == FAIL) |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4426 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
|
4427 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4428 { |
16080
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4429 if (buf == curbuf && (save_curwin != NULL |
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4430 || save_curbuf.br_buf == NULL)) |
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4431 // Using an existing window for the buffer, adjust the cursor |
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4432 // position. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4433 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
|
4434 if (save_curbuf.br_buf == NULL) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4435 // Only adjust marks if we managed to switch to a window that |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4436 // holds the buffer, otherwise line numbers will be invalid. |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4437 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
|
4438 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4439 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4440 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
|
4441 |
4498 | 4442 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4443 return FAIL; |
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 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4446 *len_change = -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4447 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4448 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4449 } |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4450 else if (PyBytes_Check(line) || PyUnicode_Check(line)) |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4451 { |
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4452 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
|
4453 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4454 if (save == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4455 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4456 |
4498 | 4457 VimTryStart(); |
4458 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4459 // We do not need to free "save" if ml_replace() consumes it. |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4460 PyErr_Clear(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4461 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
|
4462 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4463 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
|
4464 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
4465 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
|
4466 vim_free(save); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4467 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4468 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
|
4469 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4470 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
|
4471 vim_free(save); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4472 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4473 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4474 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
|
4475 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4476 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
|
4477 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4478 // 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
|
4479 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
|
4480 check_cursor_col(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4481 |
4498 | 4482 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4483 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4484 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4485 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4486 *len_change = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4487 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4488 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4489 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4490 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4491 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4492 PyErr_BadArgument(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4493 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4494 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4495 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4496 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4497 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4498 * Replace a range of lines in the specified buffer. The line numbers are in |
2894 | 4499 * Vim format (1-based). The range is from lo up to, but not including, hi. |
4500 * The replacement lines are given as a Python list of string objects. The | |
4501 * list is checked for validity and correct format. Errors are returned as a | |
4502 * value of FAIL. The return value is OK on success. | |
4503 * If OK is returned and len_change is not NULL, *len_change | |
4504 * is set to the change in the buffer length. | |
4505 */ | |
4506 static int | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4507 SetBufferLineList( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4508 buf_T *buf, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4509 PyInt lo, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4510 PyInt hi, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4511 PyObject *list, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4512 PyInt *len_change) |
2894 | 4513 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4514 bufref_T save_curbuf = {NULL, 0, 0}; |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4515 win_T *save_curwin = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4516 tabpage_T *save_curtab = NULL; |
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4517 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4518 // First of all, we check the type of the supplied Python object. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4519 // There are three cases: |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4520 // 1. NULL, or None - this is a deletion. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4521 // 2. A list - this is a replacement. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4522 // 3. Anything else - this is an error. |
2894 | 4523 if (list == Py_None || list == NULL) |
4524 { | |
4525 PyInt i; | |
4526 PyInt n = (int)(hi - lo); | |
4527 | |
4528 PyErr_Clear(); | |
4498 | 4529 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4530 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2894 | 4531 |
4532 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
|
4533 RAISE_UNDO_FAIL; |
2894 | 4534 else |
4535 { | |
4536 for (i = 0; i < n; ++i) | |
4537 { | |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
4538 if (ml_delete((linenr_T)lo) == FAIL) |
2894 | 4539 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4540 RAISE_DELETE_LINE_FAIL; |
2894 | 4541 break; |
4542 } | |
4543 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4544 if (buf == curbuf && (save_curwin != NULL |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4545 || save_curbuf.br_buf == NULL)) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4546 // Using an existing window for the buffer, adjust the cursor |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4547 // position. |
2894 | 4548 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
|
4549 if (save_curbuf.br_buf == NULL) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4550 // Only adjust marks if we managed to switch to a window that |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4551 // holds the buffer, otherwise line numbers will be invalid. |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4552 deleted_lines_mark((linenr_T)lo, (long)i); |
2894 | 4553 } |
4554 | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4555 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2894 | 4556 |
4498 | 4557 if (VimTryEnd()) |
2894 | 4558 return FAIL; |
4559 | |
4560 if (len_change) | |
4561 *len_change = -n; | |
4562 | |
4563 return OK; | |
4564 } | |
4565 else if (PyList_Check(list)) | |
4566 { | |
4567 PyInt i; | |
4568 PyInt new_len = PyList_Size(list); | |
4569 PyInt old_len = hi - lo; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4570 PyInt extra = 0; // lines added to text, can be negative |
2894 | 4571 char **array; |
4572 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4573 if (new_len == 0) // avoid allocating zero bytes |
2894 | 4574 array = NULL; |
4575 else | |
4576 { | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4577 array = PyMem_New(char *, new_len); |
2894 | 4578 if (array == NULL) |
4579 { | |
4580 PyErr_NoMemory(); | |
4581 return FAIL; | |
4582 } | |
4583 } | |
4584 | |
4585 for (i = 0; i < new_len; ++i) | |
4586 { | |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4587 PyObject *line; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4588 |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4589 if (!(line = PyList_GetItem(list, i)) || |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4590 !(array[i] = StringToLine(line))) |
2894 | 4591 { |
4592 while (i) | |
4593 vim_free(array[--i]); | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4594 PyMem_Free(array); |
2894 | 4595 return FAIL; |
4596 } | |
4597 } | |
4598 | |
4498 | 4599 VimTryStart(); |
2894 | 4600 PyErr_Clear(); |
4429 | 4601 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4602 // 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
|
4603 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); |
2894 | 4604 |
4605 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
|
4606 RAISE_UNDO_FAIL; |
2894 | 4607 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4608 // If the size of the range is reducing (ie, new_len < old_len) we |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4609 // need to delete some old_len. We do this at the start, by |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4610 // repeatedly deleting line "lo". |
2894 | 4611 if (!PyErr_Occurred()) |
4612 { | |
4613 for (i = 0; i < old_len - new_len; ++i) | |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
4614 if (ml_delete((linenr_T)lo) == FAIL) |
2894 | 4615 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4616 RAISE_DELETE_LINE_FAIL; |
2894 | 4617 break; |
4618 } | |
4619 extra -= i; | |
4620 } | |
4621 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4622 // For as long as possible, replace the existing old_len with the |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4623 // new old_len. This is a more efficient operation, as it requires |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4624 // less memory allocation and freeing. |
2894 | 4625 if (!PyErr_Occurred()) |
4626 { | |
4627 for (i = 0; i < old_len && i < new_len; ++i) | |
4628 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE) | |
4629 == FAIL) | |
4630 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4631 RAISE_REPLACE_LINE_FAIL; |
2894 | 4632 break; |
4633 } | |
4634 } | |
4635 else | |
4636 i = 0; | |
4637 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4638 // Now we may need to insert the remaining new old_len. If we do, we |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4639 // must free the strings as we finish with them (we can't pass the |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
4640 // responsibility to Vim in this case). |
2894 | 4641 if (!PyErr_Occurred()) |
4642 { | |
4643 while (i < new_len) | |
4644 { | |
4645 if (ml_append((linenr_T)(lo + i - 1), | |
4646 (char_u *)array[i], 0, FALSE) == FAIL) | |
4647 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4648 RAISE_INSERT_LINE_FAIL; |
2894 | 4649 break; |
4650 } | |
4651 vim_free(array[i]); | |
4652 ++i; | |
4653 ++extra; | |
4654 } | |
4655 } | |
4656 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4657 // Free any left-over old_len, as a result of an error |
2894 | 4658 while (i < new_len) |
4659 { | |
4660 vim_free(array[i]); | |
4661 ++i; | |
4662 } | |
4663 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4664 // Free the array of old_len. All of its contents have now |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4665 // been dealt with (either freed, or the responsibility passed |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4666 // to vim. |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4667 PyMem_Free(array); |
2894 | 4668 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4669 // Adjust marks. Invalidate any which lie in the |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4670 // changed range, and move any in the remainder of the buffer. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4671 // Only adjust marks if we managed to switch to a window that holds |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4672 // 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
|
4673 if (save_curbuf.br_buf == NULL) |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4674 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), |
2894 | 4675 (long)MAXLNUM, (long)extra); |
4676 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); | |
4677 | |
16080
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4678 if (buf == curbuf && (save_curwin != NULL |
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4679 || save_curbuf.br_buf == NULL)) |
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4680 // Using an existing window for the buffer, adjust the cursor |
bf8cf5c3b784
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
Bram Moolenaar <Bram@vim.org>
parents:
15818
diff
changeset
|
4681 // position. |
2894 | 4682 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra); |
4683 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4684 // END of region without "return". |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4685 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); |
2894 | 4686 |
4498 | 4687 if (VimTryEnd()) |
2894 | 4688 return FAIL; |
4689 | |
4690 if (len_change) | |
4691 *len_change = new_len - old_len; | |
4692 | |
4693 return OK; | |
4694 } | |
4695 else | |
4696 { | |
4697 PyErr_BadArgument(); | |
4698 return FAIL; | |
4699 } | |
4700 } | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4701 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4702 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4703 * 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
|
4704 * 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
|
4705 * 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
|
4706 * 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
|
4707 * 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
|
4708 * 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
|
4709 * 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
|
4710 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4711 static int |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4712 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
|
4713 { |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
4714 bufref_T save_curbuf = {NULL, 0, 0}; |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4715 win_T *save_curwin = NULL; |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4716 tabpage_T *save_curtab = NULL; |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4717 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4718 // First of all, we check the type of the supplied Python object. |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4719 // It must be a string or a list, or the call is in error. |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
4720 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
|
4721 { |
5202
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4722 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
|
4723 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4724 if (str == NULL) |
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 PyErr_Clear(); |
4498 | 4728 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4729 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
|
4730 |
8edba3805d78
updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents:
5166
diff
changeset
|
4731 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
|
4732 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
|
4733 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
|
4734 RAISE_INSERT_LINE_FAIL; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4735 else if (save_curbuf.br_buf == NULL) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4736 // Only adjust marks if we managed to switch to a window that |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4737 // 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
|
4738 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
|
4739 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4740 vim_free(str); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4741 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
|
4742 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4743 |
4498 | 4744 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4745 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4746 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4747 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4748 *len_change = 1; |
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 return OK; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4751 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4752 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
|
4753 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4754 PyInt i; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4755 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
|
4756 char **array; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4757 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4758 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
|
4759 if (array == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4760 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4761 PyErr_NoMemory(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4762 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4763 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4764 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4765 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
|
4766 { |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4767 PyObject *line; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4768 |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4769 if (!(line = PyList_GetItem(lines, i)) || |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
4770 !(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
|
4771 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4772 while (i) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4773 vim_free(array[--i]); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4774 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
|
4775 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4776 } |
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 PyErr_Clear(); |
4498 | 4780 VimTryStart(); |
5235
6fa64615c8d3
updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents:
5202
diff
changeset
|
4781 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
|
4782 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4783 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
|
4784 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
|
4785 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4786 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4787 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
|
4788 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4789 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
|
4790 (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
|
4791 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4792 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
|
4793 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4794 // Free the rest of the lines |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4795 while (i < size) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4796 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
|
4797 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4798 break; |
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 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
|
4801 } |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4802 if (i > 0 && save_curbuf.br_buf == NULL) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4803 // Only adjust marks if we managed to switch to a window that |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4804 // 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
|
4805 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
|
4806 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4807 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4808 // Free the array of lines. All of its contents have now |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4809 // been freed. |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
4810 PyMem_Free(array); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
4811 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
|
4812 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4813 update_screen(VALID); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4814 |
4498 | 4815 if (VimTryEnd()) |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4816 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4817 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4818 if (len_change) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4819 *len_change = size; |
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 OK; |
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 else |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4824 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4825 PyErr_BadArgument(); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4826 return FAIL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4827 } |
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4830 /* |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4831 * 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
|
4832 * ------------------------------------------- |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4833 */ |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4834 |
4385 | 4835 typedef struct |
4836 { | |
4837 PyObject_HEAD | |
4838 buf_T *buf; | |
4839 } BufferObject; | |
4840 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4841 static int |
4488 | 4842 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
|
4843 { |
4488 | 4844 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
|
4845 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4846 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
|
4847 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4848 } |
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 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4851 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4852 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4853 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4854 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
|
4855 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4856 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4857 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4858 |
4387 | 4859 if (end == -1) |
4860 end = self->buf->b_ml.ml_line_count; | |
4861 | |
4389 | 4862 if (n < 0) |
4863 n += end - start + 1; | |
4864 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4865 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
|
4866 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4867 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
|
4868 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4869 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4870 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4871 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
|
4872 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4873 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4874 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4875 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
|
4876 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4877 PyInt size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4878 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4879 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4880 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4881 |
4387 | 4882 if (end == -1) |
4883 end = self->buf->b_ml.ml_line_count; | |
4884 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4885 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
|
4886 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4887 if (lo < 0) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4888 lo = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4889 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
|
4890 lo = size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4891 if (hi < 0) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4892 hi = 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4893 if (hi < lo) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4894 hi = lo; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4895 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
|
4896 hi = size; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4897 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4898 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
|
4899 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4900 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4901 static PyInt |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4902 RBAsItem( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4903 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4904 PyInt n, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4905 PyObject *valObject, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4906 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4907 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4908 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
|
4909 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4910 PyInt len_change; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4911 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4912 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4913 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4914 |
4387 | 4915 if (end == -1) |
4916 end = self->buf->b_ml.ml_line_count; | |
4917 | |
4389 | 4918 if (n < 0) |
4919 n += end - start + 1; | |
4920 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4921 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
|
4922 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
4923 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
|
4924 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4925 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4926 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4927 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
|
4928 return -1; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4929 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4930 if (new_end) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4931 *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
|
4932 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4933 return 0; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4934 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4935 |
2894 | 4936 static PyInt |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4937 RBAsSlice( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4938 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4939 PyInt lo, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4940 PyInt hi, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4941 PyObject *valObject, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4942 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4943 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4944 PyInt *new_end) |
2894 | 4945 { |
4946 PyInt size; | |
4947 PyInt len_change; | |
4948 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4949 // Self must be a valid buffer |
2894 | 4950 if (CheckBuffer(self)) |
4951 return -1; | |
4952 | |
4387 | 4953 if (end == -1) |
4954 end = self->buf->b_ml.ml_line_count; | |
4955 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
4956 // Sort out the slice range |
2894 | 4957 size = end - start + 1; |
4958 | |
4959 if (lo < 0) | |
4960 lo = 0; | |
4961 else if (lo > size) | |
4962 lo = size; | |
4963 if (hi < 0) | |
4964 hi = 0; | |
4965 if (hi < lo) | |
4966 hi = lo; | |
4967 else if (hi > size) | |
4968 hi = size; | |
4969 | |
4970 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
|
4971 valObject, &len_change) == FAIL) |
2894 | 4972 return -1; |
4973 | |
4974 if (new_end) | |
4975 *new_end = end + len_change; | |
4976 | |
4977 return 0; | |
4978 } | |
4979 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4980 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4981 static PyObject * |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4982 RBAppend( |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4983 BufferObject *self, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4984 PyObject *args, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4985 PyInt start, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4986 PyInt end, |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
4987 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
|
4988 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4989 PyObject *lines; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4990 PyInt len_change; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4991 PyInt max; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4992 PyInt n; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4993 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4994 if (CheckBuffer(self)) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4995 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
4996 |
4387 | 4997 if (end == -1) |
4998 end = self->buf->b_ml.ml_line_count; | |
4999 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5000 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
|
5001 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5002 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
|
5003 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5004 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5005 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
|
5006 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5007 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
|
5008 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5009 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5010 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5011 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
|
5012 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5013 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5014 if (new_end) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5015 *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
|
5016 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5017 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
|
5018 return Py_None; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5019 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5020 |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5021 // Range object |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5022 |
4319 | 5023 static PyTypeObject RangeType; |
4385 | 5024 static PySequenceMethods RangeAsSeq; |
5025 static PyMappingMethods RangeAsMapping; | |
4319 | 5026 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5027 typedef struct |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5028 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5029 PyObject_HEAD |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5030 BufferObject *buf; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5031 PyInt start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5032 PyInt end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5033 } RangeObject; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5034 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5035 static PyObject * |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5036 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
|
5037 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5038 BufferObject *bufr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5039 RangeObject *self; |
4500 | 5040 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
|
5041 if (self == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5042 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5043 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5044 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
|
5045 if (bufr == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5046 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5047 Py_DECREF(self); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5048 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5049 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5050 Py_INCREF(bufr); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5051 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5052 self->buf = bufr; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5053 self->start = start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5054 self->end = end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5055 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5056 return (PyObject *)(self); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5057 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5058 |
4319 | 5059 static void |
4488 | 5060 RangeDestructor(RangeObject *self) |
4319 | 5061 { |
4500 | 5062 PyObject_GC_UnTrack((void *)(self)); |
4498 | 5063 Py_XDECREF(self->buf); |
4500 | 5064 PyObject_GC_Del((void *)(self)); |
5065 } | |
5066 | |
5067 static int | |
5068 RangeTraverse(RangeObject *self, visitproc visit, void *arg) | |
5069 { | |
5070 Py_VISIT(((PyObject *)(self->buf))); | |
5071 return 0; | |
5072 } | |
5073 | |
5074 static int | |
5075 RangeClear(RangeObject *self) | |
5076 { | |
5077 Py_CLEAR(self->buf); | |
5078 return 0; | |
4319 | 5079 } |
5080 | |
4385 | 5081 static PyInt |
4488 | 5082 RangeLength(RangeObject *self) |
4385 | 5083 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5084 // HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? |
4488 | 5085 if (CheckBuffer(self->buf)) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5086 return -1; // ??? |
4385 | 5087 |
4488 | 5088 return (self->end - self->start + 1); |
4385 | 5089 } |
5090 | |
5091 static PyObject * | |
4488 | 5092 RangeItem(RangeObject *self, PyInt n) |
4385 | 5093 { |
4488 | 5094 return RBItem(self->buf, n, self->start, self->end); |
4385 | 5095 } |
5096 | |
5097 static PyObject * | |
4488 | 5098 RangeSlice(RangeObject *self, PyInt lo, PyInt hi) |
4385 | 5099 { |
4488 | 5100 return RBSlice(self->buf, lo, hi, self->start, self->end); |
4385 | 5101 } |
5102 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5103 static char *RangeAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5104 "start", "end", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5105 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5106 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5107 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5108 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5109 RangeDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5110 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5111 return ObjectDir(self, RangeAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5112 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5113 |
4385 | 5114 static PyObject * |
4488 | 5115 RangeAppend(RangeObject *self, PyObject *args) |
4385 | 5116 { |
4488 | 5117 return RBAppend(self->buf, args, self->start, self->end, &self->end); |
4385 | 5118 } |
5119 | |
5120 static PyObject * | |
4488 | 5121 RangeRepr(RangeObject *self) |
4385 | 5122 { |
4488 | 5123 if (self->buf->buf == INVALID_BUFFER_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5124 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
|
5125 (self)); |
4385 | 5126 else |
5127 { | |
4488 | 5128 char *name = (char *)self->buf->buf->b_fname; |
4385 | 5129 |
5130 if (name == NULL) | |
5131 name = ""; | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5132 |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5133 return PyString_FromFormat("<range %s (%d:%d)>", |
4653
b943fd24c351
updated for version 7.3.1074
Bram Moolenaar <bram@vim.org>
parents:
4645
diff
changeset
|
5134 name, (int)self->start, (int)self->end); |
4385 | 5135 } |
5136 } | |
5137 | |
5138 static struct PyMethodDef RangeMethods[] = { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5139 // name, function, calling, documentation |
4492 | 5140 {"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
|
5141 {"__dir__", (PyCFunction)RangeDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5142 { NULL, NULL, 0, NULL} |
4385 | 5143 }; |
5144 | |
4319 | 5145 static PyTypeObject BufferType; |
5146 static PySequenceMethods BufferAsSeq; | |
5147 static PyMappingMethods BufferAsMapping; | |
5148 | |
5149 static PyObject * | |
4377 | 5150 BufferNew(buf_T *buf) |
5151 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5152 /* |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5153 * We need to handle deletion of buffers underneath us. |
4377 | 5154 * If we add a "b_python*_ref" field to the buf_T structure, |
5155 * then we can get at it in buf_freeall() in vim. We then | |
5156 * need to create only ONE Python object per buffer - if | |
5157 * we try to create a second, just INCREF the existing one | |
5158 * and return it. The (single) Python object referring to | |
5159 * the buffer is stored in "b_python*_ref". | |
5160 * Question: what to do on a buf_freeall(). We'll probably | |
5161 * have to either delete the Python object (DECREF it to | |
5162 * zero - a bad idea, as it leaves dangling refs!) or | |
5163 * set the buf_T * value to an invalid value (-1?), which | |
5164 * means we need checks in all access functions... Bah. | |
5165 * | |
4385 | 5166 * Python2 and Python3 get different fields and different objects: |
4377 | 5167 * b_python_ref and b_python3_ref fields respectively. |
5168 */ | |
5169 | |
5170 BufferObject *self; | |
5171 | |
5172 if (BUF_PYTHON_REF(buf) != NULL) | |
5173 { | |
5174 self = BUF_PYTHON_REF(buf); | |
5175 Py_INCREF(self); | |
5176 } | |
5177 else | |
5178 { | |
5179 self = PyObject_NEW(BufferObject, &BufferType); | |
5180 if (self == NULL) | |
5181 return NULL; | |
5182 self->buf = buf; | |
5183 BUF_PYTHON_REF(buf) = self; | |
5184 } | |
5185 | |
5186 return (PyObject *)(self); | |
5187 } | |
5188 | |
4385 | 5189 static void |
4488 | 5190 BufferDestructor(BufferObject *self) |
4319 | 5191 { |
4488 | 5192 if (self->buf && self->buf != INVALID_BUFFER_VALUE) |
5193 BUF_PYTHON_REF(self->buf) = NULL; | |
4385 | 5194 |
5195 DESTRUCTOR_FINISH(self); | |
4319 | 5196 } |
5197 | |
4377 | 5198 static PyInt |
4488 | 5199 BufferLength(BufferObject *self) |
4377 | 5200 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5201 // HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? |
4488 | 5202 if (CheckBuffer(self)) |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5203 return -1; // ??? |
4377 | 5204 |
4488 | 5205 return (PyInt)(self->buf->b_ml.ml_line_count); |
4377 | 5206 } |
5207 | |
5208 static PyObject * | |
4488 | 5209 BufferItem(BufferObject *self, PyInt n) |
4377 | 5210 { |
4488 | 5211 return RBItem(self, n, 1, -1); |
4377 | 5212 } |
5213 | |
5214 static PyObject * | |
4488 | 5215 BufferSlice(BufferObject *self, PyInt lo, PyInt hi) |
4377 | 5216 { |
4488 | 5217 return RBSlice(self, lo, hi, 1, -1); |
4377 | 5218 } |
5219 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5220 static char *BufferAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5221 "name", "number", "vars", "options", "valid", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5222 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5223 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5224 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5225 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5226 BufferDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5227 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5228 return ObjectDir(self, BufferAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5229 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5230 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5231 static PyObject * |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5232 BufferAttrValid(BufferObject *self, char *name) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5233 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5234 PyObject *ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5235 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5236 if (strcmp(name, "valid") != 0) |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5237 return NULL; |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5238 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5239 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
|
5240 Py_INCREF(ret); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5241 return ret; |
4593
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5242 } |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5243 |
0cf552b325b5
updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
5244 static PyObject * |
4488 | 5245 BufferAttr(BufferObject *self, char *name) |
4385 | 5246 { |
5247 if (strcmp(name, "name") == 0) | |
4597
00eecb2f8e3e
updated for version 7.3.1046
Bram Moolenaar <bram@vim.org>
parents:
4595
diff
changeset
|
5248 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
|
5249 ? "" : (char *)self->buf->b_ffname)); |
4385 | 5250 else if (strcmp(name, "number") == 0) |
4488 | 5251 return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum); |
4385 | 5252 else if (strcmp(name, "vars") == 0) |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
5253 return NEW_DICTIONARY(self->buf->b_vars); |
4385 | 5254 else if (strcmp(name, "options") == 0) |
4488 | 5255 return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer, |
5256 (PyObject *) self); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5257 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5258 return ObjectDir(NULL, BufferAttrs); |
4385 | 5259 else |
5260 return NULL; | |
5261 } | |
5262 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5263 static int |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5264 BufferSetattr(BufferObject *self, char *name, PyObject *valObject) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5265 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5266 if (CheckBuffer(self)) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5267 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5268 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5269 if (strcmp(name, "name") == 0) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5270 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5271 char_u *val; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5272 aco_save_T aco; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5273 int ren_ret; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5274 PyObject *todecref; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5275 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5276 if (!(val = StringToChars(valObject, &todecref))) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5277 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5278 |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5279 VimTryStart(); |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5280 // Using aucmd_*: autocommands will be executed by rename_buffer |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5281 aucmd_prepbuf(&aco, self->buf); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5282 ren_ret = rename_buffer(val); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5283 aucmd_restbuf(&aco); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5284 Py_XDECREF(todecref); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5285 if (VimTryEnd()) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5286 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5287 |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5288 if (ren_ret == FAIL) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5289 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5290 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
|
5291 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5292 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5293 return 0; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5294 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5295 else |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5296 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5297 PyErr_SetString(PyExc_AttributeError, name); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5298 return -1; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5299 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5300 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
5301 |
4385 | 5302 static PyObject * |
4488 | 5303 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
|
5304 { |
4488 | 5305 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
|
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 * |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5309 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
|
5310 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5311 pos_T *posp; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5312 char_u *pmark; |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5313 char_u mark; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
5314 bufref_T savebuf; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5315 PyObject *todecref; |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5316 |
4488 | 5317 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
|
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 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5320 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
|
5321 return NULL; |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5322 |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5323 if (pmark[0] == '\0' || pmark[1] != '\0') |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5324 { |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5325 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5326 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
|
5327 Py_XDECREF(todecref); |
4633
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5328 return NULL; |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5329 } |
3857d399ab41
updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents:
4631
diff
changeset
|
5330 |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5331 mark = *pmark; |
4964
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5332 |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5333 Py_XDECREF(todecref); |
5cee875f3096
updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents:
4962
diff
changeset
|
5334 |
4498 | 5335 VimTryStart(); |
4488 | 5336 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
|
5337 posp = getmark(mark, FALSE); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9161
diff
changeset
|
5338 restore_buffer(&savebuf); |
4498 | 5339 if (VimTryEnd()) |
5340 return NULL; | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5341 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5342 if (posp == NULL) |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5343 { |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5344 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
|
5345 return NULL; |
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 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5348 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
|
5349 { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5350 // Or raise an error? |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5351 Py_INCREF(Py_None); |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5352 return Py_None; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5353 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5354 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5355 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
|
5356 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5357 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5358 static PyObject * |
4488 | 5359 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
|
5360 { |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5361 PyInt start; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5362 PyInt end; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5363 |
4488 | 5364 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
|
5365 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5366 |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5367 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
|
5368 return NULL; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5369 |
4488 | 5370 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
|
5371 } |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5372 |
4319 | 5373 static PyObject * |
4488 | 5374 BufferRepr(BufferObject *self) |
4319 | 5375 { |
4488 | 5376 if (self->buf == INVALID_BUFFER_VALUE) |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5377 return PyString_FromFormat("<buffer object (deleted) at %p>", self); |
4319 | 5378 else |
5379 { | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5380 char *name = (char *)self->buf->b_fname; |
4319 | 5381 |
5382 if (name == NULL) | |
5383 name = ""; | |
4623
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5384 |
548b889fe3cf
updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents:
4619
diff
changeset
|
5385 return PyString_FromFormat("<buffer %s>", name); |
4319 | 5386 } |
5387 } | |
5388 | |
2447
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5389 static struct PyMethodDef BufferMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5390 // name, function, calling, documentation |
4492 | 5391 {"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
|
5392 {"mark", (PyCFunction)BufferMark, METH_O, "Return (row,col) representing position of named mark" }, |
4492 | 5393 {"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
|
5394 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5395 { 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
|
5396 }; |
84d353762845
Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents:
2399
diff
changeset
|
5397 |
4397 | 5398 /* |
5399 * Buffer list object - Implementation | |
5400 */ | |
5401 | |
5402 static PyTypeObject BufMapType; | |
5403 | |
5404 typedef struct | |
5405 { | |
5406 PyObject_HEAD | |
5407 } BufMapObject; | |
5408 | |
5409 static PyInt | |
5410 BufMapLength(PyObject *self UNUSED) | |
5411 { | |
5412 buf_T *b = firstbuf; | |
5413 PyInt n = 0; | |
5414 | |
5415 while (b) | |
5416 { | |
5417 ++n; | |
5418 b = b->b_next; | |
5419 } | |
5420 | |
5421 return n; | |
5422 } | |
5423 | |
5424 static PyObject * | |
5425 BufMapItem(PyObject *self UNUSED, PyObject *keyObject) | |
5426 { | |
5427 buf_T *b; | |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5428 long bnr; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5429 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5430 if (NumberToLong(keyObject, &bnr, NUMBER_INT|NUMBER_NATURAL)) |
4397 | 5431 return NULL; |
4972
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5432 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
5433 b = buflist_findnr((int) bnr); |
4397 | 5434 |
5435 if (b) | |
5436 return BufferNew(b); | |
5437 else | |
5438 { | |
4403 | 5439 PyErr_SetObject(PyExc_KeyError, keyObject); |
4397 | 5440 return NULL; |
5441 } | |
5442 } | |
5443 | |
5444 static void | |
5445 BufMapIterDestruct(PyObject *buffer) | |
5446 { | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5447 // Iteration was stopped before all buffers were processed |
4397 | 5448 if (buffer) |
5449 { | |
5450 Py_DECREF(buffer); | |
5451 } | |
5452 } | |
5453 | |
4433 | 5454 static int |
5455 BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg) | |
5456 { | |
4500 | 5457 if (buffer) |
5458 Py_VISIT(buffer); | |
4433 | 5459 return 0; |
5460 } | |
5461 | |
5462 static int | |
5463 BufMapIterClear(PyObject **buffer) | |
5464 { | |
4500 | 5465 if (*buffer) |
5466 Py_CLEAR(*buffer); | |
4433 | 5467 return 0; |
5468 } | |
5469 | |
4397 | 5470 static PyObject * |
5471 BufMapIterNext(PyObject **buffer) | |
5472 { | |
5473 PyObject *next; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5474 PyObject *ret; |
4397 | 5475 |
5476 if (!*buffer) | |
5477 return NULL; | |
5478 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5479 ret = *buffer; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5480 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5481 if (CheckBuffer((BufferObject *)(ret))) |
4397 | 5482 { |
5483 *buffer = NULL; | |
5484 return NULL; | |
5485 } | |
5486 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5487 if (!((BufferObject *)(ret))->buf->b_next) |
4397 | 5488 next = NULL; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5489 else if (!(next = BufferNew(((BufferObject *)(ret))->buf->b_next))) |
4397 | 5490 return NULL; |
5491 *buffer = next; | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5492 // Do not increment reference: we no longer hold it (decref), but whoever |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5493 // 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
|
5494 return ret; |
4397 | 5495 } |
5496 | |
5497 static PyObject * | |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
5498 BufMapIter(PyObject *self) |
4397 | 5499 { |
5500 PyObject *buffer; | |
5501 | |
5502 buffer = BufferNew(firstbuf); | |
5503 return IterNew(buffer, | |
4433 | 5504 (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext, |
21977
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
5505 (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear, |
d1a7088c6efe
patch 8.2.1538: Python: iteration over vim objects fails to keep reference
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
5506 (PyObject *)self); |
4397 | 5507 } |
5508 | |
5509 static PyMappingMethods BufMapAsMapping = { | |
5510 (lenfunc) BufMapLength, | |
5511 (binaryfunc) BufMapItem, | |
5512 (objobjargproc) 0, | |
5513 }; | |
5514 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5515 // 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
|
5516 |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5517 static char *CurrentAttrs[] = { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5518 "buffer", "window", "line", "range", "tabpage", |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5519 NULL |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5520 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5521 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5522 static PyObject * |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5523 CurrentDir(PyObject *self) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5524 { |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5525 return ObjectDir(self, CurrentAttrs); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5526 } |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5527 |
4319 | 5528 static PyObject * |
5529 CurrentGetattr(PyObject *self UNUSED, char *name) | |
5530 { | |
5531 if (strcmp(name, "buffer") == 0) | |
5532 return (PyObject *)BufferNew(curbuf); | |
5533 else if (strcmp(name, "window") == 0) | |
4431 | 5534 return (PyObject *)WindowNew(curwin, curtab); |
4401 | 5535 else if (strcmp(name, "tabpage") == 0) |
5536 return (PyObject *)TabPageNew(curtab); | |
4319 | 5537 else if (strcmp(name, "line") == 0) |
5538 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum); | |
5539 else if (strcmp(name, "range") == 0) | |
5540 return RangeNew(curbuf, RangeStart, RangeEnd); | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5541 else if (strcmp(name, "__members__") == 0) |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5542 return ObjectDir(NULL, CurrentAttrs); |
4319 | 5543 else |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5544 #if PY_MAJOR_VERSION < 3 |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5545 return Py_FindMethod(WindowMethods, self, name); |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5546 #else |
4319 | 5547 return NULL; |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5548 #endif |
4319 | 5549 } |
5550 | |
5551 static int | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5552 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *valObject) |
4319 | 5553 { |
5554 if (strcmp(name, "line") == 0) | |
5555 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5556 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
|
5557 NULL) == FAIL) |
4319 | 5558 return -1; |
5559 | |
5560 return 0; | |
5561 } | |
4407 | 5562 else if (strcmp(name, "buffer") == 0) |
5563 { | |
5564 int count; | |
5565 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5566 if (valObject->ob_type != &BufferType) |
4407 | 5567 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5568 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5569 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
|
5570 Py_TYPE_NAME(valObject)); |
4407 | 5571 return -1; |
5572 } | |
5573 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5574 if (CheckBuffer((BufferObject *)(valObject))) |
4407 | 5575 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5576 count = ((BufferObject *)(valObject))->buf->b_fnum; |
4407 | 5577 |
4498 | 5578 VimTryStart(); |
4407 | 5579 if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL) |
5580 { | |
4498 | 5581 if (VimTryEnd()) |
5582 return -1; | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5583 PyErr_VIM_FORMAT(N_("failed to switch to buffer %d"), count); |
4407 | 5584 return -1; |
5585 } | |
5586 | |
4498 | 5587 return VimTryEnd(); |
4407 | 5588 } |
5589 else if (strcmp(name, "window") == 0) | |
5590 { | |
5591 int count; | |
5592 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5593 if (valObject->ob_type != &WindowType) |
4407 | 5594 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5595 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5596 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
|
5597 Py_TYPE_NAME(valObject)); |
4407 | 5598 return -1; |
5599 } | |
5600 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5601 if (CheckWindow((WindowObject *)(valObject))) |
4407 | 5602 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5603 count = get_win_number(((WindowObject *)(valObject))->win, firstwin); |
4407 | 5604 |
5605 if (!count) | |
5606 { | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5607 PyErr_SET_STRING(PyExc_ValueError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5608 N_("failed to find window in the current tab page")); |
4407 | 5609 return -1; |
5610 } | |
5611 | |
4498 | 5612 VimTryStart(); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5613 win_goto(((WindowObject *)(valObject))->win); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5614 if (((WindowObject *)(valObject))->win != curwin) |
4407 | 5615 { |
4498 | 5616 if (VimTryEnd()) |
5617 return -1; | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5618 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5619 N_("did not switch to the specified window")); |
4407 | 5620 return -1; |
5621 } | |
5622 | |
4498 | 5623 return VimTryEnd(); |
4407 | 5624 } |
5625 else if (strcmp(name, "tabpage") == 0) | |
5626 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5627 if (valObject->ob_type != &TabPageType) |
4407 | 5628 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5629 PyErr_FORMAT(PyExc_TypeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5630 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
|
5631 Py_TYPE_NAME(valObject)); |
4407 | 5632 return -1; |
5633 } | |
5634 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5635 if (CheckTabPage((TabPageObject *)(valObject))) |
4407 | 5636 return -1; |
5637 | |
4498 | 5638 VimTryStart(); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5639 goto_tabpage_tp(((TabPageObject *)(valObject))->tab, TRUE, TRUE); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5640 if (((TabPageObject *)(valObject))->tab != curtab) |
4407 | 5641 { |
4498 | 5642 if (VimTryEnd()) |
5643 return -1; | |
4968
b6e693e1f946
updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents:
4966
diff
changeset
|
5644 PyErr_SET_STRING(PyExc_RuntimeError, |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
5645 N_("did not switch to the specified tab page")); |
4407 | 5646 return -1; |
5647 } | |
5648 | |
4498 | 5649 return VimTryEnd(); |
4407 | 5650 } |
4319 | 5651 else |
5652 { | |
5653 PyErr_SetString(PyExc_AttributeError, name); | |
5654 return -1; | |
5655 } | |
5656 } | |
5657 | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5658 static struct PyMethodDef CurrentMethods[] = { |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5659 // name, function, calling, documentation |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5660 {"__dir__", (PyCFunction)CurrentDir, METH_NOARGS, ""}, |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5661 { NULL, NULL, 0, NULL} |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5662 }; |
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
5663 |
3618 | 5664 static void |
4486 | 5665 init_range_cmd(exarg_T *eap) |
5666 { | |
5667 RangeStart = eap->line1; | |
5668 RangeEnd = eap->line2; | |
5669 } | |
5670 | |
5671 static void | |
5672 init_range_eval(typval_T *rettv UNUSED) | |
5673 { | |
5674 RangeStart = (PyInt) curwin->w_cursor.lnum; | |
5675 RangeEnd = RangeStart; | |
5676 } | |
5677 | |
5678 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5679 run_cmd(const char *cmd, void *arg UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5680 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5681 , PyGILState_STATE *pygilstate UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5682 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5683 ) |
4486 | 5684 { |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5685 PyObject *run_ret; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5686 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
|
5687 if (run_ret != NULL) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5688 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5689 Py_DECREF(run_ret); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5690 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5691 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5692 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5693 semsg(_(e_py_systemexit), "python"); |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5694 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5695 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5696 else |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5697 PyErr_PrintEx(1); |
4486 | 5698 } |
5699 | |
5700 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n "; | |
5701 static int code_hdr_len = 30; | |
5702 | |
5703 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5704 run_do(const char *cmd, void *arg UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5705 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5706 , PyGILState_STATE *pygilstate |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5707 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5708 ) |
4486 | 5709 { |
5710 PyInt lnum; | |
5711 size_t len; | |
5712 char *code; | |
5713 int status; | |
5714 PyObject *pyfunc, *pymain; | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5715 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
|
5716 buf_T *was_curbuf = curbuf; |
4486 | 5717 |
4575
626e9ccb7c48
updated for version 7.3.1035
Bram Moolenaar <bram@vim.org>
parents:
4523
diff
changeset
|
5718 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK) |
4486 | 5719 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5720 emsg(_("cannot save undo information")); |
4486 | 5721 return; |
5722 } | |
5723 | |
5724 len = code_hdr_len + STRLEN(cmd); | |
5725 code = PyMem_New(char, len + 1); | |
5726 memcpy(code, code_hdr, code_hdr_len); | |
5727 STRCPY(code + code_hdr_len, cmd); | |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5728 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
|
5729 status = -1; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5730 if (run_ret != NULL) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5731 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5732 status = 0; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5733 Py_DECREF(run_ret); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5734 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5735 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5736 { |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5737 PyMem_Free(code); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5738 semsg(_(e_py_systemexit), "python"); |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5739 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5740 return; |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5741 } |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5742 else |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5743 PyErr_PrintEx(1); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5744 |
4486 | 5745 PyMem_Free(code); |
5746 | |
5747 if (status) | |
5748 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5749 emsg(_("failed to run the code")); |
4486 | 5750 return; |
5751 } | |
5752 | |
5753 status = 0; | |
5754 pymain = PyImport_AddModule("__main__"); | |
5755 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC); | |
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_Release(*pygilstate); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5758 #endif |
4486 | 5759 |
5760 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum) | |
5761 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5762 PyObject *line; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5763 PyObject *linenr; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5764 PyObject *ret; |
4486 | 5765 |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5766 #ifdef PY_CAN_RECURSE |
4486 | 5767 *pygilstate = PyGILState_Ensure(); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5768 #endif |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5769 // Check the line number, the command my have deleted lines. |
10751
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5770 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
|
5771 || !(line = GetBufferLine(curbuf, lnum))) |
4486 | 5772 goto err; |
5773 if (!(linenr = PyInt_FromLong((long) lnum))) | |
5774 { | |
5775 Py_DECREF(line); | |
5776 goto err; | |
5777 } | |
5778 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL); | |
5779 Py_DECREF(line); | |
5780 Py_DECREF(linenr); | |
5781 if (!ret) | |
5782 goto err; | |
5783 | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
5784 // Check that the command didn't switch to another buffer. |
10751
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5785 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
|
5786 { |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5787 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
|
5788 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
|
5789 } |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5790 |
4486 | 5791 if (ret != Py_None) |
5792 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
|
5793 { |
27b42717662b
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents:
9967
diff
changeset
|
5794 Py_XDECREF(ret); |
4486 | 5795 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
|
5796 } |
4486 | 5797 |
5798 Py_XDECREF(ret); | |
5799 PythonIO_Flush(); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5800 #ifdef PY_CAN_RECURSE |
4486 | 5801 PyGILState_Release(*pygilstate); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5802 #endif |
4486 | 5803 } |
5804 goto out; | |
5805 err: | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5806 #ifdef PY_CAN_RECURSE |
4486 | 5807 *pygilstate = PyGILState_Ensure(); |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5808 #endif |
4486 | 5809 PyErr_PrintEx(0); |
5810 PythonIO_Flush(); | |
5811 status = 1; | |
5812 out: | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5813 #ifdef PY_CAN_RECURSE |
4486 | 5814 if (!status) |
5815 *pygilstate = PyGILState_Ensure(); | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5816 #endif |
4486 | 5817 Py_DECREF(pyfunc); |
5818 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL); | |
5819 if (status) | |
5820 return; | |
5821 check_cursor(); | |
5822 update_curbuf(NOT_VALID); | |
5823 } | |
5824 | |
5825 static void | |
4511
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5826 run_eval(const char *cmd, typval_T *rettv |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5827 #ifdef PY_CAN_RECURSE |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5828 , PyGILState_STATE *pygilstate UNUSED |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5829 #endif |
ce94a870b59b
updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents:
4509
diff
changeset
|
5830 ) |
4486 | 5831 { |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5832 PyObject *run_ret; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5833 |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5834 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
|
5835 if (run_ret == NULL) |
4486 | 5836 { |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5837 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5838 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5839 semsg(_(e_py_systemexit), "python"); |
5088
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5840 PyErr_Clear(); |
34c629c3b4ba
updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents:
4995
diff
changeset
|
5841 } |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5842 else |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5843 { |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5844 if (PyErr_Occurred() && !msg_silent) |
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5845 PyErr_PrintEx(0); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
5846 emsg(_("E858: Eval did not return a valid python object")); |
5139
80bab8b1a30d
updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents:
5088
diff
changeset
|
5847 } |
4486 | 5848 } |
5849 else | |
5850 { | |
12806
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
5851 if (ConvertFromPyObject(run_ret, rettv) == -1) |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
5852 emsg(_("E859: Failed to convert returned python object to a Vim value")); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
5853 Py_DECREF(run_ret); |
4486 | 5854 } |
5855 PyErr_Clear(); | |
5856 } | |
5857 | |
6565 | 5858 static int |
3618 | 5859 set_ref_in_py(const int copyID) |
5860 { | |
5861 pylinkedlist_T *cur; | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5862 list_T *ll; |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5863 int i; |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5864 int abort = FALSE; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5865 FunctionObject *func; |
3618 | 5866 |
5867 if (lastdict != NULL) | |
6565 | 5868 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5869 for (cur = lastdict ; !abort && cur != NULL ; cur = cur->pll_prev) |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5870 abort = set_ref_in_dict(((DictionaryObject *)(cur->pll_obj))->dict, |
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5871 copyID); |
6565 | 5872 } |
3618 | 5873 |
5874 if (lastlist != NULL) | |
6565 | 5875 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5876 for (cur = lastlist ; !abort && cur != NULL ; cur = cur->pll_prev) |
3618 | 5877 { |
5878 ll = ((ListObject *) (cur->pll_obj))->list; | |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5879 abort = set_ref_in_list(ll, copyID); |
3618 | 5880 } |
6565 | 5881 } |
5882 | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5883 if (lastfunc != NULL) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5884 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5885 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
|
5886 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5887 func = (FunctionObject *) cur->pll_obj; |
17168
1d30eb64a7a2
patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5888 abort = set_ref_in_dict(func->self, copyID); |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5889 if (func->argc) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5890 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
|
5891 abort = abort |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5892 || 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
|
5893 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5894 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
5895 |
6565 | 5896 return abort; |
3618 | 5897 } |
5898 | |
5899 static int | |
5900 set_string_copy(char_u *str, typval_T *tv) | |
5901 { | |
5902 tv->vval.v_string = vim_strsave(str); | |
5903 if (tv->vval.v_string == NULL) | |
5904 { | |
5905 PyErr_NoMemory(); | |
5906 return -1; | |
5907 } | |
5908 return 0; | |
5909 } | |
5910 | |
4385 | 5911 static int |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5912 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 5913 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5914 dict_T *dict; |
4385 | 5915 char_u *key; |
5916 dictitem_T *di; | |
5917 PyObject *keyObject; | |
5918 PyObject *valObject; | |
5919 Py_ssize_t iter = 0; | |
5920 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5921 if (!(dict = py_dict_alloc())) |
4385 | 5922 return -1; |
5923 | |
5924 tv->v_type = VAR_DICT; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5925 tv->vval.v_dict = dict; |
4385 | 5926 |
5927 while (PyDict_Next(obj, &iter, &keyObject, &valObject)) | |
5928 { | |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5929 PyObject *todecref = NULL; |
4385 | 5930 |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
5931 if (keyObject == NULL || valObject == NULL) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5932 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5933 dict_unref(dict); |
4385 | 5934 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5935 } |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5936 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5937 if (!(key = StringToChars(keyObject, &todecref))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5938 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5939 dict_unref(dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5940 return -1; |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5941 } |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
5942 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5943 if (*key == NUL) |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5944 { |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5945 dict_unref(dict); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5946 Py_XDECREF(todecref); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5947 RAISE_NO_EMPTY_KEYS; |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5948 return -1; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5949 } |
4385 | 5950 |
5951 di = dictitem_alloc(key); | |
5952 | |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
5953 Py_XDECREF(todecref); |
4385 | 5954 |
5955 if (di == NULL) | |
5956 { | |
5957 PyErr_NoMemory(); | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5958 dict_unref(dict); |
4385 | 5959 return -1; |
5960 } | |
5961 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5962 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1) |
4385 | 5963 { |
5964 vim_free(di); | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5965 dict_unref(dict); |
4385 | 5966 return -1; |
5967 } | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5968 |
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5969 if (dict_add(dict, di) == FAIL) |
4385 | 5970 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
5971 RAISE_KEY_ADD_FAIL(di->di_key); |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
5972 clear_tv(&di->di_tv); |
4385 | 5973 vim_free(di); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5974 dict_unref(dict); |
4385 | 5975 return -1; |
5976 } | |
5977 } | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5978 |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
5979 --dict->dv_refcount; |
4385 | 5980 return 0; |
5981 } | |
5982 | |
5983 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5984 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 5985 { |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5986 dict_T *dict; |
4385 | 5987 char_u *key; |
5988 dictitem_T *di; | |
5989 PyObject *list; | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
5990 PyObject *iterator; |
4385 | 5991 PyObject *keyObject; |
5992 PyObject *valObject; | |
5993 | |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
5994 if (!(dict = py_dict_alloc())) |
4385 | 5995 return -1; |
5996 | |
5997 tv->v_type = VAR_DICT; | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
5998 tv->vval.v_dict = dict; |
4385 | 5999 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6000 if (!(list = PyMapping_Keys(obj))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6001 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6002 dict_unref(dict); |
4385 | 6003 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6004 } |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6005 |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6006 if (!(iterator = PyObject_GetIter(list))) |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6007 { |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6008 dict_unref(dict); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6009 Py_DECREF(list); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6010 return -1; |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6011 } |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6012 Py_DECREF(list); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6013 |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6014 while ((keyObject = PyIter_Next(iterator))) |
4385 | 6015 { |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6016 PyObject *todecref; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6017 |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6018 if (!(key = StringToChars(keyObject, &todecref))) |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6019 { |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6020 Py_DECREF(keyObject); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6021 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6022 dict_unref(dict); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6023 return -1; |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6024 } |
4702
26f2dbea7443
updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents:
4698
diff
changeset
|
6025 |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6026 if (*key == NUL) |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6027 { |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6028 Py_DECREF(keyObject); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6029 Py_DECREF(iterator); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6030 Py_XDECREF(todecref); |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6031 dict_unref(dict); |
4659
80b0081824fa
updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents:
4653
diff
changeset
|
6032 RAISE_NO_EMPTY_KEYS; |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6033 return -1; |
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6034 } |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6035 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6036 if (!(valObject = PyObject_GetItem(obj, keyObject))) |
4385 | 6037 { |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6038 Py_DECREF(keyObject); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6039 Py_DECREF(iterator); |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6040 Py_XDECREF(todecref); |
4617
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 | |
6045 di = dictitem_alloc(key); | |
6046 | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6047 Py_DECREF(keyObject); |
4643
6ec3dada4ad3
updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents:
4641
diff
changeset
|
6048 Py_XDECREF(todecref); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6049 |
4385 | 6050 if (di == NULL) |
6051 { | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6052 Py_DECREF(iterator); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6053 Py_DECREF(valObject); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6054 dict_unref(dict); |
4385 | 6055 PyErr_NoMemory(); |
6056 return -1; | |
6057 } | |
6058 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6059 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1) |
4385 | 6060 { |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6061 Py_DECREF(iterator); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6062 Py_DECREF(valObject); |
4385 | 6063 vim_free(di); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6064 dict_unref(dict); |
4385 | 6065 return -1; |
6066 } | |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6067 |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6068 Py_DECREF(valObject); |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6069 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6070 if (dict_add(dict, di) == FAIL) |
4385 | 6071 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6072 RAISE_KEY_ADD_FAIL(di->di_key); |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6073 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6074 dictitem_free(di); |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6075 dict_unref(dict); |
4385 | 6076 return -1; |
6077 } | |
6078 } | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6079 Py_DECREF(iterator); |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6080 --dict->dv_refcount; |
4385 | 6081 return 0; |
6082 } | |
6083 | |
6084 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6085 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
4385 | 6086 { |
6087 list_T *l; | |
6088 | |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6089 if (!(l = py_list_alloc())) |
4385 | 6090 return -1; |
6091 | |
6092 tv->v_type = VAR_LIST; | |
6093 tv->vval.v_list = l; | |
6094 | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6095 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
|
6096 { |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6097 list_unref(l); |
4385 | 6098 return -1; |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6099 } |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6100 |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6101 --l->lv_refcount; |
4385 | 6102 return 0; |
6103 } | |
6104 | |
3618 | 6105 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *); |
6106 | |
6107 static int | |
6108 convert_dl(PyObject *obj, typval_T *tv, | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6109 pytotvfunc py_to_tv, PyObject *lookup_dict) |
3618 | 6110 { |
6111 PyObject *capsule; | |
6112 char hexBuf[sizeof(void *) * 2 + 3]; | |
6113 | |
13353
8412df1479a3
patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents:
12812
diff
changeset
|
6114 sprintf(hexBuf, "%p", (void *)obj); |
3618 | 6115 |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6116 #ifdef PY_USE_CAPSULE |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6117 capsule = PyDict_GetItemString(lookup_dict, hexBuf); |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6118 #else |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6119 capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf); |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6120 #endif |
3618 | 6121 if (capsule == NULL) |
6122 { | |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6123 #ifdef PY_USE_CAPSULE |
3618 | 6124 capsule = PyCapsule_New(tv, NULL, NULL); |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6125 #else |
3648 | 6126 capsule = PyCObject_FromVoidPtr(tv, NULL); |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6127 #endif |
4607
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6128 if (PyDict_SetItemString(lookup_dict, hexBuf, capsule)) |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6129 { |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6130 Py_DECREF(capsule); |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6131 tv->v_type = VAR_UNKNOWN; |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6132 return -1; |
70600448f9e7
updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents:
4605
diff
changeset
|
6133 } |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6134 |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6135 Py_DECREF(capsule); |
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6136 |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6137 if (py_to_tv(obj, tv, lookup_dict) == -1) |
3618 | 6138 { |
6139 tv->v_type = VAR_UNKNOWN; | |
6140 return -1; | |
6141 } | |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
6142 // As we are not using copy_tv which increments reference count we must |
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
6143 // do it ourself. |
7949
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6144 if (tv->v_type == VAR_DICT) |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6145 ++tv->vval.v_dict->dv_refcount; |
3f7382858d4d
commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
6146 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
|
6147 ++tv->vval.v_list->lv_refcount; |
3618 | 6148 } |
6149 else | |
6150 { | |
3638 | 6151 typval_T *v; |
6152 | |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6153 #ifdef PY_USE_CAPSULE |
3638 | 6154 v = PyCapsule_GetPointer(capsule, NULL); |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6155 #else |
3648 | 6156 v = PyCObject_AsVoidPtr(capsule); |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6157 #endif |
3618 | 6158 copy_tv(v, tv); |
6159 } | |
6160 return 0; | |
6161 } | |
6162 | |
6163 static int | |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6164 ConvertFromPyMapping(PyObject *obj, typval_T *tv) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6165 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6166 PyObject *lookup_dict; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6167 int ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6168 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6169 if (!(lookup_dict = PyDict_New())) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6170 return -1; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6171 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6172 if (PyType_IsSubtype(obj->ob_type, &DictionaryType)) |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6173 { |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6174 tv->v_type = VAR_DICT; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6175 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict); |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6176 ++tv->vval.v_dict->dv_refcount; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6177 ret = 0; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6178 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6179 else if (PyDict_Check(obj)) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6180 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
|
6181 else if (PyMapping_Check(obj)) |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6182 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
|
6183 else |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6184 { |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6185 PyErr_FORMAT(PyExc_TypeError, |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
6186 N_("unable to convert %s to a Vim dictionary"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6187 Py_TYPE_NAME(obj)); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6188 ret = -1; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6189 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6190 Py_DECREF(lookup_dict); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6191 return ret; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6192 } |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6193 |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6194 static int |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6195 ConvertFromPySequence(PyObject *obj, typval_T *tv) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6196 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6197 PyObject *lookup_dict; |
8915
8cbf472483fa
commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents:
8913
diff
changeset
|
6198 int ret; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6199 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6200 if (!(lookup_dict = PyDict_New())) |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6201 return -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6202 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6203 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
|
6204 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6205 tv->v_type = VAR_LIST; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6206 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
|
6207 ++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
|
6208 ret = 0; |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6209 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6210 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
|
6211 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
|
6212 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6213 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6214 PyErr_FORMAT(PyExc_TypeError, |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
6215 N_("unable to convert %s to a Vim list"), |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6216 Py_TYPE_NAME(obj)); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6217 ret = -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6218 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6219 Py_DECREF(lookup_dict); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6220 return ret; |
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 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6223 static int |
3618 | 6224 ConvertFromPyObject(PyObject *obj, typval_T *tv) |
6225 { | |
6226 PyObject *lookup_dict; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6227 int ret; |
3618 | 6228 |
4617
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6229 if (!(lookup_dict = PyDict_New())) |
21a99611149b
updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents:
4611
diff
changeset
|
6230 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6231 ret = _ConvertFromPyObject(obj, tv, lookup_dict); |
3618 | 6232 Py_DECREF(lookup_dict); |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6233 return ret; |
3618 | 6234 } |
6235 | |
6236 static int | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6237 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict) |
3618 | 6238 { |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6239 if (PyType_IsSubtype(obj->ob_type, &DictionaryType)) |
3618 | 6240 { |
6241 tv->v_type = VAR_DICT; | |
6242 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict); | |
6243 ++tv->vval.v_dict->dv_refcount; | |
6244 } | |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6245 else if (PyType_IsSubtype(obj->ob_type, &ListType)) |
3618 | 6246 { |
6247 tv->v_type = VAR_LIST; | |
6248 tv->vval.v_list = (((ListObject *)(obj))->list); | |
6249 ++tv->vval.v_list->lv_refcount; | |
6250 } | |
4976
4ed713442c51
updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents:
4974
diff
changeset
|
6251 else if (PyType_IsSubtype(obj->ob_type, &FunctionType)) |
3618 | 6252 { |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6253 FunctionObject *func = (FunctionObject *) obj; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6254 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
|
6255 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6256 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6257 |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6258 set_partial(func, pt, TRUE); |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6259 tv->vval.v_partial = pt; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6260 tv->v_type = VAR_PARTIAL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6261 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6262 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6263 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6264 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
|
6265 return -1; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6266 |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6267 tv->v_type = VAR_FUNC; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6268 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6269 func_ref(func->name); |
3618 | 6270 } |
6271 else if (PyBytes_Check(obj)) | |
6272 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6273 char_u *str; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6274 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6275 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1) |
3800 | 6276 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6277 if (str == NULL) |
3618 | 6278 return -1; |
6279 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6280 if (set_string_copy(str, tv) == -1) |
3618 | 6281 return -1; |
6282 | |
6283 tv->v_type = VAR_STRING; | |
6284 } | |
6285 else if (PyUnicode_Check(obj)) | |
6286 { | |
6287 PyObject *bytes; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6288 char_u *str; |
3618 | 6289 |
4966
620d9b59d4ed
updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents:
4964
diff
changeset
|
6290 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL); |
3618 | 6291 if (bytes == NULL) |
6292 return -1; | |
6293 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6294 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1) |
3800 | 6295 return -1; |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6296 if (str == NULL) |
3618 | 6297 return -1; |
6298 | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6299 if (set_string_copy(str, tv)) |
3618 | 6300 { |
6301 Py_XDECREF(bytes); | |
6302 return -1; | |
6303 } | |
6304 Py_XDECREF(bytes); | |
6305 | |
6306 tv->v_type = VAR_STRING; | |
6307 } | |
4321 | 6308 #if PY_MAJOR_VERSION < 3 |
3618 | 6309 else if (PyInt_Check(obj)) |
6310 { | |
6311 tv->v_type = VAR_NUMBER; | |
6312 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
|
6313 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6314 return -1; |
3618 | 6315 } |
6316 #endif | |
6317 else if (PyLong_Check(obj)) | |
6318 { | |
6319 tv->v_type = VAR_NUMBER; | |
6320 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
|
6321 if (PyErr_Occurred()) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6322 return -1; |
3618 | 6323 } |
6324 else if (PyDict_Check(obj)) | |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6325 return convert_dl(obj, tv, pydict_to_tv, lookup_dict); |
3618 | 6326 #ifdef FEAT_FLOAT |
6327 else if (PyFloat_Check(obj)) | |
6328 { | |
6329 tv->v_type = VAR_FLOAT; | |
6330 tv->vval.v_float = (float_T) PyFloat_AsDouble(obj); | |
6331 } | |
6332 #endif | |
4635
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6333 else if (PyObject_HasAttrString(obj, "keys")) |
07c534fe9b6c
updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents:
4633
diff
changeset
|
6334 return convert_dl(obj, tv, pymap_to_tv, lookup_dict); |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
6335 // 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
|
6336 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
|
6337 return convert_dl(obj, tv, pyseq_to_tv, lookup_dict); |
3618 | 6338 else if (PyMapping_Check(obj)) |
4601
19d406a8509d
updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents:
4599
diff
changeset
|
6339 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
|
6340 else if (PyNumber_Check(obj)) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6341 { |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6342 PyObject *num; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6343 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6344 if (!(num = PyNumber_Long(obj))) |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6345 return -1; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6346 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6347 tv->v_type = VAR_NUMBER; |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6348 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
|
6349 |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6350 Py_DECREF(num); |
537bbfff0c5c
updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents:
4970
diff
changeset
|
6351 } |
12806
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6352 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
|
6353 { |
ef93c4415667
patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
6354 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
|
6355 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
|
6356 } |
3618 | 6357 else |
6358 { | |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6359 PyErr_FORMAT(PyExc_TypeError, |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
6360 N_("unable to convert %s to a Vim structure"), |
4970
f5c822e5a0eb
updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents:
4968
diff
changeset
|
6361 Py_TYPE_NAME(obj)); |
3618 | 6362 return -1; |
6363 } | |
6364 return 0; | |
6365 } | |
6366 | |
6367 static PyObject * | |
6368 ConvertToPyObject(typval_T *tv) | |
6369 { | |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6370 typval_T *argv; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6371 int i; |
3618 | 6372 if (tv == NULL) |
6373 { | |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6374 PyErr_SET_VIM(N_("internal error: NULL reference passed")); |
3618 | 6375 return NULL; |
6376 } | |
6377 switch (tv->v_type) | |
6378 { | |
6379 case VAR_STRING: | |
3852 | 6380 return PyBytes_FromString(tv->vval.v_string == NULL |
6381 ? "" : (char *)tv->vval.v_string); | |
3618 | 6382 case VAR_NUMBER: |
6383 return PyLong_FromLong((long) tv->vval.v_number); | |
19193
9f98957582d6
patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
6384 case VAR_FLOAT: |
3618 | 6385 #ifdef FEAT_FLOAT |
6386 return PyFloat_FromDouble((double) tv->vval.v_float); | |
6387 #endif | |
6388 case VAR_LIST: | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6389 return NEW_LIST(tv->vval.v_list); |
3618 | 6390 case VAR_DICT: |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6391 return NEW_DICTIONARY(tv->vval.v_dict); |
3618 | 6392 case VAR_FUNC: |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6393 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
|
6394 ? (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
|
6395 0, NULL, NULL, TRUE); |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6396 case VAR_PARTIAL: |
8889
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6397 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
|
6398 { |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6399 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
|
6400 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
|
6401 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
|
6402 } |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6403 else |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6404 argv = NULL; |
8755d57debaa
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents:
8714
diff
changeset
|
6405 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
|
6406 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
|
6407 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
|
6408 ? (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
|
6409 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
|
6410 tv->vval.v_partial->pt_dict, |
39cc63e8df7c
commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents:
8967
diff
changeset
|
6411 tv->vval.v_partial->pt_auto); |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
6412 case VAR_BLOB: |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
6413 return PyBytes_FromStringAndSize( |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
6414 (char*) tv->vval.v_blob->bv_ga.ga_data, |
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15236
diff
changeset
|
6415 (Py_ssize_t) tv->vval.v_blob->bv_ga.ga_len); |
3618 | 6416 case VAR_UNKNOWN: |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
6417 case VAR_ANY: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19102
diff
changeset
|
6418 case VAR_VOID: |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6419 case VAR_CHANNEL: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6420 case VAR_JOB: |
3618 | 6421 Py_INCREF(Py_None); |
6422 return Py_None; | |
19102
ba9f50bfda83
patch 8.2.0111: VAR_SPECIAL is also used for booleans
Bram Moolenaar <Bram@vim.org>
parents:
19019
diff
changeset
|
6423 case VAR_BOOL: |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6424 case VAR_SPECIAL: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6425 switch (tv->vval.v_number) |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6426 { |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6427 case VVAL_FALSE: return AlwaysFalse(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6428 case VVAL_TRUE: return AlwaysTrue(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6429 case VVAL_NONE: |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6430 case VVAL_NULL: return AlwaysNone(NULL); |
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6431 } |
4978
f4969f8f66e9
updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents:
4976
diff
changeset
|
6432 PyErr_SET_VIM(N_("internal error: invalid value type")); |
3618 | 6433 return NULL; |
6434 } | |
8714
a5224eeb3546
commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
6435 return NULL; |
3618 | 6436 } |
4319 | 6437 |
6438 typedef struct | |
6439 { | |
6440 PyObject_HEAD | |
6441 } CurrentObject; | |
6442 static PyTypeObject CurrentType; | |
6443 | |
6444 static void | |
6445 init_structs(void) | |
6446 { | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6447 CLEAR_FIELD(OutputType); |
4319 | 6448 OutputType.tp_name = "vim.message"; |
6449 OutputType.tp_basicsize = sizeof(OutputObject); | |
6450 OutputType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6451 OutputType.tp_doc = "vim message object"; | |
6452 OutputType.tp_methods = OutputMethods; | |
6453 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6454 OutputType.tp_getattro = (getattrofunc)OutputGetattro; |
6455 OutputType.tp_setattro = (setattrofunc)OutputSetattro; | |
4319 | 6456 OutputType.tp_alloc = call_PyType_GenericAlloc; |
6457 OutputType.tp_new = call_PyType_GenericNew; | |
6458 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
|
6459 OutputType.tp_base = &PyStdPrinter_Type; |
4319 | 6460 #else |
4488 | 6461 OutputType.tp_getattr = (getattrfunc)OutputGetattr; |
6462 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
|
6463 // 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
|
6464 // OutputType.tp_base = &PyFile_Type; |
4319 | 6465 #endif |
6466 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6467 CLEAR_FIELD(IterType); |
4397 | 6468 IterType.tp_name = "vim.iter"; |
6469 IterType.tp_basicsize = sizeof(IterObject); | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6470 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4397 | 6471 IterType.tp_doc = "generic iterator object"; |
4488 | 6472 IterType.tp_iter = (getiterfunc)IterIter; |
6473 IterType.tp_iternext = (iternextfunc)IterNext; | |
6474 IterType.tp_dealloc = (destructor)IterDestructor; | |
6475 IterType.tp_traverse = (traverseproc)IterTraverse; | |
6476 IterType.tp_clear = (inquiry)IterClear; | |
4397 | 6477 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6478 CLEAR_FIELD(BufferType); |
4319 | 6479 BufferType.tp_name = "vim.buffer"; |
6480 BufferType.tp_basicsize = sizeof(BufferType); | |
4488 | 6481 BufferType.tp_dealloc = (destructor)BufferDestructor; |
6482 BufferType.tp_repr = (reprfunc)BufferRepr; | |
4319 | 6483 BufferType.tp_as_sequence = &BufferAsSeq; |
6484 BufferType.tp_as_mapping = &BufferAsMapping; | |
6485 BufferType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6486 BufferType.tp_doc = "vim buffer object"; | |
6487 BufferType.tp_methods = BufferMethods; | |
6488 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6489 BufferType.tp_getattro = (getattrofunc)BufferGetattro; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
6490 BufferType.tp_setattro = (setattrofunc)BufferSetattro; |
4319 | 6491 BufferType.tp_alloc = call_PyType_GenericAlloc; |
6492 BufferType.tp_new = call_PyType_GenericNew; | |
6493 BufferType.tp_free = call_PyObject_Free; | |
6494 #else | |
4488 | 6495 BufferType.tp_getattr = (getattrfunc)BufferGetattr; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4587
diff
changeset
|
6496 BufferType.tp_setattr = (setattrfunc)BufferSetattr; |
4319 | 6497 #endif |
6498 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6499 CLEAR_FIELD(WindowType); |
4319 | 6500 WindowType.tp_name = "vim.window"; |
6501 WindowType.tp_basicsize = sizeof(WindowObject); | |
4488 | 6502 WindowType.tp_dealloc = (destructor)WindowDestructor; |
6503 WindowType.tp_repr = (reprfunc)WindowRepr; | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6504 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4319 | 6505 WindowType.tp_doc = "vim Window object"; |
6506 WindowType.tp_methods = WindowMethods; | |
4488 | 6507 WindowType.tp_traverse = (traverseproc)WindowTraverse; |
6508 WindowType.tp_clear = (inquiry)WindowClear; | |
4319 | 6509 #if PY_MAJOR_VERSION >= 3 |
4488 | 6510 WindowType.tp_getattro = (getattrofunc)WindowGetattro; |
6511 WindowType.tp_setattro = (setattrofunc)WindowSetattro; | |
4319 | 6512 WindowType.tp_alloc = call_PyType_GenericAlloc; |
6513 WindowType.tp_new = call_PyType_GenericNew; | |
6514 WindowType.tp_free = call_PyObject_Free; | |
6515 #else | |
4488 | 6516 WindowType.tp_getattr = (getattrfunc)WindowGetattr; |
6517 WindowType.tp_setattr = (setattrfunc)WindowSetattr; | |
4319 | 6518 #endif |
6519 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6520 CLEAR_FIELD(TabPageType); |
4401 | 6521 TabPageType.tp_name = "vim.tabpage"; |
6522 TabPageType.tp_basicsize = sizeof(TabPageObject); | |
4488 | 6523 TabPageType.tp_dealloc = (destructor)TabPageDestructor; |
6524 TabPageType.tp_repr = (reprfunc)TabPageRepr; | |
4401 | 6525 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT; |
6526 TabPageType.tp_doc = "vim tab page object"; | |
6527 TabPageType.tp_methods = TabPageMethods; | |
6528 #if PY_MAJOR_VERSION >= 3 | |
4488 | 6529 TabPageType.tp_getattro = (getattrofunc)TabPageGetattro; |
4401 | 6530 TabPageType.tp_alloc = call_PyType_GenericAlloc; |
6531 TabPageType.tp_new = call_PyType_GenericNew; | |
6532 TabPageType.tp_free = call_PyObject_Free; | |
6533 #else | |
4488 | 6534 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr; |
4401 | 6535 #endif |
6536 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6537 CLEAR_FIELD(BufMapType); |
4393 | 6538 BufMapType.tp_name = "vim.bufferlist"; |
6539 BufMapType.tp_basicsize = sizeof(BufMapObject); | |
6540 BufMapType.tp_as_mapping = &BufMapAsMapping; | |
6541 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT; | |
4397 | 6542 BufMapType.tp_iter = BufMapIter; |
4319 | 6543 BufferType.tp_doc = "vim buffer list"; |
6544 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6545 CLEAR_FIELD(WinListType); |
4319 | 6546 WinListType.tp_name = "vim.windowlist"; |
6547 WinListType.tp_basicsize = sizeof(WinListType); | |
6548 WinListType.tp_as_sequence = &WinListAsSeq; | |
6549 WinListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6550 WinListType.tp_doc = "vim window list"; | |
4488 | 6551 WinListType.tp_dealloc = (destructor)WinListDestructor; |
4401 | 6552 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6553 CLEAR_FIELD(TabListType); |
4401 | 6554 TabListType.tp_name = "vim.tabpagelist"; |
6555 TabListType.tp_basicsize = sizeof(TabListType); | |
6556 TabListType.tp_as_sequence = &TabListAsSeq; | |
6557 TabListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6558 TabListType.tp_doc = "vim tab page list"; | |
4319 | 6559 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6560 CLEAR_FIELD(RangeType); |
4319 | 6561 RangeType.tp_name = "vim.range"; |
6562 RangeType.tp_basicsize = sizeof(RangeObject); | |
4488 | 6563 RangeType.tp_dealloc = (destructor)RangeDestructor; |
6564 RangeType.tp_repr = (reprfunc)RangeRepr; | |
4319 | 6565 RangeType.tp_as_sequence = &RangeAsSeq; |
6566 RangeType.tp_as_mapping = &RangeAsMapping; | |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6567 RangeType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4319 | 6568 RangeType.tp_doc = "vim Range object"; |
6569 RangeType.tp_methods = RangeMethods; | |
4500 | 6570 RangeType.tp_traverse = (traverseproc)RangeTraverse; |
6571 RangeType.tp_clear = (inquiry)RangeClear; | |
4319 | 6572 #if PY_MAJOR_VERSION >= 3 |
4488 | 6573 RangeType.tp_getattro = (getattrofunc)RangeGetattro; |
4319 | 6574 RangeType.tp_alloc = call_PyType_GenericAlloc; |
6575 RangeType.tp_new = call_PyType_GenericNew; | |
6576 RangeType.tp_free = call_PyObject_Free; | |
6577 #else | |
4488 | 6578 RangeType.tp_getattr = (getattrfunc)RangeGetattr; |
4319 | 6579 #endif |
6580 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6581 CLEAR_FIELD(CurrentType); |
4319 | 6582 CurrentType.tp_name = "vim.currentdata"; |
6583 CurrentType.tp_basicsize = sizeof(CurrentObject); | |
6584 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT; | |
6585 CurrentType.tp_doc = "vim current object"; | |
4599
89bec74fd793
updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents:
4597
diff
changeset
|
6586 CurrentType.tp_methods = CurrentMethods; |
4319 | 6587 #if PY_MAJOR_VERSION >= 3 |
4488 | 6588 CurrentType.tp_getattro = (getattrofunc)CurrentGetattro; |
6589 CurrentType.tp_setattro = (setattrofunc)CurrentSetattro; | |
4319 | 6590 #else |
4488 | 6591 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr; |
6592 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr; | |
4319 | 6593 #endif |
6594 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6595 CLEAR_FIELD(DictionaryType); |
4319 | 6596 DictionaryType.tp_name = "vim.dictionary"; |
6597 DictionaryType.tp_basicsize = sizeof(DictionaryObject); | |
4488 | 6598 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6599 DictionaryType.tp_as_sequence = &DictionaryAsSeq; |
4319 | 6600 DictionaryType.tp_as_mapping = &DictionaryAsMapping; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6601 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
6602 DictionaryType.tp_doc = "dictionary pushing modifications to Vim structure"; |
4319 | 6603 DictionaryType.tp_methods = DictionaryMethods; |
4627
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6604 DictionaryType.tp_iter = (getiterfunc)DictionaryIter; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6605 DictionaryType.tp_new = (newfunc)DictionaryConstructor; |
18ba89e06fab
updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents:
4625
diff
changeset
|
6606 DictionaryType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6607 #if PY_MAJOR_VERSION >= 3 |
4488 | 6608 DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro; |
6609 DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro; | |
4319 | 6610 #else |
4488 | 6611 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr; |
6612 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr; | |
4319 | 6613 #endif |
6614 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6615 CLEAR_FIELD(ListType); |
4319 | 6616 ListType.tp_name = "vim.list"; |
4488 | 6617 ListType.tp_dealloc = (destructor)ListDestructor; |
4319 | 6618 ListType.tp_basicsize = sizeof(ListObject); |
6619 ListType.tp_as_sequence = &ListAsSeq; | |
6620 ListType.tp_as_mapping = &ListAsMapping; | |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6621 ListType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
6622 ListType.tp_doc = "list pushing modifications to Vim structure"; |
4319 | 6623 ListType.tp_methods = ListMethods; |
4488 | 6624 ListType.tp_iter = (getiterfunc)ListIter; |
4629
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6625 ListType.tp_new = (newfunc)ListConstructor; |
e4e48d4ee040
updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents:
4627
diff
changeset
|
6626 ListType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6627 #if PY_MAJOR_VERSION >= 3 |
4488 | 6628 ListType.tp_getattro = (getattrofunc)ListGetattro; |
6629 ListType.tp_setattro = (setattrofunc)ListSetattro; | |
4319 | 6630 #else |
4488 | 6631 ListType.tp_getattr = (getattrfunc)ListGetattr; |
6632 ListType.tp_setattr = (setattrfunc)ListSetattr; | |
4319 | 6633 #endif |
6634 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6635 CLEAR_FIELD(FunctionType); |
4397 | 6636 FunctionType.tp_name = "vim.function"; |
4319 | 6637 FunctionType.tp_basicsize = sizeof(FunctionObject); |
4488 | 6638 FunctionType.tp_dealloc = (destructor)FunctionDestructor; |
6639 FunctionType.tp_call = (ternaryfunc)FunctionCall; | |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6640 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE; |
20369
6e1e4d7a7b39
patch 8.2.0740: minor message mistakes
Bram Moolenaar <Bram@vim.org>
parents:
20197
diff
changeset
|
6641 FunctionType.tp_doc = "object that calls Vim function"; |
4319 | 6642 FunctionType.tp_methods = FunctionMethods; |
4625
cb5c1e37ad4d
updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents:
4623
diff
changeset
|
6643 FunctionType.tp_repr = (reprfunc)FunctionRepr; |
4631
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6644 FunctionType.tp_new = (newfunc)FunctionConstructor; |
4157fef7b950
updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents:
4629
diff
changeset
|
6645 FunctionType.tp_alloc = (allocfunc)PyType_GenericAlloc; |
4319 | 6646 #if PY_MAJOR_VERSION >= 3 |
4488 | 6647 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro; |
4319 | 6648 #else |
4488 | 6649 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr; |
4319 | 6650 #endif |
6651 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6652 CLEAR_FIELD(OptionsType); |
4350 | 6653 OptionsType.tp_name = "vim.options"; |
6654 OptionsType.tp_basicsize = sizeof(OptionsObject); | |
5610 | 6655 OptionsType.tp_as_sequence = &OptionsAsSeq; |
4611
49f0fcd9762c
updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents:
4609
diff
changeset
|
6656 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC; |
4350 | 6657 OptionsType.tp_doc = "object for manipulating options"; |
5610 | 6658 OptionsType.tp_iter = (getiterfunc)OptionsIter; |
4350 | 6659 OptionsType.tp_as_mapping = &OptionsAsMapping; |
4488 | 6660 OptionsType.tp_dealloc = (destructor)OptionsDestructor; |
6661 OptionsType.tp_traverse = (traverseproc)OptionsTraverse; | |
6662 OptionsType.tp_clear = (inquiry)OptionsClear; | |
4350 | 6663 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6664 #if PY_VERSION_HEX < 0x030700f0 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6665 CLEAR_FIELD(LoaderType); |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6666 LoaderType.tp_name = "vim.Loader"; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6667 LoaderType.tp_basicsize = sizeof(LoaderObject); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6668 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6669 LoaderType.tp_doc = "vim message object"; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6670 LoaderType.tp_methods = LoaderMethods; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6671 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
|
6672 #endif |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6673 |
4319 | 6674 #if PY_MAJOR_VERSION >= 3 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19922
diff
changeset
|
6675 CLEAR_FIELD(vimmodule); |
4319 | 6676 vimmodule.m_name = "vim"; |
6677 vimmodule.m_doc = "Vim Python interface\n"; | |
6678 vimmodule.m_size = -1; | |
6679 vimmodule.m_methods = VimMethods; | |
6680 #endif | |
6681 } | |
4494 | 6682 |
6683 #define PYTYPE_READY(type) \ | |
6684 if (PyType_Ready(&type)) \ | |
6685 return -1; | |
6686 | |
6687 static int | |
5166
467efeee8f9e
updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents:
5139
diff
changeset
|
6688 init_types(void) |
4494 | 6689 { |
6690 PYTYPE_READY(IterType); | |
6691 PYTYPE_READY(BufferType); | |
6692 PYTYPE_READY(RangeType); | |
6693 PYTYPE_READY(WindowType); | |
6694 PYTYPE_READY(TabPageType); | |
6695 PYTYPE_READY(BufMapType); | |
6696 PYTYPE_READY(WinListType); | |
6697 PYTYPE_READY(TabListType); | |
6698 PYTYPE_READY(CurrentType); | |
6699 PYTYPE_READY(DictionaryType); | |
6700 PYTYPE_READY(ListType); | |
6701 PYTYPE_READY(FunctionType); | |
6702 PYTYPE_READY(OptionsType); | |
6703 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
|
6704 #if PY_VERSION_HEX < 0x030700f0 |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6705 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
|
6706 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6707 return 0; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6708 } |
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 static int |
4922
8dd2769ab75c
updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents:
4918
diff
changeset
|
6711 init_sys_path(void) |
4833
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 PyObject *path; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6714 PyObject *path_hook; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6715 PyObject *path_hooks; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6716 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6717 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
|
6718 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6719 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6720 if (!(path_hooks = PySys_GetObject("path_hooks"))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6721 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6722 PyErr_Clear(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6723 path_hooks = PyList_New(1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6724 PyList_SET_ITEM(path_hooks, 0, path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6725 if (PySys_SetObject("path_hooks", path_hooks)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6726 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6727 Py_DECREF(path_hooks); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6728 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6729 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6730 Py_DECREF(path_hooks); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6731 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6732 else if (PyList_Check(path_hooks)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6733 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6734 if (PyList_Append(path_hooks, path_hook)) |
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 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6737 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6738 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6739 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6740 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6741 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6742 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6743 VimTryStart(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
6744 emsg(_("Failed to set path hook: sys.path_hooks is not a list\n" |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6745 "You should now do the following:\n" |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6746 "- 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
|
6747 "- append vim.VIM_SPECIAL_PATH to sys.path\n")); |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
6748 VimTryEnd(); // Discard the error |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6749 Py_DECREF(path_hook); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6750 return 0; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6751 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6752 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6753 if (!(path = PySys_GetObject("path"))) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6754 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6755 PyErr_Clear(); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6756 path = PyList_New(1); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6757 Py_INCREF(vim_special_path_object); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6758 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
|
6759 if (PySys_SetObject("path", path)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6760 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6761 Py_DECREF(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6762 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6763 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6764 Py_DECREF(path); |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6765 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6766 else if (PyList_Check(path)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6767 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6768 if (PyList_Append(path, vim_special_path_object)) |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6769 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6770 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6771 else |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6772 { |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6773 VimTryStart(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15454
diff
changeset
|
6774 emsg(_("Failed to set path: sys.path is not a list\n" |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6775 "You should now append vim.VIM_SPECIAL_PATH to sys.path")); |
18753
6e3dc2d630c2
patch 8.1.2366: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18370
diff
changeset
|
6776 VimTryEnd(); // Discard the error |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6777 } |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6778 |
4494 | 6779 return 0; |
6780 } | |
6781 | |
6782 static BufMapObject TheBufferMap = | |
6783 { | |
6784 PyObject_HEAD_INIT(&BufMapType) | |
6785 }; | |
6786 | |
6787 static WinListObject TheWindowList = | |
6788 { | |
6789 PyObject_HEAD_INIT(&WinListType) | |
6790 NULL | |
6791 }; | |
6792 | |
6793 static CurrentObject TheCurrent = | |
6794 { | |
6795 PyObject_HEAD_INIT(&CurrentType) | |
6796 }; | |
6797 | |
6798 static TabListObject TheTabPageList = | |
6799 { | |
6800 PyObject_HEAD_INIT(&TabListType) | |
6801 }; | |
6802 | |
6803 static struct numeric_constant { | |
6804 char *name; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6805 int val; |
4494 | 6806 } numeric_constants[] = { |
6807 {"VAR_LOCKED", VAR_LOCKED}, | |
6808 {"VAR_FIXED", VAR_FIXED}, | |
6809 {"VAR_SCOPE", VAR_SCOPE}, | |
6810 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE}, | |
6811 }; | |
6812 | |
6813 static struct object_constant { | |
6814 char *name; | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6815 PyObject *valObject; |
4494 | 6816 } object_constants[] = { |
6817 {"buffers", (PyObject *)(void *)&TheBufferMap}, | |
6818 {"windows", (PyObject *)(void *)&TheWindowList}, | |
6819 {"tabpages", (PyObject *)(void *)&TheTabPageList}, | |
6820 {"current", (PyObject *)(void *)&TheCurrent}, | |
4496 | 6821 |
6822 {"Buffer", (PyObject *)&BufferType}, | |
6823 {"Range", (PyObject *)&RangeType}, | |
6824 {"Window", (PyObject *)&WindowType}, | |
6825 {"TabPage", (PyObject *)&TabPageType}, | |
6826 {"Dictionary", (PyObject *)&DictionaryType}, | |
6827 {"List", (PyObject *)&ListType}, | |
6828 {"Function", (PyObject *)&FunctionType}, | |
6829 {"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
|
6830 #if PY_VERSION_HEX < 0x030700f0 |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6831 {"_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
|
6832 #endif |
4494 | 6833 }; |
6834 | |
6835 #define ADD_OBJECT(m, name, obj) \ | |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6836 if (PyModule_AddObject(m, name, obj)) \ |
4494 | 6837 return -1; |
6838 | |
6839 #define ADD_CHECKED_OBJECT(m, name, obj) \ | |
6840 { \ | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6841 PyObject *valObject = obj; \ |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6842 if (!valObject) \ |
4494 | 6843 return -1; \ |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6844 ADD_OBJECT(m, name, valObject); \ |
4494 | 6845 } |
6846 | |
6847 static int | |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6848 populate_module(PyObject *m) |
4494 | 6849 { |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6850 int i; |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6851 PyObject *other_module; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6852 PyObject *attr; |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6853 PyObject *imp; |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6854 #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
|
6855 PyObject *dict; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6856 PyObject *cls; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6857 #endif |
4494 | 6858 |
6859 for (i = 0; i < (int)(sizeof(numeric_constants) | |
6860 / sizeof(struct numeric_constant)); | |
6861 ++i) | |
6862 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
|
6863 PyInt_FromLong(numeric_constants[i].val)); |
4494 | 6864 |
6865 for (i = 0; i < (int)(sizeof(object_constants) | |
6866 / sizeof(struct object_constant)); | |
6867 ++i) | |
6868 { | |
4974
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6869 PyObject *valObject; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6870 |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6871 valObject = object_constants[i].valObject; |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6872 Py_INCREF(valObject); |
a594ce86b5ea
updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents:
4972
diff
changeset
|
6873 ADD_OBJECT(m, object_constants[i].name, valObject); |
4494 | 6874 } |
6875 | |
6876 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL))) | |
6877 return -1; | |
6878 ADD_OBJECT(m, "error", VimError); | |
6879 | |
17922
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17168
diff
changeset
|
6880 ADD_CHECKED_OBJECT(m, "vars", NEW_DICTIONARY(get_globvar_dict())); |
4d63d47d87ef
patch 8.1.1957: more code can be moved to evalvars.c
Bram Moolenaar <Bram@vim.org>
parents:
17168
diff
changeset
|
6881 ADD_CHECKED_OBJECT(m, "vvars", NEW_DICTIONARY(get_vimvar_dict())); |
4494 | 6882 ADD_CHECKED_OBJECT(m, "options", |
6883 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL)); | |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6884 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6885 if (!(other_module = PyImport_ImportModule("os"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6886 return -1; |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6887 ADD_OBJECT(m, "os", other_module); |
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6888 |
9161
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6889 #if PY_MAJOR_VERSION >= 3 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6890 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
|
6891 return -1; |
9161
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6892 #else |
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6893 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
|
6894 return -1; |
56c93626f6f3
commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents:
9119
diff
changeset
|
6895 #endif |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6896 ADD_OBJECT(m, "_getcwd", py_getcwd) |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6897 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6898 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
|
6899 return -1; |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6900 ADD_OBJECT(m, "_chdir", py_chdir); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6901 if (!(attr = PyObject_GetAttrString(m, "chdir"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6902 return -1; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6903 if (PyObject_SetAttrString(other_module, "chdir", attr)) |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6904 { |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6905 Py_DECREF(attr); |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6906 return -1; |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6907 } |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6908 Py_DECREF(attr); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6909 |
4829
ff3935926449
updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents:
4754
diff
changeset
|
6910 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
|
6911 { |
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6912 ADD_OBJECT(m, "_fchdir", py_fchdir); |
4982
39980afcf54a
updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents:
4978
diff
changeset
|
6913 if (!(attr = PyObject_GetAttrString(m, "fchdir"))) |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6914 return -1; |
4831
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6915 if (PyObject_SetAttrString(other_module, "fchdir", attr)) |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6916 { |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6917 Py_DECREF(attr); |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6918 return -1; |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6919 } |
b8eabb6a9687
updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents:
4829
diff
changeset
|
6920 Py_DECREF(attr); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6921 } |
4722
3534e9b4fa42
updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents:
4706
diff
changeset
|
6922 else |
3534e9b4fa42
updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents:
4706
diff
changeset
|
6923 PyErr_Clear(); |
4704
542af01979be
updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents:
4702
diff
changeset
|
6924 |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6925 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
|
6926 return -1; |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6927 |
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6928 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
|
6929 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6930 #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
|
6931 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
|
6932 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6933 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6934 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
|
6935 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6936 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
|
6937 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6938 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6939 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6940 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6941 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6942 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
|
6943 { |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6944 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6945 return -1; |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6946 } |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6947 |
15818
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6948 if ((py_find_module = PyObject_GetAttrString(cls, "find_module"))) |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6949 { |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6950 // find_module() is deprecated, this may stop working in some later |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6951 // version. |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6952 ADD_OBJECT(m, "_find_module", py_find_module); |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6953 } |
89486329d9e6
patch 8.1.0916: with Python 3.7 "find_module" is not made available
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
6954 |
14373
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6955 Py_DECREF(imp); |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6956 |
380217380738
patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
6957 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
|
6958 #else |
4855
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6959 if (!(imp = PyImport_ImportModule("imp"))) |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6960 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6961 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6962 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
|
6963 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6964 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6965 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6966 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6967 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6968 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
|
6969 { |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6970 Py_DECREF(py_find_module); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6971 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6972 return -1; |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6973 } |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6974 |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6975 Py_DECREF(imp); |
52850ef928f8
updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents:
4851
diff
changeset
|
6976 |
4851
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6977 ADD_OBJECT(m, "_find_module", py_find_module); |
96e154e825a7
updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents:
4833
diff
changeset
|
6978 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
|
6979 #endif |
4833
70b1178dec79
updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents:
4831
diff
changeset
|
6980 |
4494 | 6981 return 0; |
6982 } |