annotate src/if_py_both.h @ 6409:83c5fd1b55bc v7.4.535

updated for version 7.4.535 Problem: Can't build with tiny features. Solution: Add #ifdefs and skip a test.
author Bram Moolenaar <bram@vim.org>
date Thu, 27 Nov 2014 18:33:02 +0100
parents 85a1802ae810
children a35752526cd0
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 *);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
75 static PyObject *WindowNew(win_T *, tabpage_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
76 static PyObject *BufferNew (buf_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
77 static PyObject *LineToString(const char *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
78
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
79 static PyInt RangeStart;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
80 static PyInt RangeEnd;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
81
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
82 static PyObject *globals;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
83
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
84 static PyObject *py_chdir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
85 static PyObject *py_fchdir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
86 static PyObject *py_getcwd;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
87 static PyObject *vim_module;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
88 static PyObject *vim_special_path_object;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
89
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
90 static PyObject *py_find_module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
91 static PyObject *py_load_module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
92
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
93 static PyObject *VimError;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
94
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
95 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 * 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
97 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 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
99 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
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 }
76f0c4918f5c Move 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 /*
76f0c4918f5c Move 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 * 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
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 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
107 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
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 }
76f0c4918f5c Move 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
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
111 /*
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
112 * 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
113 * 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
114 * was needed to generate returned value is object.
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
115 *
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
116 * Use Py_XDECREF to decrement reference count.
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
117 */
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
118 static char_u *
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
119 StringToChars(PyObject *obj, PyObject **todecref)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
120 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
121 char_u *str;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
122
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
123 if (PyBytes_Check(obj))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
124 {
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 if (PyBytes_AsStringAndSize(obj, (char **) &str, NULL) == -1
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
127 || str == NULL)
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
128 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
129
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
130 *todecref = NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
131 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
132 else if (PyUnicode_Check(obj))
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
133 {
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
134 PyObject *bytes;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
135
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
136 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
137 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
138
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
139 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
140 || str == NULL)
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
141 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
142 Py_DECREF(bytes);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
143 return NULL;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
144 }
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
145
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
146 *todecref = bytes;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
147 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
148 else
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
149 {
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
150 #if PY_MAJOR_VERSION < 3
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
151 PyErr_FORMAT(PyExc_TypeError,
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
152 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
153 Py_TYPE_NAME(obj));
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
154 #else
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
155 PyErr_FORMAT(PyExc_TypeError,
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
156 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
157 Py_TYPE_NAME(obj));
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
158 #endif
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
159 return NULL;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
160 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
161
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
162 return (char_u *) str;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
163 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
164
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
165 #define NUMBER_LONG 1
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
166 #define NUMBER_INT 2
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
167 #define NUMBER_NATURAL 4
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
168 #define NUMBER_UNSIGNED 8
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
169
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
170 static int
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
171 NumberToLong(PyObject *obj, long *result, int flags)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
172 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
173 #if PY_MAJOR_VERSION < 3
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
174 if (PyInt_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
175 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
176 *result = PyInt_AsLong(obj);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
177 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
178 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
179 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
180 else
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
181 #endif
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
182 if (PyLong_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
183 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
184 *result = PyLong_AsLong(obj);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
185 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
186 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
187 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
188 else if (PyNumber_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
189 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
190 PyObject *num;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
191
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
192 if (!(num = PyNumber_Long(obj)))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
193 return -1;
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 *result = PyLong_AsLong(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 Py_DECREF(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
198
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
199 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
200 return -1;
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 else
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
203 {
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
204 #if PY_MAJOR_VERSION < 3
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
205 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
206 N_("expected int(), long() or something supporting "
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
207 "coercing to long(), but got %s"),
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
208 Py_TYPE_NAME(obj));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
209 #else
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
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() or something supporting coercing to int(), "
4988
e130cc3d17af updated for version 7.3.1239
Bram Moolenaar <bram@vim.org>
parents: 4984
diff changeset
212 "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 #endif
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
215 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
216 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
217
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
218 if (flags & NUMBER_INT)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
219 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
220 if (*result > INT_MAX)
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 PyErr_SET_STRING(PyExc_OverflowError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
223 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
224 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
225 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
226 else if (*result < INT_MIN)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
227 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
228 PyErr_SET_STRING(PyExc_OverflowError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
229 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
230 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
231 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
232 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
233
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
234 if (flags & NUMBER_NATURAL)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
235 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
236 if (*result <= 0)
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 PyErr_SET_STRING(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
239 N_("number must be greater than zero"));
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
240 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
241 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
242 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
243 else if (flags & NUMBER_UNSIGNED)
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
244 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
245 if (*result < 0)
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 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
248 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
249 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
250 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
251 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
252
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
253 return 0;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
254 }
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
255
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
256 static int
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
257 add_string(PyObject *list, char *s)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
258 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
259 PyObject *string;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
260
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
261 if (!(string = PyString_FromString(s)))
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
262 return -1;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
263
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
264 if (PyList_Append(list, 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 Py_DECREF(string);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
267 return -1;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
268 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
269
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
270 Py_DECREF(string);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
271 return 0;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
272 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
273
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
274 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
275 ObjectDir(PyObject *self, char **attributes)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
276 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
277 PyMethodDef *method;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
278 char **attr;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
279 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
280
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
281 if (!(ret = PyList_New(0)))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
282 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
283
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
284 if (self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
285 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
286 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
287 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
288 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
289 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
290 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
291
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
292 for (attr = attributes ; *attr ; ++attr)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
293 if (add_string(ret, *attr))
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
294 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
295 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
296 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
297 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
298
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
299 #if PY_MAJOR_VERSION < 3
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
300 if (add_string(ret, "__members__"))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
301 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
302 Py_DECREF(ret);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
303 return NULL;
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
304 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
305 #endif
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
306
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
307 return ret;
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
308 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
309
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
310 /* 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
311 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312
2582
2cdbc91795ca updated for version 7.3.007
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
313 /* 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
314 typedef void (*writefn)(char_u *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
315
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
316 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
317
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 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
319 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 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
321 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
322 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
323 } 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
324
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
325 static char *OutputAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
326 "softspace",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
327 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
328 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
329
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
330 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
331 OutputDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
332 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
333 return ObjectDir(self, OutputAttrs);
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
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
336 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
337 OutputSetattr(OutputObject *self, char *name, PyObject *valObject)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
338 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
339 if (valObject == NULL)
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
340 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
341 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
342 N_("can't delete OutputObject attributes"));
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
343 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
344 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
345
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
346 if (strcmp(name, "softspace") == 0)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
347 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
348 if (NumberToLong(valObject, &(self->softspace), NUMBER_UNSIGNED))
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
349 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
350 return 0;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
351 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
352
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
353 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
354 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
355 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
356
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
357 /* 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
358 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
359 static writefn old_fn = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
360
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
361 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
362 PythonIO_Flush(void)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
363 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
364 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
365 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
366 ((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
367 old_fn((char_u *)io_ga.ga_data);
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 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
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
372 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
373 writer(writefn fn, char_u *str, PyInt n)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
374 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
375 char_u *ptr;
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 /* Flush when switching output function. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
378 if (fn != old_fn)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
379 PythonIO_Flush();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
380 old_fn = fn;
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 /* 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
383 * writing later. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
384 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
385 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
386 PyInt len = ptr - str;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
387
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
388 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
389 break;
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 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
392 ((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
393 fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
394 str = ptr + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
395 n -= len + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
396 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
397 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
398
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
399 /* 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
400 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
401 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
402 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
403 io_ga.ga_len += (int)n;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
404 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
405 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
406
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
407 static int
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
408 write_output(OutputObject *self, PyObject *string)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
409 {
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
410 Py_ssize_t len = 0;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
411 char *str = NULL;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
412 int error = self->error;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
413
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
414 if (!PyArg_Parse(string, "et#", ENC_OPT, &str, &len))
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
415 return -1;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 Py_BEGIN_ALLOW_THREADS
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418 Python_Lock_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 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
420 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
421 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
422 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
423
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
424 return 0;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
425 }
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
426
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
427 static PyObject *
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
428 OutputWrite(OutputObject *self, PyObject *string)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
429 {
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
430 if (write_output(self, string))
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
431 return NULL;
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
432
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
433 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
434 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
435 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
436
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 static PyObject *
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
438 OutputWritelines(OutputObject *self, PyObject *seq)
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
439 {
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
440 PyObject *iterator;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
441 PyObject *item;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
442
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
443 if (!(iterator = PyObject_GetIter(seq)))
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
444 return NULL;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
445
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
446 while ((item = PyIter_Next(iterator)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
447 {
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
448 if (write_output(self, item))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
449 {
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
450 Py_DECREF(iterator);
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
451 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
452 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
453 }
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
454 Py_DECREF(item);
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
455 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456
4619
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
457 Py_DECREF(iterator);
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
458
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
459 /* Iterator may have finished due to an exception */
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
460 if (PyErr_Occurred())
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
461 return NULL;
90beab957ba9 updated for version 7.3.1057
Bram Moolenaar <bram@vim.org>
parents: 4617
diff changeset
462
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
463 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
464 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
465 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
466
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
467 static PyObject *
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
468 OutputFlush(PyObject *self UNUSED)
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
469 {
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
470 /* do nothing */
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
471 Py_INCREF(Py_None);
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
472 return Py_None;
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
473 }
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
474
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
475 /***************/
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
476
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
477 static struct PyMethodDef OutputMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
478 /* name, function, calling, doc */
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
479 {"write", (PyCFunction)OutputWrite, METH_O, ""},
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
480 {"writelines", (PyCFunction)OutputWritelines, METH_O, ""},
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
481 {"flush", (PyCFunction)OutputFlush, METH_NOARGS, ""},
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
482 {"__dir__", (PyCFunction)OutputDir, METH_NOARGS, ""},
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
483 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
484 };
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
485
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
486 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
487 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
488 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
489 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
490 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
491 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
492
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
493 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
494 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
495 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
496 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
497 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
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
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
500 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
501 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
502 {
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
503 if (PySys_SetObject("stdout", (PyObject *)(void *)&Output))
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
504 return -1;
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
505 if (PySys_SetObject("stderr", (PyObject *)(void *)&Error))
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
506 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
507
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
508 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
509 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
510 EMSG(_("E264: Python: Error initialising I/O objects"));
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
511 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
512 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513
76f0c4918f5c Move 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 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
515 }
76f0c4918f5c Move 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
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
517 typedef struct
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
518 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
519 PyObject_HEAD
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
520 PyObject *module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
521 } LoaderObject;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
522 static PyTypeObject LoaderType;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
523
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
524 static void
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
525 LoaderDestructor(LoaderObject *self)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
526 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
527 Py_DECREF(self->module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
528 DESTRUCTOR_FINISH(self);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
529 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
530
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
531 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
532 LoaderLoadModule(LoaderObject *self, PyObject *args UNUSED)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
533 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
534 PyObject *ret = self->module;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
535
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
536 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
537 return ret;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
538 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
539
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
540 static struct PyMethodDef LoaderMethods[] = {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
541 /* name, function, calling, doc */
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
542 {"load_module", (PyCFunction)LoaderLoadModule, METH_VARARGS, ""},
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
543 { NULL, NULL, 0, NULL}
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
544 };
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
545
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
546 /* 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
547 * 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
548 */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
549
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
550 static void
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
551 VimTryStart(void)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
552 {
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
553 ++trylevel;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
554 }
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
555
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
556 static int
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
557 VimTryEnd(void)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
558 {
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
559 --trylevel;
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
560 /* Without this it stops processing all subsequent VimL commands and
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
561 * generates strange error messages if I e.g. try calling Test() in a
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
562 * cycle */
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
563 did_emsg = FALSE;
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
564 /* 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
565 if (got_int)
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
566 {
5629
91f3908748c2 updated for version 7.4.161
Bram Moolenaar <bram@vim.org>
parents: 5612
diff changeset
567 if (did_throw)
5469
a56f60cf6834 updated for version 7.4.084
Bram Moolenaar <bram@vim.org>
parents: 5426
diff changeset
568 discard_current_exception();
a56f60cf6834 updated for version 7.4.084
Bram Moolenaar <bram@vim.org>
parents: 5426
diff changeset
569 got_int = FALSE;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
570 PyErr_SetNone(PyExc_KeyboardInterrupt);
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
571 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
572 }
5517
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
573 else if (msg_list != NULL && *msg_list != NULL)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
574 {
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
575 int should_free;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
576 char_u *msg;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
577
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
578 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
579
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
580 if (msg == NULL)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
581 {
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
582 PyErr_NoMemory();
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
583 return -1;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
584 }
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
585
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
586 PyErr_SetVim((char *) msg);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
587
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
588 free_global_msglist();
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
589
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
590 if (should_free)
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
591 vim_free(msg);
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
592
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
593 return -1;
064e2a080e2e updated for version 7.4.107
Bram Moolenaar <bram@vim.org>
parents: 5469
diff changeset
594 }
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
595 else if (!did_throw)
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
596 return (PyErr_Occurred() ? -1 : 0);
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
597 /* 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
598 else if (PyErr_Occurred())
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
599 {
5629
91f3908748c2 updated for version 7.4.161
Bram Moolenaar <bram@vim.org>
parents: 5612
diff changeset
600 discard_current_exception();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
601 return -1;
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
602 }
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
603 /* Finally transform VimL exception to python one */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
604 else
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
605 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
606 PyErr_SetVim((char *)current_exception->value);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
607 discard_current_exception();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
608 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
609 }
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
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
612 static int
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
613 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
614 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 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
616 {
76f0c4918f5c Move 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 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
618 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
619 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 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
621 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
622
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
623 /* Vim module - Implementation
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
624 */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
625
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
626 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
627 VimCommand(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
628 {
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
629 char_u *cmd;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
630 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
631 PyObject *todecref;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
632
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
633 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
634 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
635
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
636 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
637 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
638
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
639 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
640 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
641 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
642
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
643 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
644 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
645
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
646 if (VimTryEnd())
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
647 ret = NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
648 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
649 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
650
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
651 Py_XINCREF(ret);
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
652 Py_XDECREF(todecref);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
653 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
654 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
655
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
656 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
657 * 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
658 * 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
659 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
660 * 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
661 * you call VimToPython.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
662 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
663 static PyObject *
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
664 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
665 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
666 PyObject *ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
667 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
668 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
669
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
670 /* Avoid infinite recursion */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
671 if (depth > 100)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
672 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
673 Py_INCREF(Py_None);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
674 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
675 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
676 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
677
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
678 /* 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
679 * 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
680 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
681 || (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
682 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
683 sprintf(ptrBuf, "%p",
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
684 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
685 : (void *)our_tv->vval.v_dict);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
686
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
687 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
688 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
689 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
690 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
691 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
692 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
693
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
694 if (our_tv->v_type == VAR_STRING)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
695 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
696 ? "" : (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
697 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
698 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
699 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
700
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
701 /* 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
702 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
703 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
704 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
705 # ifdef FEAT_FLOAT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
706 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
707 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
708 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
709
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
710 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
711 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
712 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
713 # endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
714 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
715 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
716 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
717 listitem_T *curr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
718
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
719 if (list == NULL)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
720 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
721
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
722 if (!(ret = PyList_New(0)))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
723 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
724
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
725 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
726 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
727 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
728 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
729 }
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
730
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
731 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
732 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
733 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
734 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
735 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
736 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
737 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
738 if (PyList_Append(ret, newObj))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
739 {
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
740 Py_DECREF(newObj);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
741 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
742 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
743 }
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
744 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
745 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
746 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
747 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
748 {
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
749
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
750 hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
751 long_u todo = ht->ht_used;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
752 hashitem_T *hi;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
753 dictitem_T *di;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
754 if (our_tv->vval.v_dict == NULL)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
755 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
756
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
757 if (!(ret = PyDict_New()))
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
758 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
759
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
760 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
761 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
762 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
763 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
764 }
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
765
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
766 for (hi = ht->ht_array; todo > 0; ++hi)
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
767 {
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
768 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
769 {
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
770 --todo;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
771
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
772 di = dict_lookup(hi);
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
773 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
774 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
775 Py_DECREF(ret);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
776 return NULL;
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
777 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
778 if (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
779 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
780 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
781 Py_DECREF(newObj);
4595
29b2be2bba0d updated for version 7.3.1045
Bram Moolenaar <bram@vim.org>
parents: 4593
diff changeset
782 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
783 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
784 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
785 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
786 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
787 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
788 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
789 Py_INCREF(Py_None);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
790 ret = Py_None;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
791 }
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
792
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
793 return ret;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
794 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
795
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
796 static PyObject *
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
797 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
798 {
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
799 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
800 typval_T *our_tv;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
801 PyObject *string;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
802 PyObject *todecref;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
803 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
804 PyObject *lookup_dict;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
805
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
806 if (!PyArg_ParseTuple(args, "O", &string))
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
807 return NULL;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
808
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
809 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
810 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
811
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
812 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
813 Python_Lock_Vim();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
814 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
815 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
816 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
817 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
818
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
819 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
820
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
821 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
822 return NULL;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
823
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
824 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
825 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
826 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
827 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
828 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
829
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
830 /* 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
831 * used to check for recursive loops. */
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
832 if (!(lookup_dict = PyDict_New()))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
833 ret = NULL;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
834 else
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
835 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
836 ret = VimToPython(our_tv, 1, lookup_dict);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
837 Py_DECREF(lookup_dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
838 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
839
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
840
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
841 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
842 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
843 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
844 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
845 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
846
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
847 return ret;
2447
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
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
850 static PyObject *ConvertToPyObject(typval_T *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
851
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
852 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
853 VimEvalPy(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
854 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
855 typval_T *our_tv;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
856 PyObject *ret;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
857 char_u *expr;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
858 PyObject *todecref;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
859
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
860 if (!(expr = StringToChars(string, &todecref)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
861 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
862
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
863 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
864 Python_Lock_Vim();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
865 VimTryStart();
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
866 our_tv = eval_expr(expr, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
867 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
868 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
869
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
870 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
871
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
872 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
873 return NULL;
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
874
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
875 if (our_tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
876 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
877 PyErr_SET_VIM(N_("invalid expression"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
878 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
879 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
880
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
881 ret = ConvertToPyObject(our_tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
882 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
883 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
884 free_tv(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
885 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
886 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
887
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
888 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
889 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
890
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
891 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
892 VimStrwidth(PyObject *self UNUSED, PyObject *string)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
893 {
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
894 char_u *str;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
895 PyObject *todecref;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
896 int len;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
897
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
898 if (!(str = StringToChars(string, &todecref)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
899 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
900
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
901 #ifdef FEAT_MBYTE
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
902 len = mb_string2cells(str, (int)STRLEN(str));
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
903 #else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
904 len = STRLEN(str);
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
905 #endif
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
906
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
907 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
908
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
909 return PyLong_FromLong(len);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
910 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
911
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
912 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
913 _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
914 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
915 PyObject *ret;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
916 PyObject *newwd;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
917 PyObject *todecref;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
918 char_u *new_dir;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
919
4754
be1e4acb30ca updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents: 4722
diff changeset
920 if (_chdir == NULL)
be1e4acb30ca updated for version 7.3.1124
Bram Moolenaar <bram@vim.org>
parents: 4722
diff changeset
921 return NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
922 if (!(ret = PyObject_Call(_chdir, args, kwargs)))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
923 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
924
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
925 if (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL)))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
926 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
927 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
928 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
929 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
930
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
931 if (!(new_dir = StringToChars(newwd, &todecref)))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
932 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
933 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
934 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
935 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
936 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
937
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
938 VimTryStart();
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
939
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
940 if (vim_chdir(new_dir))
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
941 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
942 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
943 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
944 Py_XDECREF(todecref);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
945
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
946 if (VimTryEnd())
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
947 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
948
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
949 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
950 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
951 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
952
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
953 Py_DECREF(newwd);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
954 Py_XDECREF(todecref);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
955
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
956 post_chdir(FALSE);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
957
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
958 if (VimTryEnd())
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
959 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
960 Py_DECREF(ret);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
961 return NULL;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
962 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
963
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
964 return ret;
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
965 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
966
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
967 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
968 VimChdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
969 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
970 return _VimChdir(py_chdir, args, kwargs);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
971 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
972
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
973 static PyObject *
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
974 VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
975 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
976 return _VimChdir(py_fchdir, args, kwargs);
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
977 }
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
978
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
979 typedef struct {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
980 PyObject *callable;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
981 PyObject *result;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
982 } map_rtp_data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
983
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
984 static void
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
985 map_rtp_callback(char_u *path, void *_data)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
986 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
987 void **data = (void **) _data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
988 PyObject *pathObject;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
989 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
990
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
991 if (!(pathObject = PyString_FromString((char *)path)))
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
992 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
993 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
994 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
995 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
996
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
997 mr_data->result = PyObject_CallFunctionObjArgs(mr_data->callable,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
998 pathObject, NULL);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
999
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1000 Py_DECREF(pathObject);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1001
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1002 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
1003 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1004 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1005 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1006 Py_DECREF(mr_data->result);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1007 mr_data->result = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1008 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1009 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1010
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1011 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1012 VimForeachRTP(PyObject *self UNUSED, PyObject *callable)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1013 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1014 map_rtp_data data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1015
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1016 data.callable = callable;
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1017 data.result = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1018
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1019 do_in_runtimepath(NULL, FALSE, &map_rtp_callback, &data);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1020
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1021 if (data.result == NULL)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1022 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1023 if (PyErr_Occurred())
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1024 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1025 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1026 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1027 Py_INCREF(Py_None);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1028 return Py_None;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1029 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1030 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1031 return data.result;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1032 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1033
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1034 /*
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1035 * _vim_runtimepath_ special path implementation.
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1036 */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1037
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1038 static void
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1039 map_finder_callback(char_u *path, void *_data)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1040 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1041 void **data = (void **) _data;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1042 PyObject *list = *((PyObject **) data);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1043 PyObject *pathObject1, *pathObject2;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1044 char *pathbuf;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1045 size_t pathlen;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1046
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1047 pathlen = STRLEN(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1048
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1049 #if PY_MAJOR_VERSION < 3
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1050 # define PY_MAIN_DIR_STRING "python2"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1051 #else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1052 # define PY_MAIN_DIR_STRING "python3"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1053 #endif
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1054 #define PY_ALTERNATE_DIR_STRING "pythonx"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1055
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1056 #define PYTHONX_STRING_LENGTH 7 /* STRLEN("pythonx") */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1057 if (!(pathbuf = PyMem_New(char,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1058 pathlen + STRLEN(PATHSEPSTR) + PYTHONX_STRING_LENGTH + 1)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1059 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1060 PyErr_NoMemory();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1061 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1062 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1063 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1064
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1065 mch_memmove(pathbuf, path, pathlen + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1066 add_pathsep((char_u *) pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1067
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1068 pathlen = STRLEN(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1069 mch_memmove(pathbuf + pathlen, PY_MAIN_DIR_STRING,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1070 PYTHONX_STRING_LENGTH + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1071
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1072 if (!(pathObject1 = PyString_FromString(pathbuf)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1073 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1074 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1075 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1076 return;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1077 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1078
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1079 mch_memmove(pathbuf + pathlen, PY_ALTERNATE_DIR_STRING,
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1080 PYTHONX_STRING_LENGTH + 1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1081
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1082 if (!(pathObject2 = PyString_FromString(pathbuf)))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1083 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1084 Py_DECREF(pathObject1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1085 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1086 *data = NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1087 return;
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
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1090 PyMem_Free(pathbuf);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1091
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1092 if (PyList_Append(list, pathObject1)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1093 || PyList_Append(list, pathObject2))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1094 *data = 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 Py_DECREF(pathObject1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1097 Py_DECREF(pathObject2);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1098 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1099
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1100 static PyObject *
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1101 Vim_GetPaths(PyObject *self UNUSED)
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1102 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1103 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1104
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1105 if (!(ret = PyList_New(0)))
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1106 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1107
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1108 do_in_runtimepath(NULL, FALSE, &map_finder_callback, ret);
4833
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 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1112 Py_DECREF(ret);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1113 return NULL;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1114 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1115
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1116 return ret;
4833
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
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1119 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1120 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
1121 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1122 PyObject *fd, *pathname, *description;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1123
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1124 if (!PyTuple_Check(find_module_result))
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1125 {
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1126 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1127 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
1128 Py_TYPE_NAME(find_module_result));
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1129 return NULL;
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1130 }
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1131 if (PyTuple_GET_SIZE(find_module_result) != 3)
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1132 {
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1133 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1134 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
1135 "tuple of size %d"),
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1136 (int) PyTuple_GET_SIZE(find_module_result));
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1137 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1138 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1139
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1140 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
1141 || !(pathname = PyTuple_GET_ITEM(find_module_result, 1))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1142 || !(description = PyTuple_GET_ITEM(find_module_result, 2)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1143 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1144 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1145 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
1146 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1147 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1148
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1149 return PyObject_CallFunction(py_load_module,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1150 "s#OOO", name, len, fd, pathname, description);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1151 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1152
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1153 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1154 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
1155 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1156 PyObject *find_module_result;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1157 PyObject *module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1158 char *dot;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1159
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1160 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
1161 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1162 /*
4859
e48cabe98453 updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents: 4855
diff changeset
1163 * 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
1164 * first component
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1165 */
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1166 PyObject *newest_path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1167 int partlen = (int) (dot - 1 - tail);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1168
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1169 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
1170 "s#O", tail, partlen, new_path)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1171 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1172
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1173 if (!(module = call_load_module(
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1174 fullname,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1175 ((int) (tail - fullname)) + partlen,
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1176 find_module_result)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1177 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1178 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1179 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1180 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1181
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1182 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1183
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1184 if (!(newest_path = PyObject_GetAttrString(module, "__path__")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1185 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1186 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1187 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1188 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1189
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1190 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1191
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1192 module = find_module(fullname, dot + 1, newest_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1193
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1194 Py_DECREF(newest_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1195
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1196 return module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1197 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1198 else
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1199 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1200 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
1201 "sO", tail, new_path)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1202 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1203
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1204 if (!(module = call_load_module(
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1205 fullname,
4859
e48cabe98453 updated for version 7.3.1176
Bram Moolenaar <bram@vim.org>
parents: 4855
diff changeset
1206 (int)STRLEN(fullname),
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1207 find_module_result)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1208 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1209 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1210 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1211 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1212
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1213 Py_DECREF(find_module_result);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1214
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1215 return module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1216 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1217 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1218
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1219 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1220 FinderFindModule(PyObject *self, PyObject *args)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1221 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1222 char *fullname;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1223 PyObject *module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1224 PyObject *new_path;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1225 LoaderObject *loader;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1226
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1227 if (!PyArg_ParseTuple(args, "s", &fullname))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1228 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1229
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1230 if (!(new_path = Vim_GetPaths(self)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1231 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1232
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1233 module = find_module(fullname, fullname, new_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1234
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1235 Py_DECREF(new_path);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1236
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1237 if (!module)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1238 {
4984
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1239 if (PyErr_Occurred())
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1240 {
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1241 if (PyErr_ExceptionMatches(PyExc_ImportError))
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1242 PyErr_Clear();
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1243 else
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1244 return NULL;
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1245 }
5b2c8f3b3906 updated for version 7.3.1237
Bram Moolenaar <bram@vim.org>
parents: 4982
diff changeset
1246
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1247 Py_INCREF(Py_None);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1248 return Py_None;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1249 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1250
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1251 if (!(loader = PyObject_NEW(LoaderObject, &LoaderType)))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1252 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1253 Py_DECREF(module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1254 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1255 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1256
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1257 loader->module = module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1258
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1259 return (PyObject *) loader;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1260 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1261
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1262 static PyObject *
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1263 VimPathHook(PyObject *self UNUSED, PyObject *args)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1264 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1265 char *path;
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 if (PyArg_ParseTuple(args, "s", &path)
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1268 && STRCMP(path, vim_special_path) == 0)
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 Py_INCREF(vim_module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1271 return vim_module;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1272 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1273
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1274 PyErr_Clear();
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1275 PyErr_SetNone(PyExc_ImportError);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1276 return NULL;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1277 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
1278
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1279 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1280 * Vim module - Definitions
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1281 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1282
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1283 static struct PyMethodDef VimMethods[] = {
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1284 /* name, function, calling, documentation */
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
1285 {"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
1286 {"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
1287 {"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
1288 {"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
1289 {"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
1290 {"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
1291 {"foreach_rtp", VimForeachRTP, METH_O, "Call given callable for each path in &rtp"},
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1292 {"find_module", FinderFindModule, METH_VARARGS, "Internal use only, returns loader object for any input it receives"},
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
1293 {"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
1294 {"_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
1295 { 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
1296 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1297
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1298 /*
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1299 * 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
1300 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1301
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1302 static PyTypeObject IterType;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1303
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1304 typedef PyObject *(*nextfun)(void **);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1305 typedef void (*destructorfun)(void *);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1306 typedef int (*traversefun)(void *, visitproc, void *);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1307 typedef int (*clearfun)(void **);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1308
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1309 /* 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
1310 * 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
1311 * bunch of objects. */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1312
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1313 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1314 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1315 PyObject_HEAD
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1316 void *cur;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1317 nextfun next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1318 destructorfun destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1319 traversefun traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1320 clearfun clear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1321 } IterObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1322
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1323 static PyObject *
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1324 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
1325 clearfun clear)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1326 {
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1327 IterObject *self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1328
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1329 self = PyObject_GC_New(IterObject, &IterType);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1330 self->cur = start;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1331 self->next = next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1332 self->destruct = destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1333 self->traverse = traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1334 self->clear = clear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1335
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1336 return (PyObject *)(self);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1337 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1338
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1339 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1340 IterDestructor(IterObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1341 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1342 PyObject_GC_UnTrack((void *)(self));
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1343 self->destruct(self->cur);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
1344 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
1345 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1346
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1347 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1348 IterTraverse(IterObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1349 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1350 if (self->traverse != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1351 return self->traverse(self->cur, visit, arg);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1352 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1353 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1354 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1355
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1356 /* Mac OSX defines clear() somewhere. */
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1357 #ifdef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1358 # undef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1359 #endif
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
1360
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1361 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1362 IterClear(IterObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1363 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1364 if (self->clear != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1365 return self->clear(&self->cur);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1366 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1367 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1368 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1369
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1370 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1371 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
1372 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1373 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
1374 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1375
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1376 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1377 IterIter(PyObject *self)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1378 {
4609
12421d8a45d5 updated for version 7.3.1052
Bram Moolenaar <bram@vim.org>
parents: 4607
diff changeset
1379 Py_INCREF(self);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1380 return self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1381 }
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
1382
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1383 typedef struct pylinkedlist_S {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1384 struct pylinkedlist_S *pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1385 struct pylinkedlist_S *pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1386 PyObject *pll_obj;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1387 } pylinkedlist_T;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1388
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1389 static pylinkedlist_T *lastdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1390 static pylinkedlist_T *lastlist = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1391
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1392 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1393 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1394 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1395 if (ref->pll_prev == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1396 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1397 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1398 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1399 *last = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1400 return;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1401 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1402 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1403 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1404 ref->pll_prev->pll_next = ref->pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1405
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1406 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1407 *last = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1408 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1409 ref->pll_next->pll_prev = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1410 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1411
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1412 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1413 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
1414 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1415 if (*last == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1416 ref->pll_prev = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1417 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1418 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1419 (*last)->pll_next = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1420 ref->pll_prev = *last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1421 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1422 ref->pll_next = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1423 ref->pll_obj = self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1424 *last = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1425 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1426
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1427 static PyTypeObject DictionaryType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1428
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1429 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1430 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1431 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1432 dict_T *dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1433 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1434 } DictionaryObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1435
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1436 static PyObject *DictionaryUpdate(DictionaryObject *, PyObject *, PyObject *);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1437
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1438 #define NEW_DICTIONARY(dict) DictionaryNew(&DictionaryType, dict)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1439
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1440 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1441 DictionaryNew(PyTypeObject *subtype, dict_T *dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1442 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1443 DictionaryObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1444
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1445 self = (DictionaryObject *) subtype->tp_alloc(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1446 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1447 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1448 self->dict = dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1449 ++dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1450
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1451 pyll_add((PyObject *)(self), &self->ref, &lastdict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1452
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1453 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1454 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1455
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1456 static dict_T *
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1457 py_dict_alloc(void)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1458 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1459 dict_T *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1460
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1461 if (!(ret = dict_alloc()))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1462 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1463 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1464 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1465 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1466 ++ret->dv_refcount;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1467
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1468 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1469 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1470
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1471 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1472 DictionaryConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1473 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1474 DictionaryObject *self;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1475 dict_T *dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1476
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1477 if (!(dict = py_dict_alloc()))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1478 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1479
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1480 self = (DictionaryObject *) DictionaryNew(subtype, dict);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1481
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1482 --dict->dv_refcount;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1483
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1484 if (kwargs || PyTuple_Size(args))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1485 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1486 PyObject *tmp;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1487 if (!(tmp = DictionaryUpdate(self, args, kwargs)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1488 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1489 Py_DECREF(self);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1490 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1491 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1492
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1493 Py_DECREF(tmp);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1494 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1495
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1496 return (PyObject *)(self);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1497 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1498
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1499 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1500 DictionaryDestructor(DictionaryObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1501 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1502 pyll_remove(&self->ref, &lastdict);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1503 dict_unref(self->dict);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1504
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1505 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1506 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1507
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1508 static char *DictionaryAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1509 "locked", "scope",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1510 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1511 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1512
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1513 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1514 DictionaryDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1515 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1516 return ObjectDir(self, DictionaryAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1517 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
1518
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1519 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1520 DictionarySetattr(DictionaryObject *self, char *name, PyObject *valObject)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1521 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1522 if (valObject == NULL)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1523 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1524 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1525 N_("cannot delete vim.Dictionary attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1526 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1527 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1528
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1529 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1530 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1531 if (self->dict->dv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1532 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1533 PyErr_SET_STRING(PyExc_TypeError,
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1534 N_("cannot modify fixed dictionary"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1535 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1536 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1537 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1538 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1539 int istrue = PyObject_IsTrue(valObject);
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1540 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1541 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1542 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1543 self->dict->dv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1544 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1545 self->dict->dv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1546 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1547 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1548 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1549 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1550 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1551 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
1552 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1553 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1554 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1555
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1556 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1557 DictionaryLength(DictionaryObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1558 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1559 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
1560 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1561
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1562 #define DICT_FLAG_HAS_DEFAULT 0x01
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1563 #define DICT_FLAG_POP 0x02
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1564 #define DICT_FLAG_NONE_DEFAULT 0x04
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1565 #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
1566 #define DICT_FLAG_RETURN_PAIR 0x10
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1567
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1568 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1569 _DictionaryItem(DictionaryObject *self, PyObject *args, int flags)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1570 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1571 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1572 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
1573 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1574 char_u *key;
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1575 dictitem_T *di;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1576 dict_T *dict = self->dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1577 hashitem_T *hi;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1578 PyObject *todecref;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1579
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1580 if (flags & DICT_FLAG_HAS_DEFAULT)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1581 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1582 if (!PyArg_ParseTuple(args, "O|O", &keyObject, &defObject))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1583 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1584 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1585 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1586 keyObject = args;
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 if (flags & DICT_FLAG_RETURN_BOOL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1589 defObject = Py_False;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1590
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1591 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1592 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1593
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1594 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1595 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1596 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
1597 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1598 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1599 }
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1600
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1601 hi = hash_find(&dict->dv_hashtab, key);
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1602
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1603 Py_XDECREF(todecref);
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
1604
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1605 if (HASHITEM_EMPTY(hi))
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 if (defObject)
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 Py_INCREF(defObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1610 return defObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1611 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1612 else
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 PyErr_SetObject(PyExc_KeyError, keyObject);
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 else if (flags & DICT_FLAG_RETURN_BOOL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1619 {
5666
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
1620 ret = Py_True;
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
1621 Py_INCREF(ret);
d1c8c1d64034 updated for version 7.4.179
Bram Moolenaar <bram@vim.org>
parents: 5659
diff changeset
1622 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1623 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1624
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1625 di = dict_lookup(hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1626
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1627 if (!(ret = ConvertToPyObject(&di->di_tv)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1628 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1629
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1630 if (flags & DICT_FLAG_POP)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1631 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1632 if (dict->dv_lock)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1633 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1634 RAISE_LOCKED_DICTIONARY;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1635 Py_DECREF(ret);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1636 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1637 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1638
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1639 hash_remove(&dict->dv_hashtab, hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1640 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1641 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1642
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1643 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1644 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1645
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1646 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1647 DictionaryItem(DictionaryObject *self, PyObject *keyObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1648 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1649 return _DictionaryItem(self, keyObject, 0);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1650 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1651
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1652 static int
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1653 DictionaryContains(DictionaryObject *self, PyObject *keyObject)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1654 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1655 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
1656 int ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1657
5426
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
1658 if (rObj == NULL)
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
1659 return -1;
9cedb4dfd4c8 updated for version 7.4.063
Bram Moolenaar <bram@vim.org>
parents: 5235
diff changeset
1660
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1661 ret = (rObj == Py_True);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1662
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
1663 Py_DECREF(rObj);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1664
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1665 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1666 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1667
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1668 typedef struct
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1669 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1670 hashitem_T *ht_array;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1671 long_u ht_used;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1672 hashtab_T *ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1673 hashitem_T *hi;
4667
9e7ef781d494 updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents: 4659
diff changeset
1674 long_u todo;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1675 } dictiterinfo_T;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1676
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1677 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1678 DictionaryIterNext(dictiterinfo_T **dii)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1679 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1680 PyObject *ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1681
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1682 if (!(*dii)->todo)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1683 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1684
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1685 if ((*dii)->ht->ht_array != (*dii)->ht_array ||
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1686 (*dii)->ht->ht_used != (*dii)->ht_used)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1687 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
1688 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1689 N_("hashtab changed during iteration"));
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1690 return NULL;
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
1691 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1692
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1693 while (((*dii)->todo) && HASHITEM_EMPTY((*dii)->hi))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1694 ++((*dii)->hi);
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 --((*dii)->todo);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1697
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
1698 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
1699 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1700
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1701 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1702 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1703
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1704 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1705 DictionaryIter(DictionaryObject *self)
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 dictiterinfo_T *dii;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1708 hashtab_T *ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1709
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1710 if (!(dii = PyMem_New(dictiterinfo_T, 1)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1711 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1712 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1713 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1714 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1715
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1716 ht = &self->dict->dv_hashtab;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1717 dii->ht_array = ht->ht_array;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1718 dii->ht_used = ht->ht_used;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1719 dii->ht = ht;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1720 dii->hi = dii->ht_array;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1721 dii->todo = dii->ht_used;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1722
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1723 return IterNew(dii,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1724 (destructorfun) PyMem_Free, (nextfun) DictionaryIterNext,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1725 NULL, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1726 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1727
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1728 static PyInt
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1729 DictionaryAssItem(
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
1730 DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1731 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1732 char_u *key;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1733 typval_T tv;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1734 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1735 dictitem_T *di;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1736 PyObject *todecref;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1737
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1738 if (dict->dv_lock)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1739 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1740 RAISE_LOCKED_DICTIONARY;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1741 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1742 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1743
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1744 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1745 return -1;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
1746
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1747 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1748 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1749 RAISE_NO_EMPTY_KEYS;
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1750 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1751 return -1;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1752 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1753
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1754 di = dict_find(dict, key, -1);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1755
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1756 if (valObject == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1757 {
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
1758 hashitem_T *hi;
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
1759
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1760 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1761 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1762 Py_XDECREF(todecref);
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
1763 PyErr_SetObject(PyExc_KeyError, keyObject);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1764 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1765 }
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1766 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
1767 hash_remove(&dict->dv_hashtab, hi);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1768 dictitem_free(di);
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1769 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1770 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1771 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1772
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1773 if (ConvertFromPyObject(valObject, &tv) == -1)
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1774 {
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1775 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1776 return -1;
4706
bf917ee1fad2 updated for version 7.3.1100
Bram Moolenaar <bram@vim.org>
parents: 4704
diff changeset
1777 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1778
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1779 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1780 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1781 if (!(di = dictitem_alloc(key)))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1782 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1783 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1784 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1785 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1786 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1787 di->di_tv.v_lock = 0;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1788 di->di_tv.v_type = VAR_UNKNOWN;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1789
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
1790 if (dict_add(dict, di) == FAIL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1791 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1792 vim_free(di);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1793 dictitem_free(di);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1794 RAISE_KEY_ADD_FAIL(key);
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1795 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1796 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1797 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1798 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1799 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1800 clear_tv(&di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1801
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
1802 Py_XDECREF(todecref);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1803
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1804 copy_tv(&tv, &di->di_tv);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
1805 clear_tv(&tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1806 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1807 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1808
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1809 typedef PyObject *(*hi_to_py)(hashitem_T *);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1810
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1811 static PyObject *
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1812 DictionaryListObjects(DictionaryObject *self, hi_to_py hiconvert)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1813 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1814 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1815 long_u todo = dict->dv_hashtab.ht_used;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1816 Py_ssize_t i = 0;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1817 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1818 hashitem_T *hi;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1819 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1820
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1821 ret = PyList_New(todo);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1822 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
1823 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1824 if (!HASHITEM_EMPTY(hi))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1825 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1826 if (!(newObj = hiconvert(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1827 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1828 Py_DECREF(ret);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1829 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1830 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1831 PyList_SET_ITEM(ret, i, newObj);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1832 --todo;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1833 ++i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1834 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1835 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1836 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1837 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1838
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1839 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1840 dict_key(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1841 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1842 return PyBytes_FromString((char *)(hi->hi_key));
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1843 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1844
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1845 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1846 DictionaryListKeys(DictionaryObject *self)
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 DictionaryListObjects(self, dict_key);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1849 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1850
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1851 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1852 dict_val(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1853 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1854 dictitem_T *di;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1855
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1856 di = dict_lookup(hi);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1857 return ConvertToPyObject(&di->di_tv);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1858 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1859
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1860 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1861 DictionaryListValues(DictionaryObject *self)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1862 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1863 return DictionaryListObjects(self, dict_val);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1864 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1865
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1866 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1867 dict_item(hashitem_T *hi)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1868 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1869 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1870 PyObject *valObject;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1871 PyObject *ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1872
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1873 if (!(keyObject = dict_key(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1874 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1875
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1876 if (!(valObject = dict_val(hi)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1877 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1878 Py_DECREF(keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1879 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1880 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1881
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1882 ret = Py_BuildValue("(OO)", keyObject, valObject);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1883
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1884 Py_DECREF(keyObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1885 Py_DECREF(valObject);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1886
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1887 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1888 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1889
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1890 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1891 DictionaryListItems(DictionaryObject *self)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1892 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1893 return DictionaryListObjects(self, dict_item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1894 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1895
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1896 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1897 DictionaryUpdate(DictionaryObject *self, PyObject *args, PyObject *kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1898 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1899 dict_T *dict = self->dict;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1900
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1901 if (dict->dv_lock)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1902 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1903 RAISE_LOCKED_DICTIONARY;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1904 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1905 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1906
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1907 if (kwargs)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1908 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1909 typval_T tv;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1910
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1911 if (ConvertFromPyMapping(kwargs, &tv) == -1)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1912 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1913
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1914 VimTryStart();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1915 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
1916 clear_tv(&tv);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1917 if (VimTryEnd())
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1918 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1919 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1920 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1921 {
5659
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1922 PyObject *obj = NULL;
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1923
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1924 if (!PyArg_ParseTuple(args, "|O", &obj))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1925 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1926
5659
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1927 if (obj == NULL)
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1928 {
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1929 Py_INCREF(Py_None);
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1930 return Py_None;
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1931 }
ae228baaec2c updated for version 7.4.176
Bram Moolenaar <bram@vim.org>
parents: 5655
diff changeset
1932
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1933 if (PyObject_HasAttrString(obj, "keys"))
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1934 return DictionaryUpdate(self, NULL, obj);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1935 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1936 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1937 PyObject *iterator;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1938 PyObject *item;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1939
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
1940 if (!(iterator = PyObject_GetIter(obj)))
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1941 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1942
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1943 while ((item = PyIter_Next(iterator)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1944 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1945 PyObject *fast;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1946 PyObject *keyObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1947 PyObject *valObject;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1948 PyObject *todecref;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1949 char_u *key;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1950 dictitem_T *di;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1951
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1952 if (!(fast = PySequence_Fast(item, "")))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1953 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1954 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1955 Py_DECREF(item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1956 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1957 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1958
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1959 Py_DECREF(item);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1960
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1961 if (PySequence_Fast_GET_SIZE(fast) != 2)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1962 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1963 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1964 Py_DECREF(fast);
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
1965 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1966 N_("expected sequence element of size 2, "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
1967 "but got sequence of size %d"),
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
1968 (int) PySequence_Fast_GET_SIZE(fast));
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1969 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1970 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1971
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1972 keyObject = PySequence_Fast_GET_ITEM(fast, 0);
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 if (!(key = StringToChars(keyObject, &todecref)))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1975 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1976 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1977 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1978 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1979 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1980
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1981 di = dictitem_alloc(key);
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 Py_XDECREF(todecref);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1984
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1985 if (di == NULL)
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 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1988 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1989 PyErr_NoMemory();
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1990 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1991 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1992 di->di_tv.v_lock = 0;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1993 di->di_tv.v_type = VAR_UNKNOWN;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1994
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1995 valObject = PySequence_Fast_GET_ITEM(fast, 1);
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 (ConvertFromPyObject(valObject, &di->di_tv) == -1)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1998 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
1999 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2000 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2001 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2002 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2003 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2004
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2005 Py_DECREF(fast);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2006
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2007 if (dict_add(dict, di) == FAIL)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2008 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2009 RAISE_KEY_ADD_FAIL(di->di_key);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2010 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2011 dictitem_free(di);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2012 return NULL;
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 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2015
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2016 Py_DECREF(iterator);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2017
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2018 /* Iterator may have finished due to an exception */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2019 if (PyErr_Occurred())
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2020 return NULL;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2021 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2022 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2023 Py_INCREF(Py_None);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2024 return Py_None;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2025 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2026
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2027 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2028 DictionaryGet(DictionaryObject *self, PyObject *args)
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 return _DictionaryItem(self, args,
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2031 DICT_FLAG_HAS_DEFAULT|DICT_FLAG_NONE_DEFAULT);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2032 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2033
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2034 static PyObject *
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2035 DictionaryPop(DictionaryObject *self, PyObject *args)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2036 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2037 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
2038 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2039
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2040 static PyObject *
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2041 DictionaryPopItem(DictionaryObject *self)
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2042 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2043 hashitem_T *hi;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2044 PyObject *ret;
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2045 PyObject *valObject;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2046 dictitem_T *di;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2047
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2048 if (self->dict->dv_hashtab.ht_used == 0)
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2049 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2050 PyErr_SetNone(PyExc_KeyError);
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2051 return NULL;
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2052 }
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2053
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2054 hi = self->dict->dv_hashtab.ht_array;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2055 while (HASHITEM_EMPTY(hi))
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2056 ++hi;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2057
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2058 di = dict_lookup(hi);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2059
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2060 if (!(valObject = ConvertToPyObject(&di->di_tv)))
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2061 return NULL;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2062
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2063 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
2064 {
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2065 Py_DECREF(valObject);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2066 return NULL;
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2067 }
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2068
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2069 hash_remove(&self->dict->dv_hashtab, hi);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2070 dictitem_free(di);
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2071
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2072 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2073 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2074
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2075 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2076 DictionaryHasKey(DictionaryObject *self, PyObject *keyObject)
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2077 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2078 return _DictionaryItem(self, keyObject, DICT_FLAG_RETURN_BOOL);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2079 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2080
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2081 static PySequenceMethods DictionaryAsSeq = {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2082 0, /* sq_length */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2083 0, /* sq_concat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2084 0, /* sq_repeat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2085 0, /* sq_item */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2086 0, /* sq_slice */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2087 0, /* sq_ass_item */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2088 0, /* sq_ass_slice */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2089 (objobjproc) DictionaryContains, /* sq_contains */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2090 0, /* sq_inplace_concat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2091 0, /* sq_inplace_repeat */
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2092 };
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2093
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2094 static PyMappingMethods DictionaryAsMapping = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2095 (lenfunc) DictionaryLength,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2096 (binaryfunc) DictionaryItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2097 (objobjargproc) DictionaryAssItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2098 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2099
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2100 static struct PyMethodDef DictionaryMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
2101 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2102 {"values", (PyCFunction)DictionaryListValues, METH_NOARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2103 {"items", (PyCFunction)DictionaryListItems, METH_NOARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2104 {"update", (PyCFunction)DictionaryUpdate, METH_VARARGS|METH_KEYWORDS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2105 {"get", (PyCFunction)DictionaryGet, METH_VARARGS, ""},
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2106 {"pop", (PyCFunction)DictionaryPop, METH_VARARGS, ""},
4698
2db005052371 updated for version 7.3.1096
Bram Moolenaar <bram@vim.org>
parents: 4667
diff changeset
2107 {"popitem", (PyCFunction)DictionaryPopItem, METH_NOARGS, ""},
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2108 {"has_key", (PyCFunction)DictionaryHasKey, METH_O, ""},
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2109 {"__dir__", (PyCFunction)DictionaryDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2110 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2111 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2112
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2113 static PyTypeObject ListType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2114
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2115 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2116 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2117 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2118 list_T *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2119 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2120 } ListObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2121
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2122 #define NEW_LIST(list) ListNew(&ListType, list)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2123
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2124 static PyObject *
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2125 ListNew(PyTypeObject *subtype, list_T *list)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2126 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2127 ListObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2128
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2129 self = (ListObject *) subtype->tp_alloc(subtype, 0);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2130 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2131 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2132 self->list = list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2133 ++list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2134
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2135 pyll_add((PyObject *)(self), &self->ref, &lastlist);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2136
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2137 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2138 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2139
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2140 static list_T *
5166
467efeee8f9e updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents: 5139
diff changeset
2141 py_list_alloc(void)
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2142 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2143 list_T *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2144
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2145 if (!(ret = list_alloc()))
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2146 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2147 PyErr_NoMemory();
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2148 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2149 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2150 ++ret->lv_refcount;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2151
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2152 return ret;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2153 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2154
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2155 static int
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2156 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
2157 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2158 PyObject *iterator;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2159 PyObject *item;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2160 listitem_T *li;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2161
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2162 if (!(iterator = PyObject_GetIter(obj)))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2163 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2164
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2165 while ((item = PyIter_Next(iterator)))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2166 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2167 if (!(li = listitem_alloc()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2168 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2169 PyErr_NoMemory();
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2170 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2171 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2172 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2173 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2174 li->li_tv.v_lock = 0;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2175 li->li_tv.v_type = VAR_UNKNOWN;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2176
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2177 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
2178 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2179 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2180 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2181 listitem_free(li);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2182 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2183 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2184
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2185 Py_DECREF(item);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2186
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2187 list_append(l, li);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2188 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2189
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2190 Py_DECREF(iterator);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2191
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2192 /* Iterator may have finished due to an exception */
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2193 if (PyErr_Occurred())
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2194 return -1;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2195
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2196 return 0;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2197 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2198
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2199 static PyObject *
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2200 ListConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2201 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2202 list_T *list;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2203 PyObject *obj = NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2204
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2205 if (kwargs)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2206 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2207 PyErr_SET_STRING(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2208 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
2209 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2210 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2211
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2212 if (!PyArg_ParseTuple(args, "|O", &obj))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2213 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2214
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2215 if (!(list = py_list_alloc()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2216 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2217
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2218 if (obj)
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2219 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2220 PyObject *lookup_dict;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2221
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2222 if (!(lookup_dict = PyDict_New()))
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2223 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2224 list_unref(list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2225 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2226 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2227
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2228 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
2229 {
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2230 Py_DECREF(lookup_dict);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2231 list_unref(list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2232 return NULL;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2233 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2234
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2235 Py_DECREF(lookup_dict);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2236 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2237
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2238 return ListNew(subtype, list);
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2239 }
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
2240
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2241 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2242 ListDestructor(ListObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2243 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2244 pyll_remove(&self->ref, &lastlist);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2245 list_unref(self->list);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2246
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2247 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2248 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2249
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2250 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2251 ListLength(ListObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2252 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2253 return ((PyInt) (self->list->lv_len));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2254 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2255
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2256 static PyObject *
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2257 ListIndex(ListObject *self, Py_ssize_t index)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2258 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2259 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2260
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2261 if (index >= ListLength(self))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2262 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2263 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
2264 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2265 }
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2266 li = list_find(self->list, (long) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2267 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2268 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2269 /* 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
2270 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
2271 (int) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2272 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2273 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2274 return ConvertToPyObject(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2275 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2276
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2277 static PyObject *
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2278 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
2279 Py_ssize_t slicelen)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2280 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2281 PyInt i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2282 PyObject *list;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2283
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2284 if (step == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2285 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2286 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
2287 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2288 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2289
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2290 list = PyList_New(slicelen);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2291 if (list == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2292 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2293
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2294 for (i = 0; i < slicelen; ++i)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2295 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2296 PyObject *item;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2297
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2298 item = ListIndex(self, first + i*step);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2299 if (item == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2300 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2301 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2302 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2303 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2304
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2305 PyList_SET_ITEM(list, i, item);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2306 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2307
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2308 return list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2309 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2310
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2311 static PyObject *
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2312 ListItem(ListObject *self, PyObject* idx)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2313 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2314 #if PY_MAJOR_VERSION < 3
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2315 if (PyInt_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2316 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2317 long _idx = PyInt_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2318 return ListIndex(self, _idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2319 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2320 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2321 #endif
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2322 if (PyLong_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2323 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2324 long _idx = PyLong_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2325 return ListIndex(self, _idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2326 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2327 else if (PySlice_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2328 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2329 Py_ssize_t start, stop, step, slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2330
5768
3ee5808a293c updated for version 7.4.228
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
2331 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
2332 &start, &stop, &step, &slicelen) < 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2333 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2334 return ListSlice(self, start, step, slicelen);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2335 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2336 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2337 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2338 RAISE_INVALID_INDEX_TYPE(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2339 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2340 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2341 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2342
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2343 static void
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2344 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
2345 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
2346 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2347 while (numreplaced--)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2348 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2349 list_insert(l, lis[numreplaced], lis[slicelen + numreplaced]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2350 listitem_remove(l, lis[slicelen + numreplaced]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2351 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2352 while (numadded--)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2353 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2354 listitem_T *next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2355
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2356 next = lastaddedli->li_prev;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2357 listitem_remove(l, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2358 lastaddedli = next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2359 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2360 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2361
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2362 static int
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2363 ListAssSlice(ListObject *self, Py_ssize_t first,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2364 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
2365 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2366 PyObject *iterator;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2367 PyObject *item;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2368 listitem_T *li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2369 listitem_T *lastaddedli = NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2370 listitem_T *next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2371 typval_T v;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2372 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2373 PyInt i;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2374 PyInt j;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2375 PyInt numreplaced = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2376 PyInt numadded = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2377 PyInt size;
5655
f2c8d86c460d updated for version 7.4.174
Bram Moolenaar <bram@vim.org>
parents: 5629
diff changeset
2378 listitem_T **lis = NULL;
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2379
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2380 size = ListLength(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2381
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2382 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2383 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2384 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2385 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2386 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2387
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2388 if (step == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2389 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2390 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
2391 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2392 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2393
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2394 if (step != 1 && slicelen == 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2395 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2396 /* 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
2397 int ret = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2398
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2399 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2400 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2401
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2402 if (!(iterator = PyObject_GetIter(obj)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2403 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2404
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2405 if ((item = PyIter_Next(iterator)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2406 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2407 PyErr_FORMAT(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
2408 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
2409 "to extended slice"), 0);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2410 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2411 ret = -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2412 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2413 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2414 return ret;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2415 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2416
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2417 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2418 /* XXX May allocate zero bytes. */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2419 if (!(lis = PyMem_New(listitem_T *, slicelen * 2)))
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 PyErr_NoMemory();
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2422 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2423 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2424
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2425 if (first == size)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2426 li = NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2427 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2428 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2429 li = list_find(l, (long) first);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2430 if (li == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2431 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2432 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
2433 (int)first);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2434 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2435 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2436 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2437 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2438 i = slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2439 while (i-- && li != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2440 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2441 j = step;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2442 next = li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2443 if (step > 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2444 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
2445 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2446 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
2447
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2448 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2449 listitem_remove(l, li);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2450 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2451 lis[slicelen - i - 1] = li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2452
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2453 li = next;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2454 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2455 if (li == NULL && i != -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2456 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2457 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
2458 if (obj != NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2459 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2460 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2461 }
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
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2464 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2465 return 0;
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 if (!(iterator = PyObject_GetIter(obj)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2468 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2469 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2470 return -1;
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
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2473 i = 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2474 while ((item = PyIter_Next(iterator)))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2475 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2476 if (ConvertFromPyObject(item, &v) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2477 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2478 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2479 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2480 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2481 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2482 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2483 Py_DECREF(item);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2484 if (list_insert_tv(l, &v, numreplaced < slicelen
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2485 ? lis[numreplaced]
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2486 : li) == FAIL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2487 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2488 clear_tv(&v);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2489 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
2490 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2491 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2492 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2493 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2494 if (numreplaced < slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2495 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2496 lis[slicelen + numreplaced] = lis[numreplaced]->li_prev;
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 5768
diff changeset
2497 vimlist_remove(l, lis[numreplaced], lis[numreplaced]);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2498 numreplaced++;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2499 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2500 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2501 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2502 if (li)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2503 lastaddedli = li->li_prev;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2504 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2505 lastaddedli = l->lv_last;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2506 numadded++;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2507 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2508 clear_tv(&v);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2509 if (step != 1 && i >= slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2510 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2511 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2512 PyErr_FORMAT(PyExc_ValueError,
5695
a8650e2a0b5a updated for version 7.4.193
Bram Moolenaar <bram@vim.org>
parents: 5668
diff changeset
2513 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
2514 "to extended slice"), (int) slicelen);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2515 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2516 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2517 return -1;
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 ++i;
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 Py_DECREF(iterator);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2522
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2523 if (step != 1 && i != slicelen)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2524 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2525 PyErr_FORMAT2(PyExc_ValueError,
5668
b1b8b097539a updated for version 7.4.180
Bram Moolenaar <bram@vim.org>
parents: 5666
diff changeset
2526 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
2527 "of size %d"), (int) i, (int) slicelen);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2528 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2529 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2530 return -1;
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
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2533 if (PyErr_Occurred())
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2534 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2535 list_restore(numadded, numreplaced, slicelen, l, lis, lastaddedli);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2536 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2537 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2538 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2539
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2540 for (i = 0; i < numreplaced; i++)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2541 listitem_free(lis[i]);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2542 if (step == 1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2543 for (i = numreplaced; i < slicelen; i++)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2544 listitem_remove(l, lis[i]);
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 PyMem_Free(lis);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2547
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2548 return 0;
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
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2551 static int
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2552 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
2553 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2554 typval_T tv;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2555 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2556 listitem_T *li;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2557 Py_ssize_t length = ListLength(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2558
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2559 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2560 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2561 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2562 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2563 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2564 if (index > length || (index == length && obj == 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 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
2567 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2568 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2569
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2570 if (obj == NULL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2571 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2572 li = list_find(l, (long) index);
5871
b4ce0e1fb5a6 updated for version 7.4.278
Bram Moolenaar <bram@vim.org>
parents: 5768
diff changeset
2573 vimlist_remove(l, li, li);
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2574 clear_tv(&li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2575 vim_free(li);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2576 return 0;
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
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2579 if (ConvertFromPyObject(obj, &tv) == -1)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2580 return -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 if (index == length)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2583 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2584 if (list_append_tv(l, &tv) == FAIL)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2585 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2586 clear_tv(&tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2587 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
2588 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2589 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2590 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2591 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2592 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2593 li = list_find(l, (long) index);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2594 clear_tv(&li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2595 copy_tv(&tv, &li->li_tv);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2596 clear_tv(&tv);
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 return 0;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2599 }
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 static Py_ssize_t
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2602 ListAssItem(ListObject *self, PyObject *idx, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2603 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2604 #if PY_MAJOR_VERSION < 3
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2605 if (PyInt_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2606 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2607 long _idx = PyInt_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2608 return ListAssIndex(self, _idx, obj);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2609 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2610 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2611 #endif
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2612 if (PyLong_Check(idx))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2613 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2614 long _idx = PyLong_AsLong(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2615 return ListAssIndex(self, _idx, obj);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2616 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2617 else if (PySlice_Check(idx))
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 Py_ssize_t start, stop, step, slicelen;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2620
5768
3ee5808a293c updated for version 7.4.228
Bram Moolenaar <bram@vim.org>
parents: 5695
diff changeset
2621 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
2622 &start, &stop, &step, &slicelen) < 0)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2623 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2624 return ListAssSlice(self, start, step, slicelen,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2625 obj);
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 else
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2628 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2629 RAISE_INVALID_INDEX_TYPE(idx);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2630 return -1;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2631 }
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
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2634 static PyObject *
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2635 ListConcatInPlace(ListObject *self, PyObject *obj)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2636 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2637 list_T *l = self->list;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2638 PyObject *lookup_dict;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2639
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2640 if (l->lv_lock)
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2641 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2642 RAISE_LOCKED_LIST;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2643 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2644 }
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 if (!(lookup_dict = PyDict_New()))
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2647 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2648
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2649 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
2650 {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2651 Py_DECREF(lookup_dict);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2652 return NULL;
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2653 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2654 Py_DECREF(lookup_dict);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2655
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2656 Py_INCREF(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2657 return (PyObject *)(self);
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2658 }
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2659
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2660 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2661 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2662 listwatch_T lw;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2663 list_T *list;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2664 } listiterinfo_T;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2665
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2666 static void
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2667 ListIterDestruct(listiterinfo_T *lii)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2668 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2669 list_rem_watch(lii->list, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2670 PyMem_Free(lii);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2671 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2672
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2673 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2674 ListIterNext(listiterinfo_T **lii)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2675 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2676 PyObject *ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2677
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2678 if (!((*lii)->lw.lw_item))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2679 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2680
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2681 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
2682 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2683
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2684 (*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
2685
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2686 return ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2687 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2688
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2689 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2690 ListIter(ListObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2691 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2692 listiterinfo_T *lii;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2693 list_T *l = self->list;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2694
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2695 if (!(lii = PyMem_New(listiterinfo_T, 1)))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2696 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2697 PyErr_NoMemory();
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2698 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2699 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2700
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2701 list_add_watch(l, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2702 lii->lw.lw_item = l->lv_first;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2703 lii->list = l;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2704
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2705 return IterNew(lii,
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2706 (destructorfun) ListIterDestruct, (nextfun) ListIterNext,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2707 NULL, NULL);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2708 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
2709
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2710 static char *ListAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2711 "locked",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2712 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2713 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2714
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2715 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2716 ListDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2717 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2718 return ObjectDir(self, ListAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2719 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2720
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2721 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2722 ListSetattr(ListObject *self, char *name, PyObject *valObject)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2723 {
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2724 if (valObject == NULL)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2725 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2726 PyErr_SET_STRING(PyExc_AttributeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2727 N_("cannot delete vim.List attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2728 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2729 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2730
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2731 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2732 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2733 if (self->list->lv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2734 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2735 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
2736 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2737 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2738 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2739 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2740 int istrue = PyObject_IsTrue(valObject);
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
2741 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
2742 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
2743 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2744 self->list->lv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2745 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2746 self->list->lv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2747 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2748 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2749 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2750 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2751 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2752 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
2753 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2754 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2755 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
2756
5608
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2757 static PySequenceMethods ListAsSeq = {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2758 (lenfunc) ListLength, /* sq_length, len(x) */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2759 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2760 0, /* RangeRepeat, sq_repeat, x*n */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2761 (PyIntArgFunc) ListIndex, /* sq_item, x[i] */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2762 0, /* was_sq_slice, x[i:j] */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2763 (PyIntObjArgProc) ListAssIndex, /* sq_as_item, x[i]=v */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2764 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
2765 0, /* sq_contains */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2766 (binaryfunc) ListConcatInPlace,/* sq_inplace_concat */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2767 0, /* sq_inplace_repeat */
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2768 };
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 static PyMappingMethods ListAsMapping = {
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2771 /* mp_length */ (lenfunc) ListLength,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2772 /* mp_subscript */ (binaryfunc) ListItem,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2773 /* mp_ass_subscript */ (objobjargproc) ListAssItem,
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2774 };
ec02e1474bc2 updated for version 7.4.151
Bram Moolenaar <bram@vim.org>
parents: 5588
diff changeset
2775
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2776 static struct PyMethodDef ListMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2777 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2778 {"__dir__", (PyCFunction)ListDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2779 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2780 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2781
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2782 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2783 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2784 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2785 char_u *name;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2786 } FunctionObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2787
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2788 static PyTypeObject FunctionType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2789
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2790 #define NEW_FUNCTION(name) FunctionNew(&FunctionType, name)
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2791
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2792 static PyObject *
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2793 FunctionNew(PyTypeObject *subtype, char_u *name)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2794 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2795 FunctionObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2796
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2797 self = (FunctionObject *) subtype->tp_alloc(subtype, 0);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2798
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2799 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2800 return NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2801
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2802 if (isdigit(*name))
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2803 {
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2804 if (!translated_function_exists(name))
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2805 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
2806 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2807 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
2808 return NULL;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2809 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2810 self->name = vim_strsave(name);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2811 func_ref(self->name);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2812 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2813 else
4641
59e6c2bd68e3 updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents: 4635
diff changeset
2814 if ((self->name = get_expanded_name(name,
59e6c2bd68e3 updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents: 4635
diff changeset
2815 vim_strchr(name, AUTOLOAD_CHAR) == NULL))
59e6c2bd68e3 updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents: 4635
diff changeset
2816 == NULL)
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2817 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2818 PyErr_FORMAT(PyExc_ValueError,
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2819 N_("function %s does not exist"), name);
4641
59e6c2bd68e3 updated for version 7.3.1068
Bram Moolenaar <bram@vim.org>
parents: 4635
diff changeset
2820 return NULL;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2821 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2822
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2823 return (PyObject *)(self);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2824 }
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2825
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2826 static PyObject *
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2827 FunctionConstructor(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2828 {
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2829 PyObject *self;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2830 char_u *name;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2831
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2832 if (kwargs)
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2833 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
2834 PyErr_SET_STRING(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2835 N_("function constructor does not accept keyword arguments"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2836 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2837 }
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2838
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2839 if (!PyArg_ParseTuple(args, "et", "ascii", &name))
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2840 return NULL;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2841
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2842 self = FunctionNew(subtype, name);
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2843
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2844 PyMem_Free(name);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
2845
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2846 return self;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2847 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2848
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2849 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2850 FunctionDestructor(FunctionObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2851 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2852 func_unref(self->name);
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
2853 vim_free(self->name);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2854
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2855 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2856 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2857
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2858 static char *FunctionAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2859 "softspace",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2860 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2861 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2862
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2863 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2864 FunctionDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2865 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2866 return ObjectDir(self, FunctionAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2867 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2868
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2869 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2870 FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2871 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2872 char_u *name = self->name;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2873 typval_T args;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2874 typval_T selfdicttv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2875 typval_T rettv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2876 dict_T *selfdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2877 PyObject *selfdictObject;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2878 PyObject *ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2879 int error;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2880
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2881 if (ConvertFromPyObject(argsObject, &args) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2882 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2883
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2884 if (kwargs != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2885 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2886 selfdictObject = PyDict_GetItemString(kwargs, "self");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2887 if (selfdictObject != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2888 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
2889 if (ConvertFromPyMapping(selfdictObject, &selfdicttv) == -1)
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
2890 {
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
2891 clear_tv(&args);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2892 return NULL;
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
2893 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2894 selfdict = selfdicttv.vval.v_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2895 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2896 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2897
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2898 Py_BEGIN_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2899 Python_Lock_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2900
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
2901 VimTryStart();
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2902 error = func_call(name, &args, selfdict, &rettv);
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2903
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2904 Python_Release_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2905 Py_END_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
2906
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
2907 if (VimTryEnd())
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2908 ret = NULL;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
2909 else if (error != OK)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2910 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2911 ret = NULL;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
2912 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
2913 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2914 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2915 ret = ConvertToPyObject(&rettv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2916
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2917 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2918 clear_tv(&rettv);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
2919 if (selfdict != NULL)
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
2920 clear_tv(&selfdicttv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2921
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
2922 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2923 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2924
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
2925 static PyObject *
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
2926 FunctionRepr(FunctionObject *self)
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
2927 {
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
2928 #ifdef Py_TRACE_REFS
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
2929 /* For unknown reason self->name may be NULL after calling
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
2930 * Finalize */
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
2931 return PyString_FromFormat("<vim.Function '%s'>",
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
2932 (self->name == NULL ? "<NULL>" : (char *)self->name));
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
2933 #else
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
2934 return PyString_FromFormat("<vim.Function '%s'>", (char *)self->name);
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
2935 #endif
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
2936 }
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
2937
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2938 static struct PyMethodDef FunctionMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2939 {"__dir__", (PyCFunction)FunctionDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
2940 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2941 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2942
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2943 /*
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2944 * Options object
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2945 */
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2946
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2947 static PyTypeObject OptionsType;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2948
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2949 typedef int (*checkfun)(void *);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2950
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2951 typedef struct
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2952 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2953 PyObject_HEAD
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
2954 int opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
2955 void *from;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
2956 checkfun Check;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
2957 PyObject *fromObj;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2958 } OptionsObject;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
2959
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2960 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2961 dummy_check(void *arg UNUSED)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2962 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2963 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2964 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2965
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2966 static PyObject *
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2967 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
2968 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2969 OptionsObject *self;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2970
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
2971 self = PyObject_GC_New(OptionsObject, &OptionsType);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2972 if (self == NULL)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2973 return NULL;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2974
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2975 self->opt_type = opt_type;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2976 self->from = from;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2977 self->Check = Check;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2978 self->fromObj = fromObj;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2979 if (fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2980 Py_INCREF(fromObj);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2981
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2982 return (PyObject *)(self);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2983 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2984
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2985 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2986 OptionsDestructor(OptionsObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2987 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
2988 PyObject_GC_UnTrack((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
2989 Py_XDECREF(self->fromObj);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
2990 PyObject_GC_Del((void *)(self));
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2991 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2992
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2993 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2994 OptionsTraverse(OptionsObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2995 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2996 Py_VISIT(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2997 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2998 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
2999
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3000 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3001 OptionsClear(OptionsObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3002 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3003 Py_CLEAR(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3004 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3005 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3006
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3007 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3008 OptionsItem(OptionsObject *self, PyObject *keyObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3009 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3010 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3011 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3012 long numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3013 char_u *stringval;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3014 PyObject *todecref;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3015
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3016 if (self->Check(self->from))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3017 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3018
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3019 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3020 return NULL;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3021
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3022 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3023 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3024 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3025 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3026 return NULL;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3027 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3028
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3029 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
3030 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3031
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3032 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3033
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3034 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3035 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3036 PyErr_SetObject(PyExc_KeyError, keyObject);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3037 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3038 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3039
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3040 if (flags & SOPT_UNSET)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3041 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3042 Py_INCREF(Py_None);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3043 return Py_None;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3044 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3045 else if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3046 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3047 PyObject *ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3048 ret = numval ? Py_True : Py_False;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3049 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3050 return ret;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3051 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3052 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3053 return PyInt_FromLong(numval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3054 else if (flags & SOPT_STRING)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3055 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3056 if (stringval)
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3057 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
3058 PyObject *ret = PyBytes_FromString((char *)stringval);
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3059 vim_free(stringval);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3060 return ret;
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3061 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3062 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3063 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
3064 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3065 N_("unable to get option value"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3066 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3067 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3068 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3069 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3070 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3071 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
3072 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3073 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3074 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3075
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3076 static int
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3077 OptionsContains(OptionsObject *self, PyObject *keyObject)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3078 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3079 char_u *key;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3080 PyObject *todecref;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3081
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3082 if (!(key = StringToChars(keyObject, &todecref)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3083 return -1;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3084
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3085 if (*key == NUL)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3086 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3087 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3088 return 0;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3089 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3090
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3091 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
3092 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3093 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3094 return 1;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3095 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3096 else
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3097 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3098 Py_XDECREF(todecref);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3099 return 0;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3100 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3101 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3102
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3103 typedef struct
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3104 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3105 void *lastoption;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3106 int opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3107 } optiterinfo_T;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3108
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3109 static PyObject *
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3110 OptionsIterNext(optiterinfo_T **oii)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3111 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3112 char_u *name;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3113
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3114 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
3115 return PyString_FromString((char *)name);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3116
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3117 return NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3118 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3119
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3120 static PyObject *
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3121 OptionsIter(OptionsObject *self)
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3122 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3123 optiterinfo_T *oii;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3124
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3125 if (!(oii = PyMem_New(optiterinfo_T, 1)))
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3126 {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3127 PyErr_NoMemory();
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3128 return NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3129 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3130
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3131 oii->opt_type = self->opt_type;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3132 oii->lastoption = NULL;
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3133
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3134 return IterNew(oii,
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3135 (destructorfun) PyMem_Free, (nextfun) OptionsIterNext,
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3136 NULL, NULL);
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3137 }
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3138
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3139 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3140 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
3141 {
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3142 char_u *errmsg;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3143
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3144 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
3145 {
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3146 if (VimTryEnd())
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3147 return FAIL;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3148 PyErr_SetVim((char *)errmsg);
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3149 return FAIL;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3150 }
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3151 return OK;
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3152 }
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3153
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3154 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3155 set_option_value_for(
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3156 char_u *key,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3157 int numval,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3158 char_u *stringval,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3159 int opt_flags,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3160 int opt_type,
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
3161 void *from)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3162 {
4509
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3163 win_T *save_curwin = NULL;
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3164 tabpage_T *save_curtab = NULL;
b498224f5b41 updated for version 7.3.1002
Bram Moolenaar <bram@vim.org>
parents: 4500
diff changeset
3165 buf_T *save_curbuf = NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3166 int set_ret = 0;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3167
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3168 VimTryStart();
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3169 switch (opt_type)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3170 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3171 case SREQ_WIN:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3172 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
3173 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
3174 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3175 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3176 return -1;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3177 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
3178 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3179 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3180 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
3181 restore_win(save_curwin, save_curtab, TRUE);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3182 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3183 case SREQ_BUF:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3184 switch_buffer(&save_curbuf, (buf_T *)from);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3185 set_ret = set_option_value_err(key, numval, stringval, opt_flags);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3186 restore_buffer(save_curbuf);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3187 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3188 case SREQ_GLOBAL:
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3189 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
3190 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3191 }
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3192 if (set_ret == FAIL)
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3193 return -1;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3194 return VimTryEnd();
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3195 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3196
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3197 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3198 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3199 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3200 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3201 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3202 int opt_flags;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3203 int ret = 0;
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3204 PyObject *todecref;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3205
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3206 if (self->Check(self->from))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3207 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3208
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3209 if (!(key = StringToChars(keyObject, &todecref)))
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3210 return -1;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3211
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3212 if (*key == NUL)
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3213 {
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3214 RAISE_NO_EMPTY_KEYS;
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
3215 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3216 return -1;
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3217 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3218
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3219 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
3220 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3221
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3222 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3223 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3224 PyErr_SetObject(PyExc_KeyError, keyObject);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3225 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3226 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3227 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3228
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3229 if (valObject == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3230 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3231 if (self->opt_type == SREQ_GLOBAL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3232 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3233 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3234 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
3235 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3236 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3237 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3238 else if (!(flags & SOPT_GLOBAL))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3239 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
3240 PyErr_FORMAT(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3241 N_("unable to unset option %s "
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3242 "which does not have global value"), key);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3243 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3244 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3245 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3246 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3247 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3248 unset_global_local_option(key, self->from);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3249 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3250 return 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3251 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3252 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3253
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3254 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
3255
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3256 if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3257 {
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3258 int istrue = PyObject_IsTrue(valObject);
4513
cadb57fbb781 updated for version 7.3.1004
Bram Moolenaar <bram@vim.org>
parents: 4511
diff changeset
3259
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
3260 if (istrue == -1)
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3261 ret = -1;
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3262 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3263 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
3264 opt_flags, self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3265 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3266 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3267 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3268 long val;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3269
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3270 if (NumberToLong(valObject, &val, NUMBER_INT))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3271 {
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3272 Py_XDECREF(todecref);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3273 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3274 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3275
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3276 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
3277 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3278 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3279 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3280 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3281 char_u *val;
5525
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3282 PyObject *todecref2;
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3283
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3284 if ((val = StringToChars(valObject, &todecref2)))
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3285 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3286 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
3287 self->opt_type, self->from);
5525
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3288 Py_XDECREF(todecref2);
3fbda56bb200 updated for version 7.4.111
Bram Moolenaar <bram@vim.org>
parents: 5517
diff changeset
3289 }
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3290 else
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3291 ret = -1;
4350
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
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
3294 Py_XDECREF(todecref);
4587
63c9b681c3db updated for version 7.3.1041
Bram Moolenaar <bram@vim.org>
parents: 4575
diff changeset
3295
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3296 return ret;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3297 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3298
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3299 static PySequenceMethods OptionsAsSeq = {
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3300 0, /* sq_length */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3301 0, /* sq_concat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3302 0, /* sq_repeat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3303 0, /* sq_item */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3304 0, /* sq_slice */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3305 0, /* sq_ass_item */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3306 0, /* sq_ass_slice */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3307 (objobjproc) OptionsContains, /* sq_contains */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3308 0, /* sq_inplace_concat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3309 0, /* sq_inplace_repeat */
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3310 };
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
3311
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3312 static PyMappingMethods OptionsAsMapping = {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3313 (lenfunc) NULL,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3314 (binaryfunc) OptionsItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3315 (objobjargproc) OptionsAssItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3316 };
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3317
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3318 /* Tabpage object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3319 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3320
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3321 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3322 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3323 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3324 tabpage_T *tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3325 } TabPageObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3326
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3327 static PyObject *WinListNew(TabPageObject *tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3328
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3329 static PyTypeObject TabPageType;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3330
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3331 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3332 CheckTabPage(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3333 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3334 if (self->tab == INVALID_TABPAGE_VALUE)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3335 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3336 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
3337 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3338 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3339
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3340 return 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3341 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3342
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3343 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3344 TabPageNew(tabpage_T *tab)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3345 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3346 TabPageObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3347
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3348 if (TAB_PYTHON_REF(tab))
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3349 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3350 self = TAB_PYTHON_REF(tab);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3351 Py_INCREF(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3352 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3353 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3354 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3355 self = PyObject_NEW(TabPageObject, &TabPageType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3356 if (self == NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3357 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3358 self->tab = tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3359 TAB_PYTHON_REF(tab) = self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3360 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3361
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3362 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3363 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3364
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3365 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3366 TabPageDestructor(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3367 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3368 if (self->tab && self->tab != INVALID_TABPAGE_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3369 TAB_PYTHON_REF(self->tab) = NULL;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3370
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3371 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3372 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3373
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3374 static char *TabPageAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3375 "windows", "number", "vars", "window", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3376 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3377 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3378
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3379 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3380 TabPageDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3381 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3382 return ObjectDir(self, TabPageAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3383 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3384
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3385 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3386 TabPageAttrValid(TabPageObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3387 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3388 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3389
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3390 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3391 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3392
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3393 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
3394 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3395 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3396 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3397
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3398 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3399 TabPageAttr(TabPageObject *self, char *name)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3400 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3401 if (strcmp(name, "windows") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3402 return WinListNew(self);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3403 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3404 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
3405 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
3406 return NEW_DICTIONARY(self->tab->tp_vars);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3407 else if (strcmp(name, "window") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3408 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3409 /* 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
3410 */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3411 if (self->tab == curtab)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3412 return WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3413 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3414 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
3415 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3416 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3417 return ObjectDir(NULL, TabPageAttrs);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3418 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3419 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3420
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3421 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3422 TabPageRepr(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3423 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3424 if (self->tab == INVALID_TABPAGE_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3425 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
3426 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3427 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3428 int t = get_tab_number(self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3429
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3430 if (t == 0)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3431 return PyString_FromFormat("<tabpage object (unknown) at %p>",
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3432 (self));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3433 else
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3434 return PyString_FromFormat("<tabpage %d>", t - 1);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3435 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3436 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3437
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3438 static struct PyMethodDef TabPageMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3439 /* name, function, calling, documentation */
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3440 {"__dir__", (PyCFunction)TabPageDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3441 { NULL, NULL, 0, NULL}
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3442 };
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3443
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3444 /*
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3445 * Window list object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3446 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3447
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3448 static PyTypeObject TabListType;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3449 static PySequenceMethods TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3450
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3451 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3452 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3453 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3454 } TabListObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3455
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3456 static PyInt
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3457 TabListLength(PyObject *self UNUSED)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3458 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3459 tabpage_T *tp = first_tabpage;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3460 PyInt n = 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3461
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3462 while (tp != NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3463 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3464 ++n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3465 tp = tp->tp_next;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3466 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3467
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3468 return n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3469 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3470
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3471 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3472 TabListItem(PyObject *self UNUSED, PyInt n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3473 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3474 tabpage_T *tp;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3475
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3476 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
3477 if (n == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3478 return TabPageNew(tp);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3479
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3480 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
3481 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3482 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3483
4962
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
3484 /*
b34d719b13cd updated for version 7.3.1226
Bram Moolenaar <bram@vim.org>
parents: 4922
diff changeset
3485 * Window object
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3486 */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3487
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3488 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3489 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3490 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3491 win_T *win;
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3492 TabPageObject *tabObject;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3493 } WindowObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3494
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3495 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
3496
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3497 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3498 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
3499 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3500 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
3501 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3502 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
3503 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3504 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3505
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3506 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3507 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3508
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3509 static PyObject *
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3510 WindowNew(win_T *win, tabpage_T *tab)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3511 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3512 /* 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
3513 * 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
3514 * 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
3515 * 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
3516 * 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
3517 * 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
3518 * the window is stored in "w_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3519 * 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
3520 * 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
3521 * 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
3522 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3523 * 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
3524 * 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
3525 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3526
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3527 WindowObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3528
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3529 if (WIN_PYTHON_REF(win))
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3530 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3531 self = WIN_PYTHON_REF(win);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3532 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3533 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3534 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3535 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3536 self = PyObject_GC_New(WindowObject, &WindowType);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3537 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3538 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3539 self->win = win;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3540 WIN_PYTHON_REF(win) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3541 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3542
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3543 self->tabObject = ((TabPageObject *)(TabPageNew(tab)));
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3544
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3545 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3546 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3547
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3548 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3549 WindowDestructor(WindowObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3550 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3551 PyObject_GC_UnTrack((void *)(self));
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3552 if (self->win && self->win != INVALID_WINDOW_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3553 WIN_PYTHON_REF(self->win) = NULL;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3554 Py_XDECREF(((PyObject *)(self->tabObject)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3555 PyObject_GC_Del((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3556 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3557
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3558 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3559 WindowTraverse(WindowObject *self, visitproc visit, void *arg)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3560 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3561 Py_VISIT(((PyObject *)(self->tabObject)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3562 return 0;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3563 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3564
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3565 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3566 WindowClear(WindowObject *self)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3567 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3568 Py_CLEAR(self->tabObject);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
3569 return 0;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3570 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3571
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3572 static win_T *
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3573 get_firstwin(TabPageObject *tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3574 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3575 if (tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3576 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3577 if (CheckTabPage(tabObject))
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3578 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3579 /* 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
3580 */
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3581 else if (tabObject->tab == curtab)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3582 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3583 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3584 return tabObject->tab->tp_firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3585 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3586 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3587 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3588 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3589 static char *WindowAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3590 "buffer", "cursor", "height", "vars", "options", "number", "row", "col",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3591 "tabpage", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3592 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3593 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3594
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3595 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3596 WindowDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3597 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3598 return ObjectDir(self, WindowAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3599 }
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3600
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3601 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3602 WindowAttrValid(WindowObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3603 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3604 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3605
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3606 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3607 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3608
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3609 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
3610 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3611 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3612 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3613
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
3614 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3615 WindowAttr(WindowObject *self, char *name)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3616 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3617 if (strcmp(name, "buffer") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3618 return (PyObject *)BufferNew(self->win->w_buffer);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3619 else if (strcmp(name, "cursor") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3620 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3621 pos_T *pos = &self->win->w_cursor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3622
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3623 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
3624 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3625 else if (strcmp(name, "height") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3626 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
3627 #ifdef FEAT_WINDOWS
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
3628 else if (strcmp(name, "row") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3629 return PyLong_FromLong((long)(self->win->w_winrow));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
3630 #endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3631 #ifdef FEAT_VERTSPLIT
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3632 else if (strcmp(name, "width") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3633 return PyLong_FromLong((long)(W_WIDTH(self->win)));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
3634 else if (strcmp(name, "col") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3635 return PyLong_FromLong((long)(W_WINCOL(self->win)));
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3636 #endif
4323
f1eab4f77a6f updated for version 7.3.911
Bram Moolenaar <bram@vim.org>
parents: 4321
diff changeset
3637 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
3638 return NEW_DICTIONARY(self->win->w_vars);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3639 else if (strcmp(name, "options") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3640 return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow,
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3641 (PyObject *) self);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
3642 else if (strcmp(name, "number") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3643 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3644 if (CheckTabPage(self->tabObject))
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3645 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3646 return PyLong_FromLong((long)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3647 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
3648 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3649 else if (strcmp(name, "tabpage") == 0)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3650 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3651 Py_INCREF(self->tabObject);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3652 return (PyObject *)(self->tabObject);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3653 }
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3654 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3655 return ObjectDir(NULL, WindowAttrs);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3656 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3657 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3658 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3659
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3660 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3661 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
3662 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3663 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
3664 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3665
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3666 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
3667 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3668 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
3669 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3670 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3671 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
3672 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3673 long lnum;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3674 long col;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3675
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3676 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
3677 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3678
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3679 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
3680 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3681 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
3682 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3683 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3684
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3685 /* Check for keyboard interrupts */
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3686 if (VimCheckInterrupt())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3687 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3688
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3689 self->win->w_cursor.lnum = lnum;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3690 self->win->w_cursor.col = col;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3691 #ifdef FEAT_VIRTUALEDIT
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3692 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
3693 #endif
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
3694 /* 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
3695 check_cursor_col_win(self->win);
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
3696
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3697 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3698 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3699 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3700 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
3701 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3702 long height;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3703 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3704
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
3705 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
3706 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3707
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3708 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3709 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
3710 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3711 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3712 curwin = self->win;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3713
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3714 VimTryStart();
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3715 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
3716 curwin = savewin;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3717 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3718 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3719
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3720 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3721 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3722 #ifdef FEAT_VERTSPLIT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3723 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
3724 {
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3725 long width;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3726 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3727
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
3728 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
3729 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3730
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3731 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3732 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
3733 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3734 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3735 curwin = self->win;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3736
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3737 VimTryStart();
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
3738 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
3739 curwin = savewin;
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
3740 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3741 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3742
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3743 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3744 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3745 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3746 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3747 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3748 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
3749 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3750 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3751 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3752
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3753 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3754 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
3755 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3756 if (self->win == INVALID_WINDOW_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3757 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
3758 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3759 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3760 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
3761
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
3762 if (w == 0)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3763 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
3764 (self));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3765 else
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
3766 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
3767 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3768 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3769
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3770 static struct PyMethodDef WindowMethods[] = {
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3771 /* name, function, calling, documentation */
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3772 {"__dir__", (PyCFunction)WindowDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
3773 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3774 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3775
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3776 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3777 * 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
3778 */
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3779
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3780 static PyTypeObject WinListType;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3781 static PySequenceMethods WinListAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3782
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3783 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3784 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3785 PyObject_HEAD
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3786 TabPageObject *tabObject;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3787 } WinListObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3788
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3789 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3790 WinListNew(TabPageObject *tabObject)
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 WinListObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3793
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3794 self = PyObject_NEW(WinListObject, &WinListType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3795 self->tabObject = tabObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3796 Py_INCREF(tabObject);
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 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3799 }
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 void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3802 WinListDestructor(WinListObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3803 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3804 TabPageObject *tabObject = self->tabObject;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3805
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3806 if (tabObject)
4523
57393dc4b811 updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents: 4513
diff changeset
3807 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3808 Py_DECREF((PyObject *)(tabObject));
4523
57393dc4b811 updated for version 7.3.1009
Bram Moolenaar <bram@vim.org>
parents: 4513
diff changeset
3809 }
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3810
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3811 DESTRUCTOR_FINISH(self);
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
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3814 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3815 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
3816 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3817 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
3818 PyInt n = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3819
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3820 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3821 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3822
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3823 while (w != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3824 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3825 ++n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3826 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
3827 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3828
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3829 return n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3830 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3831
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3832 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3833 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
3834 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3835 win_T *w;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3836
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3837 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3838 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3839
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3840 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
3841 if (n == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3842 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
3843
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3844 PyErr_SET_STRING(PyExc_IndexError, N_("no such window"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3845 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3846 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3847
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3848 /* 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
3849 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3850 * 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
3851 * 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
3852 * characters.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3853 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3854 * 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
3855 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3856 static char *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3857 StringToLine(PyObject *obj)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3858 {
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3859 char *str;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3860 char *save;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3861 PyObject *bytes = NULL;
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
3862 Py_ssize_t len = 0;
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3863 PyInt i;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3864 char *p;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3865
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3866 if (PyBytes_Check(obj))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3867 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3868 if (PyBytes_AsStringAndSize(obj, &str, &len) == -1
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3869 || str == NULL)
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3870 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3871 }
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3872 else if (PyUnicode_Check(obj))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3873 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3874 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3875 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3876
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3877 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3878 || str == NULL)
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3879 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3880 Py_DECREF(bytes);
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3881 return NULL;
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3882 }
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3883 }
4995
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3884 else
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3885 {
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3886 #if PY_MAJOR_VERSION < 3
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3887 PyErr_FORMAT(PyExc_TypeError,
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3888 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
3889 Py_TYPE_NAME(obj));
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3890 #else
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3891 PyErr_FORMAT(PyExc_TypeError,
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3892 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
3893 Py_TYPE_NAME(obj));
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3894 #endif
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3895 return NULL;
b4a2eaf28b51 updated for version 7.3.1242
Bram Moolenaar <bram@vim.org>
parents: 4988
diff changeset
3896 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3897
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3898 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3899 * 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
3900 * 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
3901 * a single line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3902 * 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
3903 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3904 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
3905 if (p != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3906 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3907 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
3908 --len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3909 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3910 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
3911 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
3912 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
3913 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3914 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3915 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3916
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3917 /* 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
3918 * 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
3919 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3920 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
3921 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3922 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3923 PyErr_NoMemory();
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
3924 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
3925 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3926 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3927
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3928 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
3929 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3930 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
3931 save[i] = '\n';
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3932 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3933 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
3934 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3935
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3936 save[i] = '\0';
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
3937 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
3938
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3939 return save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3940 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3941
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3942 /* 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
3943 * 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
3944 * string object.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3945 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3946 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3947 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
3948 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3949 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
3950 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3951
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3952
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3953 /* 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
3954 * 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
3955 * 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
3956 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3957 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3958 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
3959 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3960 PyInt i;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3961 PyInt n = hi - lo;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3962 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
3963
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3964 if (list == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3965 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3966
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3967 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
3968 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3969 PyObject *string = LineToString(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3970 (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
3971
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3972 /* 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
3973 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
3974 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3975 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3976 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3977 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3978
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
3979 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
3980 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3981
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3982 /* 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
3983 * 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
3984 * with it).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3985 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3986
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3987 return list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3988 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3989
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3990 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3991 * 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
3992 * 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
3993 * deleted).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3994 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3995 static void
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3996 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
3997 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3998 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
3999 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4000 /* 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
4001 * lines. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4002 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
4003 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4004 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
4005 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4006 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4007 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
4008 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4009 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
4010 check_cursor();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4011 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4012 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4013 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4014 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
4015 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4016 invalidate_botline();
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
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4019 /*
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4020 * Find a window that contains "buf" and switch to it.
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4021 * If there is no such window, use the current window and change "curbuf".
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4022 * Caller must initialize save_curbuf to NULL.
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4023 * restore_win_for_buf() MUST be called later!
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4024 */
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4025 static void
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4026 switch_to_win_for_buf(
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4027 buf_T *buf,
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4028 win_T **save_curwinp,
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4029 tabpage_T **save_curtabp,
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4030 buf_T **save_curbufp)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4031 {
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4032 win_T *wp;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4033 tabpage_T *tp;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4034
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4035 if (find_win_for_buf(buf, &wp, &tp) == FAIL
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4036 || switch_win(save_curwinp, save_curtabp, wp, tp, TRUE) == FAIL)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4037 switch_buffer(save_curbufp, buf);
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4038 }
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4039
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4040 static void
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4041 restore_win_for_buf(
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4042 win_T *save_curwin,
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4043 tabpage_T *save_curtab,
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4044 buf_T *save_curbuf)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4045 {
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4046 if (save_curbuf == NULL)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4047 restore_win(save_curwin, save_curtab, TRUE);
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4048 else
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4049 restore_buffer(save_curbuf);
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4050 }
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4051
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4052 /*
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4053 * 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
4054 * 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
4055 * 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
4056 * 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
4057 * 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
4058 * 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
4059 * 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
4060 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4061 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4062 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
4063 {
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4064 buf_T *save_curbuf = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4065 win_T *save_curwin = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4066 tabpage_T *save_curtab = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4067
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
4068 /* 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
4069 * 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
4070 * 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
4071 * 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
4072 * 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
4073 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4074 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
4075 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4076 PyErr_Clear();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4077 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
4078
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4079 VimTryStart();
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4080
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4081 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
4082 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
4083 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
4084 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
4085 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4086 {
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4087 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
4088 py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4089 if (save_curbuf == NULL)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4090 /* 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
4091 * 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
4092 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
4093 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4094
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4095 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
4096
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4097 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4098 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4099
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4100 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4101 *len_change = -1;
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 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4104 }
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4105 else if (PyBytes_Check(line) || PyUnicode_Check(line))
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4106 {
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4107 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
4108
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4109 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4110 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4111
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4112 VimTryStart();
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4113
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4114 /* 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
4115 PyErr_Clear();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4116 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
4117
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4118 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
4119 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
4120 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
4121 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4122 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4123 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
4124 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4125 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
4126 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4127 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4128 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4129 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
4130
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4131 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
4132
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4133 /* 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
4134 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
4135 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4136
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4137 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4138 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4139
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4140 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4141 *len_change = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4142
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4143 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4144 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4145 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4146 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4147 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4148 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4149 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4150 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4151
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4152 /* 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
4153 * 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
4154 * 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
4155 * 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
4156 * 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
4157 * 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
4158 * 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
4159 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4160 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4161 SetBufferLineList(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4162 buf_T *buf,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4163 PyInt lo,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4164 PyInt hi,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4165 PyObject *list,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4166 PyInt *len_change)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4167 {
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4168 buf_T *save_curbuf = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4169 win_T *save_curwin = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4170 tabpage_T *save_curtab = NULL;
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4171
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
4172 /* 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
4173 * There are three cases:
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4174 * 1. NULL, or None - this is a deletion.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4175 * 2. A list - this is a replacement.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4176 * 3. Anything else - this is an error.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4177 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4178 if (list == Py_None || list == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4179 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4180 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4181 PyInt n = (int)(hi - lo);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4182
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4183 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4184 VimTryStart();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4185 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
4186
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4187 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
4188 RAISE_UNDO_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4189 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4190 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4191 for (i = 0; i < n; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4192 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4193 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4194 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4195 RAISE_DELETE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4196 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4197 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4198 }
6176
85a1802ae810 updated for version 7.4.424
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
4199 if (buf == curbuf && (save_curwin != NULL || save_curbuf == NULL))
85a1802ae810 updated for version 7.4.424
Bram Moolenaar <bram@vim.org>
parents: 5871
diff changeset
4200 /* 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
4201 * position. */
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4202 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4203 if (save_curbuf == NULL)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4204 /* 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
4205 * 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
4206 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
4207 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4208
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4209 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
4210
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4211 if (VimTryEnd())
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4212 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4213
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4214 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4215 *len_change = -n;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4216
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4217 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4218 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4219 else if (PyList_Check(list))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4220 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4221 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4222 PyInt new_len = PyList_Size(list);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4223 PyInt old_len = hi - lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4224 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
4225 char **array;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4226
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4227 if (new_len == 0) /* avoid allocating zero bytes */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4228 array = NULL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4229 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4230 {
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4231 array = PyMem_New(char *, new_len);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4232 if (array == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4233 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4234 PyErr_NoMemory();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4235 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4236 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4237 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4238
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4239 for (i = 0; i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4240 {
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4241 PyObject *line;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4242
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4243 if (!(line = PyList_GetItem(list, i)) ||
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4244 !(array[i] = StringToLine(line)))
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4245 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4246 while (i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4247 vim_free(array[--i]);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4248 PyMem_Free(array);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4249 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4250 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4251 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4252
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4253 VimTryStart();
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4254 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
4255
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4256 /* 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
4257 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
4258
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4259 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
4260 RAISE_UNDO_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4261
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4262 /* 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
4263 * 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
4264 * repeatedly deleting line "lo".
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4265 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4266 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4267 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4268 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
4269 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4270 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4271 RAISE_DELETE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4272 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4273 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4274 extra -= i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4275 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4276
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4277 /* 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
4278 * 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
4279 * less memory allocation and freeing.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4280 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4281 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4282 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4283 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
4284 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
4285 == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4286 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4287 RAISE_REPLACE_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4288 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4289 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4290 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4291 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4292 i = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4293
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4294 /* 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
4295 * 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
4296 * responsibility to vim in this case).
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4297 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4298 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4299 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4300 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4301 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4302 if (ml_append((linenr_T)(lo + i - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4303 (char_u *)array[i], 0, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4304 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4305 RAISE_INSERT_LINE_FAIL;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4306 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4307 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4308 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4309 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4310 ++extra;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4311 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4312 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4313
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4314 /* 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
4315 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4316 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4317 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4318 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4319 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4320
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4321 /* 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
4322 * 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
4323 * to vim.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4324 */
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4325 PyMem_Free(array);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4326
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4327 /* Adjust marks. Invalidate any which lie in the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4328 * 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
4329 * 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
4330 * the buffer, otherwise line numbers will be invalid. */
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4331 if (save_curbuf == NULL)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4332 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
4333 (long)MAXLNUM, (long)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4334 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
4335
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4336 if (buf == curbuf)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4337 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
4338
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4339 /* END of region without "return". */
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4340 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
4341
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4342 if (VimTryEnd())
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4343 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4344
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4345 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4346 *len_change = new_len - old_len;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4347
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4348 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4349 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4350 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4351 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4352 PyErr_BadArgument();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4353 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4354 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4355 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4356
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
4357 /* 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
4358 * 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
4359 * 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
4360 * 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
4361 * 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
4362 * 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
4363 * 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
4364 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4365 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4366 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
4367 {
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4368 buf_T *save_curbuf = NULL;
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4369 win_T *save_curwin = NULL;
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4370 tabpage_T *save_curtab = NULL;
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4371
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4372 /* 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
4373 * 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
4374 */
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
4375 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
4376 {
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4377 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
4378
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4379 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4380 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4381
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4382 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4383 VimTryStart();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4384 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
4385
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4386 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
4387 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
4388 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
4389 RAISE_INSERT_LINE_FAIL;
5202
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4390 else if (save_curbuf == NULL)
8edba3805d78 updated for version 7.4a.027
Bram Moolenaar <bram@vim.org>
parents: 5166
diff changeset
4391 /* 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
4392 * 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
4393 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
4394
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4395 vim_free(str);
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4396 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
4397 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4398
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4399 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4400 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4401
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4402 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4403 *len_change = 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4404
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4405 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4406 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4407 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
4408 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4409 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4410 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
4411 char **array;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4412
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4413 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
4414 if (array == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4415 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4416 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4417 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4418 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4419
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4420 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
4421 {
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4422 PyObject *line;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4423
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4424 if (!(line = PyList_GetItem(lines, i)) ||
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4425 !(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
4426 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4427 while (i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4428 vim_free(array[--i]);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4429 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
4430 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4431 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4432 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4433
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4434 PyErr_Clear();
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4435 VimTryStart();
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4436 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
4437
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4438 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
4439 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
4440 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4441 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4442 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
4443 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4444 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
4445 (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
4446 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4447 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
4448
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4449 /* 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
4450 while (i < size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4451 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
4452
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4453 break;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4454 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4455 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
4456 }
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4457 if (i > 0 && save_curbuf == NULL)
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4458 /* 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
4459 * 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
4460 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
4461 }
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 /* 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
4464 * been freed. */
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4465 PyMem_Free(array);
5235
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4466 restore_win_for_buf(save_curwin, save_curtab, save_curbuf);
6fa64615c8d3 updated for version 7.4a.043
Bram Moolenaar <bram@vim.org>
parents: 5202
diff changeset
4467
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4468 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4469
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4470 if (VimTryEnd())
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4471 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4472
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4473 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4474 *len_change = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4475
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4476 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4477 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4478 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4479 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4480 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4481 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4482 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4483 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4484
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4485 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4486 * 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
4487 * -------------------------------------------
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4488 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4489
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4490 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4491 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4492 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4493 buf_T *buf;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4494 } BufferObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4495
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4496 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4497 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
4498 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4499 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
4500 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4501 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
4502 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4503 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4504
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4505 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4506 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4507
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4508 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4509 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
4510 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4511 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4512 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4513
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4514 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4515 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4516
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4517 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4518 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4519
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4520 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
4521 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4522 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
4523 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4524 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4525
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4526 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
4527 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4528
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4529 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4530 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
4531 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4532 PyInt size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4533
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4534 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4535 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4536
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4537 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4538 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4539
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4540 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
4541
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4542 if (lo < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4543 lo = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4544 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
4545 lo = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4546 if (hi < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4547 hi = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4548 if (hi < lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4549 hi = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4550 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
4551 hi = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4552
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4553 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
4554 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4555
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4556 static PyInt
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4557 RBAsItem(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4558 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4559 PyInt n,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4560 PyObject *valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4561 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4562 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4563 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
4564 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4565 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4566
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4567 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4568 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4569
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4570 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4571 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4572
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4573 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4574 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
4575
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4576 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
4577 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4578 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
4579 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4580 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4581
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4582 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
4583 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4584
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4585 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4586 *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
4587
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4588 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4589 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4590
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4591 static PyInt
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4592 RBAsSlice(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4593 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4594 PyInt lo,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4595 PyInt hi,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4596 PyObject *valObject,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4597 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4598 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4599 PyInt *new_end)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4600 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4601 PyInt size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4602 PyInt len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4603
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4604 /* Self must be a valid buffer */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4605 if (CheckBuffer(self))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4606 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4607
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4608 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4609 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4610
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4611 /* Sort out the slice range */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4612 size = end - start + 1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4613
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4614 if (lo < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4615 lo = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4616 else if (lo > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4617 lo = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4618 if (hi < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4619 hi = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4620 if (hi < lo)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4621 hi = lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4622 else if (hi > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4623 hi = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4624
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4625 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
4626 valObject, &len_change) == FAIL)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4627 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4628
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4629 if (new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4630 *new_end = end + len_change;
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 return 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4633 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
4634
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4635
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4636 static PyObject *
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4637 RBAppend(
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4638 BufferObject *self,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4639 PyObject *args,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4640 PyInt start,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4641 PyInt end,
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4642 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
4643 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4644 PyObject *lines;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4645 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4646 PyInt max;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4647 PyInt n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4648
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4649 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4650 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4651
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4652 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4653 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
4654
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4655 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
4656
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4657 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
4658 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4659
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4660 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
4661 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4662 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
4663 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4664 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4665
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4666 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
4667 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4668
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4669 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4670 *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
4671
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4672 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
4673 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4674 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4675
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4676 /* Range object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4677 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4678
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4679 static PyTypeObject RangeType;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4680 static PySequenceMethods RangeAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4681 static PyMappingMethods RangeAsMapping;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4682
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4683 typedef struct
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4684 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4685 PyObject_HEAD
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4686 BufferObject *buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4687 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4688 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4689 } RangeObject;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4690
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4691 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4692 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
4693 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4694 BufferObject *bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4695 RangeObject *self;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4696 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
4697 if (self == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4698 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4699
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4700 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
4701 if (bufr == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4702 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4703 Py_DECREF(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4704 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4705 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4706 Py_INCREF(bufr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4707
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4708 self->buf = bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4709 self->start = start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4710 self->end = end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4711
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4712 return (PyObject *)(self);
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
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4715 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4716 RangeDestructor(RangeObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4717 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4718 PyObject_GC_UnTrack((void *)(self));
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4719 Py_XDECREF(self->buf);
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4720 PyObject_GC_Del((void *)(self));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4721 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4722
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4723 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4724 RangeTraverse(RangeObject *self, visitproc visit, void *arg)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4725 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4726 Py_VISIT(((PyObject *)(self->buf)));
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4727 return 0;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4728 }
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4729
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4730 static int
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4731 RangeClear(RangeObject *self)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4732 {
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4733 Py_CLEAR(self->buf);
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
4734 return 0;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4735 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4736
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4737 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4738 RangeLength(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4739 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4740 /* 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
4741 if (CheckBuffer(self->buf))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4742 return -1; /* ??? */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4743
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4744 return (self->end - self->start + 1);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4745 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4746
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4747 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4748 RangeItem(RangeObject *self, PyInt n)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4749 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4750 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
4751 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4752
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4753 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4754 RangeSlice(RangeObject *self, PyInt lo, PyInt hi)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4755 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4756 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
4757 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4758
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4759 static char *RangeAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4760 "start", "end",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4761 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4762 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4763
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4764 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4765 RangeDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4766 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4767 return ObjectDir(self, RangeAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4768 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4769
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4770 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4771 RangeAppend(RangeObject *self, PyObject *args)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4772 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4773 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
4774 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4775
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4776 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4777 RangeRepr(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4778 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4779 if (self->buf->buf == INVALID_BUFFER_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4780 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
4781 (self));
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4782 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4783 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4784 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
4785
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4786 if (name == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4787 name = "";
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4788
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
4789 return PyString_FromFormat("<range %s (%d:%d)>",
4653
b943fd24c351 updated for version 7.3.1074
Bram Moolenaar <bram@vim.org>
parents: 4645
diff changeset
4790 name, (int)self->start, (int)self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4791 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4792 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4793
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4794 static struct PyMethodDef RangeMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
4795 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
4796 {"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
4797 {"__dir__", (PyCFunction)RangeDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4798 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4799 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4800
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4801 static PyTypeObject BufferType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4802 static PySequenceMethods BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4803 static PyMappingMethods BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4804
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4805 static PyObject *
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4806 BufferNew(buf_T *buf)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4807 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4808 /* 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
4809 * 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
4810 * 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
4811 * 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
4812 * 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
4813 * 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
4814 * the buffer is stored in "b_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4815 * 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
4816 * 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
4817 * 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
4818 * 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
4819 * 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
4820 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4821 * 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
4822 * 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
4823 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4824
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4825 BufferObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4826
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4827 if (BUF_PYTHON_REF(buf) != NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4828 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4829 self = BUF_PYTHON_REF(buf);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4830 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4831 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4832 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4833 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4834 self = PyObject_NEW(BufferObject, &BufferType);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4835 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4836 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4837 self->buf = buf;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4838 BUF_PYTHON_REF(buf) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4839 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4840
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4841 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4842 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4843
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4844 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4845 BufferDestructor(BufferObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4846 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4847 if (self->buf && self->buf != INVALID_BUFFER_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4848 BUF_PYTHON_REF(self->buf) = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4849
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4850 DESTRUCTOR_FINISH(self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4851 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4852
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4853 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4854 BufferLength(BufferObject *self)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4855 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4856 /* 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
4857 if (CheckBuffer(self))
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4858 return -1; /* ??? */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4859
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4860 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
4861 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4862
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4863 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4864 BufferItem(BufferObject *self, PyInt n)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4865 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4866 return RBItem(self, n, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4867 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4868
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4869 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4870 BufferSlice(BufferObject *self, PyInt lo, PyInt hi)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4871 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4872 return RBSlice(self, lo, hi, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4873 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
4874
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4875 static char *BufferAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4876 "name", "number", "vars", "options", "valid",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4877 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4878 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4879
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4880 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4881 BufferDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4882 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4883 return ObjectDir(self, BufferAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4884 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4885
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4886 static PyObject *
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4887 BufferAttrValid(BufferObject *self, char *name)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4888 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4889 PyObject *ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4890
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4891 if (strcmp(name, "valid") != 0)
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4892 return NULL;
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4893
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4894 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
4895 Py_INCREF(ret);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4896 return ret;
4593
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4897 }
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4898
0cf552b325b5 updated for version 7.3.1044
Bram Moolenaar <bram@vim.org>
parents: 4589
diff changeset
4899 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4900 BufferAttr(BufferObject *self, char *name)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4901 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4902 if (strcmp(name, "name") == 0)
4597
00eecb2f8e3e updated for version 7.3.1046
Bram Moolenaar <bram@vim.org>
parents: 4595
diff changeset
4903 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
4904 ? "" : (char *)self->buf->b_ffname));
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4905 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4906 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
4907 else if (strcmp(name, "vars") == 0)
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
4908 return NEW_DICTIONARY(self->buf->b_vars);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4909 else if (strcmp(name, "options") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4910 return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4911 (PyObject *) self);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4912 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
4913 return ObjectDir(NULL, BufferAttrs);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4914 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4915 return NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4916 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4917
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4918 static int
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4919 BufferSetattr(BufferObject *self, char *name, PyObject *valObject)
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4920 {
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4921 if (CheckBuffer(self))
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4922 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4923
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4924 if (strcmp(name, "name") == 0)
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4925 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4926 char_u *val;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4927 aco_save_T aco;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4928 int ren_ret;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4929 PyObject *todecref;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4930
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4931 if (!(val = StringToChars(valObject, &todecref)))
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4932 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4933
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4934 VimTryStart();
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4935 /* 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
4936 aucmd_prepbuf(&aco, self->buf);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4937 ren_ret = rename_buffer(val);
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4938 aucmd_restbuf(&aco);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4939 Py_XDECREF(todecref);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4940 if (VimTryEnd())
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4941 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4942
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
4943 if (ren_ret == FAIL)
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4944 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4945 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
4946 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4947 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4948 return 0;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4949 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4950 else
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4951 {
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4952 PyErr_SetString(PyExc_AttributeError, name);
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4953 return -1;
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4954 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4955 }
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
4956
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
4957 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4958 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
4959 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4960 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
4961 }
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 static PyObject *
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4964 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
4965 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4966 pos_T *posp;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4967 char_u *pmark;
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4968 char_u mark;
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
4969 buf_T *savebuf;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4970 PyObject *todecref;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4971
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4972 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
4973 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4974
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4975 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
4976 return NULL;
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4977
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4978 if (pmark[0] == '\0' || pmark[1] != '\0')
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4979 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
4980 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4981 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
4982 Py_XDECREF(todecref);
4633
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4983 return NULL;
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4984 }
3857d399ab41 updated for version 7.3.1064
Bram Moolenaar <bram@vim.org>
parents: 4631
diff changeset
4985
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4986 mark = *pmark;
4964
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4987
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4988 Py_XDECREF(todecref);
5cee875f3096 updated for version 7.3.1227
Bram Moolenaar <bram@vim.org>
parents: 4962
diff changeset
4989
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4990 VimTryStart();
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4991 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
4992 posp = getmark(mark, FALSE);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
4993 restore_buffer(savebuf);
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4994 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
4995 return NULL;
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 if (posp == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
4998 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
4999 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
5000 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5001 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5002
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5003 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
5004 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5005 /* 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
5006 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
5007 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5008 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5009
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5010 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
5011 }
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 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5014 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
5015 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5016 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5017 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5018
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5019 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
5020 return 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 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
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
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5025 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
5026 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5027
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5028 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5029 BufferRepr(BufferObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5030 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
5031 if (self->buf == INVALID_BUFFER_VALUE)
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5032 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
5033 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5034 {
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5035 char *name = (char *)self->buf->b_fname;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5036
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5037 if (name == NULL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5038 name = "";
4623
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5039
548b889fe3cf updated for version 7.3.1059
Bram Moolenaar <bram@vim.org>
parents: 4619
diff changeset
5040 return PyString_FromFormat("<buffer %s>", name);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5041 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5042 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5043
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5044 static struct PyMethodDef BufferMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5045 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
5046 {"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
5047 {"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
5048 {"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
5049 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5050 { 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
5051 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5052
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5053 /*
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5054 * Buffer list object - Implementation
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5055 */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5056
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5057 static PyTypeObject BufMapType;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5058
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5059 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5060 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5061 PyObject_HEAD
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5062 } BufMapObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5063
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5064 static PyInt
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5065 BufMapLength(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5066 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5067 buf_T *b = firstbuf;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5068 PyInt n = 0;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5069
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5070 while (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5071 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5072 ++n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5073 b = b->b_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5074 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5075
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5076 return n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5077 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5078
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5079 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5080 BufMapItem(PyObject *self UNUSED, PyObject *keyObject)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5081 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5082 buf_T *b;
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5083 long bnr;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5084
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5085 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
5086 return NULL;
4972
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5087
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5088 b = buflist_findnr((int) bnr);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5089
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5090 if (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5091 return BufferNew(b);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5092 else
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5093 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
5094 PyErr_SetObject(PyExc_KeyError, keyObject);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5095 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5096 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5097 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5098
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5099 static void
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5100 BufMapIterDestruct(PyObject *buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5101 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5102 /* Iteration was stopped before all buffers were processed */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5103 if (buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5104 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5105 Py_DECREF(buffer);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5106 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5107 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5108
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5109 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5110 BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5111 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5112 if (buffer)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5113 Py_VISIT(buffer);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5114 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5115 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5116
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5117 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5118 BufMapIterClear(PyObject **buffer)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5119 {
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5120 if (*buffer)
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
5121 Py_CLEAR(*buffer);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5122 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5123 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5124
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5125 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5126 BufMapIterNext(PyObject **buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5127 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5128 PyObject *next;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5129 PyObject *ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5130
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5131 if (!*buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5132 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5133
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5134 ret = *buffer;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5135
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5136 if (CheckBuffer((BufferObject *)(ret)))
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5137 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5138 *buffer = NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5139 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5140 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5141
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5142 if (!((BufferObject *)(ret))->buf->b_next)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5143 next = NULL;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5144 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
5145 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5146 *buffer = next;
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
5147 /* 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
5148 * 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
5149 return ret;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5150 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5151
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5152 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5153 BufMapIter(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5154 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5155 PyObject *buffer;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5156
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5157 buffer = BufferNew(firstbuf);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5158 return IterNew(buffer,
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5159 (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
5160 (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5161 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5162
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5163 static PyMappingMethods BufMapAsMapping = {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5164 (lenfunc) BufMapLength,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5165 (binaryfunc) BufMapItem,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5166 (objobjargproc) 0,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5167 };
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
5168
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5169 /* 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
5170 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
5171
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5172 static char *CurrentAttrs[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5173 "buffer", "window", "line", "range", "tabpage",
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5174 NULL
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5175 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5176
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5177 static PyObject *
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5178 CurrentDir(PyObject *self)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5179 {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5180 return ObjectDir(self, CurrentAttrs);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5181 }
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5182
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5183 static PyObject *
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5184 CurrentGetattr(PyObject *self UNUSED, char *name)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5185 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5186 if (strcmp(name, "buffer") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5187 return (PyObject *)BufferNew(curbuf);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5188 else if (strcmp(name, "window") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
5189 return (PyObject *)WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
5190 else if (strcmp(name, "tabpage") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
5191 return (PyObject *)TabPageNew(curtab);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5192 else if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5193 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5194 else if (strcmp(name, "range") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5195 return RangeNew(curbuf, RangeStart, RangeEnd);
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5196 else if (strcmp(name, "__members__") == 0)
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5197 return ObjectDir(NULL, CurrentAttrs);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5198 else
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5199 #if PY_MAJOR_VERSION < 3
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5200 return Py_FindMethod(WindowMethods, self, name);
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5201 #else
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5202 return NULL;
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5203 #endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5204 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5205
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5206 static int
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5207 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
5208 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5209 if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5210 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5211 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
5212 NULL) == FAIL)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5213 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5214
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5215 return 0;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5216 }
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5217 else if (strcmp(name, "buffer") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5218 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5219 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5220
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5221 if (valObject->ob_type != &BufferType)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5222 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5223 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5224 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
5225 Py_TYPE_NAME(valObject));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5226 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5227 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5228
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5229 if (CheckBuffer((BufferObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5230 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5231 count = ((BufferObject *)(valObject))->buf->b_fnum;
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5232
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5233 VimTryStart();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5234 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
5235 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5236 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5237 return -1;
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5238 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
5239 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5240 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5241
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5242 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5243 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5244 else if (strcmp(name, "window") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5245 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5246 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5247
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5248 if (valObject->ob_type != &WindowType)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5249 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5250 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5251 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
5252 Py_TYPE_NAME(valObject));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5253 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5254 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5255
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5256 if (CheckWindow((WindowObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5257 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5258 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
5259
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5260 if (!count)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5261 {
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5262 PyErr_SET_STRING(PyExc_ValueError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5263 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
5264 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5265 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5266
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5267 VimTryStart();
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5268 win_goto(((WindowObject *)(valObject))->win);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5269 if (((WindowObject *)(valObject))->win != curwin)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5270 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5271 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5272 return -1;
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5273 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5274 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
5275 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5276 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5277
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5278 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5279 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5280 else if (strcmp(name, "tabpage") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5281 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5282 if (valObject->ob_type != &TabPageType)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5283 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5284 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5285 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
5286 Py_TYPE_NAME(valObject));
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5287 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5288 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5289
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5290 if (CheckTabPage((TabPageObject *)(valObject)))
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5291 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5292
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5293 VimTryStart();
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5294 goto_tabpage_tp(((TabPageObject *)(valObject))->tab, TRUE, TRUE);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5295 if (((TabPageObject *)(valObject))->tab != curtab)
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5296 {
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5297 if (VimTryEnd())
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5298 return -1;
4968
b6e693e1f946 updated for version 7.3.1229
Bram Moolenaar <bram@vim.org>
parents: 4966
diff changeset
5299 PyErr_SET_STRING(PyExc_RuntimeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5300 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
5301 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5302 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5303
4498
ef02f32d8e53 updated for version 7.3.997
Bram Moolenaar <bram@vim.org>
parents: 4496
diff changeset
5304 return VimTryEnd();
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
5305 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5306 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5307 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5308 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5309 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5310 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5311 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5312
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5313 static struct PyMethodDef CurrentMethods[] = {
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5314 /* name, function, calling, documentation */
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5315 {"__dir__", (PyCFunction)CurrentDir, METH_NOARGS, ""},
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5316 { NULL, NULL, 0, NULL}
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5317 };
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
5318
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5319 static void
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5320 init_range_cmd(exarg_T *eap)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5321 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5322 RangeStart = eap->line1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5323 RangeEnd = eap->line2;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5324 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5325
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5326 static void
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5327 init_range_eval(typval_T *rettv UNUSED)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5328 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5329 RangeStart = (PyInt) curwin->w_cursor.lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5330 RangeEnd = RangeStart;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5331 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5332
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5333 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5334 run_cmd(const char *cmd, void *arg UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5335 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5336 , PyGILState_STATE *pygilstate UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5337 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5338 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5339 {
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5340 PyObject *run_ret;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5341 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
5342 if (run_ret != NULL)
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5343 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5344 Py_DECREF(run_ret);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5345 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5346 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5347 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5348 EMSG2(_(e_py_systemexit), "python");
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5349 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5350 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5351 else
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5352 PyErr_PrintEx(1);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5353 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5354
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5355 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
5356 static int code_hdr_len = 30;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5357
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5358 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5359 run_do(const char *cmd, void *arg UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5360 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5361 , PyGILState_STATE *pygilstate
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5362 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5363 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5364 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5365 PyInt lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5366 size_t len;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5367 char *code;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5368 int status;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5369 PyObject *pyfunc, *pymain;
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5370 PyObject *run_ret;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5371
4575
626e9ccb7c48 updated for version 7.3.1035
Bram Moolenaar <bram@vim.org>
parents: 4523
diff changeset
5372 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
5373 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5374 EMSG(_("cannot save undo information"));
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5375 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5376 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5377
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5378 len = code_hdr_len + STRLEN(cmd);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5379 code = PyMem_New(char, len + 1);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5380 memcpy(code, code_hdr, code_hdr_len);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5381 STRCPY(code + code_hdr_len, cmd);
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5382 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
5383 status = -1;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5384 if (run_ret != NULL)
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5385 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5386 status = 0;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5387 Py_DECREF(run_ret);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5388 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5389 else if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5390 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5391 PyMem_Free(code);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5392 EMSG2(_(e_py_systemexit), "python");
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5393 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5394 return;
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5395 }
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5396 else
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5397 PyErr_PrintEx(1);
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5398
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5399 PyMem_Free(code);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5400
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5401 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5402 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5403 EMSG(_("failed to run the code"));
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5404 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5405 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5406
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5407 status = 0;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5408 pymain = PyImport_AddModule("__main__");
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5409 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5410 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5411 PyGILState_Release(*pygilstate);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5412 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5413
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5414 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5415 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5416 PyObject *line;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5417 PyObject *linenr;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5418 PyObject *ret;
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5419
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5420 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5421 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5422 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5423 if (!(line = GetBufferLine(curbuf, lnum)))
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5424 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5425 if (!(linenr = PyInt_FromLong((long) lnum)))
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5426 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5427 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5428 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5429 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5430 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5431 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5432 Py_DECREF(linenr);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5433 if (!ret)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5434 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5435
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5436 if (ret != Py_None)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5437 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5438 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5439
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5440 Py_XDECREF(ret);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5441 PythonIO_Flush();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5442 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5443 PyGILState_Release(*pygilstate);
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5444 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5445 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5446 goto out;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5447 err:
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5448 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5449 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5450 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5451 PyErr_PrintEx(0);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5452 PythonIO_Flush();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5453 status = 1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5454 out:
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5455 #ifdef PY_CAN_RECURSE
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5456 if (!status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5457 *pygilstate = PyGILState_Ensure();
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5458 #endif
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5459 Py_DECREF(pyfunc);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5460 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5461 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5462 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5463 check_cursor();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5464 update_curbuf(NOT_VALID);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5465 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5466
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5467 static void
4511
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5468 run_eval(const char *cmd, typval_T *rettv
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5469 #ifdef PY_CAN_RECURSE
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5470 , PyGILState_STATE *pygilstate UNUSED
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5471 #endif
ce94a870b59b updated for version 7.3.1003
Bram Moolenaar <bram@vim.org>
parents: 4509
diff changeset
5472 )
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5473 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5474 PyObject *run_ret;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5475
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5476 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
5477 if (run_ret == NULL)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5478 {
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5479 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
5088
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5480 {
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5481 EMSG2(_(e_py_systemexit), "python");
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5482 PyErr_Clear();
34c629c3b4ba updated for version 7.3.1287
Bram Moolenaar <bram@vim.org>
parents: 4995
diff changeset
5483 }
5139
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5484 else
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5485 {
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5486 if (PyErr_Occurred() && !msg_silent)
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5487 PyErr_PrintEx(0);
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5488 EMSG(_("E858: Eval did not return a valid python object"));
80bab8b1a30d updated for version 7.3.1312
Bram Moolenaar <bram@vim.org>
parents: 5088
diff changeset
5489 }
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5490 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5491 else
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5492 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5493 if (ConvertFromPyObject(run_ret, rettv) == -1)
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5494 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
5495 Py_DECREF(run_ret);
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5496 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5497 PyErr_Clear();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5498 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5499
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
5500 static void
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5501 set_ref_in_py(const int copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5502 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5503 pylinkedlist_T *cur;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5504 dict_T *dd;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5505 list_T *ll;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5506
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5507 if (lastdict != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5508 for(cur = lastdict ; cur != NULL ; cur = cur->pll_prev)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5509 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5510 dd = ((DictionaryObject *) (cur->pll_obj))->dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5511 if (dd->dv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5512 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5513 dd->dv_copyID = copyID;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5514 set_ref_in_ht(&dd->dv_hashtab, copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5515 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5516 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5517
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5518 if (lastlist != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5519 for(cur = lastlist ; cur != NULL ; cur = cur->pll_prev)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5520 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5521 ll = ((ListObject *) (cur->pll_obj))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5522 if (ll->lv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5523 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5524 ll->lv_copyID = copyID;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5525 set_ref_in_list(ll, copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5526 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5527 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5528 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5529
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5530 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5531 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
5532 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5533 tv->vval.v_string = vim_strsave(str);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5534 if (tv->vval.v_string == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5535 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5536 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5537 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5538 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5539 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5540 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5541
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5542 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5543 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
5544 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5545 dict_T *dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5546 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5547 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5548 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5549 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5550 Py_ssize_t iter = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5551
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5552 if (!(dict = py_dict_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5553 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5554
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5555 tv->v_type = VAR_DICT;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5556 tv->vval.v_dict = dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5557
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5558 while (PyDict_Next(obj, &iter, &keyObject, &valObject))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5559 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5560 PyObject *todecref = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5561
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5562 if (keyObject == NULL || valObject == NULL)
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5563 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5564 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5565 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5566 }
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5567
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5568 if (!(key = StringToChars(keyObject, &todecref)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5569 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5570 dict_unref(dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5571 return -1;
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5572 }
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
5573
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5574 if (*key == NUL)
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5575 {
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5576 dict_unref(dict);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5577 Py_XDECREF(todecref);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5578 RAISE_NO_EMPTY_KEYS;
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5579 return -1;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5580 }
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5581
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5582 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5583
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5584 Py_XDECREF(todecref);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5585
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5586 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5587 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5588 PyErr_NoMemory();
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5589 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5590 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5591 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5592 di->di_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5593
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5594 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
5595 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5596 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5597 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5598 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5599 }
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5600
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5601 if (dict_add(dict, di) == FAIL)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5602 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5603 RAISE_KEY_ADD_FAIL(di->di_key);
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5604 clear_tv(&di->di_tv);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5605 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5606 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5607 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5608 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5609 }
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5610
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5611 --dict->dv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5612 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5613 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5614
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5615 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5616 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
5617 {
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5618 dict_T *dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5619 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5620 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5621 PyObject *list;
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5622 PyObject *iterator;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5623 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5624 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5625
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5626 if (!(dict = py_dict_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5627 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5628
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5629 tv->v_type = VAR_DICT;
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5630 tv->vval.v_dict = dict;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5631
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5632 if (!(list = PyMapping_Keys(obj)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5633 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5634 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5635 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5636 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5637
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5638 if (!(iterator = PyObject_GetIter(list)))
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5639 {
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5640 dict_unref(dict);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5641 Py_DECREF(list);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5642 return -1;
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5643 }
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5644 Py_DECREF(list);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5645
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5646 while ((keyObject = PyIter_Next(iterator)))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5647 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5648 PyObject *todecref;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5649
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5650 if (!(key = StringToChars(keyObject, &todecref)))
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5651 {
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5652 Py_DECREF(keyObject);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5653 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5654 dict_unref(dict);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5655 return -1;
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5656 }
4702
26f2dbea7443 updated for version 7.3.1098
Bram Moolenaar <bram@vim.org>
parents: 4698
diff changeset
5657
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5658 if (*key == NUL)
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5659 {
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5660 Py_DECREF(keyObject);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5661 Py_DECREF(iterator);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5662 Py_XDECREF(todecref);
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5663 dict_unref(dict);
4659
80b0081824fa updated for version 7.3.1077
Bram Moolenaar <bram@vim.org>
parents: 4653
diff changeset
5664 RAISE_NO_EMPTY_KEYS;
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5665 return -1;
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5666 }
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5667
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5668 if (!(valObject = PyObject_GetItem(obj, keyObject)))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5669 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5670 Py_DECREF(keyObject);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5671 Py_DECREF(iterator);
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5672 Py_XDECREF(todecref);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5673 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5674 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5675 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5676
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5677 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5678
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5679 Py_DECREF(keyObject);
4643
6ec3dada4ad3 updated for version 7.3.1069
Bram Moolenaar <bram@vim.org>
parents: 4641
diff changeset
5680 Py_XDECREF(todecref);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5681
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5682 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5683 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5684 Py_DECREF(iterator);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5685 Py_DECREF(valObject);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5686 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5687 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5688 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5689 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5690 di->di_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5691
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5692 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
5693 {
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5694 Py_DECREF(iterator);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5695 Py_DECREF(valObject);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5696 vim_free(di);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5697 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5698 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5699 }
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5700
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5701 Py_DECREF(valObject);
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5702
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5703 if (dict_add(dict, di) == FAIL)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5704 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5705 RAISE_KEY_ADD_FAIL(di->di_key);
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5706 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5707 dictitem_free(di);
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5708 dict_unref(dict);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5709 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5710 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5711 }
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5712 Py_DECREF(iterator);
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5713 --dict->dv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5714 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5715 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5716
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5717 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5718 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
5719 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5720 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5721
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5722 if (!(l = py_list_alloc()))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5723 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5724
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5725 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5726 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5727
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5728 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
5729 {
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5730 list_unref(l);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5731 return -1;
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5732 }
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5733
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5734 --l->lv_refcount;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5735 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5736 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
5737
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5738 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5739
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5740 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5741 convert_dl(PyObject *obj, typval_T *tv,
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5742 pytotvfunc py_to_tv, PyObject *lookup_dict)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5743 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5744 PyObject *capsule;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5745 char hexBuf[sizeof(void *) * 2 + 3];
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5746
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5747 sprintf(hexBuf, "%p", obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5748
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5749 # ifdef PY_USE_CAPSULE
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5750 capsule = PyDict_GetItemString(lookup_dict, hexBuf);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
5751 # else
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5752 capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
5753 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5754 if (capsule == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5755 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5756 # ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5757 capsule = PyCapsule_New(tv, NULL, NULL);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
5758 # else
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
5759 capsule = PyCObject_FromVoidPtr(tv, NULL);
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
5760 # endif
4607
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5761 if (PyDict_SetItemString(lookup_dict, hexBuf, capsule))
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5762 {
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5763 Py_DECREF(capsule);
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5764 tv->v_type = VAR_UNKNOWN;
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5765 return -1;
70600448f9e7 updated for version 7.3.1051
Bram Moolenaar <bram@vim.org>
parents: 4605
diff changeset
5766 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
5767
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
5768 Py_DECREF(capsule);
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
5769
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5770 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
5771 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5772 tv->v_type = VAR_UNKNOWN;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5773 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5774 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5775 /* 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
5776 * do it ourself. */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5777 switch(tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5778 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5779 case VAR_DICT: ++tv->vval.v_dict->dv_refcount; break;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5780 case VAR_LIST: ++tv->vval.v_list->lv_refcount; break;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5781 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5782 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5783 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5784 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5785 typval_T *v;
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5786
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5787 # ifdef PY_USE_CAPSULE
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5788 v = PyCapsule_GetPointer(capsule, NULL);
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5789 # else
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
5790 v = PyCObject_AsVoidPtr(capsule);
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
5791 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5792 copy_tv(v, tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5793 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5794 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5795 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5796
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5797 static int
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5798 ConvertFromPyMapping(PyObject *obj, typval_T *tv)
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5799 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5800 PyObject *lookup_dict;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5801 int ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5802
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5803 if (!(lookup_dict = PyDict_New()))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5804 return -1;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5805
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5806 if (PyType_IsSubtype(obj->ob_type, &DictionaryType))
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5807 {
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5808 tv->v_type = VAR_DICT;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5809 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5810 ++tv->vval.v_dict->dv_refcount;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5811 ret = 0;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5812 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5813 else if (PyDict_Check(obj))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5814 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
5815 else if (PyMapping_Check(obj))
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5816 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
5817 else
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5818 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5819 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5820 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
5821 Py_TYPE_NAME(obj));
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5822 ret = -1;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5823 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5824 Py_DECREF(lookup_dict);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5825 return ret;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5826 }
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5827
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5828 static int
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5829 ConvertFromPyObject(PyObject *obj, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5830 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5831 PyObject *lookup_dict;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5832 int ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5833
4617
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5834 if (!(lookup_dict = PyDict_New()))
21a99611149b updated for version 7.3.1056
Bram Moolenaar <bram@vim.org>
parents: 4611
diff changeset
5835 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5836 ret = _ConvertFromPyObject(obj, tv, lookup_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5837 Py_DECREF(lookup_dict);
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5838 return ret;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5839 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5840
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5841 static int
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5842 _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
5843 {
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5844 if (PyType_IsSubtype(obj->ob_type, &DictionaryType))
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 tv->v_type = VAR_DICT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5847 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5848 ++tv->vval.v_dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5849 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
5850 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
5851 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5852 tv->v_type = VAR_LIST;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5853 tv->vval.v_list = (((ListObject *)(obj))->list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5854 ++tv->vval.v_list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5855 }
4976
4ed713442c51 updated for version 7.3.1233
Bram Moolenaar <bram@vim.org>
parents: 4974
diff changeset
5856 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
5857 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5858 if (set_string_copy(((FunctionObject *) (obj))->name, tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5859 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5860
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5861 tv->v_type = VAR_FUNC;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5862 func_ref(tv->vval.v_string);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5863 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5864 else if (PyBytes_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5865 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5866 char_u *str;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5867
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5868 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
5869 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5870 if (str == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5871 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5872
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5873 if (set_string_copy(str, tv) == -1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5874 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5875
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5876 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5877 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5878 else if (PyUnicode_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5879 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5880 PyObject *bytes;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5881 char_u *str;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5882
4966
620d9b59d4ed updated for version 7.3.1228
Bram Moolenaar <bram@vim.org>
parents: 4964
diff changeset
5883 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5884 if (bytes == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5885 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5886
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5887 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
5888 return -1;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5889 if (str == NULL)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5890 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5891
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
5892 if (set_string_copy(str, tv))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5893 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5894 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5895 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5896 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5897 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5898
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5899 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5900 }
4321
d8d9c591c50f updated for version 7.3.910
Bram Moolenaar <bram@vim.org>
parents: 4319
diff changeset
5901 #if PY_MAJOR_VERSION < 3
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5902 else if (PyInt_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5903 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5904 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5905 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
5906 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5907 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5908 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5909 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5910 else if (PyLong_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5911 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5912 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5913 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
5914 if (PyErr_Occurred())
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5915 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5916 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5917 else if (PyDict_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5918 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
5919 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5920 else if (PyFloat_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5921 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5922 tv->v_type = VAR_FLOAT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5923 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
5924 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5925 #endif
4635
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5926 else if (PyObject_HasAttrString(obj, "keys"))
07c534fe9b6c updated for version 7.3.1065
Bram Moolenaar <bram@vim.org>
parents: 4633
diff changeset
5927 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
5928 /* 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
5929 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
5930 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
5931 else if (PyMapping_Check(obj))
4601
19d406a8509d updated for version 7.3.1048
Bram Moolenaar <bram@vim.org>
parents: 4599
diff changeset
5932 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
5933 else if (PyNumber_Check(obj))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5934 {
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5935 PyObject *num;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5936
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5937 if (!(num = PyNumber_Long(obj)))
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5938 return -1;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5939
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5940 tv->v_type = VAR_NUMBER;
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5941 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
5942
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5943 Py_DECREF(num);
537bbfff0c5c updated for version 7.3.1231
Bram Moolenaar <bram@vim.org>
parents: 4970
diff changeset
5944 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5945 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5946 {
4970
f5c822e5a0eb updated for version 7.3.1230
Bram Moolenaar <bram@vim.org>
parents: 4968
diff changeset
5947 PyErr_FORMAT(PyExc_TypeError,
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5948 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
5949 Py_TYPE_NAME(obj));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5950 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5951 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5952 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5953 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5954
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5955 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5956 ConvertToPyObject(typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5957 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5958 if (tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5959 {
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5960 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
5961 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5962 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5963 switch (tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5964 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5965 case VAR_STRING:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
5966 return PyBytes_FromString(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
5967 ? "" : (char *)tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5968 case VAR_NUMBER:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5969 return PyLong_FromLong((long) tv->vval.v_number);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5970 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5971 case VAR_FLOAT:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5972 return PyFloat_FromDouble((double) tv->vval.v_float);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5973 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5974 case VAR_LIST:
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
5975 return NEW_LIST(tv->vval.v_list);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5976 case VAR_DICT:
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
5977 return NEW_DICTIONARY(tv->vval.v_dict);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5978 case VAR_FUNC:
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
5979 return NEW_FUNCTION(tv->vval.v_string == NULL
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
5980 ? (char_u *)"" : tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5981 case VAR_UNKNOWN:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5982 Py_INCREF(Py_None);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5983 return Py_None;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5984 default:
4978
f4969f8f66e9 updated for version 7.3.1234
Bram Moolenaar <bram@vim.org>
parents: 4976
diff changeset
5985 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
5986 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5987 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
5988 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5989
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5990 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5991 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5992 PyObject_HEAD
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5993 } CurrentObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5994 static PyTypeObject CurrentType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5995
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5996 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5997 init_structs(void)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5998 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
5999 vim_memset(&OutputType, 0, sizeof(OutputType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6000 OutputType.tp_name = "vim.message";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6001 OutputType.tp_basicsize = sizeof(OutputObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6002 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6003 OutputType.tp_doc = "vim message object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6004 OutputType.tp_methods = OutputMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6005 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6006 OutputType.tp_getattro = (getattrofunc)OutputGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6007 OutputType.tp_setattro = (setattrofunc)OutputSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6008 OutputType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6009 OutputType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6010 OutputType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6011 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6012 OutputType.tp_getattr = (getattrfunc)OutputGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6013 OutputType.tp_setattr = (setattrfunc)OutputSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6014 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6015
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6016 vim_memset(&IterType, 0, sizeof(IterType));
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6017 IterType.tp_name = "vim.iter";
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6018 IterType.tp_basicsize = sizeof(IterObject);
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6019 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
6020 IterType.tp_doc = "generic iterator object";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6021 IterType.tp_iter = (getiterfunc)IterIter;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6022 IterType.tp_iternext = (iternextfunc)IterNext;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6023 IterType.tp_dealloc = (destructor)IterDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6024 IterType.tp_traverse = (traverseproc)IterTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6025 IterType.tp_clear = (inquiry)IterClear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6026
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6027 vim_memset(&BufferType, 0, sizeof(BufferType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6028 BufferType.tp_name = "vim.buffer";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6029 BufferType.tp_basicsize = sizeof(BufferType);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6030 BufferType.tp_dealloc = (destructor)BufferDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6031 BufferType.tp_repr = (reprfunc)BufferRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6032 BufferType.tp_as_sequence = &BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6033 BufferType.tp_as_mapping = &BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6034 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6035 BufferType.tp_doc = "vim buffer object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6036 BufferType.tp_methods = BufferMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6037 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6038 BufferType.tp_getattro = (getattrofunc)BufferGetattro;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
6039 BufferType.tp_setattro = (setattrofunc)BufferSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6040 BufferType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6041 BufferType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6042 BufferType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6043 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6044 BufferType.tp_getattr = (getattrfunc)BufferGetattr;
4589
fa39483a1363 updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents: 4587
diff changeset
6045 BufferType.tp_setattr = (setattrfunc)BufferSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6046 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6047
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6048 vim_memset(&WindowType, 0, sizeof(WindowType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6049 WindowType.tp_name = "vim.window";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6050 WindowType.tp_basicsize = sizeof(WindowObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6051 WindowType.tp_dealloc = (destructor)WindowDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6052 WindowType.tp_repr = (reprfunc)WindowRepr;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6053 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
6054 WindowType.tp_doc = "vim Window object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6055 WindowType.tp_methods = WindowMethods;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6056 WindowType.tp_traverse = (traverseproc)WindowTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6057 WindowType.tp_clear = (inquiry)WindowClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6058 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6059 WindowType.tp_getattro = (getattrofunc)WindowGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6060 WindowType.tp_setattro = (setattrofunc)WindowSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6061 WindowType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6062 WindowType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6063 WindowType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6064 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6065 WindowType.tp_getattr = (getattrfunc)WindowGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6066 WindowType.tp_setattr = (setattrfunc)WindowSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6067 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6068
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6069 vim_memset(&TabPageType, 0, sizeof(TabPageType));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6070 TabPageType.tp_name = "vim.tabpage";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6071 TabPageType.tp_basicsize = sizeof(TabPageObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6072 TabPageType.tp_dealloc = (destructor)TabPageDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6073 TabPageType.tp_repr = (reprfunc)TabPageRepr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6074 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6075 TabPageType.tp_doc = "vim tab page object";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6076 TabPageType.tp_methods = TabPageMethods;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6077 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6078 TabPageType.tp_getattro = (getattrofunc)TabPageGetattro;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6079 TabPageType.tp_alloc = call_PyType_GenericAlloc;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6080 TabPageType.tp_new = call_PyType_GenericNew;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6081 TabPageType.tp_free = call_PyObject_Free;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6082 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6083 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6084 #endif
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6085
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6086 vim_memset(&BufMapType, 0, sizeof(BufMapType));
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6087 BufMapType.tp_name = "vim.bufferlist";
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6088 BufMapType.tp_basicsize = sizeof(BufMapObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6089 BufMapType.tp_as_mapping = &BufMapAsMapping;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
6090 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6091 BufMapType.tp_iter = BufMapIter;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6092 BufferType.tp_doc = "vim buffer list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6093
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6094 vim_memset(&WinListType, 0, sizeof(WinListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6095 WinListType.tp_name = "vim.windowlist";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6096 WinListType.tp_basicsize = sizeof(WinListType);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6097 WinListType.tp_as_sequence = &WinListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6098 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6099 WinListType.tp_doc = "vim window list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6100 WinListType.tp_dealloc = (destructor)WinListDestructor;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6101
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6102 vim_memset(&TabListType, 0, sizeof(TabListType));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6103 TabListType.tp_name = "vim.tabpagelist";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6104 TabListType.tp_basicsize = sizeof(TabListType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6105 TabListType.tp_as_sequence = &TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6106 TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
6107 TabListType.tp_doc = "vim tab page list";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6108
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6109 vim_memset(&RangeType, 0, sizeof(RangeType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6110 RangeType.tp_name = "vim.range";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6111 RangeType.tp_basicsize = sizeof(RangeObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6112 RangeType.tp_dealloc = (destructor)RangeDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6113 RangeType.tp_repr = (reprfunc)RangeRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6114 RangeType.tp_as_sequence = &RangeAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6115 RangeType.tp_as_mapping = &RangeAsMapping;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6116 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
6117 RangeType.tp_doc = "vim Range object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6118 RangeType.tp_methods = RangeMethods;
4500
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
6119 RangeType.tp_traverse = (traverseproc)RangeTraverse;
47e6dec5ce3c updated for version 7.3.998
Bram Moolenaar <bram@vim.org>
parents: 4498
diff changeset
6120 RangeType.tp_clear = (inquiry)RangeClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6121 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6122 RangeType.tp_getattro = (getattrofunc)RangeGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6123 RangeType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6124 RangeType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6125 RangeType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6126 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6127 RangeType.tp_getattr = (getattrfunc)RangeGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6128 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6129
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6130 vim_memset(&CurrentType, 0, sizeof(CurrentType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6131 CurrentType.tp_name = "vim.currentdata";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6132 CurrentType.tp_basicsize = sizeof(CurrentObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6133 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6134 CurrentType.tp_doc = "vim current object";
4599
89bec74fd793 updated for version 7.3.1047
Bram Moolenaar <bram@vim.org>
parents: 4597
diff changeset
6135 CurrentType.tp_methods = CurrentMethods;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6136 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6137 CurrentType.tp_getattro = (getattrofunc)CurrentGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6138 CurrentType.tp_setattro = (setattrofunc)CurrentSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6139 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6140 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6141 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6142 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6143
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6144 vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6145 DictionaryType.tp_name = "vim.dictionary";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6146 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6147 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6148 DictionaryType.tp_as_sequence = &DictionaryAsSeq;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6149 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6150 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
6151 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
6152 DictionaryType.tp_methods = DictionaryMethods;
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6153 DictionaryType.tp_iter = (getiterfunc)DictionaryIter;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6154 DictionaryType.tp_new = (newfunc)DictionaryConstructor;
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6155 DictionaryType.tp_alloc = (allocfunc)PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6156 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6157 DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6158 DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6159 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6160 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6161 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6162 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6163
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6164 vim_memset(&ListType, 0, sizeof(ListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6165 ListType.tp_name = "vim.list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6166 ListType.tp_dealloc = (destructor)ListDestructor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6167 ListType.tp_basicsize = sizeof(ListObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6168 ListType.tp_as_sequence = &ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6169 ListType.tp_as_mapping = &ListAsMapping;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6170 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
6171 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
6172 ListType.tp_methods = ListMethods;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6173 ListType.tp_iter = (getiterfunc)ListIter;
4629
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6174 ListType.tp_new = (newfunc)ListConstructor;
e4e48d4ee040 updated for version 7.3.1062
Bram Moolenaar <bram@vim.org>
parents: 4627
diff changeset
6175 ListType.tp_alloc = (allocfunc)PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6176 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6177 ListType.tp_getattro = (getattrofunc)ListGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6178 ListType.tp_setattro = (setattrofunc)ListSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6179 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6180 ListType.tp_getattr = (getattrfunc)ListGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6181 ListType.tp_setattr = (setattrfunc)ListSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6182 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6183
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6184 vim_memset(&FunctionType, 0, sizeof(FunctionType));
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
6185 FunctionType.tp_name = "vim.function";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6186 FunctionType.tp_basicsize = sizeof(FunctionObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6187 FunctionType.tp_dealloc = (destructor)FunctionDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6188 FunctionType.tp_call = (ternaryfunc)FunctionCall;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6189 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
6190 FunctionType.tp_doc = "object that calls vim function";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6191 FunctionType.tp_methods = FunctionMethods;
4625
cb5c1e37ad4d updated for version 7.3.1060
Bram Moolenaar <bram@vim.org>
parents: 4623
diff changeset
6192 FunctionType.tp_repr = (reprfunc)FunctionRepr;
4631
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6193 FunctionType.tp_new = (newfunc)FunctionConstructor;
4157fef7b950 updated for version 7.3.1063
Bram Moolenaar <bram@vim.org>
parents: 4629
diff changeset
6194 FunctionType.tp_alloc = (allocfunc)PyType_GenericAlloc;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6195 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6196 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6197 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6198 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6199 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6200
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6201 vim_memset(&OptionsType, 0, sizeof(OptionsType));
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6202 OptionsType.tp_name = "vim.options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6203 OptionsType.tp_basicsize = sizeof(OptionsObject);
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
6204 OptionsType.tp_as_sequence = &OptionsAsSeq;
4611
49f0fcd9762c updated for version 7.3.1053
Bram Moolenaar <bram@vim.org>
parents: 4609
diff changeset
6205 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
6206 OptionsType.tp_doc = "object for manipulating options";
5610
2ace11abcfb5 updated for version 7.4.152
Bram Moolenaar <bram@vim.org>
parents: 5608
diff changeset
6207 OptionsType.tp_iter = (getiterfunc)OptionsIter;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6208 OptionsType.tp_as_mapping = &OptionsAsMapping;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6209 OptionsType.tp_dealloc = (destructor)OptionsDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6210 OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
6211 OptionsType.tp_clear = (inquiry)OptionsClear;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
6212
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6213 vim_memset(&LoaderType, 0, sizeof(LoaderType));
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6214 LoaderType.tp_name = "vim.Loader";
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6215 LoaderType.tp_basicsize = sizeof(LoaderObject);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6216 LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6217 LoaderType.tp_doc = "vim message object";
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6218 LoaderType.tp_methods = LoaderMethods;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6219 LoaderType.tp_dealloc = (destructor)LoaderDestructor;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6220
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6221 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6222 vim_memset(&vimmodule, 0, sizeof(vimmodule));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6223 vimmodule.m_name = "vim";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6224 vimmodule.m_doc = "Vim Python interface\n";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6225 vimmodule.m_size = -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6226 vimmodule.m_methods = VimMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6227 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
6228 }
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6229
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6230 #define PYTYPE_READY(type) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6231 if (PyType_Ready(&type)) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6232 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6233
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6234 static int
5166
467efeee8f9e updated for version 7.4a.009
Bram Moolenaar <bram@vim.org>
parents: 5139
diff changeset
6235 init_types(void)
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6236 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6237 PYTYPE_READY(IterType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6238 PYTYPE_READY(BufferType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6239 PYTYPE_READY(RangeType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6240 PYTYPE_READY(WindowType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6241 PYTYPE_READY(TabPageType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6242 PYTYPE_READY(BufMapType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6243 PYTYPE_READY(WinListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6244 PYTYPE_READY(TabListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6245 PYTYPE_READY(CurrentType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6246 PYTYPE_READY(DictionaryType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6247 PYTYPE_READY(ListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6248 PYTYPE_READY(FunctionType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6249 PYTYPE_READY(OptionsType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6250 PYTYPE_READY(OutputType);
4851
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
6251 PYTYPE_READY(LoaderType);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6252 return 0;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6253 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6254
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6255 static int
4922
8dd2769ab75c updated for version 7.3.1206
Bram Moolenaar <bram@vim.org>
parents: 4918
diff changeset
6256 init_sys_path(void)
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6257 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6258 PyObject *path;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6259 PyObject *path_hook;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6260 PyObject *path_hooks;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6261
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6262 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
6263 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6264
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6265 if (!(path_hooks = PySys_GetObject("path_hooks")))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6266 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6267 PyErr_Clear();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6268 path_hooks = PyList_New(1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6269 PyList_SET_ITEM(path_hooks, 0, path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6270 if (PySys_SetObject("path_hooks", path_hooks))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6271 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6272 Py_DECREF(path_hooks);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6273 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6274 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6275 Py_DECREF(path_hooks);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6276 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6277 else if (PyList_Check(path_hooks))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6278 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6279 if (PyList_Append(path_hooks, path_hook))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6280 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6281 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6282 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6283 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6284 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6285 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6286 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6287 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6288 VimTryStart();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6289 EMSG(_("Failed to set path hook: sys.path_hooks is not a list\n"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6290 "You should now do the following:\n"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6291 "- 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
6292 "- 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
6293 VimTryEnd(); /* Discard the error */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6294 Py_DECREF(path_hook);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6295 return 0;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6296 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6297
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6298 if (!(path = PySys_GetObject("path")))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6299 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6300 PyErr_Clear();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6301 path = PyList_New(1);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6302 Py_INCREF(vim_special_path_object);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6303 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
6304 if (PySys_SetObject("path", path))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6305 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6306 Py_DECREF(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6307 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6308 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6309 Py_DECREF(path);
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6310 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6311 else if (PyList_Check(path))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6312 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6313 if (PyList_Append(path, vim_special_path_object))
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6314 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6315 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6316 else
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6317 {
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6318 VimTryStart();
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6319 EMSG(_("Failed to set path: sys.path is not a list\n"
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6320 "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
6321 VimTryEnd(); /* Discard the error */
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6322 }
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6323
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6324 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6325 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6326
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6327 static BufMapObject TheBufferMap =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6328 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6329 PyObject_HEAD_INIT(&BufMapType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6330 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6331
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6332 static WinListObject TheWindowList =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6333 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6334 PyObject_HEAD_INIT(&WinListType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6335 NULL
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6336 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6337
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6338 static CurrentObject TheCurrent =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6339 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6340 PyObject_HEAD_INIT(&CurrentType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6341 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6342
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6343 static TabListObject TheTabPageList =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6344 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6345 PyObject_HEAD_INIT(&TabListType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6346 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6347
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6348 static struct numeric_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6349 char *name;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6350 int val;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6351 } numeric_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6352 {"VAR_LOCKED", VAR_LOCKED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6353 {"VAR_FIXED", VAR_FIXED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6354 {"VAR_SCOPE", VAR_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6355 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6356 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6357
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6358 static struct object_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6359 char *name;
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6360 PyObject *valObject;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6361 } object_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6362 {"buffers", (PyObject *)(void *)&TheBufferMap},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6363 {"windows", (PyObject *)(void *)&TheWindowList},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6364 {"tabpages", (PyObject *)(void *)&TheTabPageList},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6365 {"current", (PyObject *)(void *)&TheCurrent},
4496
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6366
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6367 {"Buffer", (PyObject *)&BufferType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6368 {"Range", (PyObject *)&RangeType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6369 {"Window", (PyObject *)&WindowType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6370 {"TabPage", (PyObject *)&TabPageType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6371 {"Dictionary", (PyObject *)&DictionaryType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6372 {"List", (PyObject *)&ListType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6373 {"Function", (PyObject *)&FunctionType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
6374 {"Options", (PyObject *)&OptionsType},
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6375 {"_Loader", (PyObject *)&LoaderType},
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6376 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6377
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6378 #define ADD_OBJECT(m, name, obj) \
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6379 if (PyModule_AddObject(m, name, obj)) \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6380 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6381
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6382 #define ADD_CHECKED_OBJECT(m, name, obj) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6383 { \
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6384 PyObject *valObject = obj; \
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6385 if (!valObject) \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6386 return -1; \
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6387 ADD_OBJECT(m, name, valObject); \
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6388 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6389
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6390 static int
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6391 populate_module(PyObject *m)
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6392 {
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6393 int i;
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6394 PyObject *other_module;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6395 PyObject *attr;
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6396 PyObject *imp;
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6397
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6398 for (i = 0; i < (int)(sizeof(numeric_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6399 / sizeof(struct numeric_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6400 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6401 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
6402 PyInt_FromLong(numeric_constants[i].val));
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6403
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6404 for (i = 0; i < (int)(sizeof(object_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6405 / sizeof(struct object_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6406 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6407 {
4974
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6408 PyObject *valObject;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6409
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6410 valObject = object_constants[i].valObject;
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6411 Py_INCREF(valObject);
a594ce86b5ea updated for version 7.3.1232
Bram Moolenaar <bram@vim.org>
parents: 4972
diff changeset
6412 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
6413 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6414
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6415 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL)))
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6416 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6417 ADD_OBJECT(m, "error", VimError);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6418
4627
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6419 ADD_CHECKED_OBJECT(m, "vars", NEW_DICTIONARY(&globvardict));
18ba89e06fab updated for version 7.3.1061
Bram Moolenaar <bram@vim.org>
parents: 4625
diff changeset
6420 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
6421 ADD_CHECKED_OBJECT(m, "options",
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6422 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6423
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6424 if (!(other_module = PyImport_ImportModule("os")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6425 return -1;
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6426 ADD_OBJECT(m, "os", other_module);
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6427
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6428 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
6429 return -1;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6430 ADD_OBJECT(m, "_getcwd", py_getcwd)
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6431
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6432 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
6433 return -1;
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6434 ADD_OBJECT(m, "_chdir", py_chdir);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6435 if (!(attr = PyObject_GetAttrString(m, "chdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6436 return -1;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6437 if (PyObject_SetAttrString(other_module, "chdir", attr))
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6438 {
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6439 Py_DECREF(attr);
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6440 return -1;
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6441 }
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6442 Py_DECREF(attr);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6443
4829
ff3935926449 updated for version 7.3.1161
Bram Moolenaar <bram@vim.org>
parents: 4754
diff changeset
6444 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
6445 {
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6446 ADD_OBJECT(m, "_fchdir", py_fchdir);
4982
39980afcf54a updated for version 7.3.1236
Bram Moolenaar <bram@vim.org>
parents: 4978
diff changeset
6447 if (!(attr = PyObject_GetAttrString(m, "fchdir")))
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6448 return -1;
4831
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6449 if (PyObject_SetAttrString(other_module, "fchdir", attr))
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6450 {
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6451 Py_DECREF(attr);
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6452 return -1;
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6453 }
b8eabb6a9687 updated for version 7.3.1162
Bram Moolenaar <bram@vim.org>
parents: 4829
diff changeset
6454 Py_DECREF(attr);
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6455 }
4722
3534e9b4fa42 updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents: 4706
diff changeset
6456 else
3534e9b4fa42 updated for version 7.3.1108
Bram Moolenaar <bram@vim.org>
parents: 4706
diff changeset
6457 PyErr_Clear();
4704
542af01979be updated for version 7.3.1099
Bram Moolenaar <bram@vim.org>
parents: 4702
diff changeset
6458
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6459 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
6460 return -1;
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6461
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6462 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
6463
4855
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6464 if (!(imp = PyImport_ImportModule("imp")))
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6465 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6466
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6467 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
6468 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6469 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6470 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6471 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6472
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6473 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
6474 {
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6475 Py_DECREF(py_find_module);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6476 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6477 return -1;
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6478 }
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6479
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6480 Py_DECREF(imp);
52850ef928f8 updated for version 7.3.1174
Bram Moolenaar <bram@vim.org>
parents: 4851
diff changeset
6481
4851
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
6482 ADD_OBJECT(m, "_find_module", py_find_module);
96e154e825a7 updated for version 7.3.1172
Bram Moolenaar <bram@vim.org>
parents: 4833
diff changeset
6483 ADD_OBJECT(m, "_load_module", py_load_module);
4833
70b1178dec79 updated for version 7.3.1163
Bram Moolenaar <bram@vim.org>
parents: 4831
diff changeset
6484
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6485 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
6486 }