annotate src/if_py_both.h @ 15470:55ccc2d353bd v8.1.0743

patch 8.1.0743: giving error messages is not flexible commit https://github.com/vim/vim/commit/f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 13 23:38:42 2019 +0100 patch 8.1.0743: giving error messages is not flexible Problem: Giving error messages is not flexible. Solution: Add semsg(). Change argument from "char_u *" to "char *", also for msg() and get rid of most MSG macros. (Ozaki Kiichi, closes #3302) Also make emsg() accept a "char *" argument. Get rid of an enormous number of type casts.
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Jan 2019 23:45:08 +0100
parents 1d2b5c016f17
children 0fcc1315c061
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
10 * Python extensions by Paul Moore, David Leonard, Roland Puntaier, Nikolay
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
11 * Pavlov.
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 * Common code for if_python.c and if_python3.c.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
5588
2ca470c6096e updated for version 7.4.141
Bram Moolenaar <bram@vim.org>
parents: 5525
diff changeset
16 #ifdef __BORLANDC__
2ca470c6096e updated for version 7.4.141
Bram Moolenaar <bram@vim.org>
parents: 5525
diff changeset
17 /* Disable Warning W8060: Possibly incorrect assignment in function ... */
2ca470c6096e updated for version 7.4.141
Bram Moolenaar <bram@vim.org>
parents: 5525
diff changeset
18 # pragma warn -8060
2ca470c6096e updated for version 7.4.141
Bram Moolenaar <bram@vim.org>
parents: 5525
diff changeset
19 #endif
2ca470c6096e updated for version 7.4.141
Bram Moolenaar <bram@vim.org>
parents: 5525
diff changeset
20
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
21 static char_u e_py_systemexit[] = "E880: Can't handle SystemExit of %s exception in vim";
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
22
3734
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
23 #if PY_VERSION_HEX < 0x02050000
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
24 typedef int Py_ssize_t; /* Python 2.4 and earlier don't have this type. */
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
25 #endif
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
26
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
27 #ifdef FEAT_MBYTE
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
28 # define ENC_OPT ((char *)p_enc)
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
29 #else
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
30 # define ENC_OPT "latin1"
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
31 #endif
4435
9b800f0a757f updated for version 7.3.966
Bram Moolenaar <bram@vim.org>
parents: 4433
diff changeset
32 #define DOPY_FUNC "_vim_pydo"
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
33
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
34 static const char *vim_special_path = "_vim_path_";
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
35
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
36 #define PyErr_SET_STRING(exc, str) PyErr_SetString(exc, _(str))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
37 #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
38 #define PyErr_SET_VIM(str) PyErr_SET_STRING(VimError, str)
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
39 #define PyErr_FORMAT(exc, str, arg) PyErr_Format(exc, _(str), arg)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
40 #define PyErr_FORMAT2(exc, str, arg1, arg2) PyErr_Format(exc, _(str), arg1,arg2)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
41 #define PyErr_VIM_FORMAT(str, arg) PyErr_FORMAT(VimError, str, arg)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
42
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
43 #define Py_TYPE_NAME(obj) (obj->ob_type->tp_name == NULL \
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
44 ? "(NULL)" \
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
45 : obj->ob_type->tp_name)
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
46
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
47 #define RAISE_NO_EMPTY_KEYS PyErr_SET_STRING(PyExc_ValueError, \
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
48 N_("empty keys are not allowed"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
49 #define RAISE_LOCKED_DICTIONARY PyErr_SET_VIM(N_("dictionary is locked"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
50 #define RAISE_LOCKED_LIST PyErr_SET_VIM(N_("list is locked"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
51 #define RAISE_UNDO_FAIL PyErr_SET_VIM(N_("cannot save undo information"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
52 #define RAISE_DELETE_LINE_FAIL PyErr_SET_VIM(N_("cannot delete line"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
53 #define RAISE_INSERT_LINE_FAIL PyErr_SET_VIM(N_("cannot insert line"))
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
54 #define RAISE_REPLACE_LINE_FAIL PyErr_SET_VIM(N_("cannot replace line"))
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
55 #define RAISE_KEY_ADD_FAIL(key) \
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
56 PyErr_VIM_FORMAT(N_("failed to add key '%s' to dictionary"), key)
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
57 #define RAISE_INVALID_INDEX_TYPE(idx) \
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
58 PyErr_FORMAT(PyExc_TypeError, N_("index must be int or slice, not %s"), \
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
59 Py_TYPE_NAME(idx));
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
60
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
61 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
62 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
63 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
64
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
65 typedef void (*rangeinitializer)(void *);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
66 typedef void (*runner)(const char *, void *
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
67 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
68 , PyGILState_STATE *
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
69 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
70 );
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
71
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
72 static int ConvertFromPyObject(PyObject *, typval_T *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
73 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
74 static int ConvertFromPyMapping(PyObject *, typval_T *);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
75 static int ConvertFromPySequence(PyObject *, typval_T *);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
76 static PyObject *WindowNew(win_T *, tabpage_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
77 static PyObject *BufferNew (buf_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
78 static PyObject *LineToString(const char *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
79
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
80 static PyInt RangeStart;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
81 static PyInt RangeEnd;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
82
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
83 static PyObject *globals;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
84
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
85 static PyObject *py_chdir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
86 static PyObject *py_fchdir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
87 static PyObject *py_getcwd;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
88 static PyObject *vim_module;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
89 static PyObject *vim_special_path_object;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
90
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
91 #if PY_VERSION_HEX >= 0x030700f0
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
92 static PyObject *py_find_spec;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
93 #else
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
94 static PyObject *py_find_module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
95 static PyObject *py_load_module;
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
96 #endif
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
97
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
98 static PyObject *VimError;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
99
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 * obtain a lock on the Vim data structures
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 static void
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 Python_Lock_Vim(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 * release a lock on the Vim data structures
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 static void
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 Python_Release_Vim(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
116 /*
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
117 * The "todecref" argument holds a pointer to PyObject * that must be
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
118 * DECREF'ed after returned char_u * is no longer needed or NULL if all what
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
119 * was needed to generate returned value is object.
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
120 *
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
121 * Use Py_XDECREF to decrement reference count.
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
122 */
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
123 static char_u *
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
124 StringToChars(PyObject *obj, PyObject **todecref)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
125 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
126 char_u *str;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
127
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
128 if (PyBytes_Check(obj))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
129 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
130
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
131 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
132 || str == NULL)
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
133 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
134
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
135 *todecref = NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
136 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
137 else if (PyUnicode_Check(obj))
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
138 {
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
139 PyObject *bytes;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
140
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
141 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
142 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
143
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
144 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
145 || str == NULL)
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
146 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
147 Py_DECREF(bytes);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
148 return NULL;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
149 }
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
150
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
151 *todecref = bytes;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
152 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
153 else
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
154 {
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
155 #if PY_MAJOR_VERSION < 3
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
156 PyErr_FORMAT(PyExc_TypeError,
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
157 N_("expected str() or unicode() instance, but got %s"),
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
158 Py_TYPE_NAME(obj));
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
159 #else
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
160 PyErr_FORMAT(PyExc_TypeError,
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
161 N_("expected bytes() or str() instance, but got %s"),
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
162 Py_TYPE_NAME(obj));
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
163 #endif
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
164 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
165 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
166
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
167 return (char_u *) str;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
168 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
169
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
170 #define NUMBER_LONG 1
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
171 #define NUMBER_INT 2
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
172 #define NUMBER_NATURAL 4
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
173 #define NUMBER_UNSIGNED 8
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
174
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
175 static int
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
176 NumberToLong(PyObject *obj, long *result, int flags)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
177 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
178 #if PY_MAJOR_VERSION < 3
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
179 if (PyInt_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
180 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
181 *result = PyInt_AsLong(obj);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
182 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
183 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
184 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
185 else
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
186 #endif
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
187 if (PyLong_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
188 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
189 *result = PyLong_AsLong(obj);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
190 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
191 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
192 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
193 else if (PyNumber_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
194 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
195 PyObject *num;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
196
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
197 if (!(num = PyNumber_Long(obj)))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
198 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
199
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
200 *result = PyLong_AsLong(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
201
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
202 Py_DECREF(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
203
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
204 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
205 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
206 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
207 else
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
208 {
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
209 #if PY_MAJOR_VERSION < 3
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
210 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
211 N_("expected int(), long() or something supporting "
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
212 "coercing to long(), but got %s"),
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
213 Py_TYPE_NAME(obj));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
214 #else
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
215 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
216 N_("expected int() or something supporting coercing to int(), "
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
217 "but got %s"),
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
218 Py_TYPE_NAME(obj));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
219 #endif
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
220 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
221 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
222
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
223 if (flags & NUMBER_INT)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
224 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
225 if (*result > INT_MAX)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
226 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
227 PyErr_SET_STRING(PyExc_OverflowError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
228 N_("value is too large to fit into C int type"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
229 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
230 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
231 else if (*result < INT_MIN)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
232 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
233 PyErr_SET_STRING(PyExc_OverflowError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
234 N_("value is too small to fit into C int type"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
235 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
236 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
237 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
238
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
239 if (flags & NUMBER_NATURAL)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
240 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
241 if (*result <= 0)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
242 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
243 PyErr_SET_STRING(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
244 N_("number must be greater than zero"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
245 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
246 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
247 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
248 else if (flags & NUMBER_UNSIGNED)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
249 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
250 if (*result < 0)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
251 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
252 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
253 N_("number must be greater or equal to zero"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
254 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
255 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
256 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
257
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
258 return 0;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
259 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
260
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
261 static int
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
262 add_string(PyObject *list, char *s)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
263 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
264 PyObject *string;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
265
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
266 if (!(string = PyString_FromString(s)))
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
267 return -1;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
268
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
269 if (PyList_Append(list, string))
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
270 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
271 Py_DECREF(string);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
272 return -1;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
273 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
274
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
275 Py_DECREF(string);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
276 return 0;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
277 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
278
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
279 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
280 ObjectDir(PyObject *self, char **attributes)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
281 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
282 PyMethodDef *method;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
283 char **attr;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
284 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
285
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
286 if (!(ret = PyList_New(0)))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
287 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
288
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
289 if (self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
290 for (method = self->ob_type->tp_methods ; method->ml_name != NULL ; ++method)
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
291 if (add_string(ret, (char *)method->ml_name))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
292 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
293 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
294 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
295 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
296
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
297 for (attr = attributes ; *attr ; ++attr)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
298 if (add_string(ret, *attr))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
299 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
300 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
301 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
302 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
303
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
304 #if PY_MAJOR_VERSION < 3
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
305 if (add_string(ret, "__members__"))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
306 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
307 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
308 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
309 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
310 #endif
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
311
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
312 return ret;
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
313 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
314
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
315 /* Output buffer management
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317
2582
2cdbc91795ca updated for version 7.3.007
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
318 /* Function to write a line, points to either msg() or emsg(). */
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 typedef void (*writefn)(char_u *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
320
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
321 static PyTypeObject OutputType;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 typedef struct
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 PyObject_HEAD
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 long softspace;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 long error;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 } OutputObject;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
330 static char *OutputAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
331 "softspace",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
332 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
333 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
334
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
335 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
336 OutputDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
337 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
338 return ObjectDir(self, OutputAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
339 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
340
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
341 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
342 OutputSetattr(OutputObject *self, char *name, PyObject *valObject)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
343 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
344 if (valObject == NULL)
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
345 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
346 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
347 N_("can't delete OutputObject attributes"));
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
348 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
349 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
350
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
351 if (strcmp(name, "softspace") == 0)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
352 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
353 if (NumberToLong(valObject, &(self->softspace), NUMBER_UNSIGNED))
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
354 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
355 return 0;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
356 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
357
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
358 PyErr_FORMAT(PyExc_AttributeError, N_("invalid attribute: %s"), name);
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
359 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
360 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
361
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
362 /* Buffer IO, we write one whole line at a time. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
363 static garray_T io_ga = {0, 0, 1, 80, NULL};
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
364 static writefn old_fn = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
365
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
366 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
367 PythonIO_Flush(void)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
368 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
369 if (old_fn != NULL && io_ga.ga_len > 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
370 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
371 ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
372 old_fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
373 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
374 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
375 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
376
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
377 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
378 writer(writefn fn, char_u *str, PyInt n)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
379 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
380 char_u *ptr;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
381
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
382 /* Flush when switching output function. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
383 if (fn != old_fn)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
384 PythonIO_Flush();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
385 old_fn = fn;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
386
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
387 /* Write each NL separated line. Text after the last NL is kept for
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
388 * writing later. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
389 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
390 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
391 PyInt len = ptr - str;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
392
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
393 if (ga_grow(&io_ga, (int)(len + 1)) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
394 break;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
395
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
396 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
397 ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
398 fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
399 str = ptr + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
400 n -= len + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
401 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
402 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
403
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
404 /* Put the remaining text into io_ga for later printing. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
405 if (n > 0 && ga_grow(&io_ga, (int)(n + 1)) == OK)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
406 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
407 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
408 io_ga.ga_len += (int)n;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
409 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
410 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
411
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
412 static int
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
413 write_output(OutputObject *self, PyObject *string)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
414 {
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
415 Py_ssize_t len = 0;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
416 char *str = NULL;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
417 int error = self->error;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
418
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
419 if (!PyArg_Parse(string, "et#", ENC_OPT, &str, &len))
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
420 return -1;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 Py_BEGIN_ALLOW_THREADS
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423 Python_Lock_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
424 writer((writefn)(error ? emsg : msg), (char_u *)str, len);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 Python_Release_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
427 PyMem_Free(str);
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
429 return 0;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
430 }
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
431
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
432 static PyObject *
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
433 OutputWrite(OutputObject *self, PyObject *string)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
434 {
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
435 if (write_output(self, string))
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
436 return NULL;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
437
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438 Py_INCREF(Py_None);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
439 return Py_None;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
440 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
441
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 static PyObject *
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
443 OutputWritelines(OutputObject *self, PyObject *seq)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
444 {
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
445 PyObject *iterator;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
446 PyObject *item;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
447
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
448 if (!(iterator = PyObject_GetIter(seq)))
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
449 return NULL;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
450
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
451 while ((item = PyIter_Next(iterator)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
452 {
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
453 if (write_output(self, item))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
454 {
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
455 Py_DECREF(iterator);
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
456 Py_DECREF(item);
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 return NULL;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 }
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
459 Py_DECREF(item);
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
461
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
462 Py_DECREF(iterator);
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
463
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
464 /* Iterator may have finished due to an exception */
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
465 if (PyErr_Occurred())
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
466 return NULL;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
467
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
468 Py_INCREF(Py_None);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
469 return Py_None;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
471
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
472 static PyObject *
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
473 AlwaysNone(PyObject *self UNUSED)
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
474 {
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
475 /* do nothing */
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
476 Py_INCREF(Py_None);
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
477 return Py_None;
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
478 }
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
479
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
480 static PyObject *
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
481 AlwaysFalse(PyObject *self UNUSED)
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
482 {
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
483 /* do nothing */
7202
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
484 PyObject *ret = Py_False;
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
485 Py_INCREF(ret);
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
486 return ret;
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
487 }
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
488
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
489 static PyObject *
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
490 AlwaysTrue(PyObject *self UNUSED)
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
491 {
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
492 /* do nothing */
7202
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
493 PyObject *ret = Py_True;
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
494 Py_INCREF(ret);
de43f10a3850 commit https://github.com/vim/vim/commit/e7427f4b7e1af6a63600183be6b4c5724beb2f66
Christian Brabandt <cb@256bit.org>
parents: 7191
diff changeset
495 return ret;
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
496 }
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
497
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
498 /***************/
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
499
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
500 static struct PyMethodDef OutputMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
501 /* name, function, calling, doc */
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
502 {"write", (PyCFunction)OutputWrite, METH_O, ""},
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
503 {"writelines", (PyCFunction)OutputWritelines, METH_O, ""},
7191
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
504 {"flush", (PyCFunction)AlwaysNone, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
505 {"close", (PyCFunction)AlwaysNone, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
506 {"isatty", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
507 {"readable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
508 {"seekable", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
692dac7183de commit https://github.com/vim/vim/commit/d424747d5821c2873e24d25d3407d08b25ea3443
Christian Brabandt <cb@256bit.org>
parents: 6598
diff changeset
509 {"writable", (PyCFunction)AlwaysTrue, METH_NOARGS, ""},
8967
df5f9284fcba commit https://github.com/vim/vim/commit/6d4431e7b675ba7a0194c0b8eb84b7d92e4e7953
Christian Brabandt <cb@256bit.org>
parents: 8921
diff changeset
510 {"closed", (PyCFunction)AlwaysFalse, METH_NOARGS, ""},
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
511 {"__dir__", (PyCFunction)OutputDir, METH_NOARGS, ""},
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
512 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
513 };
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
514
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
515 static OutputObject Output =
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
517 PyObject_HEAD_INIT(&OutputType)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
518 0,
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
519 0
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
520 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
521
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
522 static OutputObject Error =
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524 PyObject_HEAD_INIT(&OutputType)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 0,
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
526 1
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 static int
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 PythonIO_Init_io(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 {
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
532 if (PySys_SetObject("stdout", (PyObject *)(void *)&Output))
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
533 return -1;
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
534 if (PySys_SetObject("stderr", (PyObject *)(void *)&Error))
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
535 return -1;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
536
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
537 if (PyErr_Occurred())
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
538 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
539 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
540 return -1;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
541 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
542
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
543 return 0;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
544 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
545
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
546 #if PY_VERSION_HEX < 0x030700f0
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
547 static PyObject *call_load_module(char *name, int len, PyObject *find_module_result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
548
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
549 typedef struct
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
550 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
551 PyObject_HEAD
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
552 char *fullname;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
553 PyObject *result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
554 } LoaderObject;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
555 static PyTypeObject LoaderType;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
556
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
557 static void
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
558 LoaderDestructor(LoaderObject *self)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
559 {
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
560 vim_free(self->fullname);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
561 Py_XDECREF(self->result);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
562 DESTRUCTOR_FINISH(self);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
563 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
564
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
565 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
566 LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
567 {
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
568 char *fullname = self->fullname;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
569 PyObject *result = self->result;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
570 PyObject *module;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
571
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
572 if (!fullname)
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
573 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
574 module = result ? result : Py_None;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
575 Py_INCREF(module);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
576 return module;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
577 }
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
578
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
579 module = call_load_module(fullname, (int)STRLEN(fullname), result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
580
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
581 self->fullname = NULL;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
582 self->result = module;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
583
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
584 vim_free(fullname);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
585 Py_DECREF(result);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
586
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
587 if (!module)
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
588 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
589 if (PyErr_Occurred())
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
590 return NULL;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
591
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
592 Py_INCREF(Py_None);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
593 return Py_None;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
594 }
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
595
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
596 Py_INCREF(module);
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
597 return module;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
598 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
599
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
600 static struct PyMethodDef LoaderMethods[] = {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
601 /* name, function, calling, doc */
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
602 {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""},
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
603 { NULL, NULL, 0, NULL}
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
604 };
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
605 #endif
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 /* Check to see whether a Vim error has been reported, or a keyboard
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 * interrupt has been detected.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609 */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
610
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
611 static void
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
612 VimTryStart(void)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
613 {
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
614 ++trylevel;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
615 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
616
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
617 static int
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
618 VimTryEnd(void)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
619 {
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
620 --trylevel;
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10751
diff changeset
621 /* Without this it stops processing all subsequent Vim script commands and
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10751
diff changeset
622 * generates strange error messages if I e.g. try calling Test() in a cycle
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10751
diff changeset
623 */
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
624 did_emsg = FALSE;
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
625 /* Keyboard interrupt should be preferred over anything else */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
626 if (got_int)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
627 {
5629
91f3908748c2 updated for version 7.4.161
Bram Moolenaar <bram@vim.org>
parents: 5612
diff changeset
628 if (did_throw)
5469
a56f60cf6834 updated for version 7.4.084
Bram Moolenaar <bram@vim.org>
parents: 5426
diff changeset
629 discard_current_exception();
a56f60cf6834 updated for version 7.4.084
Bram Moolenaar <bram@vim.org>
parents: 5426
diff changeset
630 got_int = FALSE;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
631 PyErr_SetNone(PyExc_KeyboardInterrupt);
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
632 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
633 }
5517
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
634 else if (msg_list != NULL && *msg_list != NULL)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
635 {
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
636 int should_free;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
637 char_u *msg;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
638
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
639 msg = get_exception_string(*msg_list, ET_ERROR, NULL, &should_free);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
640
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
641 if (msg == NULL)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
642 {
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
643 PyErr_NoMemory();
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
644 return -1;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
645 }
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
646
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
647 PyErr_SetVim((char *) msg);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
648
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
649 free_global_msglist();
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
650
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
651 if (should_free)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
652 vim_free(msg);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
653
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
654 return -1;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
655 }
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
656 else if (!did_throw)
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
657 return (PyErr_Occurred() ? -1 : 0);
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
658 /* Python exception is preferred over vim one; unlikely to occur though */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
659 else if (PyErr_Occurred())
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
660 {
5629
91f3908748c2 updated for version 7.4.161
Bram Moolenaar <bram@vim.org>
parents: 5612
diff changeset
661 discard_current_exception();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
662 return -1;
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
663 }
10942
e05695e59f6d patch 8.0.0360: sometimes VimL is used instead of "Vim script"
Christian Brabandt <cb@256bit.org>
parents: 10751
diff changeset
664 /* Finally transform Vim script exception to python one */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
665 else
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
666 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
667 PyErr_SetVim((char *)current_exception->value);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
668 discard_current_exception();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
669 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
670 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
671 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
672
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
673 static int
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
674 VimCheckInterrupt(void)
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 if (got_int)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 PyErr_SetNone(PyExc_KeyboardInterrupt);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
679 return 1;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
680 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 return 0;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
682 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
683
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
684 /* Vim module - Implementation
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
685 */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
686
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
687 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
688 VimCommand(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
689 {
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
690 char_u *cmd;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
691 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
692 PyObject *todecref;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
693
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
694 if (!(cmd = StringToChars(string, &todecref)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
695 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
696
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
697 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
698 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
699
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
700 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
701 do_cmdline_cmd(cmd);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
702 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
703
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
704 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
705 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
706
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
707 if (VimTryEnd())
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
708 ret = NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
709 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
710 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
711
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
712 Py_XINCREF(ret);
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
713 Py_XDECREF(todecref);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
714 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
715 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
716
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
717 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
718 * Function to translate a typval_T into a PyObject; this will recursively
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
719 * translate lists/dictionaries into their Python equivalents.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
720 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
721 * The depth parameter is to avoid infinite recursion, set it to 1 when
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
722 * you call VimToPython.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
723 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
724 static PyObject *
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
725 VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
726 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
727 PyObject *ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
728 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
729 char ptrBuf[sizeof(void *) * 2 + 3];
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
730
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
731 /* Avoid infinite recursion */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
732 if (depth > 100)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
733 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
734 Py_INCREF(Py_None);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
735 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
736 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
737 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
738
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
739 /* Check if we run into a recursive loop. The item must be in lookup_dict
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
740 * then and we can use it again. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
741 if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
742 || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
743 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
744 sprintf(ptrBuf, "%p",
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
745 our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
746 : (void *)our_tv->vval.v_dict);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
747
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
748 if ((ret = PyDict_GetItemString(lookup_dict, ptrBuf)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
749 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
750 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
751 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
752 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
753 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
754
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
755 if (our_tv->v_type == VAR_STRING)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
756 ret = PyString_FromString(our_tv->vval.v_string == NULL
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
757 ? "" : (char *)our_tv->vval.v_string);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
758 else if (our_tv->v_type == VAR_NUMBER)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
759 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
760 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
761
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
762 /* For backwards compatibility numbers are stored as strings. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
763 sprintf(buf, "%ld", (long)our_tv->vval.v_number);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
764 ret = PyString_FromString((char *)buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
765 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
766 # ifdef FEAT_FLOAT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
767 else if (our_tv->v_type == VAR_FLOAT)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
768 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
769 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
770
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
771 sprintf(buf, "%f", our_tv->vval.v_float);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
772 ret = PyString_FromString((char *)buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
773 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
774 # endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
775 else if (our_tv->v_type == VAR_LIST)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
776 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
777 list_T *list = our_tv->vval.v_list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
778 listitem_T *curr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
779
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
780 if (list == NULL)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
781 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
782
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
783 if (!(ret = PyList_New(0)))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
784 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
785
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
786 if (PyDict_SetItemString(lookup_dict, ptrBuf, ret))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
787 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
788 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
789 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
790 }
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
791
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
792 for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
793 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
794 if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookup_dict)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
795 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
796 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
797 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
798 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
799 if (PyList_Append(ret, newObj))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
800 {
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
801 Py_DECREF(newObj);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
802 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
803 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
804 }
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
805 Py_DECREF(newObj);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
806 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
807 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
808 else if (our_tv->v_type == VAR_DICT)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
809 {
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
810
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
811 hashtab_T *ht;
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
812 long_u todo;
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
813 hashitem_T *hi;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
814 dictitem_T *di;
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
815
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
816 if (our_tv->vval.v_dict == NULL)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
817 return NULL;
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
818 ht = &our_tv->vval.v_dict->dv_hashtab;
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
819
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
820 if (!(ret = PyDict_New()))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
821 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
822
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
823 if (PyDict_SetItemString(lookup_dict, ptrBuf, ret))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
824 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
825 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
826 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
827 }
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
828
6598
4b1e3b3aa78a updated for version 7.4.625
Bram Moolenaar <bram@vim.org>
parents: 6565
diff changeset
829 todo = ht->ht_used;
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
830 for (hi = ht->ht_array; todo > 0; ++hi)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
831 {
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
832 if (!HASHITEM_EMPTY(hi))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
833 {
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
834 --todo;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
835
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
836 di = dict_lookup(hi);
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
837 if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookup_dict)))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
838 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
839 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
840 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
841 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
842 if (PyDict_SetItemString(ret, (char *)hi->hi_key, newObj))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
843 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
844 Py_DECREF(ret);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
845 Py_DECREF(newObj);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
846 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
847 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
848 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
849 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
850 }
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
851 else if (our_tv->v_type == VAR_SPECIAL)
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
852 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
853 if (our_tv->vval.v_number == VVAL_FALSE)
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
854 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
855 ret = Py_False;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
856 Py_INCREF(ret);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
857 }
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
858 else if (our_tv->vval.v_number == VVAL_TRUE)
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
859 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
860 ret = Py_True;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
861 Py_INCREF(ret);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
862 }
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
863 else
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
864 {
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
865 Py_INCREF(Py_None);
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
866 ret = Py_None;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
867 }
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
868 return ret;
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents: 7660
diff changeset
869 }
15454
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
870 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
871 ret = PyBytes_FromStringAndSize(
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
872 (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
873 (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
874 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
875 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
876 Py_INCREF(Py_None);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
877 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
878 }
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
879
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
880 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
881 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
882
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
883 static PyObject *
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
884 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
885 {
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
886 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
887 typval_T *our_tv;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
888 PyObject *string;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
889 PyObject *todecref;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
890 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
891 PyObject *lookup_dict;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
892
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
893 if (!PyArg_ParseTuple(args, "O", &string))
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
894 return NULL;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
895
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
896 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
897 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
898
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
899 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
900 Python_Lock_Vim();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
901 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
902 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
903 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
904 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
905
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
906 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
907
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
908 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
909 return NULL;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
910
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
911 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
912 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
913 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
914 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
915 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
916
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
917 /* Convert the Vim type into a Python type. Create a dictionary that's
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
918 * used to check for recursive loops. */
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
919 if (!(lookup_dict = PyDict_New()))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
920 ret = NULL;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
921 else
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
922 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
923 ret = VimToPython(our_tv, 1, lookup_dict);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
924 Py_DECREF(lookup_dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
925 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
926
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
927
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
928 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
929 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
930 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
931 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
932 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
933
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
934 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
935 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
936
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
937 static PyObject *ConvertToPyObject(typval_T *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
938
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
939 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
940 VimEvalPy(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
941 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
942 typval_T *our_tv;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
943 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
944 char_u *expr;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
945 PyObject *todecref;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
946
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
947 if (!(expr = StringToChars(string, &todecref)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
948 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
949
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
950 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
951 Python_Lock_Vim();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
952 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
953 our_tv = eval_expr(expr, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
954 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
955 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
956
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
957 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
958
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
959 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
960 return NULL;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
961
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
962 if (our_tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
963 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
964 PyErr_SET_VIM(N_("invalid expression"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
965 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
966 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
967
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
968 ret = ConvertToPyObject(our_tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
969 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
970 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
971 free_tv(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
972 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
973 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
974
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
975 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
976 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
977
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
978 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
979 VimStrwidth(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
980 {
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
981 char_u *str;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
982 PyObject *todecref;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
983 int len;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
984
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
985 if (!(str = StringToChars(string, &todecref)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
986 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
987
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
988 #ifdef FEAT_MBYTE
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
989 len = mb_string2cells(str, (int)STRLEN(str));
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
990 #else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
991 len = STRLEN(str);
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
992 #endif
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
993
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
994 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
995
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
996 return PyLong_FromLong(len);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
997 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
998
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
999 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1000 _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1001 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1002 PyObject *ret;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1003 PyObject *newwd;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1004 PyObject *todecref;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1005 char_u *new_dir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1006
4754
be1e4acb30ca updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents: 4722
diff changeset
1007 if (_chdir == NULL)
be1e4acb30ca updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents: 4722
diff changeset
1008 return NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1009 if (!(ret = PyObject_Call(_chdir, args, kwargs)))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1010 return NULL;
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 (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL)))
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 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1016 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1017
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1018 if (!(new_dir = StringToChars(newwd, &todecref)))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1019 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1020 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1021 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1022 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1023 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1024
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1025 VimTryStart();
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 (vim_chdir(new_dir))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1028 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1029 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1030 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1031 Py_XDECREF(todecref);
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 if (VimTryEnd())
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1034 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1035
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1036 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
1037 return NULL;
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
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1040 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1041 Py_XDECREF(todecref);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1042
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1043 post_chdir(FALSE);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1044
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1045 if (VimTryEnd())
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1046 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1047 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1048 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1049 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1050
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1051 return ret;
4704
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 VimChdir(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_chdir, 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
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1060 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1061 VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1062 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1063 return _VimChdir(py_fchdir, args, kwargs);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1064 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
1065
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1066 typedef struct {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1067 PyObject *callable;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1068 PyObject *result;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1069 } map_rtp_data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1070
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1071 static void
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1072 map_rtp_callback(char_u *path, void *_data)
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 void **data = (void **) _data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1075 PyObject *pathObject;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1076 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
1077
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1078 if (!(pathObject = PyString_FromString((char *)path)))
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1079 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1080 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1081 return;
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
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1084 mr_data->result = PyObject_CallFunctionObjArgs(mr_data->callable,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1085 pathObject, NULL);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1086
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1087 Py_DECREF(pathObject);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1088
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1089 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
1090 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1091 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1092 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1093 Py_DECREF(mr_data->result);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1094 mr_data->result = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1095 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1096 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1097
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1098 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1099 VimForeachRTP(PyObject *self UNUSED, PyObject *callable)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1100 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1101 map_rtp_data data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1102
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1103 data.callable = callable;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1104 data.result = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1105
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7949
diff changeset
1106 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
1107
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1108 if (data.result == NULL)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1109 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1110 if (PyErr_Occurred())
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1111 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1112 else
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 Py_INCREF(Py_None);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1115 return Py_None;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1116 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1117 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1118 return data.result;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1119 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1120
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1121 /*
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1122 * _vim_runtimepath_ special path implementation.
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1123 */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1124
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1125 static void
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1126 map_finder_callback(char_u *path, void *_data)
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 void **data = (void **) _data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1129 PyObject *list = *((PyObject **) data);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1130 PyObject *pathObject1, *pathObject2;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1131 char *pathbuf;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1132 size_t pathlen;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1133
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1134 pathlen = STRLEN(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1135
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1136 #if PY_MAJOR_VERSION < 3
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1137 # define PY_MAIN_DIR_STRING "python2"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1138 #else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1139 # define PY_MAIN_DIR_STRING "python3"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1140 #endif
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1141 #define PY_ALTERNATE_DIR_STRING "pythonx"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1142
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1143 #define PYTHONX_STRING_LENGTH 7 /* STRLEN("pythonx") */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1144 if (!(pathbuf = PyMem_New(char,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1145 pathlen + STRLEN(PATHSEPSTR) + PYTHONX_STRING_LENGTH + 1)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1146 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1147 PyErr_NoMemory();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1148 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1149 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1150 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1151
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1152 mch_memmove(pathbuf, path, pathlen + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1153 add_pathsep((char_u *) 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 pathlen = STRLEN(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1156 mch_memmove(pathbuf + pathlen, PY_MAIN_DIR_STRING,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1157 PYTHONX_STRING_LENGTH + 1);
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 if (!(pathObject1 = PyString_FromString(pathbuf)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1160 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1161 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1162 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1163 return;
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
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1166 mch_memmove(pathbuf + pathlen, PY_ALTERNATE_DIR_STRING,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1167 PYTHONX_STRING_LENGTH + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1168
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1169 if (!(pathObject2 = PyString_FromString(pathbuf)))
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 Py_DECREF(pathObject1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1172 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1173 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1174 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1175 }
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 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1178
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1179 if (PyList_Append(list, pathObject1)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1180 || PyList_Append(list, pathObject2))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1181 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1182
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1183 Py_DECREF(pathObject1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1184 Py_DECREF(pathObject2);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1185 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1186
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1187 static PyObject *
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1188 Vim_GetPaths(PyObject *self UNUSED)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1189 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1190 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1191
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1192 if (!(ret = PyList_New(0)))
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1193 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1194
8524
2f57bbe870ea commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents: 7949
diff changeset
1195 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
1196
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1197 if (PyErr_Occurred())
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1198 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1199 Py_DECREF(ret);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1200 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1201 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1202
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1203 return ret;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1204 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1205
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1206 #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
1207 static PyObject *
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1208 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
1209 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1210 char *fullname;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1211 PyObject *paths;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1212 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
1213 PyObject *spec;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1214
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1215 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
1216 return NULL;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1217
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1218 if (!(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
1219 return NULL;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1220
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1221 spec = PyObject_CallFunction(py_find_spec, "sNN", fullname, paths, target);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1222
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1223 Py_DECREF(paths);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1224
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1225 if (!spec)
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 if (PyErr_Occurred())
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1228 return NULL;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1229
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1230 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
1231 return Py_None;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1232 }
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1233
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1234 return spec;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1235 }
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1236 #else
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1237 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1238 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
1239 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1240 PyObject *fd, *pathname, *description;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1241
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1242 if (!PyTuple_Check(find_module_result))
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1243 {
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1244 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1245 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
1246 Py_TYPE_NAME(find_module_result));
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1247 return NULL;
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1248 }
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1249 if (PyTuple_GET_SIZE(find_module_result) != 3)
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 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1252 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
1253 "tuple of size %d"),
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1254 (int) PyTuple_GET_SIZE(find_module_result));
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1255 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1256 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1257
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1258 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
1259 || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1260 || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1261 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1262 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1263 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
1264 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1265 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1266
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1267 return PyObject_CallFunction(py_load_module,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1268 "s#OOO", name, len, fd, pathname, description);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1269 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1270
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1271 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1272 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
1273 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1274 PyObject *find_module_result;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1275 PyObject *module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1276 char *dot;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1277
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1278 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
1279 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1280 /*
4859
e48cabe98453 updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents: 4855
diff changeset
1281 * 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
1282 * first component
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1283 */
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1284 PyObject *newest_path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1285 int partlen = (int) (dot - 1 - tail);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1286
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1287 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
1288 "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
1289 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1290 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
1291 PyErr_Clear();
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1292 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
1293 }
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1294
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1295 if (!(module = call_load_module(
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1296 fullname,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1297 ((int) (tail - fullname)) + partlen,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1298 find_module_result)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1299 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1300 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1301 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1302 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1303
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1304 Py_DECREF(find_module_result);
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 if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1307 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1308 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1309 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1310 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1311
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1312 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1313
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1314 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
1315
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1316 Py_DECREF(newest_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1317
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1318 return find_module_result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1319 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1320 else
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 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
1323 "sO", tail, new_path)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1324 {
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1325 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
1326 PyErr_Clear();
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1327 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1328 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1329
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1330 return find_module_result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1331 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1332 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1333
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1334 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1335 FinderFindModule(PyObject *self, PyObject *args)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1336 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1337 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
1338 PyObject *result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1339 PyObject *new_path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1340 LoaderObject *loader;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1341
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1342 if (!PyArg_ParseTuple(args, "s", &fullname))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1343 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1344
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1345 if (!(new_path = Vim_GetPaths(self)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1346 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1347
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1348 result = find_module(fullname, fullname, new_path);
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1349
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1350 Py_DECREF(new_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1351
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1352 if (!result)
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1353 {
4984
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1354 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
1355 return NULL;
4984
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1356
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1357 Py_INCREF(Py_None);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1358 return Py_None;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1359 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1360
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1361 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
1362 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1363 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
1364 PyErr_NoMemory();
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1365 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1366 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1367
14467
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1368 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
1369 {
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1370 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
1371 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
1372 return NULL;
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1373 }
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1374
16cccc953909 patch 8.1.0247: Python: error message for failing import is incorrect
Christian Brabandt <cb@256bit.org>
parents: 14395
diff changeset
1375 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
1376 loader->result = result;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1377
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1378 return (PyObject *) loader;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1379 }
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1380 #endif
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1381
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1382 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1383 VimPathHook(PyObject *self UNUSED, PyObject *args)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1384 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1385 char *path;
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 if (PyArg_ParseTuple(args, "s", &path)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1388 && STRCMP(path, vim_special_path) == 0)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1389 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1390 Py_INCREF(vim_module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1391 return vim_module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1392 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1393
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1394 PyErr_Clear();
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1395 PyErr_SetNone(PyExc_ImportError);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1396 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1397 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1398
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1399 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1400 * Vim module - Definitions
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
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1403 static struct PyMethodDef VimMethods[] = {
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1404 /* name, function, calling, documentation */
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1405 {"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
1406 {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" },
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1407 {"bindeval", VimEvalPy, METH_O, "Like eval(), but returns objects attached to vim ones"},
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1408 {"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
1409 {"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
1410 {"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
1411 {"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
1412 #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
1413 {"find_spec", FinderFindSpec, METH_VARARGS, "Internal use only, returns spec object for any input it receives"},
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1414 #else
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1415 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"},
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1416 #endif
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1417 {"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
1418 {"_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
1419 { 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
1420 };
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 /*
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1423 * 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
1424 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1425
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1426 static PyTypeObject IterType;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1427
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1428 typedef PyObject *(*nextfun)(void **);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1429 typedef void (*destructorfun)(void *);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1430 typedef int (*traversefun)(void *, visitproc, void *);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1431 typedef int (*clearfun)(void **);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1432
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1433 /* Main purpose of this object is removing the need for do python
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1434 * initialization (i.e. PyType_Ready and setting type attributes) for a big
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1435 * bunch of objects. */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1436
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1437 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1438 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1439 PyObject_HEAD
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1440 void *cur;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1441 nextfun next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1442 destructorfun destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1443 traversefun traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1444 clearfun clear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1445 } IterObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1446
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1447 static PyObject *
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1448 IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1449 clearfun clear)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1450 {
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1451 IterObject *self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1452
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1453 self = PyObject_GC_New(IterObject, &IterType);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1454 self->cur = start;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1455 self->next = next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1456 self->destruct = destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1457 self->traverse = traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1458 self->clear = clear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1459
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1460 return (PyObject *)(self);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1461 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1462
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1463 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1464 IterDestructor(IterObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1465 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1466 PyObject_GC_UnTrack((void *)(self));
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1467 self->destruct(self->cur);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1468 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
1469 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1470
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1471 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1472 IterTraverse(IterObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1473 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1474 if (self->traverse != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1475 return self->traverse(self->cur, visit, arg);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1476 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1477 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1478 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1479
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1480 /* Mac OSX defines clear() somewhere. */
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1481 #ifdef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1482 # undef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1483 #endif
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1484
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1485 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1486 IterClear(IterObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1487 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1488 if (self->clear != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1489 return self->clear(&self->cur);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1490 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1491 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1492 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1493
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1494 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1495 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
1496 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1497 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
1498 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1499
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1500 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1501 IterIter(PyObject *self)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1502 {
4609
12421d8a45d5 updated for version 7.3.1052
Bram Moolenaar <bram@vim.org>
parents: 4607
diff changeset
1503 Py_INCREF(self);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1504 return self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1505 }
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
1506
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1507 typedef struct pylinkedlist_S {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1508 struct pylinkedlist_S *pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1509 struct pylinkedlist_S *pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1510 PyObject *pll_obj;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1511 } pylinkedlist_T;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1512
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1513 static pylinkedlist_T *lastdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1514 static pylinkedlist_T *lastlist = NULL;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
1515 static pylinkedlist_T *lastfunc = NULL;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1516
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1517 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1518 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1519 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1520 if (ref->pll_prev == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1521 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1522 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1523 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1524 *last = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1525 return;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1526 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1527 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1528 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1529 ref->pll_prev->pll_next = ref->pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1530
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1531 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1532 *last = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1533 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1534 ref->pll_next->pll_prev = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1535 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1536
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1537 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1538 pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1539 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1540 if (*last == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1541 ref->pll_prev = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1542 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1543 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1544 (*last)->pll_next = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1545 ref->pll_prev = *last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1546 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1547 ref->pll_next = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1548 ref->pll_obj = self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1549 *last = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1550 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1551
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1552 static PyTypeObject DictionaryType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1553
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1554 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1555 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1556 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1557 dict_T *dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1558 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1559 } DictionaryObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1560
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1561 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1562
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1563 #define NEW_DICTIONARY(dict) DictionaryNew(&DictionaryType, dict)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1564
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1565 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1566 DictionaryNew(PyTypeObject *subtype, dict_T *dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1567 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1568 DictionaryObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1569
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1570 self = (DictionaryObject *) subtype->tp_alloc(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1571 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1572 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1573 self->dict = dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1574 ++dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1575
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1576 pyll_add((PyObject *)(self), &self->ref, &lastdict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1577
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1578 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1579 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1580
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1581 static dict_T *
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1582 py_dict_alloc(void)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1583 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1584 dict_T *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1585
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1586 if (!(ret = dict_alloc()))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1587 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1588 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1589 return NULL;
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 ++ret->dv_refcount;
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 return ret;
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
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1596 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1597 DictionaryConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1598 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1599 DictionaryObject *self;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1600 dict_T *dict;
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 if (!(dict = py_dict_alloc()))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1603 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1604
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1605 self = (DictionaryObject *) DictionaryNew(subtype, dict);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1606
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1607 --dict->dv_refcount;
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 (kwargs || PyTuple_Size(args))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1610 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1611 PyObject *tmp;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1612 if (!(tmp = DictionaryUpdate(self, args, kwargs)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1613 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1614 Py_DECREF(self);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1615 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1616 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1617
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1618 Py_DECREF(tmp);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1619 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1620
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1621 return (PyObject *)(self);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1622 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1623
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1624 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1625 DictionaryDestructor(DictionaryObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1626 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1627 pyll_remove(&self->ref, &lastdict);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1628 dict_unref(self->dict);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1629
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1630 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1631 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1632
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1633 static char *DictionaryAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1634 "locked", "scope",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1635 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1636 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1637
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1638 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1639 DictionaryDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1640 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1641 return ObjectDir(self, DictionaryAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1642 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1643
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1644 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1645 DictionarySetattr(DictionaryObject *self, char *name, PyObject *valObject)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1646 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1647 if (valObject == NULL)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1648 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1649 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1650 N_("cannot delete vim.Dictionary attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1651 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1652 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1653
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1654 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1655 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1656 if (self->dict->dv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1657 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1658 PyErr_SET_STRING(PyExc_TypeError,
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1659 N_("cannot modify fixed dictionary"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1660 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1661 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1662 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1663 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1664 int istrue = PyObject_IsTrue(valObject);
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1665 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1666 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1667 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1668 self->dict->dv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1669 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1670 self->dict->dv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1671 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1672 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1673 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1674 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1675 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1676 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name);
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1677 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1678 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1679 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1680
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1681 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1682 DictionaryLength(DictionaryObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1683 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1684 return ((PyInt) (self->dict->dv_hashtab.ht_used));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1685 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1686
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1687 #define DICT_FLAG_HAS_DEFAULT 0x01
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1688 #define DICT_FLAG_POP 0x02
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1689 #define DICT_FLAG_NONE_DEFAULT 0x04
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1690 #define DICT_FLAG_RETURN_BOOL 0x08 /* Incompatible with DICT_FLAG_POP */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1691 #define DICT_FLAG_RETURN_PAIR 0x10
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1692
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1693 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1694 _DictionaryItem(DictionaryObject *self, PyObject *args, int flags)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1695 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1696 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1697 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
1698 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1699 char_u *key;
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1700 dictitem_T *di;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1701 dict_T *dict = self->dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1702 hashitem_T *hi;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1703 PyObject *todecref;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1704
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1705 if (flags & DICT_FLAG_HAS_DEFAULT)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1706 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1707 if (!PyArg_ParseTuple(args, "O|O", &keyObject, &defObject))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1708 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1709 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1710 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1711 keyObject = args;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1712
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1713 if (flags & DICT_FLAG_RETURN_BOOL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1714 defObject = Py_False;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1715
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1716 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1717 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1718
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1719 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1720 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1721 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
1722 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1723 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1724 }
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1725
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1726 hi = hash_find(&dict->dv_hashtab, key);
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1727
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1728 Py_XDECREF(todecref);
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
1729
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1730 if (HASHITEM_EMPTY(hi))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1731 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1732 if (defObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1733 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1734 Py_INCREF(defObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1735 return defObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1736 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1737 else
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 PyErr_SetObject(PyExc_KeyError, keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1740 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1741 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1742 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1743 else if (flags & DICT_FLAG_RETURN_BOOL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1744 {
5666
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
1745 ret = Py_True;
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
1746 Py_INCREF(ret);
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
1747 return ret;
4627
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 di = dict_lookup(hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1751
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1752 if (!(ret = ConvertToPyObject(&di->di_tv)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1753 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1754
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1755 if (flags & DICT_FLAG_POP)
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 if (dict->dv_lock)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1758 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1759 RAISE_LOCKED_DICTIONARY;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1760 Py_DECREF(ret);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1761 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1762 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1763
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1764 hash_remove(&dict->dv_hashtab, hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1765 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1766 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1767
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1768 return ret;
4627
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 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1772 DictionaryItem(DictionaryObject *self, PyObject *keyObject)
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 return _DictionaryItem(self, keyObject, 0);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1775 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1776
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1777 static int
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1778 DictionaryContains(DictionaryObject *self, PyObject *keyObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1779 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1780 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
1781 int ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1782
5426
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
1783 if (rObj == NULL)
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
1784 return -1;
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
1785
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1786 ret = (rObj == Py_True);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1787
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
1788 Py_DECREF(rObj);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1789
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1790 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1791 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1792
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1793 typedef struct
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1794 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1795 hashitem_T *ht_array;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1796 long_u ht_used;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1797 hashtab_T *ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1798 hashitem_T *hi;
4667
9e7ef781d494 updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents: 4659
diff changeset
1799 long_u todo;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1800 } dictiterinfo_T;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1801
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1802 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1803 DictionaryIterNext(dictiterinfo_T **dii)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1804 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1805 PyObject *ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1806
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1807 if (!(*dii)->todo)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1808 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1809
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1810 if ((*dii)->ht->ht_array != (*dii)->ht_array ||
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1811 (*dii)->ht->ht_used != (*dii)->ht_used)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1812 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1813 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1814 N_("hashtab changed during iteration"));
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1815 return NULL;
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1816 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1817
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1818 while (((*dii)->todo) && HASHITEM_EMPTY((*dii)->hi))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1819 ++((*dii)->hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1820
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1821 --((*dii)->todo);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1822
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1823 if (!(ret = PyBytes_FromString((char *)(*dii)->hi->hi_key)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1824 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1825
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1826 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1827 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1828
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1829 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1830 DictionaryIter(DictionaryObject *self)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1831 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1832 dictiterinfo_T *dii;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1833 hashtab_T *ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1834
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1835 if (!(dii = PyMem_New(dictiterinfo_T, 1)))
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 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1838 return NULL;
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
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1841 ht = &self->dict->dv_hashtab;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1842 dii->ht_array = ht->ht_array;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1843 dii->ht_used = ht->ht_used;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1844 dii->ht = ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1845 dii->hi = dii->ht_array;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1846 dii->todo = dii->ht_used;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1847
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1848 return IterNew(dii,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1849 (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1850 NULL, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1851 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1852
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1853 static PyInt
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1854 DictionaryAssItem(
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1855 DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1856 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1857 char_u *key;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1858 typval_T tv;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1859 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1860 dictitem_T *di;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1861 PyObject *todecref;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1862
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1863 if (dict->dv_lock)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1864 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1865 RAISE_LOCKED_DICTIONARY;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1866 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1867 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1868
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1869 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1870 return -1;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
1871
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1872 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1873 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1874 RAISE_NO_EMPTY_KEYS;
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1875 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1876 return -1;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1877 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1878
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1879 di = dict_find(dict, key, -1);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1880
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1881 if (valObject == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1882 {
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
1883 hashitem_T *hi;
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
1884
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1885 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1886 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1887 Py_XDECREF(todecref);
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
1888 PyErr_SetObject(PyExc_KeyError, keyObject);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1889 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1890 }
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1891 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
1892 hash_remove(&dict->dv_hashtab, hi);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1893 dictitem_free(di);
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1894 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1895 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1896 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1897
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1898 if (ConvertFromPyObject(valObject, &tv) == -1)
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1899 {
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1900 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1901 return -1;
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1902 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1903
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1904 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1905 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1906 if (!(di = dictitem_alloc(key)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1907 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1908 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1909 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1910 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1911 }
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1912 di->di_tv.v_type = VAR_UNKNOWN;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1913
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1914 if (dict_add(dict, di) == FAIL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1915 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1916 vim_free(di);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1917 dictitem_free(di);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1918 RAISE_KEY_ADD_FAIL(key);
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1919 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1920 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1921 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1922 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1923 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1924 clear_tv(&di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1925
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1926 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1927
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1928 copy_tv(&tv, &di->di_tv);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
1929 clear_tv(&tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1930 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1931 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1932
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1933 typedef PyObject *(*hi_to_py)(hashitem_T *);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1934
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1935 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1936 DictionaryListObjects(DictionaryObject *self, hi_to_py hiconvert)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1937 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1938 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1939 long_u todo = dict->dv_hashtab.ht_used;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1940 Py_ssize_t i = 0;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1941 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1942 hashitem_T *hi;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1943 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1944
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1945 ret = PyList_New(todo);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1946 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1947 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1948 if (!HASHITEM_EMPTY(hi))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1949 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1950 if (!(newObj = hiconvert(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1951 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1952 Py_DECREF(ret);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1953 return NULL;
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 PyList_SET_ITEM(ret, i, newObj);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1956 --todo;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1957 ++i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1958 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1959 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1960 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1961 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1962
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1963 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1964 dict_key(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1965 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1966 return PyBytes_FromString((char *)(hi->hi_key));
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1967 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1968
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1969 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1970 DictionaryListKeys(DictionaryObject *self)
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 return DictionaryListObjects(self, dict_key);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1973 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1974
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1975 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1976 dict_val(hashitem_T *hi)
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 dictitem_T *di;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1979
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1980 di = dict_lookup(hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1981 return ConvertToPyObject(&di->di_tv);
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
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1984 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1985 DictionaryListValues(DictionaryObject *self)
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 return DictionaryListObjects(self, dict_val);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1988 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1989
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1990 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1991 dict_item(hashitem_T *hi)
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 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1994 PyObject *valObject;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1995 PyObject *ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1996
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1997 if (!(keyObject = dict_key(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1998 return NULL;
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 (!(valObject = dict_val(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2001 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2002 Py_DECREF(keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2003 return NULL;
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
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2006 ret = Py_BuildValue("(OO)", keyObject, valObject);
4627
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 Py_DECREF(keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2009 Py_DECREF(valObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2010
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2011 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2012 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2013
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2014 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2015 DictionaryListItems(DictionaryObject *self)
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 return DictionaryListObjects(self, dict_item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2018 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2019
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2020 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2021 DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs)
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 dict_T *dict = self->dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2024
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2025 if (dict->dv_lock)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2026 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2027 RAISE_LOCKED_DICTIONARY;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2028 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2029 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2030
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2031 if (kwargs)
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 typval_T tv;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2034
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2035 if (ConvertFromPyMapping(kwargs, &tv) == -1)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2036 return NULL;
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 VimTryStart();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2039 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
2040 clear_tv(&tv);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2041 if (VimTryEnd())
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2042 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2043 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2044 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2045 {
5659
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2046 PyObject *obj = NULL;
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2047
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2048 if (!PyArg_ParseTuple(args, "|O", &obj))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2049 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2050
5659
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2051 if (obj == NULL)
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2052 {
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2053 Py_INCREF(Py_None);
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2054 return Py_None;
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2055 }
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
2056
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2057 if (PyObject_HasAttrString(obj, "keys"))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2058 return DictionaryUpdate(self, NULL, obj);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2059 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2060 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2061 PyObject *iterator;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2062 PyObject *item;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2063
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2064 if (!(iterator = PyObject_GetIter(obj)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2065 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2066
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2067 while ((item = PyIter_Next(iterator)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2068 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2069 PyObject *fast;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2070 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2071 PyObject *valObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2072 PyObject *todecref;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2073 char_u *key;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2074 dictitem_T *di;
12812
381e67ccf02c patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents: 12806
diff changeset
2075 hashitem_T *hi;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2076
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2077 if (!(fast = PySequence_Fast(item, "")))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2078 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2079 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2080 Py_DECREF(item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2081 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2082 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2083
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2084 Py_DECREF(item);
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 if (PySequence_Fast_GET_SIZE(fast) != 2)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2087 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2088 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2089 Py_DECREF(fast);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2090 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2091 N_("expected sequence element of size 2, "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2092 "but got sequence of size %d"),
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
2093 (int) PySequence_Fast_GET_SIZE(fast));
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2094 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2095 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2096
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2097 keyObject = PySequence_Fast_GET_ITEM(fast, 0);
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 if (!(key = StringToChars(keyObject, &todecref)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2100 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2101 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2102 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2103 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2104 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2105
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2106 di = dictitem_alloc(key);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2107
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2108 Py_XDECREF(todecref);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2109
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2110 if (di == NULL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2111 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2112 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2113 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2114 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2115 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2116 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2117 di->di_tv.v_type = VAR_UNKNOWN;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2118
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2119 valObject = PySequence_Fast_GET_ITEM(fast, 1);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2120
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2121 if (ConvertFromPyObject(valObject, &di->di_tv) == -1)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2122 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2123 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2124 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2125 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2126 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2127 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2128
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2129 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2130
12812
381e67ccf02c patch 8.0.1283: test 86 fails under ASAN
Christian Brabandt <cb@256bit.org>
parents: 12806
diff changeset
2131 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
2132 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
2133 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2134 RAISE_KEY_ADD_FAIL(di->di_key);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2135 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2136 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2137 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2138 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2139 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2140
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2141 Py_DECREF(iterator);
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 /* Iterator may have finished due to an exception */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2144 if (PyErr_Occurred())
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2145 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2146 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2147 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2148 Py_INCREF(Py_None);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2149 return Py_None;
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
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2152 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2153 DictionaryGet(DictionaryObject *self, PyObject *args)
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 return _DictionaryItem(self, args,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2156 DICT_FLAG_HAS_DEFAULT|DICT_FLAG_NONE_DEFAULT);
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
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2159 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2160 DictionaryPop(DictionaryObject *self, PyObject *args)
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 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
2163 }
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 static PyObject *
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2166 DictionaryPopItem(DictionaryObject *self)
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2167 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2168 hashitem_T *hi;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2169 PyObject *ret;
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2170 PyObject *valObject;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2171 dictitem_T *di;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2172
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2173 if (self->dict->dv_hashtab.ht_used == 0)
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2174 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2175 PyErr_SetNone(PyExc_KeyError);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2176 return NULL;
4698
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
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2179 hi = self->dict->dv_hashtab.ht_array;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2180 while (HASHITEM_EMPTY(hi))
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2181 ++hi;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2182
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2183 di = dict_lookup(hi);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2184
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2185 if (!(valObject = ConvertToPyObject(&di->di_tv)))
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2186 return NULL;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2187
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2188 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
2189 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2190 Py_DECREF(valObject);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2191 return NULL;
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
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2194 hash_remove(&self->dict->dv_hashtab, hi);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2195 dictitem_free(di);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2196
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2197 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2198 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2199
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2200 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2201 DictionaryHasKey(DictionaryObject *self, PyObject *keyObject)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2202 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2203 return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2204 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2205
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2206 static PySequenceMethods DictionaryAsSeq = {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2207 0, /* sq_length */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2208 0, /* sq_concat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2209 0, /* sq_repeat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2210 0, /* sq_item */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2211 0, /* sq_slice */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2212 0, /* sq_ass_item */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2213 0, /* sq_ass_slice */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2214 (objobjproc) DictionaryContains, /* sq_contains */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2215 0, /* sq_inplace_concat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2216 0, /* sq_inplace_repeat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2217 };
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2218
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2219 static PyMappingMethods DictionaryAsMapping = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2220 (lenfunc) DictionaryLength,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2221 (binaryfunc) DictionaryItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2222 (objobjargproc) DictionaryAssItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2223 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2224
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2225 static struct PyMethodDef DictionaryMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
2226 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2227 {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2228 {"items", (PyCFunction)DictionaryListItems, METH_NOARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2229 {"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2230 {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2231 {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2232 {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""},
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2233 {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""},
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2234 {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2235 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2236 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2237
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2238 static PyTypeObject ListType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2239
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2240 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2241 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2242 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2243 list_T *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2244 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2245 } ListObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2246
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2247 #define NEW_LIST(list) ListNew(&ListType, list)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2248
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2249 static PyObject *
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2250 ListNew(PyTypeObject *subtype, list_T *list)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2251 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2252 ListObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2253
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2254 self = (ListObject *) subtype->tp_alloc(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2255 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2256 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2257 self->list = list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2258 ++list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2259
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2260 pyll_add((PyObject *)(self), &self->ref, &lastlist);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2261
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2262 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2263 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2264
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2265 static list_T *
5166
467efeee8f9e updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents: 5139
diff changeset
2266 py_list_alloc(void)
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2267 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2268 list_T *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2269
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2270 if (!(ret = list_alloc()))
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2271 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2272 PyErr_NoMemory();
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2273 return NULL;
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 ++ret->lv_refcount;
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 return ret;
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
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2280 static int
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2281 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
2282 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2283 PyObject *iterator;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2284 PyObject *item;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2285 listitem_T *li;
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 if (!(iterator = PyObject_GetIter(obj)))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2288 return -1;
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 while ((item = PyIter_Next(iterator)))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2291 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2292 if (!(li = listitem_alloc()))
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 PyErr_NoMemory();
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2295 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2296 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2297 return -1;
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 li->li_tv.v_lock = 0;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2300 li->li_tv.v_type = VAR_UNKNOWN;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2301
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2302 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
2303 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2304 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2305 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2306 listitem_free(li);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2307 return -1;
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
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2310 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2311
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2312 list_append(l, li);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2313 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2314
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2315 Py_DECREF(iterator);
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 /* Iterator may have finished due to an exception */
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2318 if (PyErr_Occurred())
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2319 return -1;
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 return 0;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2322 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2323
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2324 static PyObject *
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2325 ListConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2326 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2327 list_T *list;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2328 PyObject *obj = NULL;
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 if (kwargs)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2331 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2332 PyErr_SET_STRING(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2333 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
2334 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2335 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2336
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2337 if (!PyArg_ParseTuple(args, "|O", &obj))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2338 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2339
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2340 if (!(list = py_list_alloc()))
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 if (obj)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2344 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2345 PyObject *lookup_dict;
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 (!(lookup_dict = PyDict_New()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2348 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2349 list_unref(list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2350 return NULL;
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
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2353 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
2354 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2355 Py_DECREF(lookup_dict);
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 Py_DECREF(lookup_dict);
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
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2363 return ListNew(subtype, list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2364 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2365
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2366 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2367 ListDestructor(ListObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2368 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2369 pyll_remove(&self->ref, &lastlist);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2370 list_unref(self->list);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2371
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2372 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2373 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2374
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2375 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2376 ListLength(ListObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2377 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2378 return ((PyInt) (self->list->lv_len));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2379 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2380
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2381 static PyObject *
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2382 ListIndex(ListObject *self, Py_ssize_t index)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2383 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2384 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2385
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2386 if (index >= ListLength(self))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2387 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2388 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2389 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2390 }
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2391 li = list_find(self->list, (long) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2392 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2393 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2394 /* No more suitable format specifications in python-2.3 */
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2395 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
2396 (int) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2397 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2398 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2399 return ConvertToPyObject(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2400 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2401
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2402 static PyObject *
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2403 ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t step,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2404 Py_ssize_t slicelen)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2405 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2406 PyInt i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2407 PyObject *list;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2408
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2409 if (step == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2410 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2411 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2412 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2413 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2414
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2415 list = PyList_New(slicelen);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2416 if (list == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2417 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2418
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2419 for (i = 0; i < slicelen; ++i)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2420 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2421 PyObject *item;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2422
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2423 item = ListIndex(self, first + i*step);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2424 if (item == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2425 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2426 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2427 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2428 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2429
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2430 PyList_SET_ITEM(list, i, item);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2431 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2432
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2433 return list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2434 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2435
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2436 static PyObject *
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2437 ListItem(ListObject *self, PyObject* idx)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2438 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2439 #if PY_MAJOR_VERSION < 3
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2440 if (PyInt_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2441 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2442 long _idx = PyInt_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2443 return ListIndex(self, _idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2444 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2445 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2446 #endif
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2447 if (PyLong_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2448 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2449 long _idx = PyLong_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2450 return ListIndex(self, _idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2451 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2452 else if (PySlice_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2453 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2454 Py_ssize_t start, stop, step, slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2455
5768
3ee5808a293c updated for version 7.4.228
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
2456 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self),
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2457 &start, &stop, &step, &slicelen) < 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2458 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2459 return ListSlice(self, start, step, slicelen);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2460 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2461 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2462 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2463 RAISE_INVALID_INDEX_TYPE(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2464 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2465 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2466 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2467
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2468 static void
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2469 list_restore(Py_ssize_t numadded, Py_ssize_t numreplaced, Py_ssize_t slicelen,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2470 list_T *l, listitem_T **lis, listitem_T *lastaddedli)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2471 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2472 while (numreplaced--)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2473 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2474 list_insert(l, lis[numreplaced], lis[slicelen + numreplaced]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2475 listitem_remove(l, lis[slicelen + numreplaced]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2476 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2477 while (numadded--)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2478 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2479 listitem_T *next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2480
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2481 next = lastaddedli->li_prev;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2482 listitem_remove(l, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2483 lastaddedli = next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2484 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2485 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2486
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2487 static int
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2488 ListAssSlice(ListObject *self, Py_ssize_t first,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2489 Py_ssize_t step, Py_ssize_t slicelen, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2490 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2491 PyObject *iterator;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2492 PyObject *item;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2493 listitem_T *li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2494 listitem_T *lastaddedli = NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2495 listitem_T *next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2496 typval_T v;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2497 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2498 PyInt i;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2499 PyInt j;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2500 PyInt numreplaced = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2501 PyInt numadded = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2502 PyInt size;
5655
f2c8d86c460d updated for version 7.4.174
Bram Moolenaar <bram@vim.org>
parents: 5629
diff changeset
2503 listitem_T **lis = NULL;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2504
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2505 size = ListLength(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2506
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2507 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2508 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2509 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2510 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2511 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2512
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2513 if (step == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2514 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2515 PyErr_SET_STRING(PyExc_ValueError, N_("slice step cannot be zero"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2516 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2517 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2518
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2519 if (step != 1 && slicelen == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2520 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2521 /* Nothing to do. Only error out if obj has some items. */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2522 int ret = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2523
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2524 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2525 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2526
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2527 if (!(iterator = PyObject_GetIter(obj)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2528 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2529
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2530 if ((item = PyIter_Next(iterator)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2531 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2532 PyErr_FORMAT(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
2533 N_("attempt to assign sequence of size greater than %d "
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2534 "to extended slice"), 0);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2535 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2536 ret = -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2537 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2538 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2539 return ret;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2540 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2541
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2542 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2543 /* XXX May allocate zero bytes. */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2544 if (!(lis = PyMem_New(listitem_T *, slicelen * 2)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2545 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2546 PyErr_NoMemory();
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2547 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2548 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2549
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2550 if (first == size)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2551 li = NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2552 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2553 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2554 li = list_find(l, (long) first);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2555 if (li == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2556 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2557 PyErr_VIM_FORMAT(N_("internal error: no vim list item %d"),
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2558 (int)first);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2559 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2560 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2561 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2562 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2563 i = slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2564 while (i-- && li != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2565 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2566 j = step;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2567 next = li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2568 if (step > 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2569 while (next != NULL && ((next = next->li_next) != NULL) && --j);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2570 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2571 while (next != NULL && ((next = next->li_prev) != NULL) && ++j);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2572
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2573 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2574 listitem_remove(l, li);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2575 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2576 lis[slicelen - i - 1] = li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2577
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2578 li = next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2579 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2580 if (li == NULL && i != -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2581 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2582 PyErr_SET_VIM(N_("internal error: not enough list items"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2583 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2584 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2585 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2586 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2587 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2588
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2589 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2590 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2591
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2592 if (!(iterator = PyObject_GetIter(obj)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2593 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2594 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2595 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2596 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2597
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2598 i = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2599 while ((item = PyIter_Next(iterator)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2600 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2601 if (ConvertFromPyObject(item, &v) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2602 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2603 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2604 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2605 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2606 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2607 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2608 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2609 if (list_insert_tv(l, &v, numreplaced < slicelen
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2610 ? lis[numreplaced]
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2611 : li) == FAIL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2612 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2613 clear_tv(&v);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2614 PyErr_SET_VIM(N_("internal error: failed to add item to list"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2615 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2616 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2617 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2618 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2619 if (numreplaced < slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2620 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2621 lis[slicelen + numreplaced] = lis[numreplaced]->li_prev;
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 5768
diff changeset
2622 vimlist_remove(l, lis[numreplaced], lis[numreplaced]);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2623 numreplaced++;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2624 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2625 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2626 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2627 if (li)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2628 lastaddedli = li->li_prev;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2629 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2630 lastaddedli = l->lv_last;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2631 numadded++;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2632 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2633 clear_tv(&v);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2634 if (step != 1 && i >= slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2635 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2636 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2637 PyErr_FORMAT(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
2638 N_("attempt to assign sequence of size greater than %d "
5668
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2639 "to extended slice"), (int) slicelen);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2640 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2641 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2642 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2643 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2644 ++i;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2645 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2646 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2647
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2648 if (step != 1 && i != slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2649 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2650 PyErr_FORMAT2(PyExc_ValueError,
5668
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2651 N_("attempt to assign sequence of size %d to extended slice "
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2652 "of size %d"), (int) i, (int) slicelen);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2653 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2654 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2655 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2656 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2657
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2658 if (PyErr_Occurred())
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2659 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2660 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2661 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2662 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2663 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2664
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2665 for (i = 0; i < numreplaced; i++)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2666 listitem_free(lis[i]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2667 if (step == 1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2668 for (i = numreplaced; i < slicelen; i++)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2669 listitem_remove(l, lis[i]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2670
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2671 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2672
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2673 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2674 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2675
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2676 static int
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2677 ListAssIndex(ListObject *self, Py_ssize_t index, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2678 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2679 typval_T tv;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2680 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2681 listitem_T *li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2682 Py_ssize_t length = ListLength(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2683
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2684 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2685 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2686 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2687 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2688 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2689 if (index > length || (index == length && obj == NULL))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2690 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2691 PyErr_SET_STRING(PyExc_IndexError, N_("list index out of range"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2692 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2693 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2694
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2695 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2696 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2697 li = list_find(l, (long) index);
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 5768
diff changeset
2698 vimlist_remove(l, li, li);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2699 clear_tv(&li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2700 vim_free(li);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2701 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2702 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2703
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2704 if (ConvertFromPyObject(obj, &tv) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2705 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2706
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2707 if (index == length)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2708 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2709 if (list_append_tv(l, &tv) == FAIL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2710 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2711 clear_tv(&tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2712 PyErr_SET_VIM(N_("failed to add item to list"));
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2713 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2714 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2715 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2716 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2717 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2718 li = list_find(l, (long) index);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2719 clear_tv(&li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2720 copy_tv(&tv, &li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2721 clear_tv(&tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2722 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2723 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2724 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2725
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2726 static Py_ssize_t
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2727 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2728 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2729 #if PY_MAJOR_VERSION < 3
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2730 if (PyInt_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2731 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2732 long _idx = PyInt_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2733 return ListAssIndex(self, _idx, obj);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2734 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2735 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2736 #endif
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2737 if (PyLong_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2738 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2739 long _idx = PyLong_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2740 return ListAssIndex(self, _idx, obj);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2741 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2742 else if (PySlice_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2743 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2744 Py_ssize_t start, stop, step, slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2745
5768
3ee5808a293c updated for version 7.4.228
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
2746 if (PySlice_GetIndicesEx((PySliceObject_T *)idx, ListLength(self),
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2747 &start, &stop, &step, &slicelen) < 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2748 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2749 return ListAssSlice(self, start, step, slicelen,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2750 obj);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2751 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2752 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2753 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2754 RAISE_INVALID_INDEX_TYPE(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2755 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2756 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2757 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2758
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2759 static PyObject *
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2760 ListConcatInPlace(ListObject *self, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2761 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2762 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2763 PyObject *lookup_dict;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2764
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2765 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2766 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2767 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2768 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2769 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2770
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2771 if (!(lookup_dict = PyDict_New()))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2772 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2773
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2774 if (list_py_concat(l, obj, lookup_dict) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2775 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2776 Py_DECREF(lookup_dict);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2777 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2778 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2779 Py_DECREF(lookup_dict);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2780
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2781 Py_INCREF(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2782 return (PyObject *)(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2783 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2784
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2785 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2786 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2787 listwatch_T lw;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2788 list_T *list;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2789 } listiterinfo_T;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2790
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2791 static void
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2792 ListIterDestruct(listiterinfo_T *lii)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2793 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2794 list_rem_watch(lii->list, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2795 PyMem_Free(lii);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2796 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2797
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2798 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2799 ListIterNext(listiterinfo_T **lii)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2800 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2801 PyObject *ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2802
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2803 if (!((*lii)->lw.lw_item))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2804 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2805
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2806 if (!(ret = ConvertToPyObject(&((*lii)->lw.lw_item->li_tv))))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2807 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2808
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2809 (*lii)->lw.lw_item = (*lii)->lw.lw_item->li_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2810
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2811 return ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2812 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2813
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2814 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2815 ListIter(ListObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2816 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2817 listiterinfo_T *lii;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2818 list_T *l = self->list;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2819
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2820 if (!(lii = PyMem_New(listiterinfo_T, 1)))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2821 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2822 PyErr_NoMemory();
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2823 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2824 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2825
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2826 list_add_watch(l, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2827 lii->lw.lw_item = l->lv_first;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2828 lii->list = l;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2829
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2830 return IterNew(lii,
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2831 (destructorfun) ListIterDestruct, (nextfun) ListIterNext,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2832 NULL, NULL);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2833 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2834
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2835 static char *ListAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2836 "locked",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2837 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2838 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2839
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2840 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2841 ListDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2842 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2843 return ObjectDir(self, ListAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2844 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2845
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2846 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2847 ListSetattr(ListObject *self, char *name, PyObject *valObject)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2848 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2849 if (valObject == NULL)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2850 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2851 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2852 N_("cannot delete vim.List attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2853 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2854 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2855
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2856 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2857 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2858 if (self->list->lv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2859 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2860 PyErr_SET_STRING(PyExc_TypeError, N_("cannot modify fixed list"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2861 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2862 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2863 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2864 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2865 int istrue = PyObject_IsTrue(valObject);
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
2866 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
2867 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
2868 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2869 self->list->lv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2870 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2871 self->list->lv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2872 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2873 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2874 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2875 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2876 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2877 PyErr_FORMAT(PyExc_AttributeError, N_("cannot set attribute %s"), name);
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2878 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2879 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2880 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2881
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2882 static PySequenceMethods ListAsSeq = {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2883 (lenfunc) ListLength, /* sq_length, len(x) */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2884 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2885 0, /* RangeRepeat, sq_repeat, x*n */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2886 (PyIntArgFunc) ListIndex, /* sq_item, x[i] */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2887 0, /* was_sq_slice, x[i:j] */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2888 (PyIntObjArgProc) ListAssIndex, /* sq_as_item, x[i]=v */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2889 0, /* was_sq_ass_slice, x[i:j]=v */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2890 0, /* sq_contains */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2891 (binaryfunc) ListConcatInPlace,/* sq_inplace_concat */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2892 0, /* sq_inplace_repeat */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2893 };
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2894
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2895 static PyMappingMethods ListAsMapping = {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2896 /* mp_length */ (lenfunc) ListLength,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2897 /* mp_subscript */ (binaryfunc) ListItem,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2898 /* mp_ass_subscript */ (objobjargproc) ListAssItem,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2899 };
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2900
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2901 static struct PyMethodDef ListMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2902 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2903 {"__dir__", (PyCFunction)ListDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2904 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2905 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2906
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2907 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2908 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2909 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2910 char_u *name;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2911 int argc;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2912 typval_T *argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2913 dict_T *self;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2914 pylinkedlist_T ref;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
2915 int auto_rebind;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2916 } FunctionObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2917
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2918 static PyTypeObject FunctionType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2919
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
2920 #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
2921 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
2922
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2923 static PyObject *
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2924 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
2925 dict_T *selfdict, int auto_rebind)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2926 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2927 FunctionObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2928
15234
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2929 self = (FunctionObject *)subtype->tp_alloc(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2930 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2931 return NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2932
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2933 if (isdigit(*name))
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2934 {
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2935 if (!translated_function_exists(name))
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2936 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2937 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2938 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
2939 return NULL;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2940 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2941 self->name = vim_strsave(name);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2942 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2943 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
2944 {
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2945 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
2946
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2947 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
2948 vim_strchr(name, AUTOLOAD_CHAR) == NULL)) == NULL)
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2949 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2950 PyErr_FORMAT(PyExc_ValueError,
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2951 N_("function %s does not exist"), name);
4641
59e6c2bd68e3 updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents: 4635
diff changeset
2952 return NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2953 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2954
15234
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2955 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
2956 {
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2957 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
2958 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
2959
15236
9e6d1e80ca2b patch 8.1.0628: Compiler warning on MS-Windows.
Bram Moolenaar <Bram@vim.org>
parents: 15234
diff changeset
2960 if ((np = alloc((int)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
2961 {
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2962 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
2963 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
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 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
2966 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
2967 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
2968 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
2969 }
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2970 else
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2971 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
2972 }
ee63f4fe3d45 patch 8.1.0627: Python cannot handle function name of script-local function
Bram Moolenaar <Bram@vim.org>
parents: 14467
diff changeset
2973
9725
4a4a71d67131 commit https://github.com/vim/vim/commit/2d3d60a7d4b410668dfc427120205ccf88789db4
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
2974 func_ref(self->name);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2975 self->argc = argc;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2976 self->argv = argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2977 self->self = selfdict;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
2978 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
2979
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2980 if (self->argv || self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2981 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
2982
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2983 return (PyObject *)(self);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2984 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2985
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2986 static PyObject *
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2987 FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2988 {
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2989 PyObject *self;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2990 PyObject *selfdictObject;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
2991 PyObject *autoRebindObject;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2992 PyObject *argsObject = NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2993 char_u *name;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2994 typval_T selfdicttv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2995 typval_T argstv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2996 list_T *argslist = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2997 dict_T *selfdict = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
2998 int argc = 0;
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
2999 int auto_rebind = TRUE;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3000 typval_T *argv = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3001 typval_T *curtv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3002 listitem_T *li;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3003
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3004 if (kwargs != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3005 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3006 selfdictObject = PyDict_GetItemString(kwargs, "self");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3007 if (selfdictObject != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3008 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3009 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3010 return NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3011 selfdict = selfdicttv.vval.v_dict;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3012 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3013 argsObject = PyDict_GetItemString(kwargs, "args");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3014 if (argsObject != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3015 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3016 if (ConvertFromPySequence(argsObject, &argstv) == -1)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3017 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3018 dict_unref(selfdict);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3019 return NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3020 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3021 argslist = argstv.vval.v_list;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3022
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3023 argc = argslist->lv_len;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3024 if (argc != 0)
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 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
3027 if (argv == NULL)
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3028 {
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3029 PyErr_NoMemory();
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3030 dict_unref(selfdict);
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3031 list_unref(argslist);
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3032 return NULL;
c3e7cc135754 commit https://github.com/vim/vim/commit/fe4b18640656ddea41f60cf7a76956c9cc5494d6
Christian Brabandt <cb@256bit.org>
parents: 8915
diff changeset
3033 }
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3034 curtv = argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3035 for (li = argslist->lv_first; li != NULL; li = li->li_next)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3036 copy_tv(&li->li_tv, curtv++);
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 list_unref(argslist);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3039 }
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3040 if (selfdict != NULL)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3041 {
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3042 auto_rebind = FALSE;
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3043 autoRebindObject = PyDict_GetItemString(kwargs, "auto_rebind");
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3044 if (autoRebindObject != NULL)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3045 {
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3046 auto_rebind = PyObject_IsTrue(autoRebindObject);
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3047 if (auto_rebind == -1)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3048 {
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3049 dict_unref(selfdict);
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3050 list_unref(argslist);
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3051 return NULL;
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3052 }
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3053 }
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3054 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3055 }
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3056
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
3057 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
3058 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3059 dict_unref(selfdict);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3060 while (argc--)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3061 clear_tv(&argv[argc]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3062 PyMem_Free(argv);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3063 return NULL;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3064 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3065
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3066 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
3067
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
3068 PyMem_Free(name);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
3069
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3070 return self;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3071 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3072
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3073 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3074 FunctionDestructor(FunctionObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3075 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3076 int i;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3077 func_unref(self->name);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
3078 vim_free(self->name);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3079 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
3080 clear_tv(&self->argv[i]);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3081 PyMem_Free(self->argv);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3082 dict_unref(self->self);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3083 if (self->argv || self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3084 pyll_remove(&self->ref, &lastfunc);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3085
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3086 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3087 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3088
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3089 static char *FunctionAttrs[] = {
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3090 "softspace", "args", "self", "auto_rebind",
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3091 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3092 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3093
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3094 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3095 FunctionDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3096 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3097 return ObjectDir(self, FunctionAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3098 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3099
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3100 static PyObject *
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3101 FunctionAttr(FunctionObject *self, char *name)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3102 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3103 list_T *list;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3104 int i;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3105 if (strcmp(name, "name") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3106 return PyString_FromString((char *)(self->name));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3107 else if (strcmp(name, "args") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3108 {
9967
45098d7f72b6 commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents: 9725
diff changeset
3109 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
3110 return AlwaysNone(NULL);
9967
45098d7f72b6 commit https://github.com/vim/vim/commit/9f28953f0c1e3d9fffd49af76503f54eaa279acb
Christian Brabandt <cb@256bit.org>
parents: 9725
diff changeset
3111
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3112 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
3113 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
3114 return NEW_LIST(list);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3115 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3116 else if (strcmp(name, "self") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3117 return self->self == NULL
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3118 ? AlwaysNone(NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3119 : NEW_DICTIONARY(self->self);
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3120 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
3121 return self->auto_rebind
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3122 ? AlwaysTrue(NULL)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3123 : AlwaysFalse(NULL);
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3124 else if (strcmp(name, "__members__") == 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3125 return ObjectDir(NULL, FunctionAttrs);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3126 return NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3127 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3128
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3129 /* Populate partial_T given function object.
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3130 *
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3131 * "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
3132 * 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
3133 */
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3134 static void
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3135 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
3136 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3137 int i;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3138
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3139 pt->pt_name = self->name;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3140 if (self->argv)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3141 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3142 pt->pt_argc = self->argc;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3143 if (exported)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3144 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3145 pt->pt_argv = (typval_T *)alloc_clear(
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3146 sizeof(typval_T) * self->argc);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3147 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
3148 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
3149 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3150 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3151 pt->pt_argv = self->argv;
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 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3154 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3155 pt->pt_argc = 0;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3156 pt->pt_argv = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3157 }
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3158 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
3159 pt->pt_dict = self->self;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3160 if (exported && self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3161 ++pt->pt_dict->dv_refcount;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3162 if (exported)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3163 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
3164 pt->pt_refcount = 1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3165 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3166
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3167 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3168 FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3169 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3170 char_u *name = self->name;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3171 typval_T args;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3172 typval_T selfdicttv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3173 typval_T rettv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3174 dict_T *selfdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3175 PyObject *selfdictObject;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3176 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3177 int error;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3178 partial_T pt;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3179 partial_T *pt_ptr = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3180
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3181 if (ConvertFromPySequence(argsObject, &args) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3182 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3183
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3184 if (kwargs != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3185 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3186 selfdictObject = PyDict_GetItemString(kwargs, "self");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3187 if (selfdictObject != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3188 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
3189 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1)
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3190 {
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3191 clear_tv(&args);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3192 return NULL;
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3193 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3194 selfdict = selfdicttv.vval.v_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3195 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3196 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3197
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3198 if (self->argv || self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3199 {
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3200 vim_memset(&pt, 0, sizeof(partial_T));
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3201 set_partial(self, &pt, FALSE);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3202 pt_ptr = &pt;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3203 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3204
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3205 Py_BEGIN_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3206 Python_Lock_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3207
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3208 VimTryStart();
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3209 error = func_call(name, &args, pt_ptr, selfdict, &rettv);
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3210
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3211 Python_Release_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3212 Py_END_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
3213
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3214 if (VimTryEnd())
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3215 ret = NULL;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3216 else if (error != OK)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3217 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3218 ret = NULL;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3219 PyErr_VIM_FORMAT(N_("failed to run function %s"), (char *)name);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3220 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3221 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3222 ret = ConvertToPyObject(&rettv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3223
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3224 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3225 clear_tv(&rettv);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3226 if (selfdict != NULL)
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3227 clear_tv(&selfdicttv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3228
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3229 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3230 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3231
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3232 static PyObject *
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3233 FunctionRepr(FunctionObject *self)
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3234 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3235 PyObject *ret;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3236 garray_T repr_ga;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3237 int i;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3238 char_u *tofree = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3239 typval_T tv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3240 char_u numbuf[NUMBUFLEN];
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3241
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3242 ga_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
3243 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
3244 if (self->name)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3245 ga_concat(&repr_ga, self->name);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3246 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3247 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
3248 ga_append(&repr_ga, '\'');
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3249 if (self->argv)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3250 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3251 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
3252 ++emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3253 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
3254 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3255 if (i != 0)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3256 ga_concat(&repr_ga, (char_u *)", ");
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3257 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
3258 get_copyID()));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3259 vim_free(tofree);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3260 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3261 --emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3262 ga_append(&repr_ga, ']');
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3263 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3264 if (self->self)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3265 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3266 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
3267 tv.v_type = VAR_DICT;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3268 tv.vval.v_dict = self->self;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3269 ++emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3270 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
3271 --emsg_silent;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3272 vim_free(tofree);
9119
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3273 if (self->auto_rebind)
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
3274 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
3275 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3276 ga_append(&repr_ga, '>');
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3277 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
3278 ga_clear(&repr_ga);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
3279 return ret;
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3280 }
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
3281
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3282 static struct PyMethodDef FunctionMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3283 {"__dir__", (PyCFunction)FunctionDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3284 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3285 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3286
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3287 /*
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3288 * Options object
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3289 */
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3290
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3291 static PyTypeObject OptionsType;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3292
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3293 typedef int (*checkfun)(void *);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3294
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3295 typedef struct
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3296 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3297 PyObject_HEAD
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3298 int opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3299 void *from;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3300 checkfun Check;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3301 PyObject *fromObj;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3302 } OptionsObject;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3303
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3304 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3305 dummy_check(void *arg UNUSED)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3306 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3307 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3308 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3309
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3310 static PyObject *
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3311 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3312 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3313 OptionsObject *self;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3314
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3315 self = PyObject_GC_New(OptionsObject, &OptionsType);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3316 if (self == NULL)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3317 return NULL;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3318
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3319 self->opt_type = opt_type;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3320 self->from = from;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3321 self->Check = Check;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3322 self->fromObj = fromObj;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3323 if (fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3324 Py_INCREF(fromObj);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3325
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3326 return (PyObject *)(self);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3327 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3328
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3329 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3330 OptionsDestructor(OptionsObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3331 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3332 PyObject_GC_UnTrack((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3333 Py_XDECREF(self->fromObj);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3334 PyObject_GC_Del((void *)(self));
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3335 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3336
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3337 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3338 OptionsTraverse(OptionsObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3339 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3340 Py_VISIT(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3341 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3342 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3343
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3344 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3345 OptionsClear(OptionsObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3346 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3347 Py_CLEAR(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3348 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3349 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3350
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3351 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3352 OptionsItem(OptionsObject *self, PyObject *keyObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3353 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3354 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3355 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3356 long numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3357 char_u *stringval;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3358 PyObject *todecref;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3359
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3360 if (self->Check(self->from))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3361 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3362
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3363 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3364 return NULL;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3365
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3366 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3367 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3368 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3369 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3370 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3371 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3372
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3373 flags = get_option_value_strict(key, &numval, &stringval,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3374 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3375
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3376 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3377
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3378 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3379 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3380 PyErr_SetObject(PyExc_KeyError, keyObject);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3381 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3382 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3383
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3384 if (flags & SOPT_UNSET)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3385 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3386 Py_INCREF(Py_None);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3387 return Py_None;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3388 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3389 else if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3390 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3391 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3392 ret = numval ? Py_True : Py_False;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3393 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3394 return ret;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3395 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3396 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3397 return PyInt_FromLong(numval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3398 else if (flags & SOPT_STRING)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3399 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3400 if (stringval)
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3401 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
3402 PyObject *ret = PyBytes_FromString((char *)stringval);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3403 vim_free(stringval);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3404 return ret;
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3405 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3406 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3407 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
3408 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3409 N_("unable to get option value"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3410 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3411 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3412 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3413 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3414 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3415 PyErr_SET_VIM(N_("internal error: unknown option type"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3416 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3417 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3418 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3419
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3420 static int
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3421 OptionsContains(OptionsObject *self, PyObject *keyObject)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3422 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3423 char_u *key;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3424 PyObject *todecref;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3425
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3426 if (!(key = StringToChars(keyObject, &todecref)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3427 return -1;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3428
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3429 if (*key == NUL)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3430 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3431 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3432 return 0;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3433 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3434
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3435 if (get_option_value_strict(key, NULL, NULL, self->opt_type, NULL))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3436 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3437 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3438 return 1;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3439 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3440 else
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3441 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3442 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3443 return 0;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3444 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3445 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3446
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3447 typedef struct
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3448 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3449 void *lastoption;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3450 int opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3451 } optiterinfo_T;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3452
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3453 static PyObject *
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3454 OptionsIterNext(optiterinfo_T **oii)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3455 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3456 char_u *name;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3457
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3458 if ((name = option_iter_next(&((*oii)->lastoption), (*oii)->opt_type)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3459 return PyString_FromString((char *)name);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3460
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3461 return NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3462 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3463
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3464 static PyObject *
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3465 OptionsIter(OptionsObject *self)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3466 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3467 optiterinfo_T *oii;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3468
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3469 if (!(oii = PyMem_New(optiterinfo_T, 1)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3470 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3471 PyErr_NoMemory();
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3472 return NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3473 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3474
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3475 oii->opt_type = self->opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3476 oii->lastoption = NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3477
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3478 return IterNew(oii,
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3479 (destructorfun) PyMem_Free, (nextfun) OptionsIterNext,
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3480 NULL, NULL);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3481 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3482
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3483 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3484 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
3485 {
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3486 char_u *errmsg;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3487
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3488 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
3489 {
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3490 if (VimTryEnd())
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3491 return FAIL;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3492 PyErr_SetVim((char *)errmsg);
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3493 return FAIL;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3494 }
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3495 return OK;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3496 }
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3497
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3498 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3499 set_option_value_for(
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3500 char_u *key,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3501 int numval,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3502 char_u *stringval,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3503 int opt_flags,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3504 int opt_type,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3505 void *from)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3506 {
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3507 win_T *save_curwin = NULL;
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3508 tabpage_T *save_curtab = NULL;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
3509 bufref_T save_curbuf;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3510 int set_ret = 0;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3511
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3512 VimTryStart();
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3513 switch (opt_type)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3514 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3515 case SREQ_WIN:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3516 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
3517 win_find_tabpage((win_T *)from), FALSE) == FAIL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3518 {
6454
a35752526cd0 updated for version 7.4.556
Bram Moolenaar <bram@vim.org>
parents: 6176
diff changeset
3519 restore_win(save_curwin, save_curtab, TRUE);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3520 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3521 return -1;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3522 PyErr_SET_VIM(N_("problem while switching windows"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3523 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3524 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3525 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
3526 restore_win(save_curwin, save_curtab, TRUE);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3527 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3528 case SREQ_BUF:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3529 switch_buffer(&save_curbuf, (buf_T *)from);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3530 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
3531 restore_buffer(&save_curbuf);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3532 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3533 case SREQ_GLOBAL:
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3534 set_ret = set_option_value_err(key, numval, stringval, opt_flags);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3535 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3536 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3537 if (set_ret == FAIL)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3538 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3539 return VimTryEnd();
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3540 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3541
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3542 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3543 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3544 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3545 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3546 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3547 int opt_flags;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3548 int ret = 0;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3549 PyObject *todecref;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3550
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3551 if (self->Check(self->from))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3552 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3553
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3554 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3555 return -1;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3556
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3557 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3558 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3559 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3560 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3561 return -1;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3562 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3563
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3564 flags = get_option_value_strict(key, NULL, NULL,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3565 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3566
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3567 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3568 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3569 PyErr_SetObject(PyExc_KeyError, keyObject);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3570 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3571 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3572 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3573
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3574 if (valObject == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3575 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3576 if (self->opt_type == SREQ_GLOBAL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3577 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3578 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3579 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
3580 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3581 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3582 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3583 else if (!(flags & SOPT_GLOBAL))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3584 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3585 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3586 N_("unable to unset option %s "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3587 "which does not have global value"), key);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3588 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3589 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3590 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3591 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3592 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3593 unset_global_local_option(key, self->from);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3594 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3595 return 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3596 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3597 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3598
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3599 opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3600
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3601 if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3602 {
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3603 int istrue = PyObject_IsTrue(valObject);
4513
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3604
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3605 if (istrue == -1)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3606 ret = -1;
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3607 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3608 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
3609 opt_flags, self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3610 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3611 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3612 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3613 long val;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3614
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3615 if (NumberToLong(valObject, &val, NUMBER_INT))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3616 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3617 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3618 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3619 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3620
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3621 ret = set_option_value_for(key, (int) val, NULL, opt_flags,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3622 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3623 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3624 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3625 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3626 char_u *val;
5525
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3627 PyObject *todecref2;
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3628
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3629 if ((val = StringToChars(valObject, &todecref2)))
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3630 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3631 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
3632 self->opt_type, self->from);
5525
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3633 Py_XDECREF(todecref2);
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3634 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3635 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3636 ret = -1;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3637 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3638
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3639 Py_XDECREF(todecref);
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3640
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3641 return ret;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3642 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3643
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3644 static PySequenceMethods OptionsAsSeq = {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3645 0, /* sq_length */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3646 0, /* sq_concat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3647 0, /* sq_repeat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3648 0, /* sq_item */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3649 0, /* sq_slice */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3650 0, /* sq_ass_item */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3651 0, /* sq_ass_slice */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3652 (objobjproc) OptionsContains, /* sq_contains */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3653 0, /* sq_inplace_concat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3654 0, /* sq_inplace_repeat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3655 };
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3656
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3657 static PyMappingMethods OptionsAsMapping = {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3658 (lenfunc) NULL,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3659 (binaryfunc) OptionsItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3660 (objobjargproc) OptionsAssItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3661 };
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3662
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3663 /* Tabpage object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3664 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3665
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3666 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3667 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3668 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3669 tabpage_T *tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3670 } TabPageObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3671
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3672 static PyObject *WinListNew(TabPageObject *tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3673
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3674 static PyTypeObject TabPageType;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3675
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3676 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3677 CheckTabPage(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3678 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3679 if (self->tab == INVALID_TABPAGE_VALUE)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3680 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3681 PyErr_SET_VIM(N_("attempt to refer to deleted tab page"));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3682 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3683 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3684
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3685 return 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3686 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3687
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3688 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3689 TabPageNew(tabpage_T *tab)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3690 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3691 TabPageObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3692
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3693 if (TAB_PYTHON_REF(tab))
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3694 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3695 self = TAB_PYTHON_REF(tab);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3696 Py_INCREF(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3697 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3698 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3699 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3700 self = PyObject_NEW(TabPageObject, &TabPageType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3701 if (self == NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3702 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3703 self->tab = tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3704 TAB_PYTHON_REF(tab) = self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3705 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3706
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3707 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3708 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3709
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3710 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3711 TabPageDestructor(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3712 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3713 if (self->tab && self->tab != INVALID_TABPAGE_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3714 TAB_PYTHON_REF(self->tab) = NULL;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3715
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3716 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3717 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3718
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3719 static char *TabPageAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3720 "windows", "number", "vars", "window", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3721 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3722 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3723
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3724 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3725 TabPageDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3726 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3727 return ObjectDir(self, TabPageAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3728 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3729
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3730 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3731 TabPageAttrValid(TabPageObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3732 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3733 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3734
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3735 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3736 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3737
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3738 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
3739 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3740 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3741 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3742
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3743 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3744 TabPageAttr(TabPageObject *self, char *name)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3745 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3746 if (strcmp(name, "windows") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3747 return WinListNew(self);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3748 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3749 return PyLong_FromLong((long) get_tab_number(self->tab));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3750 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
3751 return NEW_DICTIONARY(self->tab->tp_vars);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3752 else if (strcmp(name, "window") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3753 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3754 /* For current tab window.c does not bother to set or update tp_curwin
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3755 */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3756 if (self->tab == curtab)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3757 return WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3758 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3759 return WindowNew(self->tab->tp_curwin, self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3760 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3761 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3762 return ObjectDir(NULL, TabPageAttrs);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3763 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3764 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3765
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3766 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3767 TabPageRepr(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3768 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3769 if (self->tab == INVALID_TABPAGE_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3770 return PyString_FromFormat("<tabpage object (deleted) at %p>", (self));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3771 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3772 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3773 int t = get_tab_number(self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3774
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3775 if (t == 0)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3776 return PyString_FromFormat("<tabpage object (unknown) at %p>",
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3777 (self));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3778 else
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3779 return PyString_FromFormat("<tabpage %d>", t - 1);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3780 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3781 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3782
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3783 static struct PyMethodDef TabPageMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3784 /* name, function, calling, documentation */
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3785 {"__dir__", (PyCFunction)TabPageDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3786 { NULL, NULL, 0, NULL}
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3787 };
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3788
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3789 /*
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3790 * Window list object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3791 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3792
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3793 static PyTypeObject TabListType;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3794 static PySequenceMethods TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3795
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3796 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3797 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3798 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3799 } TabListObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3800
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3801 static PyInt
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3802 TabListLength(PyObject *self UNUSED)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3803 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3804 tabpage_T *tp = first_tabpage;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3805 PyInt n = 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3806
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3807 while (tp != NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3808 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3809 ++n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3810 tp = tp->tp_next;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3811 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3812
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3813 return n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3814 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3815
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3816 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3817 TabListItem(PyObject *self UNUSED, PyInt n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3818 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3819 tabpage_T *tp;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3820
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3821 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, --n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3822 if (n == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3823 return TabPageNew(tp);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3824
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3825 PyErr_SET_STRING(PyExc_IndexError, N_("no such tab page"));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3826 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3827 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3828
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
3829 /*
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
3830 * Window object
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3831 */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3832
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3833 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3834 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3835 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3836 win_T *win;
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3837 TabPageObject *tabObject;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3838 } WindowObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3839
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3840 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
3841
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3842 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3843 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
3844 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3845 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
3846 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3847 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
3848 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3849 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3850
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3851 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3852 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3853
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3854 static PyObject *
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3855 WindowNew(win_T *win, tabpage_T *tab)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3856 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3857 /* We need to handle deletion of windows underneath us.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3858 * If we add a "w_python*_ref" field to the win_T structure,
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3859 * then we can get at it in win_free() in vim. We then
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3860 * need to create only ONE Python object per window - if
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3861 * we try to create a second, just INCREF the existing one
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3862 * and return it. The (single) Python object referring to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3863 * the window is stored in "w_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3864 * On a win_free() we set the Python object's win_T* field
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3865 * to an invalid value. We trap all uses of a window
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3866 * object, and reject them if the win_T* field is invalid.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3867 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3868 * Python2 and Python3 get different fields and different objects:
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3869 * w_python_ref and w_python3_ref fields respectively.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3870 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3871
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3872 WindowObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3873
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3874 if (WIN_PYTHON_REF(win))
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3875 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3876 self = WIN_PYTHON_REF(win);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3877 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3878 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3879 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3880 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3881 self = PyObject_GC_New(WindowObject, &WindowType);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3882 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3883 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3884 self->win = win;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3885 WIN_PYTHON_REF(win) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3886 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3887
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3888 self->tabObject = ((TabPageObject *)(TabPageNew(tab)));
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3889
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3890 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3891 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3892
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3893 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3894 WindowDestructor(WindowObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3895 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3896 PyObject_GC_UnTrack((void *)(self));
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3897 if (self->win && self->win != INVALID_WINDOW_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3898 WIN_PYTHON_REF(self->win) = NULL;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3899 Py_XDECREF(((PyObject *)(self->tabObject)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3900 PyObject_GC_Del((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3901 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3902
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3903 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3904 WindowTraverse(WindowObject *self, visitproc visit, void *arg)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3905 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3906 Py_VISIT(((PyObject *)(self->tabObject)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3907 return 0;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3908 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3909
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3910 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3911 WindowClear(WindowObject *self)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3912 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3913 Py_CLEAR(self->tabObject);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3914 return 0;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3915 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3916
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3917 static win_T *
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3918 get_firstwin(TabPageObject *tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3919 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3920 if (tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3921 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3922 if (CheckTabPage(tabObject))
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3923 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3924 /* For current tab window.c does not bother to set or update tp_firstwin
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3925 */
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3926 else if (tabObject->tab == curtab)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3927 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3928 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3929 return tabObject->tab->tp_firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3930 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3931 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3932 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3933 }
14047
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3934
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3935 // 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
3936 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
3937 "buffer",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3938 "cursor",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3939 "height",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3940 "row",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3941 "width",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3942 "col",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3943 "vars",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3944 "options",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3945 "number",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3946 "tabpage",
30a0068f6167 patch 8.1.0041: attribute "width" missing from python window attribute list
Christian Brabandt <cb@256bit.org>
parents: 13952
diff changeset
3947 "valid",
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3948 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3949 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3950
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3951 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3952 WindowDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3953 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3954 return ObjectDir(self, WindowAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3955 }
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3956
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3957 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3958 WindowAttrValid(WindowObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3959 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3960 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3961
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3962 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3963 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3964
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3965 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
3966 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3967 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3968 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3969
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3970 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3971 WindowAttr(WindowObject *self, char *name)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3972 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3973 if (strcmp(name, "buffer") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3974 return (PyObject *)BufferNew(self->win->w_buffer);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3975 else if (strcmp(name, "cursor") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3976 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3977 pos_T *pos = &self->win->w_cursor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3978
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3979 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3980 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3981 else if (strcmp(name, "height") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3982 return PyLong_FromLong((long)(self->win->w_height));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
3983 else if (strcmp(name, "row") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3984 return PyLong_FromLong((long)(self->win->w_winrow));
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3985 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
3986 return PyLong_FromLong((long)(self->win->w_width));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
3987 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
3988 return PyLong_FromLong((long)(self->win->w_wincol));
4323
f1eab4f77a6f updated for version 7.3.911
Bram Moolenaar <bram@vim.org>
parents: 4321
diff changeset
3989 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
3990 return NEW_DICTIONARY(self->win->w_vars);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3991 else if (strcmp(name, "options") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3992 return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow,
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3993 (PyObject *) self);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
3994 else if (strcmp(name, "number") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3995 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3996 if (CheckTabPage(self->tabObject))
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3997 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3998 return PyLong_FromLong((long)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3999 get_win_number(self->win, get_firstwin(self->tabObject)));
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4000 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4001 else if (strcmp(name, "tabpage") == 0)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4002 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4003 Py_INCREF(self->tabObject);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4004 return (PyObject *)(self->tabObject);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
4005 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4006 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4007 return ObjectDir(NULL, WindowAttrs);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4008 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4009 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4010 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4011
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4012 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4013 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
4014 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4015 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
4016 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4017
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4018 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
4019 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4020 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
4021 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4022 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4023 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
4024 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4025 long lnum;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4026 long col;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4027
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4028 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
4029 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4030
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4031 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
4032 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4033 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
4034 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4035 }
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 /* Check for keyboard interrupts */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4038 if (VimCheckInterrupt())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4039 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4040
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4041 self->win->w_cursor.lnum = lnum;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4042 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
4043 self->win->w_set_curswant = TRUE;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4044 #ifdef FEAT_VIRTUALEDIT
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4045 self->win->w_cursor.coladd = 0;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4046 #endif
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
4047 /* When column is out of range silently correct it. */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4048 check_cursor_col_win(self->win);
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
4049
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4050 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4051 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4052 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4053 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
4054 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4055 long height;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4056 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4057
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
4058 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
4059 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4060
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4061 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4062 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
4063 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4064 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4065 curwin = self->win;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4066
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4067 VimTryStart();
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4068 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
4069 curwin = savewin;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4070 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4071 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4072
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4073 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4074 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4075 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
4076 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4077 long width;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4078 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4079
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
4080 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
4081 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4082
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4083 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4084 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
4085 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4086 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4087 curwin = self->win;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4088
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4089 VimTryStart();
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
4090 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
4091 curwin = savewin;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4092 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4093 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4094
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4095 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4096 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4097 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4098 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4099 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
4100 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4101 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4102 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4103
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4104 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4105 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
4106 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4107 if (self->win == INVALID_WINDOW_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4108 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
4109 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4110 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4111 int w = get_win_number(self->win, firstwin);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
4112
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
4113 if (w == 0)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4114 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
4115 (self));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4116 else
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4117 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
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
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4121 static struct PyMethodDef WindowMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4122 /* name, function, calling, documentation */
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4123 {"__dir__", (PyCFunction)WindowDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4124 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4125 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4126
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4127 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4128 * 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
4129 */
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4130
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4131 static PyTypeObject WinListType;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4132 static PySequenceMethods WinListAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4133
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4134 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4135 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4136 PyObject_HEAD
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4137 TabPageObject *tabObject;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4138 } WinListObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4139
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4140 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4141 WinListNew(TabPageObject *tabObject)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4142 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4143 WinListObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4144
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4145 self = PyObject_NEW(WinListObject, &WinListType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4146 self->tabObject = tabObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4147 Py_INCREF(tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4148
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4149 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4150 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4151
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4152 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4153 WinListDestructor(WinListObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4154 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4155 TabPageObject *tabObject = self->tabObject;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4156
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4157 if (tabObject)
4523
57393dc4b811 updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents: 4513
diff changeset
4158 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4159 Py_DECREF((PyObject *)(tabObject));
4523
57393dc4b811 updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents: 4513
diff changeset
4160 }
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4161
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4162 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4163 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4164
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4165 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4166 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
4167 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4168 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
4169 PyInt n = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4170
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4171 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4172 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4173
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4174 while (w != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4175 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4176 ++n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4177 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
4178 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4179
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4180 return n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4181 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4182
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4183 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4184 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
4185 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4186 win_T *w;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4187
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4188 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4189 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4190
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4191 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
4192 if (n == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4193 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
4194
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4195 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
4196 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4197 }
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 /* Convert a Python string into a Vim line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4200 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4201 * 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
4202 * 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
4203 * characters.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4204 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4205 * 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
4206 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4207 static char *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4208 StringToLine(PyObject *obj)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4209 {
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4210 char *str;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4211 char *save;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4212 PyObject *bytes = NULL;
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
4213 Py_ssize_t len = 0;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4214 PyInt i;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4215 char *p;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4216
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4217 if (PyBytes_Check(obj))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4218 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4219 if (PyBytes_AsStringAndSize(obj, &str, &len) == -1
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4220 || str == NULL)
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4221 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4222 }
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4223 else if (PyUnicode_Check(obj))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4224 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4225 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4226 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4227
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4228 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4229 || str == NULL)
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4230 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4231 Py_DECREF(bytes);
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4232 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4233 }
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4234 }
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4235 else
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4236 {
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4237 #if PY_MAJOR_VERSION < 3
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4238 PyErr_FORMAT(PyExc_TypeError,
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4239 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
4240 Py_TYPE_NAME(obj));
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4241 #else
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4242 PyErr_FORMAT(PyExc_TypeError,
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4243 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
4244 Py_TYPE_NAME(obj));
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4245 #endif
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4246 return NULL;
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
4247 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4248
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4249 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4250 * 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
4251 * 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
4252 * a single line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4253 * 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
4254 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4255 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
4256 if (p != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4257 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4258 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
4259 --len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4260 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4261 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4262 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
4263 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
4264 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4265 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4266 }
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 /* Create a copy of the string, with internal nulls replaced by
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4269 * newline characters, as is the vim convention.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4270 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4271 save = (char *)alloc((unsigned)(len+1));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4272 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4273 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4274 PyErr_NoMemory();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
4275 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
4276 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4277 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4278
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4279 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
4280 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4281 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
4282 save[i] = '\n';
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4283 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4284 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
4285 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4286
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4287 save[i] = '\0';
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4288 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
4289
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4290 return save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4291 }
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 /* Get a line from the specified buffer. The line number is
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4294 * 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
4295 * string object.
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 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4298 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
4299 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4300 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
4301 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4302
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4303
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4304 /* Get a list of lines from the specified buffer. The line numbers
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4305 * 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
4306 * 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
4307 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4308 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4309 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
4310 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4311 PyInt i;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4312 PyInt n = hi - lo;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4313 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
4314
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4315 if (list == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4316 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4317
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4318 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
4319 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4320 PyObject *string = LineToString(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4321 (char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4322
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4323 /* Error check - was the Python string creation OK? */
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4324 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
4325 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4326 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4327 return NULL;
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
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4330 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
4331 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4332
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4333 /* The ownership of the Python list is passed to the caller (ie,
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4334 * the caller should Py_DECREF() the object when it is finished
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4335 * with it).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4336 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4337
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4338 return list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4339 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4340
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4341 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4342 * 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
4343 * 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
4344 * deleted).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4345 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4346 static void
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4347 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
4348 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4349 if (curwin->w_cursor.lnum >= lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4350 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4351 /* Adjust the cursor position if it's in/after the changed
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4352 * lines. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4353 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
4354 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4355 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
4356 check_cursor_col();
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 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
4359 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4360 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
4361 check_cursor();
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 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4364 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4365 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
4366 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4367 invalidate_botline();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4368 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4369
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4370 /*
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4371 * 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
4372 * 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
4373 * 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
4374 * 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
4375 * 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
4376 * 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
4377 * 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
4378 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4379 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4380 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
4381 {
11447
698ee9d4fe9f patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents: 10942
diff changeset
4382 bufref_T save_curbuf = {NULL, 0, 0};
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4383 win_T *save_curwin = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4384 tabpage_T *save_curtab = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4385
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
4386 /* First of all, we check the type of the supplied Python object.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4387 * There are three cases:
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4388 * 1. NULL, or None - this is a deletion.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4389 * 2. A string - this is a replacement.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4390 * 3. Anything else - this is an error.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4391 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4392 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
4393 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4394 PyErr_Clear();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4395 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
4396
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4397 VimTryStart();
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4398
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4399 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
4400 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
4401 else if (ml_delete((linenr_T)n, FALSE) == FAIL)
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4402 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
4403 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4404 {
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4405 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
4406 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
4407 if (save_curbuf.br_buf == NULL)
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4408 /* Only adjust marks if we managed to switch to a window that
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4409 * holds the buffer, otherwise line numbers will be invalid. */
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4410 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
4411 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4412
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4413 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
4414
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4415 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4416 return FAIL;
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 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4419 *len_change = -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4420
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4421 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4422 }
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4423 else if (PyBytes_Check(line) || PyUnicode_Check(line))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4424 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4425 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
4426
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4427 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4428 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4429
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4430 VimTryStart();
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4431
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4432 /* We do not need to free "save" if ml_replace() consumes it. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4433 PyErr_Clear();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4434 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
4435
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4436 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
4437 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
4438 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
4439 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4440 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4441 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
4442 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4443 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
4444 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4445 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4446 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4447 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
4448
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4449 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
4450
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4451 /* 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
4452 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
4453 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4454
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4455 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4456 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4457
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4458 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4459 *len_change = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4460
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4461 return OK;
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 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4464 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4465 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4466 return FAIL;
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 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4469
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4470 /* Replace a range of lines in the specified buffer. The line numbers are in
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4471 * Vim format (1-based). The range is from lo up to, but not including, hi.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4472 * The replacement lines are given as a Python list of string objects. The
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4473 * list is checked for validity and correct format. Errors are returned as a
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4474 * value of FAIL. The return value is OK on success.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4475 * If OK is returned and len_change is not NULL, *len_change
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4476 * is set to the change in the buffer length.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4477 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4478 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4479 SetBufferLineList(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4480 buf_T *buf,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4481 PyInt lo,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4482 PyInt hi,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4483 PyObject *list,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4484 PyInt *len_change)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4485 {
11447
698ee9d4fe9f patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents: 10942
diff changeset
4486 bufref_T save_curbuf = {NULL, 0, 0};
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4487 win_T *save_curwin = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4488 tabpage_T *save_curtab = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4489
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
4490 /* First of all, we check the type of the supplied Python object.
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4491 * There are three cases:
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4492 * 1. NULL, or None - this is a deletion.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4493 * 2. A list - this is a replacement.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4494 * 3. Anything else - this is an error.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4495 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4496 if (list == Py_None || list == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4497 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4498 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4499 PyInt n = (int)(hi - lo);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4500
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4501 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4502 VimTryStart();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4503 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4504
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4505 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
4506 RAISE_UNDO_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4507 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4508 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4509 for (i = 0; i < n; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4510 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4511 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4512 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4513 RAISE_DELETE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4514 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4515 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4516 }
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4517 if (buf == curbuf && (save_curwin != NULL
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4518 || save_curbuf.br_buf == NULL))
6176
85a1802ae810 updated for version 7.4.424
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
4519 /* Using an existing window for the buffer, adjust the cursor
85a1802ae810 updated for version 7.4.424
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
4520 * position. */
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4521 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
4522 if (save_curbuf.br_buf == NULL)
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4523 /* Only adjust marks if we managed to switch to a window that
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4524 * holds the buffer, otherwise line numbers will be invalid. */
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4525 deleted_lines_mark((linenr_T)lo, (long)i);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4526 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4527
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4528 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4529
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4530 if (VimTryEnd())
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4531 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4532
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4533 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4534 *len_change = -n;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4535
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4536 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4537 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4538 else if (PyList_Check(list))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4539 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4540 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4541 PyInt new_len = PyList_Size(list);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4542 PyInt old_len = hi - lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4543 PyInt extra = 0; /* lines added to text, can be negative */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4544 char **array;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4545
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4546 if (new_len == 0) /* avoid allocating zero bytes */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4547 array = NULL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4548 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4549 {
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4550 array = PyMem_New(char *, new_len);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4551 if (array == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4552 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4553 PyErr_NoMemory();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4554 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4555 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4556 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4557
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4558 for (i = 0; i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4559 {
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4560 PyObject *line;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4561
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4562 if (!(line = PyList_GetItem(list, i)) ||
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4563 !(array[i] = StringToLine(line)))
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4564 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4565 while (i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4566 vim_free(array[--i]);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4567 PyMem_Free(array);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4568 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4569 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4570 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4571
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4572 VimTryStart();
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4573 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
4574
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4575 /* 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
4576 switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4577
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4578 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
4579 RAISE_UNDO_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4580
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4581 /* If the size of the range is reducing (ie, new_len < old_len) we
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4582 * need to delete some old_len. We do this at the start, by
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4583 * repeatedly deleting line "lo".
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4584 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4585 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4586 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4587 for (i = 0; i < old_len - new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4588 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4589 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4590 RAISE_DELETE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4591 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4592 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4593 extra -= i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4594 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4595
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4596 /* For as long as possible, replace the existing old_len with the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4597 * new old_len. This is a more efficient operation, as it requires
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4598 * less memory allocation and freeing.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4599 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4600 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4601 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4602 for (i = 0; i < old_len && i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4603 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4604 == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4605 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4606 RAISE_REPLACE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4607 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4608 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4609 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4610 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4611 i = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4612
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4613 /* Now we may need to insert the remaining new old_len. If we do, we
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4614 * must free the strings as we finish with them (we can't pass the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4615 * responsibility to vim in this case).
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4616 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4617 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4618 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4619 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4620 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4621 if (ml_append((linenr_T)(lo + i - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4622 (char_u *)array[i], 0, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4623 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4624 RAISE_INSERT_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4625 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4626 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4627 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4628 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4629 ++extra;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4630 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4631 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4632
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4633 /* Free any left-over old_len, as a result of an error */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4634 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4635 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4636 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4637 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4638 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4639
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4640 /* Free the array of old_len. All of its contents have now
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4641 * been dealt with (either freed, or the responsibility passed
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4642 * to vim.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4643 */
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4644 PyMem_Free(array);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4645
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4646 /* Adjust marks. Invalidate any which lie in the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4647 * changed range, and move any in the remainder of the buffer.
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4648 * Only adjust marks if we managed to switch to a window that holds
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4649 * 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
4650 if (save_curbuf.br_buf == NULL)
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4651 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4652 (long)MAXLNUM, (long)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4653 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4654
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4655 if (buf == curbuf)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4656 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4657
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4658 /* END of region without "return". */
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4659 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4660
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4661 if (VimTryEnd())
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4662 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4663
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4664 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4665 *len_change = new_len - old_len;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4666
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4667 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4668 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4669 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4670 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4671 PyErr_BadArgument();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4672 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4673 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4674 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4675
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
4676 /* 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
4677 * 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
4678 * 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
4679 * 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
4680 * 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
4681 * 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
4682 * 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
4683 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4684 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4685 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
4686 {
11447
698ee9d4fe9f patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents: 10942
diff changeset
4687 bufref_T save_curbuf = {NULL, 0, 0};
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4688 win_T *save_curwin = NULL;
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4689 tabpage_T *save_curtab = NULL;
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4690
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4691 /* First of all, we check the type of the supplied Python object.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4692 * It must be a string or a list, or the call is in error.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4693 */
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4694 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
4695 {
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4696 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
4697
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4698 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4699 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4700
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4701 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4702 VimTryStart();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4703 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
4704
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4705 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
4706 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
4707 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
4708 RAISE_INSERT_LINE_FAIL;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4709 else if (save_curbuf.br_buf == NULL)
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4710 /* Only adjust marks if we managed to switch to a window that
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4711 * 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
4712 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
4713
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4714 vim_free(str);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4715 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
4716 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4717
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4718 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4719 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4720
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4721 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4722 *len_change = 1;
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 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4725 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4726 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
4727 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4728 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4729 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
4730 char **array;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4731
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4732 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
4733 if (array == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4734 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4735 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4736 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4737 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4738
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4739 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
4740 {
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4741 PyObject *line;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4742
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4743 if (!(line = PyList_GetItem(lines, i)) ||
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4744 !(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
4745 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4746 while (i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4747 vim_free(array[--i]);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4748 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
4749 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4750 }
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
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4753 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4754 VimTryStart();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4755 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
4756
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4757 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
4758 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
4759 else
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 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
4762 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4763 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
4764 (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
4765 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4766 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
4767
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4768 /* Free the rest of the lines */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4769 while (i < size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4770 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
4771
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4772 break;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4773 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4774 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
4775 }
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4776 if (i > 0 && save_curbuf.br_buf == NULL)
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4777 /* Only adjust marks if we managed to switch to a window that
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4778 * 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
4779 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
4780 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4781
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4782 /* Free the array of lines. All of its contents have now
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4783 * been freed. */
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4784 PyMem_Free(array);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
4785 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
4786
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4787 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4788
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4789 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4790 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4791
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4792 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4793 *len_change = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4794
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4795 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4796 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4797 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4798 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4799 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4800 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4801 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4802 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4803
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4804 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4805 * 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
4806 * -------------------------------------------
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4807 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4808
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4809 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4810 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4811 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4812 buf_T *buf;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4813 } BufferObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4814
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4815 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4816 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
4817 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4818 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
4819 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4820 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
4821 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4822 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4823
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4824 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4825 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4826
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4827 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4828 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
4829 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4830 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4831 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4832
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4833 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4834 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4835
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4836 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4837 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4838
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4839 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
4840 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4841 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
4842 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4843 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4844
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4845 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
4846 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4847
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4848 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4849 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
4850 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4851 PyInt size;
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 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4854 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4855
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4856 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4857 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4858
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4859 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
4860
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4861 if (lo < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4862 lo = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4863 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
4864 lo = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4865 if (hi < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4866 hi = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4867 if (hi < lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4868 hi = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4869 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
4870 hi = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4871
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4872 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
4873 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4874
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4875 static PyInt
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4876 RBAsItem(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4877 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4878 PyInt n,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4879 PyObject *valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4880 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4881 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4882 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
4883 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4884 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4885
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4886 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4887 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4888
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4889 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4890 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4891
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4892 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4893 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4894
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4895 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
4896 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4897 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
4898 return -1;
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
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4901 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
4902 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4903
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4904 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4905 *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
4906
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4907 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4908 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4909
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4910 static PyInt
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4911 RBAsSlice(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4912 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4913 PyInt lo,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4914 PyInt hi,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4915 PyObject *valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4916 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4917 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4918 PyInt *new_end)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4919 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4920 PyInt size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4921 PyInt len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4922
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4923 /* Self must be a valid buffer */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4924 if (CheckBuffer(self))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4925 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4926
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4927 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4928 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4929
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4930 /* Sort out the slice range */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4931 size = end - start + 1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4932
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4933 if (lo < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4934 lo = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4935 else if (lo > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4936 lo = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4937 if (hi < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4938 hi = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4939 if (hi < lo)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4940 hi = lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4941 else if (hi > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4942 hi = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4943
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4944 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
4945 valObject, &len_change) == FAIL)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4946 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4947
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4948 if (new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4949 *new_end = end + len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4950
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4951 return 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4952 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4953
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4954
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4955 static PyObject *
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4956 RBAppend(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4957 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4958 PyObject *args,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4959 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4960 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4961 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
4962 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4963 PyObject *lines;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4964 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4965 PyInt max;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4966 PyInt n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4967
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4968 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4969 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4970
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4971 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4972 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4973
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4974 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
4975
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4976 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
4977 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4978
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4979 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
4980 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4981 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
4982 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4983 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4984
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4985 if (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
4986 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4987
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4988 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4989 *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
4990
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4991 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
4992 return Py_None;
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
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4995 /* Range object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4996 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4997
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4998 static PyTypeObject RangeType;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4999 static PySequenceMethods RangeAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5000 static PyMappingMethods RangeAsMapping;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5001
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5002 typedef struct
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5003 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5004 PyObject_HEAD
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5005 BufferObject *buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5006 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5007 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5008 } RangeObject;
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 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5011 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
5012 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5013 BufferObject *bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5014 RangeObject *self;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5015 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
5016 if (self == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5017 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5018
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5019 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
5020 if (bufr == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5021 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5022 Py_DECREF(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5023 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5024 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5025 Py_INCREF(bufr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5026
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5027 self->buf = bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5028 self->start = start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5029 self->end = end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5030
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5031 return (PyObject *)(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5032 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5033
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5034 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5035 RangeDestructor(RangeObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5036 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5037 PyObject_GC_UnTrack((void *)(self));
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5038 Py_XDECREF(self->buf);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5039 PyObject_GC_Del((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5040 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5041
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5042 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5043 RangeTraverse(RangeObject *self, visitproc visit, void *arg)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5044 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5045 Py_VISIT(((PyObject *)(self->buf)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5046 return 0;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5047 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5048
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5049 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5050 RangeClear(RangeObject *self)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5051 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5052 Py_CLEAR(self->buf);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5053 return 0;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5054 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5055
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5056 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5057 RangeLength(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5058 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5059 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5060 if (CheckBuffer(self->buf))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5061 return -1; /* ??? */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5062
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5063 return (self->end - self->start + 1);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5064 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5065
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5066 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5067 RangeItem(RangeObject *self, PyInt n)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5068 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5069 return RBItem(self->buf, n, self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5070 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5071
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5072 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5073 RangeSlice(RangeObject *self, PyInt lo, PyInt hi)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5074 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5075 return RBSlice(self->buf, lo, hi, self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5076 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5077
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5078 static char *RangeAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5079 "start", "end",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5080 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5081 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5082
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5083 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5084 RangeDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5085 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5086 return ObjectDir(self, RangeAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5087 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5088
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5089 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5090 RangeAppend(RangeObject *self, PyObject *args)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5091 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5092 return RBAppend(self->buf, args, self->start, self->end, &self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5093 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5094
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5095 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5096 RangeRepr(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5097 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5098 if (self->buf->buf == INVALID_BUFFER_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5099 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
5100 (self));
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5101 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5102 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5103 char *name = (char *)self->buf->buf->b_fname;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5104
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5105 if (name == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5106 name = "";
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5107
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5108 return PyString_FromFormat("<range %s (%d:%d)>",
4653
b943fd24c351 updated for version 7.3.1074
Bram Moolenaar <bram@vim.org>
parents: 4645
diff changeset
5109 name, (int)self->start, (int)self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5110 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5111 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5112
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5113 static struct PyMethodDef RangeMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5114 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5115 {"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
5116 {"__dir__", (PyCFunction)RangeDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5117 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5118 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5119
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5120 static PyTypeObject BufferType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5121 static PySequenceMethods BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5122 static PyMappingMethods BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5123
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5124 static PyObject *
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5125 BufferNew(buf_T *buf)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5126 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5127 /* We need to handle deletion of buffers underneath us.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5128 * If we add a "b_python*_ref" field to the buf_T structure,
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5129 * then we can get at it in buf_freeall() in vim. We then
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5130 * need to create only ONE Python object per buffer - if
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5131 * we try to create a second, just INCREF the existing one
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5132 * and return it. The (single) Python object referring to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5133 * the buffer is stored in "b_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5134 * Question: what to do on a buf_freeall(). We'll probably
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5135 * have to either delete the Python object (DECREF it to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5136 * zero - a bad idea, as it leaves dangling refs!) or
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5137 * set the buf_T * value to an invalid value (-1?), which
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5138 * means we need checks in all access functions... Bah.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5139 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5140 * Python2 and Python3 get different fields and different objects:
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5141 * b_python_ref and b_python3_ref fields respectively.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5142 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5143
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5144 BufferObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5145
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5146 if (BUF_PYTHON_REF(buf) != NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5147 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5148 self = BUF_PYTHON_REF(buf);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5149 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5150 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5151 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5152 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5153 self = PyObject_NEW(BufferObject, &BufferType);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5154 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5155 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5156 self->buf = buf;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5157 BUF_PYTHON_REF(buf) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5158 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5159
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5160 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5161 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5162
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5163 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5164 BufferDestructor(BufferObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5165 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5166 if (self->buf && self->buf != INVALID_BUFFER_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5167 BUF_PYTHON_REF(self->buf) = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5168
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5169 DESTRUCTOR_FINISH(self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5170 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5171
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5172 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5173 BufferLength(BufferObject *self)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5174 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5175 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5176 if (CheckBuffer(self))
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5177 return -1; /* ??? */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5178
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5179 return (PyInt)(self->buf->b_ml.ml_line_count);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5180 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5181
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5182 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5183 BufferItem(BufferObject *self, PyInt n)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5184 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5185 return RBItem(self, n, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5186 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5187
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5188 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5189 BufferSlice(BufferObject *self, PyInt lo, PyInt hi)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5190 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5191 return RBSlice(self, lo, hi, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5192 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
5193
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5194 static char *BufferAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5195 "name", "number", "vars", "options", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5196 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5197 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5198
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5199 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5200 BufferDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5201 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5202 return ObjectDir(self, BufferAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5203 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5204
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5205 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5206 BufferAttrValid(BufferObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5207 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5208 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5209
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5210 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5211 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5212
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5213 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
5214 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5215 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5216 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5217
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
5218 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5219 BufferAttr(BufferObject *self, char *name)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5220 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5221 if (strcmp(name, "name") == 0)
4597
00eecb2f8e3e updated for version 7.3.1046
Bram Moolenaar <bram@vim.org>
parents: 4595
diff changeset
5222 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
5223 ? "" : (char *)self->buf->b_ffname));
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5224 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5225 return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5226 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5227 return NEW_DICTIONARY(self->buf->b_vars);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5228 else if (strcmp(name, "options") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5229 return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5230 (PyObject *) self);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5231 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5232 return ObjectDir(NULL, BufferAttrs);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5233 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5234 return NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5235 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5236
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5237 static int
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5238 BufferSetattr(BufferObject *self, char *name, PyObject *valObject)
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5239 {
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5240 if (CheckBuffer(self))
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5241 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5242
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5243 if (strcmp(name, "name") == 0)
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5244 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5245 char_u *val;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5246 aco_save_T aco;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5247 int ren_ret;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5248 PyObject *todecref;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5249
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5250 if (!(val = StringToChars(valObject, &todecref)))
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5251 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5252
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5253 VimTryStart();
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5254 /* Using aucmd_*: autocommands will be executed by rename_buffer */
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5255 aucmd_prepbuf(&aco, self->buf);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5256 ren_ret = rename_buffer(val);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5257 aucmd_restbuf(&aco);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5258 Py_XDECREF(todecref);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5259 if (VimTryEnd())
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5260 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5261
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5262 if (ren_ret == FAIL)
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5263 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5264 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
5265 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5266 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5267 return 0;
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 else
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5270 {
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5271 PyErr_SetString(PyExc_AttributeError, name);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5272 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5273 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5274 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
5275
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5276 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5277 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
5278 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5279 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
5280 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5281
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5282 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5283 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
5284 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5285 pos_T *posp;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5286 char_u *pmark;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5287 char_u mark;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5288 bufref_T savebuf;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5289 PyObject *todecref;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5290
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5291 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
5292 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5293
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5294 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
5295 return NULL;
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5296
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5297 if (pmark[0] == '\0' || pmark[1] != '\0')
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5298 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5299 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5300 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
5301 Py_XDECREF(todecref);
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5302 return NULL;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5303 }
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
5304
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5305 mark = *pmark;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5306
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5307 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
5308
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5309 VimTryStart();
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5310 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
5311 posp = getmark(mark, FALSE);
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9161
diff changeset
5312 restore_buffer(&savebuf);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5313 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5314 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5315
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5316 if (posp == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5317 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5318 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
5319 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5320 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5321
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5322 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
5323 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5324 /* Or raise an error? */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5325 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
5326 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5327 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5328
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5329 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
5330 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5331
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5332 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5333 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
5334 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5335 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5336 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5337
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5338 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
5339 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5340
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5341 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
5342 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5343
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5344 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
5345 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5346
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5347 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5348 BufferRepr(BufferObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5349 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5350 if (self->buf == INVALID_BUFFER_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5351 return PyString_FromFormat("<buffer object (deleted) at %p>", self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5352 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5353 {
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5354 char *name = (char *)self->buf->b_fname;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5355
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5356 if (name == NULL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5357 name = "";
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5358
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5359 return PyString_FromFormat("<buffer %s>", name);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5360 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5361 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5362
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5363 static struct PyMethodDef BufferMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5364 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5365 {"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
5366 {"mark", (PyCFunction)BufferMark, METH_O, "Return (row,col) representing position of named mark" },
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5367 {"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
5368 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5369 { 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
5370 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5371
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5372 /*
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5373 * Buffer list object - Implementation
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5374 */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5375
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5376 static PyTypeObject BufMapType;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5377
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5378 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5379 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5380 PyObject_HEAD
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5381 } BufMapObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5382
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5383 static PyInt
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5384 BufMapLength(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5385 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5386 buf_T *b = firstbuf;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5387 PyInt n = 0;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5388
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5389 while (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5390 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5391 ++n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5392 b = b->b_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5393 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5394
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5395 return n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5396 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5398 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5399 BufMapItem(PyObject *self UNUSED, PyObject *keyObject)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5400 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5401 buf_T *b;
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5402 long bnr;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5403
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5404 if (NumberToLong(keyObject, &bnr, NUMBER_INT|NUMBER_NATURAL))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5405 return NULL;
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5406
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5407 b = buflist_findnr((int) bnr);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5408
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5409 if (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5410 return BufferNew(b);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5411 else
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5412 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
5413 PyErr_SetObject(PyExc_KeyError, keyObject);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5414 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5415 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5416 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5417
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5418 static void
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5419 BufMapIterDestruct(PyObject *buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5420 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5421 /* Iteration was stopped before all buffers were processed */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5422 if (buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5423 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5424 Py_DECREF(buffer);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5425 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5426 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5427
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5428 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5429 BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5430 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5431 if (buffer)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5432 Py_VISIT(buffer);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5433 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5434 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5435
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5436 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5437 BufMapIterClear(PyObject **buffer)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5438 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5439 if (*buffer)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5440 Py_CLEAR(*buffer);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5441 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5442 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5443
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5444 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5445 BufMapIterNext(PyObject **buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5446 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5447 PyObject *next;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5448 PyObject *ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5449
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5450 if (!*buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5451 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5452
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5453 ret = *buffer;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5454
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5455 if (CheckBuffer((BufferObject *)(ret)))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5456 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5457 *buffer = NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5458 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5459 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5460
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5461 if (!((BufferObject *)(ret))->buf->b_next)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5462 next = NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5463 else if (!(next = BufferNew(((BufferObject *)(ret))->buf->b_next)))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5464 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5465 *buffer = next;
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
5466 /* Do not increment reference: we no longer hold it (decref), but whoever
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
5467 * 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
5468 return ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5469 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5470
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5471 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5472 BufMapIter(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5473 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5474 PyObject *buffer;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5475
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5476 buffer = BufferNew(firstbuf);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5477 return IterNew(buffer,
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5478 (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5479 (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5480 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5481
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5482 static PyMappingMethods BufMapAsMapping = {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5483 (lenfunc) BufMapLength,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5484 (binaryfunc) BufMapItem,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5485 (objobjargproc) 0,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5486 };
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5487
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5488 /* 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
5489 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5490
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5491 static char *CurrentAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5492 "buffer", "window", "line", "range", "tabpage",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5493 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5494 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5495
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5496 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5497 CurrentDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5498 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5499 return ObjectDir(self, CurrentAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5500 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5501
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5502 static PyObject *
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5503 CurrentGetattr(PyObject *self UNUSED, char *name)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5504 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5505 if (strcmp(name, "buffer") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5506 return (PyObject *)BufferNew(curbuf);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5507 else if (strcmp(name, "window") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
5508 return (PyObject *)WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
5509 else if (strcmp(name, "tabpage") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
5510 return (PyObject *)TabPageNew(curtab);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5511 else if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5512 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5513 else if (strcmp(name, "range") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5514 return RangeNew(curbuf, RangeStart, RangeEnd);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5515 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5516 return ObjectDir(NULL, CurrentAttrs);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5517 else
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5518 #if PY_MAJOR_VERSION < 3
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5519 return Py_FindMethod(WindowMethods, self, name);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5520 #else
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5521 return NULL;
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5522 #endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5523 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5524
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5525 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5526 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *valObject)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5527 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5528 if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5529 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5530 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
5531 NULL) == FAIL)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5532 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5533
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5534 return 0;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5535 }
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5536 else if (strcmp(name, "buffer") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5537 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5538 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5539
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5540 if (valObject->ob_type != &BufferType)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5541 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5542 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5543 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
5544 Py_TYPE_NAME(valObject));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5545 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5546 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5547
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5548 if (CheckBuffer((BufferObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5549 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5550 count = ((BufferObject *)(valObject))->buf->b_fnum;
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5551
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5552 VimTryStart();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5553 if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5554 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5555 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5556 return -1;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5557 PyErr_VIM_FORMAT(N_("failed to switch to buffer %d"), count);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5558 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5559 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5560
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5561 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5562 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5563 else if (strcmp(name, "window") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5564 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5565 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5566
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5567 if (valObject->ob_type != &WindowType)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5568 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5569 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5570 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
5571 Py_TYPE_NAME(valObject));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5572 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5573 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5574
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5575 if (CheckWindow((WindowObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5576 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5577 count = get_win_number(((WindowObject *)(valObject))->win, firstwin);
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5578
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5579 if (!count)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5580 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5581 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5582 N_("failed to find window in the current tab page"));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5583 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5584 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5585
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5586 VimTryStart();
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5587 win_goto(((WindowObject *)(valObject))->win);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5588 if (((WindowObject *)(valObject))->win != curwin)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5589 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5590 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5591 return -1;
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5592 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5593 N_("did not switch to the specified window"));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5594 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5595 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5596
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5597 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5598 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5599 else if (strcmp(name, "tabpage") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5600 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5601 if (valObject->ob_type != &TabPageType)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5602 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5603 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5604 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
5605 Py_TYPE_NAME(valObject));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5606 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5607 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5608
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5609 if (CheckTabPage((TabPageObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5610 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5611
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5612 VimTryStart();
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5613 goto_tabpage_tp(((TabPageObject *)(valObject))->tab, TRUE, TRUE);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5614 if (((TabPageObject *)(valObject))->tab != curtab)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5615 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5616 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
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 tab page"));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5620 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5621 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5622
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5623 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5624 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5625 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5626 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5627 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5628 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5629 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5630 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5631
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5632 static struct PyMethodDef CurrentMethods[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5633 /* name, function, calling, documentation */
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5634 {"__dir__", (PyCFunction)CurrentDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5635 { NULL, NULL, 0, NULL}
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5636 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5637
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5638 static void
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5639 init_range_cmd(exarg_T *eap)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5640 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5641 RangeStart = eap->line1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5642 RangeEnd = eap->line2;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5643 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5644
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5645 static void
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5646 init_range_eval(typval_T *rettv UNUSED)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5647 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5648 RangeStart = (PyInt) curwin->w_cursor.lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5649 RangeEnd = RangeStart;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5650 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5651
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5652 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5653 run_cmd(const char *cmd, void *arg UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5654 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5655 , PyGILState_STATE *pygilstate UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5656 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5657 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5658 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5659 PyObject *run_ret;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5660 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
5661 if (run_ret != NULL)
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5662 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5663 Py_DECREF(run_ret);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5664 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5665 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5666 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5667 semsg(_(e_py_systemexit), "python");
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5668 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5669 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5670 else
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5671 PyErr_PrintEx(1);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5672 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5673
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5674 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n ";
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5675 static int code_hdr_len = 30;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5676
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5677 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5678 run_do(const char *cmd, void *arg UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5679 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5680 , PyGILState_STATE *pygilstate
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5681 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5682 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5683 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5684 PyInt lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5685 size_t len;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5686 char *code;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5687 int status;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5688 PyObject *pyfunc, *pymain;
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5689 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
5690 buf_T *was_curbuf = curbuf;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5691
4575
626e9ccb7c48 updated for version 7.3.1035
Bram Moolenaar <bram@vim.org>
parents: 4523
diff changeset
5692 if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5693 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5694 emsg(_("cannot save undo information"));
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5695 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5696 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5697
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5698 len = code_hdr_len + STRLEN(cmd);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5699 code = PyMem_New(char, len + 1);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5700 memcpy(code, code_hdr, code_hdr_len);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5701 STRCPY(code + code_hdr_len, cmd);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5702 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
5703 status = -1;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5704 if (run_ret != NULL)
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5705 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5706 status = 0;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5707 Py_DECREF(run_ret);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5708 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5709 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5710 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5711 PyMem_Free(code);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5712 semsg(_(e_py_systemexit), "python");
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5713 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5714 return;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5715 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5716 else
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5717 PyErr_PrintEx(1);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5718
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5719 PyMem_Free(code);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5720
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5721 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5722 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5723 emsg(_("failed to run the code"));
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5724 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5725 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5726
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5727 status = 0;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5728 pymain = PyImport_AddModule("__main__");
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5729 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5730 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5731 PyGILState_Release(*pygilstate);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5732 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5733
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5734 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5735 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5736 PyObject *line;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5737 PyObject *linenr;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5738 PyObject *ret;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5739
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5740 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5741 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5742 #endif
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5743 /* Check the line number, the command my have deleted lines. */
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5744 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
5745 || !(line = GetBufferLine(curbuf, lnum)))
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5746 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5747 if (!(linenr = PyInt_FromLong((long) lnum)))
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5748 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5749 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5750 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5751 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5752 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5753 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5754 Py_DECREF(linenr);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5755 if (!ret)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5756 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5757
10751
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5758 /* Check that the command didn't switch to another buffer. */
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5759 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
5760 {
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5761 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
5762 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
5763 }
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5764
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5765 if (ret != Py_None)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5766 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
5767 {
27b42717662b patch 8.0.0265: may get ml_get error when :pydo deletes lines
Christian Brabandt <cb@256bit.org>
parents: 9967
diff changeset
5768 Py_XDECREF(ret);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5769 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
5770 }
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5771
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5772 Py_XDECREF(ret);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5773 PythonIO_Flush();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5774 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5775 PyGILState_Release(*pygilstate);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5776 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5777 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5778 goto out;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5779 err:
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5780 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5781 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5782 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5783 PyErr_PrintEx(0);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5784 PythonIO_Flush();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5785 status = 1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5786 out:
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5787 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5788 if (!status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5789 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5790 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5791 Py_DECREF(pyfunc);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5792 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5793 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5794 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5795 check_cursor();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5796 update_curbuf(NOT_VALID);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5797 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5798
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5799 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5800 run_eval(const char *cmd, typval_T *rettv
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5801 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5802 , PyGILState_STATE *pygilstate UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5803 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5804 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5805 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5806 PyObject *run_ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5807
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5808 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
5809 if (run_ret == NULL)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5810 {
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5811 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5812 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5813 semsg(_(e_py_systemexit), "python");
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5814 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5815 }
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5816 else
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5817 {
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5818 if (PyErr_Occurred() && !msg_silent)
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5819 PyErr_PrintEx(0);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5820 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
5821 }
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5822 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5823 else
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5824 {
12806
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
5825 if (ConvertFromPyObject(run_ret, rettv) == -1)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
5826 emsg(_("E859: Failed to convert returned python object to vim value"));
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5827 Py_DECREF(run_ret);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5828 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5829 PyErr_Clear();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5830 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5831
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5832 static int
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5833 set_ref_in_py(const int copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5834 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5835 pylinkedlist_T *cur;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5836 dict_T *dd;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5837 list_T *ll;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5838 int i;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5839 int abort = FALSE;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5840 FunctionObject *func;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5841
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5842 if (lastdict != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5843 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5844 for (cur = lastdict ; !abort && cur != NULL ; cur = cur->pll_prev)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5845 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5846 dd = ((DictionaryObject *) (cur->pll_obj))->dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5847 if (dd->dv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5848 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5849 dd->dv_copyID = copyID;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5850 abort = abort || set_ref_in_ht(&dd->dv_hashtab, copyID, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5851 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5852 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5853 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5854
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5855 if (lastlist != NULL)
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5856 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5857 for (cur = lastlist ; !abort && cur != NULL ; cur = cur->pll_prev)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5858 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5859 ll = ((ListObject *) (cur->pll_obj))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5860 if (ll->lv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5861 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5862 ll->lv_copyID = copyID;
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5863 abort = abort || set_ref_in_list(ll, copyID, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5864 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5865 }
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5866 }
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5867
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5868 if (lastfunc != NULL)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5869 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5870 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
5871 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5872 func = (FunctionObject *) cur->pll_obj;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5873 if (func->self != NULL && func->self->dv_copyID != copyID)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5874 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5875 func->self->dv_copyID = copyID;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5876 abort = abort || set_ref_in_ht(
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5877 &func->self->dv_hashtab, copyID, NULL);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5878 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5879 if (func->argc)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5880 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
5881 abort = abort
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
5882 || 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
5883 }
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
6565
38add5a3d617 updated for version 7.4.609
Bram Moolenaar <bram@vim.org>
parents: 6454
diff changeset
5886 return abort;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5887 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5888
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5889 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5890 set_string_copy(char_u *str, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5891 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5892 tv->vval.v_string = vim_strsave(str);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5893 if (tv->vval.v_string == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5894 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5895 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5896 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5897 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5898 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5899 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5900
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5901 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5902 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5903 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5904 dict_T *dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5905 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5906 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5907 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5908 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5909 Py_ssize_t iter = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5910
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5911 if (!(dict = py_dict_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5912 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5913
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5914 tv->v_type = VAR_DICT;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5915 tv->vval.v_dict = dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5916
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5917 while (PyDict_Next(obj, &iter, &keyObject, &valObject))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5918 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5919 PyObject *todecref = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5920
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5921 if (keyObject == NULL || valObject == NULL)
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5922 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5923 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5924 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5925 }
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5926
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5927 if (!(key = StringToChars(keyObject, &todecref)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5928 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5929 dict_unref(dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5930 return -1;
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5931 }
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
5932
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5933 if (*key == NUL)
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5934 {
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5935 dict_unref(dict);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5936 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5937 RAISE_NO_EMPTY_KEYS;
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5938 return -1;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5939 }
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5940
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5941 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5942
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5943 Py_XDECREF(todecref);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5944
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5945 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5946 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5947 PyErr_NoMemory();
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5948 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5949 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5950 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5951
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5952 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5953 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5954 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5955 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5956 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5957 }
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5958
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5959 if (dict_add(dict, di) == FAIL)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5960 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5961 RAISE_KEY_ADD_FAIL(di->di_key);
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5962 clear_tv(&di->di_tv);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5963 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5964 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5965 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5966 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5967 }
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5968
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5969 --dict->dv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5970 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5971 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5972
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5973 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5974 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5975 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5976 dict_T *dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5977 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5978 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5979 PyObject *list;
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5980 PyObject *iterator;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5981 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5982 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5983
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5984 if (!(dict = py_dict_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5985 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5986
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5987 tv->v_type = VAR_DICT;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5988 tv->vval.v_dict = dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5989
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5990 if (!(list = PyMapping_Keys(obj)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5991 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5992 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5993 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5994 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5995
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5996 if (!(iterator = PyObject_GetIter(list)))
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5997 {
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5998 dict_unref(dict);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5999 Py_DECREF(list);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6000 return -1;
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6001 }
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6002 Py_DECREF(list);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6003
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6004 while ((keyObject = PyIter_Next(iterator)))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6005 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6006 PyObject *todecref;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6007
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6008 if (!(key = StringToChars(keyObject, &todecref)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6009 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6010 Py_DECREF(keyObject);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6011 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6012 dict_unref(dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6013 return -1;
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6014 }
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
6015
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6016 if (*key == NUL)
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 Py_DECREF(keyObject);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6019 Py_DECREF(iterator);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6020 Py_XDECREF(todecref);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6021 dict_unref(dict);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
6022 RAISE_NO_EMPTY_KEYS;
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6023 return -1;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6024 }
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6025
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6026 if (!(valObject = PyObject_GetItem(obj, keyObject)))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6027 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6028 Py_DECREF(keyObject);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6029 Py_DECREF(iterator);
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6030 Py_XDECREF(todecref);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6031 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6032 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6033 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6034
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6035 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6036
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6037 Py_DECREF(keyObject);
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
6038 Py_XDECREF(todecref);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6039
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6040 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6041 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6042 Py_DECREF(iterator);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6043 Py_DECREF(valObject);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6044 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6045 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6046 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6047 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6048
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6049 if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6050 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6051 Py_DECREF(iterator);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6052 Py_DECREF(valObject);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6053 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6054 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6055 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6056 }
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6057
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6058 Py_DECREF(valObject);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6059
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6060 if (dict_add(dict, di) == FAIL)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6061 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6062 RAISE_KEY_ADD_FAIL(di->di_key);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6063 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6064 dictitem_free(di);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6065 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6066 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6067 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6068 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6069 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6070 --dict->dv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6071 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6072 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6073
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6074 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6075 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6076 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6077 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6078
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6079 if (!(l = py_list_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6080 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6081
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6082 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6083 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6084
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6085 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
6086 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6087 list_unref(l);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6088 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6089 }
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6090
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6091 --l->lv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6092 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6093 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
6094
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6095 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6096
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6097 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6098 convert_dl(PyObject *obj, typval_T *tv,
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6099 pytotvfunc py_to_tv, PyObject *lookup_dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6100 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6101 PyObject *capsule;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6102 char hexBuf[sizeof(void *) * 2 + 3];
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6103
13353
8412df1479a3 patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents: 12812
diff changeset
6104 sprintf(hexBuf, "%p", (void *)obj);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6105
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6106 # ifdef PY_USE_CAPSULE
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6107 capsule = PyDict_GetItemString(lookup_dict, hexBuf);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6108 # else
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6109 capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6110 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6111 if (capsule == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6112 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6113 # ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6114 capsule = PyCapsule_New(tv, NULL, NULL);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6115 # else
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6116 capsule = PyCObject_FromVoidPtr(tv, NULL);
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6117 # endif
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6118 if (PyDict_SetItemString(lookup_dict, hexBuf, capsule))
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6119 {
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6120 Py_DECREF(capsule);
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6121 tv->v_type = VAR_UNKNOWN;
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6122 return -1;
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
6123 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6124
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6125 Py_DECREF(capsule);
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6126
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6127 if (py_to_tv(obj, tv, lookup_dict) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6128 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6129 tv->v_type = VAR_UNKNOWN;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6130 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6131 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6132 /* As we are not using copy_tv which increments reference count we must
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6133 * do it ourself. */
7949
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6134 if (tv->v_type == VAR_DICT)
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6135 ++tv->vval.v_dict->dv_refcount;
3f7382858d4d commit https://github.com/vim/vim/commit/81e7a9c3fb37cad46c8f04a5ce871fb06819a371
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
6136 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
6137 ++tv->vval.v_list->lv_refcount;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6138 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6139 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6140 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6141 typval_T *v;
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6142
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6143 # ifdef PY_USE_CAPSULE
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6144 v = PyCapsule_GetPointer(capsule, NULL);
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6145 # else
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
6146 v = PyCObject_AsVoidPtr(capsule);
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
6147 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6148 copy_tv(v, tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6149 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6150 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6151 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6152
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6153 static int
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6154 ConvertFromPyMapping(PyObject *obj, typval_T *tv)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6155 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6156 PyObject *lookup_dict;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6157 int ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6158
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6159 if (!(lookup_dict = PyDict_New()))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6160 return -1;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6161
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6162 if (PyType_IsSubtype(obj->ob_type, &DictionaryType))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6163 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6164 tv->v_type = VAR_DICT;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6165 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6166 ++tv->vval.v_dict->dv_refcount;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6167 ret = 0;
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 else if (PyDict_Check(obj))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6170 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
6171 else if (PyMapping_Check(obj))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6172 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
6173 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6174 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6175 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
6176 N_("unable to convert %s to vim dictionary"),
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6177 Py_TYPE_NAME(obj));
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6178 ret = -1;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6179 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6180 Py_DECREF(lookup_dict);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6181 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6182 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6183
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6184 static int
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6185 ConvertFromPySequence(PyObject *obj, typval_T *tv)
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6186 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6187 PyObject *lookup_dict;
8915
8cbf472483fa commit https://github.com/vim/vim/commit/66210042892389d36e3d37203ec77f61467bfb1c
Christian Brabandt <cb@256bit.org>
parents: 8913
diff changeset
6188 int ret;
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6189
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6190 if (!(lookup_dict = PyDict_New()))
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6191 return -1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6192
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6193 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
6194 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6195 tv->v_type = VAR_LIST;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6196 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
6197 ++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
6198 ret = 0;
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 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
6201 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
6202 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6203 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6204 PyErr_FORMAT(PyExc_TypeError,
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6205 N_("unable to convert %s to vim list"),
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6206 Py_TYPE_NAME(obj));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6207 ret = -1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6208 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6209 Py_DECREF(lookup_dict);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6210 return ret;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6211 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6212
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6213 static int
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6214 ConvertFromPyObject(PyObject *obj, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6215 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6216 PyObject *lookup_dict;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6217 int ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6218
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6219 if (!(lookup_dict = PyDict_New()))
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
6220 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6221 ret = _ConvertFromPyObject(obj, tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6222 Py_DECREF(lookup_dict);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6223 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6224 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6225
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6226 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6227 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6228 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6229 if (PyType_IsSubtype(obj->ob_type, &DictionaryType))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6230 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6231 tv->v_type = VAR_DICT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6232 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6233 ++tv->vval.v_dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6234 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6235 else if (PyType_IsSubtype(obj->ob_type, &ListType))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6236 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6237 tv->v_type = VAR_LIST;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6238 tv->vval.v_list = (((ListObject *)(obj))->list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6239 ++tv->vval.v_list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6240 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
6241 else if (PyType_IsSubtype(obj->ob_type, &FunctionType))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6242 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6243 FunctionObject *func = (FunctionObject *) obj;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6244 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
6245 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6246 partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T));
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6247 set_partial(func, pt, TRUE);
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6248 tv->vval.v_partial = pt;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6249 tv->v_type = VAR_PARTIAL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6250 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6251 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6252 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6253 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
6254 return -1;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6255
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6256 tv->v_type = VAR_FUNC;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6257 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6258 func_ref(func->name);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6259 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6260 else if (PyBytes_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6261 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6262 char_u *str;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6263
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6264 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1)
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
6265 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6266 if (str == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6267 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6268
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6269 if (set_string_copy(str, tv) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6270 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6271
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6272 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6273 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6274 else if (PyUnicode_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6275 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6276 PyObject *bytes;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6277 char_u *str;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6278
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
6279 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6280 if (bytes == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6281 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6282
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6283 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1)
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
6284 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6285 if (str == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6286 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6287
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6288 if (set_string_copy(str, tv))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6289 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6290 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6291 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6292 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6293 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6294
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6295 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6296 }
4321
d8d9c591c50f updated for version 7.3.910
Bram Moolenaar <bram@vim.org>
parents: 4319
diff changeset
6297 #if PY_MAJOR_VERSION < 3
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6298 else if (PyInt_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6299 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6300 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6301 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
6302 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6303 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6304 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6305 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6306 else if (PyLong_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6307 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6308 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6309 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
6310 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6311 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6312 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6313 else if (PyDict_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6314 return convert_dl(obj, tv, pydict_to_tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6315 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6316 else if (PyFloat_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6317 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6318 tv->v_type = VAR_FLOAT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6319 tv->vval.v_float = (float_T) PyFloat_AsDouble(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6320 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6321 #endif
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6322 else if (PyObject_HasAttrString(obj, "keys"))
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
6323 return convert_dl(obj, tv, pymap_to_tv, lookup_dict);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6324 /* 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
6325 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
6326 return convert_dl(obj, tv, pyseq_to_tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6327 else if (PyMapping_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
6328 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
6329 else if (PyNumber_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6330 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6331 PyObject *num;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6332
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6333 if (!(num = PyNumber_Long(obj)))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6334 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6335
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6336 tv->v_type = VAR_NUMBER;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6337 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
6338
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6339 Py_DECREF(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
6340 }
12806
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6341 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
6342 {
ef93c4415667 patch 8.0.1280: Python None cannot be converted to a Vim type
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
6343 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
6344 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
6345 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6346 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6347 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6348 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
6349 N_("unable to convert %s to vim structure"),
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
6350 Py_TYPE_NAME(obj));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6351 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6352 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6353 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6354 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6355
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6356 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6357 ConvertToPyObject(typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6358 {
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6359 typval_T *argv;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6360 int i;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6361 if (tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6362 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
6363 PyErr_SET_VIM(N_("internal error: NULL reference passed"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6364 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6365 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6366 switch (tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6367 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6368 case VAR_STRING:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
6369 return PyBytes_FromString(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
6370 ? "" : (char *)tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6371 case VAR_NUMBER:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6372 return PyLong_FromLong((long) tv->vval.v_number);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6373 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6374 case VAR_FLOAT:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6375 return PyFloat_FromDouble((double) tv->vval.v_float);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6376 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6377 case VAR_LIST:
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6378 return NEW_LIST(tv->vval.v_list);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6379 case VAR_DICT:
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6380 return NEW_DICTIONARY(tv->vval.v_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6381 case VAR_FUNC:
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6382 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
6383 ? (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
6384 0, NULL, NULL, TRUE);
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6385 case VAR_PARTIAL:
8889
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6386 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
6387 {
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6388 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
6389 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
6390 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
6391 }
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6392 else
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6393 argv = NULL;
8755d57debaa commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Christian Brabandt <cb@256bit.org>
parents: 8714
diff changeset
6394 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
6395 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
6396 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
6397 ? (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
6398 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
6399 tv->vval.v_partial->pt_dict,
39cc63e8df7c commit https://github.com/vim/vim/commit/2177f9fe18a927ef65ccebb0856722a28dc00252
Christian Brabandt <cb@256bit.org>
parents: 8967
diff changeset
6400 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
6401 case VAR_BLOB:
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
6402 return PyBytes_FromStringAndSize(
1d2b5c016f17 patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents: 15236
diff changeset
6403 (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
6404 (Py_ssize_t) tv->vval.v_blob->bv_ga.ga_len);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6405 case VAR_UNKNOWN:
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6406 case VAR_CHANNEL:
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6407 case VAR_JOB:
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6408 Py_INCREF(Py_None);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6409 return Py_None;
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6410 case VAR_SPECIAL:
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6411 switch (tv->vval.v_number)
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6412 {
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6413 case VVAL_FALSE: return AlwaysFalse(NULL);
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6414 case VVAL_TRUE: return AlwaysTrue(NULL);
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6415 case VVAL_NONE:
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6416 case VVAL_NULL: return AlwaysNone(NULL);
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6417 }
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
6418 PyErr_SET_VIM(N_("internal error: invalid value type"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6419 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6420 }
8714
a5224eeb3546 commit https://github.com/vim/vim/commit/4c90861e9f864eab94f043c432acff508396ed62
Christian Brabandt <cb@256bit.org>
parents: 8643
diff changeset
6421 return NULL;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
6422 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6423
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6424 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6425 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6426 PyObject_HEAD
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6427 } CurrentObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6428 static PyTypeObject CurrentType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6429
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6430 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6431 init_structs(void)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6432 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6433 vim_memset(&OutputType, 0, sizeof(OutputType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6434 OutputType.tp_name = "vim.message";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6435 OutputType.tp_basicsize = sizeof(OutputObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6436 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6437 OutputType.tp_doc = "vim message object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6438 OutputType.tp_methods = OutputMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6439 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6440 OutputType.tp_getattro = (getattrofunc)OutputGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6441 OutputType.tp_setattro = (setattrofunc)OutputSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6442 OutputType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6443 OutputType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6444 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
6445 OutputType.tp_base = &PyStdPrinter_Type;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6446 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6447 OutputType.tp_getattr = (getattrfunc)OutputGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6448 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
6449 // 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
6450 // OutputType.tp_base = &PyFile_Type;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6451 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6452
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6453 vim_memset(&IterType, 0, sizeof(IterType));
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6454 IterType.tp_name = "vim.iter";
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6455 IterType.tp_basicsize = sizeof(IterObject);
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6456 IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6457 IterType.tp_doc = "generic iterator object";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6458 IterType.tp_iter = (getiterfunc)IterIter;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6459 IterType.tp_iternext = (iternextfunc)IterNext;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6460 IterType.tp_dealloc = (destructor)IterDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6461 IterType.tp_traverse = (traverseproc)IterTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6462 IterType.tp_clear = (inquiry)IterClear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6463
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6464 vim_memset(&BufferType, 0, sizeof(BufferType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6465 BufferType.tp_name = "vim.buffer";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6466 BufferType.tp_basicsize = sizeof(BufferType);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6467 BufferType.tp_dealloc = (destructor)BufferDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6468 BufferType.tp_repr = (reprfunc)BufferRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6469 BufferType.tp_as_sequence = &BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6470 BufferType.tp_as_mapping = &BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6471 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6472 BufferType.tp_doc = "vim buffer object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6473 BufferType.tp_methods = BufferMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6474 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6475 BufferType.tp_getattro = (getattrofunc)BufferGetattro;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
6476 BufferType.tp_setattro = (setattrofunc)BufferSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6477 BufferType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6478 BufferType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6479 BufferType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6480 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6481 BufferType.tp_getattr = (getattrfunc)BufferGetattr;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
6482 BufferType.tp_setattr = (setattrfunc)BufferSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6483 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6484
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6485 vim_memset(&WindowType, 0, sizeof(WindowType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6486 WindowType.tp_name = "vim.window";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6487 WindowType.tp_basicsize = sizeof(WindowObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6488 WindowType.tp_dealloc = (destructor)WindowDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6489 WindowType.tp_repr = (reprfunc)WindowRepr;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6490 WindowType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6491 WindowType.tp_doc = "vim Window object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6492 WindowType.tp_methods = WindowMethods;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6493 WindowType.tp_traverse = (traverseproc)WindowTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6494 WindowType.tp_clear = (inquiry)WindowClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6495 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6496 WindowType.tp_getattro = (getattrofunc)WindowGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6497 WindowType.tp_setattro = (setattrofunc)WindowSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6498 WindowType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6499 WindowType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6500 WindowType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6501 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6502 WindowType.tp_getattr = (getattrfunc)WindowGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6503 WindowType.tp_setattr = (setattrfunc)WindowSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6504 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6505
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6506 vim_memset(&TabPageType, 0, sizeof(TabPageType));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6507 TabPageType.tp_name = "vim.tabpage";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6508 TabPageType.tp_basicsize = sizeof(TabPageObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6509 TabPageType.tp_dealloc = (destructor)TabPageDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6510 TabPageType.tp_repr = (reprfunc)TabPageRepr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6511 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6512 TabPageType.tp_doc = "vim tab page object";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6513 TabPageType.tp_methods = TabPageMethods;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6514 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6515 TabPageType.tp_getattro = (getattrofunc)TabPageGetattro;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6516 TabPageType.tp_alloc = call_PyType_GenericAlloc;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6517 TabPageType.tp_new = call_PyType_GenericNew;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6518 TabPageType.tp_free = call_PyObject_Free;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6519 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6520 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6521 #endif
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6522
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6523 vim_memset(&BufMapType, 0, sizeof(BufMapType));
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6524 BufMapType.tp_name = "vim.bufferlist";
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6525 BufMapType.tp_basicsize = sizeof(BufMapObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6526 BufMapType.tp_as_mapping = &BufMapAsMapping;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6527 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6528 BufMapType.tp_iter = BufMapIter;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6529 BufferType.tp_doc = "vim buffer list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6530
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6531 vim_memset(&WinListType, 0, sizeof(WinListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6532 WinListType.tp_name = "vim.windowlist";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6533 WinListType.tp_basicsize = sizeof(WinListType);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6534 WinListType.tp_as_sequence = &WinListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6535 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6536 WinListType.tp_doc = "vim window list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6537 WinListType.tp_dealloc = (destructor)WinListDestructor;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6538
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6539 vim_memset(&TabListType, 0, sizeof(TabListType));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6540 TabListType.tp_name = "vim.tabpagelist";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6541 TabListType.tp_basicsize = sizeof(TabListType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6542 TabListType.tp_as_sequence = &TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6543 TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6544 TabListType.tp_doc = "vim tab page list";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6545
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6546 vim_memset(&RangeType, 0, sizeof(RangeType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6547 RangeType.tp_name = "vim.range";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6548 RangeType.tp_basicsize = sizeof(RangeObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6549 RangeType.tp_dealloc = (destructor)RangeDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6550 RangeType.tp_repr = (reprfunc)RangeRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6551 RangeType.tp_as_sequence = &RangeAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6552 RangeType.tp_as_mapping = &RangeAsMapping;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6553 RangeType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6554 RangeType.tp_doc = "vim Range object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6555 RangeType.tp_methods = RangeMethods;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
6556 RangeType.tp_traverse = (traverseproc)RangeTraverse;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
6557 RangeType.tp_clear = (inquiry)RangeClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6558 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6559 RangeType.tp_getattro = (getattrofunc)RangeGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6560 RangeType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6561 RangeType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6562 RangeType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6563 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6564 RangeType.tp_getattr = (getattrfunc)RangeGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6565 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6566
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6567 vim_memset(&CurrentType, 0, sizeof(CurrentType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6568 CurrentType.tp_name = "vim.currentdata";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6569 CurrentType.tp_basicsize = sizeof(CurrentObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6570 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6571 CurrentType.tp_doc = "vim current object";
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6572 CurrentType.tp_methods = CurrentMethods;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6573 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6574 CurrentType.tp_getattro = (getattrofunc)CurrentGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6575 CurrentType.tp_setattro = (setattrofunc)CurrentSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6576 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6577 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6578 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6579 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6580
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6581 vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6582 DictionaryType.tp_name = "vim.dictionary";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6583 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6584 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6585 DictionaryType.tp_as_sequence = &DictionaryAsSeq;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6586 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6587 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6588 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6589 DictionaryType.tp_methods = DictionaryMethods;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6590 DictionaryType.tp_iter = (getiterfunc)DictionaryIter;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6591 DictionaryType.tp_new = (newfunc)DictionaryConstructor;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6592 DictionaryType.tp_alloc = (allocfunc)PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6593 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6594 DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6595 DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6596 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6597 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6598 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6599 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6600
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6601 vim_memset(&ListType, 0, sizeof(ListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6602 ListType.tp_name = "vim.list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6603 ListType.tp_dealloc = (destructor)ListDestructor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6604 ListType.tp_basicsize = sizeof(ListObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6605 ListType.tp_as_sequence = &ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6606 ListType.tp_as_mapping = &ListAsMapping;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6607 ListType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6608 ListType.tp_doc = "list pushing modifications to vim structure";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6609 ListType.tp_methods = ListMethods;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6610 ListType.tp_iter = (getiterfunc)ListIter;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6611 ListType.tp_new = (newfunc)ListConstructor;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6612 ListType.tp_alloc = (allocfunc)PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6613 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6614 ListType.tp_getattro = (getattrofunc)ListGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6615 ListType.tp_setattro = (setattrofunc)ListSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6616 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6617 ListType.tp_getattr = (getattrfunc)ListGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6618 ListType.tp_setattr = (setattrfunc)ListSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6619 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6620
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6621 vim_memset(&FunctionType, 0, sizeof(FunctionType));
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6622 FunctionType.tp_name = "vim.function";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6623 FunctionType.tp_basicsize = sizeof(FunctionObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6624 FunctionType.tp_dealloc = (destructor)FunctionDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6625 FunctionType.tp_call = (ternaryfunc)FunctionCall;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6626 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6627 FunctionType.tp_doc = "object that calls vim function";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6628 FunctionType.tp_methods = FunctionMethods;
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
6629 FunctionType.tp_repr = (reprfunc)FunctionRepr;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6630 FunctionType.tp_new = (newfunc)FunctionConstructor;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6631 FunctionType.tp_alloc = (allocfunc)PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6632 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6633 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6634 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6635 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6636 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6637
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6638 vim_memset(&OptionsType, 0, sizeof(OptionsType));
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6639 OptionsType.tp_name = "vim.options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6640 OptionsType.tp_basicsize = sizeof(OptionsObject);
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
6641 OptionsType.tp_as_sequence = &OptionsAsSeq;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6642 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6643 OptionsType.tp_doc = "object for manipulating options";
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
6644 OptionsType.tp_iter = (getiterfunc)OptionsIter;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6645 OptionsType.tp_as_mapping = &OptionsAsMapping;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6646 OptionsType.tp_dealloc = (destructor)OptionsDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6647 OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6648 OptionsType.tp_clear = (inquiry)OptionsClear;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6649
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6650 #if PY_VERSION_HEX < 0x030700f0
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6651 vim_memset(&LoaderType, 0, sizeof(LoaderType));
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6652 LoaderType.tp_name = "vim.Loader";
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6653 LoaderType.tp_basicsize = sizeof(LoaderObject);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6654 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6655 LoaderType.tp_doc = "vim message object";
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6656 LoaderType.tp_methods = LoaderMethods;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6657 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
6658 #endif
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6659
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6660 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6661 vim_memset(&vimmodule, 0, sizeof(vimmodule));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6662 vimmodule.m_name = "vim";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6663 vimmodule.m_doc = "Vim Python interface\n";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6664 vimmodule.m_size = -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6665 vimmodule.m_methods = VimMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6666 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6667 }
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6668
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6669 #define PYTYPE_READY(type) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6670 if (PyType_Ready(&type)) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6671 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6672
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6673 static int
5166
467efeee8f9e updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents: 5139
diff changeset
6674 init_types(void)
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6675 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6676 PYTYPE_READY(IterType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6677 PYTYPE_READY(BufferType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6678 PYTYPE_READY(RangeType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6679 PYTYPE_READY(WindowType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6680 PYTYPE_READY(TabPageType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6681 PYTYPE_READY(BufMapType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6682 PYTYPE_READY(WinListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6683 PYTYPE_READY(TabListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6684 PYTYPE_READY(CurrentType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6685 PYTYPE_READY(DictionaryType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6686 PYTYPE_READY(ListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6687 PYTYPE_READY(FunctionType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6688 PYTYPE_READY(OptionsType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6689 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
6690 #if PY_VERSION_HEX < 0x030700f0
4851
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
6691 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
6692 #endif
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6693 return 0;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6694 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6695
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6696 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
6697 init_sys_path(void)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6698 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6699 PyObject *path;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6700 PyObject *path_hook;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6701 PyObject *path_hooks;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6702
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6703 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
6704 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6705
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6706 if (!(path_hooks = PySys_GetObject("path_hooks")))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6707 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6708 PyErr_Clear();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6709 path_hooks = PyList_New(1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6710 PyList_SET_ITEM(path_hooks, 0, path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6711 if (PySys_SetObject("path_hooks", path_hooks))
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 Py_DECREF(path_hooks);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6714 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6715 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6716 Py_DECREF(path_hooks);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6717 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6718 else if (PyList_Check(path_hooks))
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 (PyList_Append(path_hooks, path_hook))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6721 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6722 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6723 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6724 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6725 Py_DECREF(path_hook);
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 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6728 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6729 VimTryStart();
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6730 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
6731 "You should now do the following:\n"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6732 "- 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
6733 "- append vim.VIM_SPECIAL_PATH to sys.path\n"));
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6734 VimTryEnd(); /* Discard the error */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6735 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6736 return 0;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6737 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6738
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6739 if (!(path = PySys_GetObject("path")))
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 PyErr_Clear();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6742 path = PyList_New(1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6743 Py_INCREF(vim_special_path_object);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6744 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
6745 if (PySys_SetObject("path", path))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6746 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6747 Py_DECREF(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6748 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6749 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6750 Py_DECREF(path);
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 else if (PyList_Check(path))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6753 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6754 if (PyList_Append(path, vim_special_path_object))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6755 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6756 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6757 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6758 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6759 VimTryStart();
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15454
diff changeset
6760 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
6761 "You should now append vim.VIM_SPECIAL_PATH to sys.path"));
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6762 VimTryEnd(); /* Discard the error */
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
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6765 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6766 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6767
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6768 static BufMapObject TheBufferMap =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6769 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6770 PyObject_HEAD_INIT(&BufMapType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6771 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6772
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6773 static WinListObject TheWindowList =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6774 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6775 PyObject_HEAD_INIT(&WinListType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6776 NULL
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6777 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6778
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6779 static CurrentObject TheCurrent =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6780 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6781 PyObject_HEAD_INIT(&CurrentType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6782 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6783
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6784 static TabListObject TheTabPageList =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6785 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6786 PyObject_HEAD_INIT(&TabListType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6787 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6788
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6789 static struct numeric_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6790 char *name;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6791 int val;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6792 } numeric_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6793 {"VAR_LOCKED", VAR_LOCKED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6794 {"VAR_FIXED", VAR_FIXED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6795 {"VAR_SCOPE", VAR_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6796 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6797 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6798
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6799 static struct object_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6800 char *name;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6801 PyObject *valObject;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6802 } object_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6803 {"buffers", (PyObject *)(void *)&TheBufferMap},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6804 {"windows", (PyObject *)(void *)&TheWindowList},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6805 {"tabpages", (PyObject *)(void *)&TheTabPageList},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6806 {"current", (PyObject *)(void *)&TheCurrent},
4496
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6807
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6808 {"Buffer", (PyObject *)&BufferType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6809 {"Range", (PyObject *)&RangeType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6810 {"Window", (PyObject *)&WindowType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6811 {"TabPage", (PyObject *)&TabPageType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6812 {"Dictionary", (PyObject *)&DictionaryType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6813 {"List", (PyObject *)&ListType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6814 {"Function", (PyObject *)&FunctionType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6815 {"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
6816 #if PY_VERSION_HEX < 0x030700f0
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6817 {"_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
6818 #endif
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6819 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6820
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6821 #define ADD_OBJECT(m, name, obj) \
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6822 if (PyModule_AddObject(m, name, obj)) \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6823 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6824
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6825 #define ADD_CHECKED_OBJECT(m, name, obj) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6826 { \
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6827 PyObject *valObject = obj; \
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6828 if (!valObject) \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6829 return -1; \
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6830 ADD_OBJECT(m, name, valObject); \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6831 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6832
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6833 static int
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6834 populate_module(PyObject *m)
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6835 {
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6836 int i;
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6837 PyObject *other_module;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6838 PyObject *attr;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6839 PyObject *imp;
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6840 #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
6841 PyObject *dict;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6842 PyObject *cls;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6843 #endif
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6844
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6845 for (i = 0; i < (int)(sizeof(numeric_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6846 / sizeof(struct numeric_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6847 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6848 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
6849 PyInt_FromLong(numeric_constants[i].val));
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6850
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6851 for (i = 0; i < (int)(sizeof(object_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6852 / sizeof(struct object_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6853 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6854 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6855 PyObject *valObject;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6856
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6857 valObject = object_constants[i].valObject;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6858 Py_INCREF(valObject);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6859 ADD_OBJECT(m, object_constants[i].name, valObject);
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6860 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6861
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6862 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL)))
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6863 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6864 ADD_OBJECT(m, "error", VimError);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6865
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6866 ADD_CHECKED_OBJECT(m, "vars", NEW_DICTIONARY(&globvardict));
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6867 ADD_CHECKED_OBJECT(m, "vvars", NEW_DICTIONARY(&vimvardict));
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6868 ADD_CHECKED_OBJECT(m, "options",
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6869 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6870
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6871 if (!(other_module = PyImport_ImportModule("os")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6872 return -1;
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6873 ADD_OBJECT(m, "os", other_module);
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6874
9161
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
6875 #if PY_MAJOR_VERSION >= 3
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6876 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
6877 return -1;
9161
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
6878 #else
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
6879 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
6880 return -1;
56c93626f6f3 commit https://github.com/vim/vim/commit/22081f4a3397704645841121d994058abd6cb481
Christian Brabandt <cb@256bit.org>
parents: 9119
diff changeset
6881 #endif
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6882 ADD_OBJECT(m, "_getcwd", py_getcwd)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6883
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6884 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
6885 return -1;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6886 ADD_OBJECT(m, "_chdir", py_chdir);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6887 if (!(attr = PyObject_GetAttrString(m, "chdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6888 return -1;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6889 if (PyObject_SetAttrString(other_module, "chdir", attr))
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6890 {
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6891 Py_DECREF(attr);
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6892 return -1;
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6893 }
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6894 Py_DECREF(attr);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6895
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6896 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
6897 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6898 ADD_OBJECT(m, "_fchdir", py_fchdir);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6899 if (!(attr = PyObject_GetAttrString(m, "fchdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6900 return -1;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6901 if (PyObject_SetAttrString(other_module, "fchdir", attr))
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6902 {
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6903 Py_DECREF(attr);
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6904 return -1;
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6905 }
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6906 Py_DECREF(attr);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6907 }
4722
3534e9b4fa42 updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents: 4706
diff changeset
6908 else
3534e9b4fa42 updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents: 4706
diff changeset
6909 PyErr_Clear();
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6910
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6911 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
6912 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6913
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6914 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
6915
14373
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6916 #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
6917 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
6918 return -1;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6919
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6920 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
6921
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6922 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
6923 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6924 Py_DECREF(imp);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6925 return -1;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6926 }
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6927
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6928 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
6929 {
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6930 Py_DECREF(imp);
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6931 return -1;
380217380738 patch 8.1.0201: newer Python uses "importlib" instead of "imp"
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
6932 }
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 Py_DECREF(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 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
6937 #else
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6938 if (!(imp = PyImport_ImportModule("imp")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6939 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6940
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6941 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
6942 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6943 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6944 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6945 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6946
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6947 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
6948 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6949 Py_DECREF(py_find_module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6950 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6951 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6952 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6953
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6954 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6955
4851
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
6956 ADD_OBJECT(m, "_find_module", py_find_module);
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
6957 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
6958 #endif
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6959
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6960 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6961 }