annotate src/if_py_both.h @ 4393:80eea7a9d6b9 v7.3.945

updated for version 7.3.945 Problem: Python: List of buffers is not very useful. Solution: Make vim.buffers a map. No iterator yet. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Wed, 15 May 2013 13:38:47 +0200
parents 736b8e18a3bc
children a84f21892563
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
3734
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
16 #if PY_VERSION_HEX < 0x02050000
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
17 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
18 #endif
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
19
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
20 #ifdef FEAT_MBYTE
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
21 # define ENC_OPT p_enc
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
22 #else
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
23 # define ENC_OPT "latin1"
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
24 #endif
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
25
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
26 #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
27
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
28 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
29 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
30
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
31 static int ConvertFromPyObject(PyObject *, typval_T *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
32 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
33
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
34 static PyInt RangeStart;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
35 static PyInt RangeEnd;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
36
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
37 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 * 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
39 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 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
41 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
42 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 * 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
47 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 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
49 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
50 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
53 /* 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
54 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55
2582
2cdbc91795ca updated for version 7.3.007
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
56 /* 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
57 typedef void (*writefn)(char_u *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
58
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
59 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
60
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 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
62 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 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
64 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
65 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
66 } 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
67
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
68 static int
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
69 OutputSetattr(PyObject *self, char *name, PyObject *val)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
70 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
71 if (val == NULL)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
72 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
73 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
74 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
75 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
76
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
77 if (strcmp(name, "softspace") == 0)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
78 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
79 if (!PyInt_Check(val))
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
80 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
81 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
82 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
83 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
84
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
85 ((OutputObject *)(self))->softspace = PyInt_AsLong(val);
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
86 return 0;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
87 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
88
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
89 PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
90 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
91 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
92
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
93 /* 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
94 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
95 static writefn old_fn = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
96
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
97 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
98 PythonIO_Flush(void)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
99 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
100 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
101 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
102 ((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
103 old_fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
104 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
105 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
106 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
107
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
108 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
109 writer(writefn fn, char_u *str, PyInt n)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
110 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
111 char_u *ptr;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
112
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
113 /* Flush when switching output function. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
114 if (fn != old_fn)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
115 PythonIO_Flush();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
116 old_fn = fn;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
117
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
118 /* 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
119 * writing later. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
120 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
121 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
122 PyInt len = ptr - str;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
123
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
124 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
125 break;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
126
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
127 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
128 ((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
129 fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
130 str = ptr + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
131 n -= len + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
132 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
133 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
134
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
135 /* 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
136 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
137 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
138 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
139 io_ga.ga_len += (int)n;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
140 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
141 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
142
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
143 static PyObject *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 OutputWrite(PyObject *self, PyObject *args)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 {
3806
5e909c379a1e updated for version 7.3.661
Bram Moolenaar <bram@vim.org>
parents: 3800
diff changeset
146 Py_ssize_t len = 0;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
147 char *str = NULL;
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
148 int error = ((OutputObject *)(self))->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
149
3056
2665b456ee59 updated for version 7.3.300
Bram Moolenaar <bram@vim.org>
parents: 2933
diff changeset
150 if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 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
152
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 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
154 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
155 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
156 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
157 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
158 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
159
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 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
161 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
162 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 static PyObject *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 OutputWritelines(PyObject *self, PyObject *args)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 PyInt n;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 PyInt i;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 PyObject *list;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 int error = ((OutputObject *)(self))->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
171
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 if (!PyArg_ParseTuple(args, "O", &list))
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 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
174 Py_INCREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
176 if (!PyList_Check(list))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
177 {
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
178 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 Py_DECREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 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
181 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 n = PyList_Size(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 for (i = 0; i < n; ++i)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 PyObject *line = PyList_GetItem(list, i);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
188 char *str = NULL;
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
189 PyInt 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
190
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
191 if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
192 {
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
193 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 Py_DECREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 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
196 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 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
199 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
200 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
201 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
202 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
203 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
204 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 Py_DECREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 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
208 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
209 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
211 static PyObject *
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
212 OutputFlush(PyObject *self UNUSED, PyObject *args UNUSED)
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
213 {
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
214 /* do nothing */
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
215 Py_INCREF(Py_None);
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
216 return Py_None;
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
217 }
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
218
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
219 /***************/
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
221 static struct PyMethodDef OutputMethods[] = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
222 /* name, function, calling, documentation */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
223 {"write", OutputWrite, 1, ""},
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
224 {"writelines", OutputWritelines, 1, ""},
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
225 {"flush", OutputFlush, 1, ""},
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
226 { NULL, NULL, 0, NULL}
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
227 };
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
228
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 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
230 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 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
232 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
233 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
234 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 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
237 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238 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
239 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
240 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
241 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 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
244 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
245 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246 PySys_SetObject("stdout", (PyObject *)(void *)&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
247 PySys_SetObject("stderr", (PyObject *)(void *)&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
248
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 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
250 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 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
252 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
253 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 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
256 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 static PyObject *VimError;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 /* 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
262 * 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
263 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 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
265 VimErrorCheck(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
266 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 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
268 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 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
270 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
271 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 else if (did_emsg && !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
273 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 PyErr_SetNone(VimError);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 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
276 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 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
279 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
280
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
281 /* Vim module - Implementation
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
282 */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
283
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
284 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
285 VimCommand(PyObject *self UNUSED, PyObject *args)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
286 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
287 char *cmd;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
288 PyObject *result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
289
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
290 if (!PyArg_ParseTuple(args, "s", &cmd))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
291 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
292
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
293 PyErr_Clear();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
294
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
295 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
296 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
297
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
298 do_cmdline_cmd((char_u *)cmd);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
299 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
300
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
301 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
302 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
303
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
304 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
305 result = NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
306 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
307 result = Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
308
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
309 Py_XINCREF(result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
310 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
311 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
312
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
313 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
314 * 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
315 * 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
316 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
317 * 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
318 * you call VimToPython.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
319 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
320 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
321 VimToPython(typval_T *our_tv, int depth, PyObject *lookupDict)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
322 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
323 PyObject *result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
324 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
325 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
326
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
327 /* Avoid infinite recursion */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
328 if (depth > 100)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
329 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
330 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
331 result = Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
332 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
333 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
334
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
335 /* Check if we run into a recursive loop. The item must be in lookupDict
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
336 * 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
337 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
338 || (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
339 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
340 sprintf(ptrBuf, "%p",
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
341 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
342 : (void *)our_tv->vval.v_dict);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
343 result = PyDict_GetItemString(lookupDict, ptrBuf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
344 if (result != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
345 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
346 Py_INCREF(result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
347 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
348 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
349 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
350
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
351 if (our_tv->v_type == VAR_STRING)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
352 {
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
353 result = Py_BuildValue("s", our_tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
354 ? "" : (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
355 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
356 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
357 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
358 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
359
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
360 /* 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
361 sprintf(buf, "%ld", (long)our_tv->vval.v_number);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
362 result = Py_BuildValue("s", buf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
363 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
364 # ifdef FEAT_FLOAT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
365 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
366 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
367 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
368
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
369 sprintf(buf, "%f", our_tv->vval.v_float);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
370 result = Py_BuildValue("s", buf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
371 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
372 # endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
373 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
374 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
375 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
376 listitem_T *curr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
377
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
378 result = PyList_New(0);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
379
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
380 if (list != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
381 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
382 PyDict_SetItemString(lookupDict, ptrBuf, result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
383
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
384 for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
385 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
386 newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
387 PyList_Append(result, newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
388 Py_DECREF(newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
389 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
390 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
391 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
392 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
393 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
394 result = PyDict_New();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
395
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
396 if (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
397 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
398 hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
399 long_u todo = ht->ht_used;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
400 hashitem_T *hi;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
401 dictitem_T *di;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
402
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
403 PyDict_SetItemString(lookupDict, ptrBuf, result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
404
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
405 for (hi = ht->ht_array; todo > 0; ++hi)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
406 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
407 if (!HASHITEM_EMPTY(hi))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
408 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
409 --todo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
410
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
411 di = dict_lookup(hi);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
412 newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
413 PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
414 Py_DECREF(newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
415 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
416 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
417 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
418 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
419 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
420 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
421 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
422 result = Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
423 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
424
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
425 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
426 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
427
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
428 static PyObject *
2520
6768ebd0bc04 Remove unused code.
Bram Moolenaar <bram@vim.org>
parents: 2447
diff changeset
429 VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
430 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
431 char *expr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
432 typval_T *our_tv;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
433 PyObject *result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
434 PyObject *lookup_dict;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
435
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
436 if (!PyArg_ParseTuple(args, "s", &expr))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
437 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
438
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
439 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
440 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
441 our_tv = eval_expr((char_u *)expr, NULL);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
442
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
443 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
444 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
445
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
446 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
447 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
448 PyErr_SetVim(_("invalid expression"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
449 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
450 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
451
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
452 /* 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
453 * used to check for recursive loops. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
454 lookup_dict = PyDict_New();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
455 result = VimToPython(our_tv, 1, lookup_dict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
456 Py_DECREF(lookup_dict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
457
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
458
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
459 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
460 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
461 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
462 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
463 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
464
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
465 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
466 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
467
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
468 static PyObject *ConvertToPyObject(typval_T *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
469
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
470 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
471 VimEvalPy(PyObject *self UNUSED, PyObject *args UNUSED)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
472 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
473 char *expr;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
474 typval_T *our_tv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
475 PyObject *result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
476
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
477 if (!PyArg_ParseTuple(args, "s", &expr))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
478 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
479
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
480 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
481 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
482 our_tv = eval_expr((char_u *)expr, NULL);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
483
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
484 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
485 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
486
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
487 if (our_tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
488 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
489 PyErr_SetVim(_("invalid expression"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
490 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
491 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
492
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
493 result = ConvertToPyObject(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
494 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
495 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
496 free_tv(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
497 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
498 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
499
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
500 return result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
501 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
502
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
503 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
504 VimStrwidth(PyObject *self UNUSED, PyObject *args)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
505 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
506 char *expr;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
507
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
508 if (!PyArg_ParseTuple(args, "s", &expr))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
509 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
510
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
511 return PyLong_FromLong(
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
512 #ifdef FEAT_MBYTE
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
513 mb_string2cells((char_u *)expr, (int)STRLEN(expr))
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
514 #else
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
515 STRLEN(expr)
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
516 #endif
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
517 );
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
518 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
519
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
520 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
521 * Vim module - Definitions
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
522 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
523
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
524 static struct PyMethodDef VimMethods[] = {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
525 /* name, function, calling, documentation */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
526 {"command", VimCommand, 1, "Execute a Vim ex-mode command" },
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
527 {"eval", VimEval, 1, "Evaluate an expression using Vim evaluator" },
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
528 {"bindeval", VimEvalPy, 1, "Like eval(), but returns objects attached to vim ones"},
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
529 {"strwidth", VimStrwidth, 1, "Screen string width, counts <Tab> as having width 1"},
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
530 { NULL, NULL, 0, NULL }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
531 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
532
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
533 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
534 * Buffer list object - Implementation
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
535 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
536
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
537 static PyTypeObject BufMapType;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
538
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
539 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
540 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
541 PyObject_HEAD
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
542 } BufMapObject;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
543
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
544 static PyInt
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
545 BufMapLength(PyObject *self UNUSED)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
546 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
547 buf_T *b = firstbuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
548 PyInt n = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
549
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
550 while (b)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
551 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
552 ++n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
553 b = b->b_next;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
554 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
555
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
556 return n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
557 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
558
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
559 static PyObject *
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
560 BufMapItem(PyObject *self UNUSED, PyObject *keyObject)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
561 {
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
562 buf_T *b;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
563 int bnr;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
564
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
565 #if PY_MAJOR_VERSION < 3
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
566 if (PyInt_Check(keyObject))
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
567 bnr = PyInt_AsLong(keyObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
568 else
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
569 #endif
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
570 if (PyLong_Check(keyObject))
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
571 bnr = PyLong_AsLong(keyObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
572 else
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
573 {
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
574 PyErr_SetString(PyExc_ValueError, _("key must be integer"));
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
575 return NULL;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
576 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
577
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
578 b = buflist_findnr(bnr);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
579
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
580 if (b)
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
581 return BufferNew(b);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
582 else
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
583 {
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
584 PyErr_SetString(PyExc_KeyError, _("no such buffer"));
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
585 return NULL;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
586 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
587 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
588
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
589 static PyMappingMethods BufMapAsMapping = {
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
590 (lenfunc) BufMapLength,
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
591 (binaryfunc) BufMapItem,
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
592 (objobjargproc) 0,
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
593 };
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
594
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
595 typedef struct pylinkedlist_S {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
596 struct pylinkedlist_S *pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
597 struct pylinkedlist_S *pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
598 PyObject *pll_obj;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
599 } pylinkedlist_T;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
600
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
601 static pylinkedlist_T *lastdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
602 static pylinkedlist_T *lastlist = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
603
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
604 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
605 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
606 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
607 if (ref->pll_prev == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
608 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
609 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
610 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
611 *last = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
612 return;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
613 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
614 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
615 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
616 ref->pll_prev->pll_next = ref->pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
617
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
618 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
619 *last = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
620 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
621 ref->pll_next->pll_prev = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
622 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
623
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
624 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
625 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
626 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
627 if (*last == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
628 ref->pll_prev = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
629 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
630 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
631 (*last)->pll_next = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
632 ref->pll_prev = *last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
633 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
634 ref->pll_next = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
635 ref->pll_obj = self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
636 *last = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
637 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
638
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
639 static PyTypeObject DictionaryType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
640
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
641 #define DICTKEY_GET_NOTEMPTY(err) \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
642 DICTKEY_GET(err) \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
643 if (*key == NUL) \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
644 { \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
645 PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
646 return err; \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
647 }
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
648
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
649 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
650 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
651 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
652 dict_T *dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
653 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
654 } DictionaryObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
655
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
656 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
657 DictionaryNew(dict_T *dict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
658 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
659 DictionaryObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
660
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
661 self = PyObject_NEW(DictionaryObject, &DictionaryType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
662 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
663 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
664 self->dict = dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
665 ++dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
666
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
667 pyll_add((PyObject *)(self), &self->ref, &lastdict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
668
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
669 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
670 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
671
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
672 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
673 DictionaryDestructor(PyObject *self)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
674 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
675 DictionaryObject *this = ((DictionaryObject *) (self));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
676
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
677 pyll_remove(&this->ref, &lastdict);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
678 dict_unref(this->dict);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
679
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
680 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
681 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
682
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
683 static int
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
684 DictionarySetattr(PyObject *self, char *name, PyObject *val)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
685 {
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
686 DictionaryObject *this = (DictionaryObject *)(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
687
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
688 if (val == NULL)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
689 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
690 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
691 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
692 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
693
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
694 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
695 {
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
696 if (this->dict->dv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
697 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
698 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
699 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
700 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
701 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
702 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
703 if (!PyBool_Check(val))
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
704 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
705 PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
706 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
707 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
708
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
709 if (val == Py_True)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
710 this->dict->dv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
711 else
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
712 this->dict->dv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
713 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
714 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
715 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
716 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
717 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
718 PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
719 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
720 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
721 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
722
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
723 static PyInt
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
724 DictionaryLength(PyObject *self)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
725 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
726 return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used)));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
727 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
728
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
729 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
730 DictionaryItem(PyObject *self, PyObject *keyObject)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
731 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
732 char_u *key;
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
733 dictitem_T *di;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
734 DICTKEY_DECL
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
735
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
736 DICTKEY_GET_NOTEMPTY(NULL)
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
737
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
738 di = dict_find(((DictionaryObject *) (self))->dict, key, -1);
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
739
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
740 DICTKEY_UNREF
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
741
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
742 if (di == NULL)
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
743 {
4315
9f3da1dea7c0 updated for version 7.3.907
Bram Moolenaar <bram@vim.org>
parents: 4260
diff changeset
744 PyErr_SetString(PyExc_KeyError, _("no such key in dictionary"));
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
745 return NULL;
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
746 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
747
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
748 return ConvertToPyObject(&di->di_tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
749 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
750
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
751 static PyInt
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
752 DictionaryAssItem(PyObject *self, PyObject *keyObject, PyObject *valObject)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
753 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
754 char_u *key;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
755 typval_T tv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
756 dict_T *d = ((DictionaryObject *)(self))->dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
757 dictitem_T *di;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
758 DICTKEY_DECL
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
759
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
760 if (d->dv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
761 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
762 PyErr_SetVim(_("dict is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
763 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
764 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
765
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
766 DICTKEY_GET_NOTEMPTY(-1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
767
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
768 di = dict_find(d, key, -1);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
769
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
770 if (valObject == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
771 {
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
772 hashitem_T *hi;
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
773
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
774 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
775 {
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
776 DICTKEY_UNREF
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
777 PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
778 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
779 }
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
780 hi = hash_find(&d->dv_hashtab, di->di_key);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
781 hash_remove(&d->dv_hashtab, hi);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
782 dictitem_free(di);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
783 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
784 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
785
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
786 if (ConvertFromPyObject(valObject, &tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
787 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
788
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
789 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
790 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
791 di = dictitem_alloc(key);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
792 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
793 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
794 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
795 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
796 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
797 di->di_tv.v_lock = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
798
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
799 if (dict_add(d, di) == FAIL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
800 {
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
801 DICTKEY_UNREF
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
802 vim_free(di);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
803 PyErr_SetVim(_("failed to add key to dictionary"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
804 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
805 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
806 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
807 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
808 clear_tv(&di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
809
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
810 DICTKEY_UNREF
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
811
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
812 copy_tv(&tv, &di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
813 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
814 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
815
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
816 static PyObject *
4133
36fd800b8c6c updated for version 7.3.819
Bram Moolenaar <bram@vim.org>
parents: 3988
diff changeset
817 DictionaryListKeys(PyObject *self UNUSED)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
818 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
819 dict_T *dict = ((DictionaryObject *)(self))->dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
820 long_u todo = dict->dv_hashtab.ht_used;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
821 Py_ssize_t i = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
822 PyObject *r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
823 hashitem_T *hi;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
824
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
825 r = PyList_New(todo);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
826 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
827 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
828 if (!HASHITEM_EMPTY(hi))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
829 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
830 PyList_SetItem(r, i, PyBytes_FromString((char *)(hi->hi_key)));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
831 --todo;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
832 ++i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
833 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
834 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
835 return r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
836 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
837
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
838 static PyMappingMethods DictionaryAsMapping = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
839 (lenfunc) DictionaryLength,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
840 (binaryfunc) DictionaryItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
841 (objobjargproc) DictionaryAssItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
842 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
843
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
844 static struct PyMethodDef DictionaryMethods[] = {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
845 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
846 { NULL, NULL, 0, NULL }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
847 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
848
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
849 static PyTypeObject ListType;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
850 static PySequenceMethods ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
851 static PyMappingMethods ListAsMapping;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
852
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
853 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
854 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
855 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
856 list_T *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
857 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
858 } ListObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
859
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
860 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
861 ListNew(list_T *list)
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 ListObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
864
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
865 self = PyObject_NEW(ListObject, &ListType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
866 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
867 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
868 self->list = list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
869 ++list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
870
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
871 pyll_add((PyObject *)(self), &self->ref, &lastlist);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
872
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
873 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
874 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
875
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
876 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
877 ListDestructor(PyObject *self)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
878 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
879 ListObject *this = (ListObject *)(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
880
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
881 pyll_remove(&this->ref, &lastlist);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
882 list_unref(this->list);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
883
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
884 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
885 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
886
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
887 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
888 list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict)
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 Py_ssize_t i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
891 Py_ssize_t lsize = PySequence_Size(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
892 PyObject *litem;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
893 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
894
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
895 for(i=0; i<lsize; i++)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
896 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
897 li = listitem_alloc();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
898 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
899 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
900 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
901 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
902 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
903 li->li_tv.v_lock = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
904
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
905 litem = PySequence_GetItem(obj, i);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
906 if (litem == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
907 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
908 if (_ConvertFromPyObject(litem, &li->li_tv, lookupDict) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
909 return -1;
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 list_append(l, li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
912 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
913 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
914 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
915
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
916 static PyInt
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
917 ListLength(PyObject *self)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
918 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
919 return ((PyInt) (((ListObject *) (self))->list->lv_len));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
920 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
921
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
922 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
923 ListItem(PyObject *self, Py_ssize_t index)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
924 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
925 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
926
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
927 if (index>=ListLength(self))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
928 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
929 PyErr_SetString(PyExc_IndexError, "list index out of range");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
930 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
931 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
932 li = list_find(((ListObject *) (self))->list, (long) index);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
933 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
934 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
935 PyErr_SetVim(_("internal error: failed to get vim list item"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
936 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
937 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
938 return ConvertToPyObject(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
939 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
940
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
941 #define PROC_RANGE \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
942 if (last < 0) {\
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
943 if (last < -size) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
944 last = 0; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
945 else \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
946 last += size; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
947 } \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
948 if (first < 0) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
949 first = 0; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
950 if (first > size) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
951 first = size; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
952 if (last > size) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
953 last = size;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
954
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
955 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
956 ListSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
957 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
958 PyInt i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
959 PyInt size = ListLength(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
960 PyInt n;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
961 PyObject *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
962 int reversed = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
963
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
964 PROC_RANGE
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
965 if (first >= last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
966 first = last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
967
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
968 n = last-first;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
969 list = PyList_New(n);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
970 if (list == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
971 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
972
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
973 for (i = 0; i < n; ++i)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
974 {
4260
d8acfc49d94e updated for version 7.3.881
Bram Moolenaar <bram@vim.org>
parents: 4133
diff changeset
975 PyObject *item = ListItem(self, first + i);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
976 if (item == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
977 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
978 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
979 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
980 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
981
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
982 if ((PyList_SetItem(list, ((reversed)?(n-i-1):(i)), item)))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
983 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
984 Py_DECREF(item);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
985 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
986 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
987 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
988 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
989
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
990 return list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
991 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
992
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
993 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
994 ListAssItem(PyObject *self, Py_ssize_t index, PyObject *obj)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
995 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
996 typval_T tv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
997 list_T *l = ((ListObject *) (self))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
998 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
999 Py_ssize_t length = ListLength(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1000
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1001 if (l->lv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1002 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1003 PyErr_SetVim(_("list is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1004 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1005 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1006 if (index>length || (index==length && obj==NULL))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1007 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1008 PyErr_SetString(PyExc_IndexError, "list index out of range");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1009 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1010 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1011
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1012 if (obj == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1013 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1014 li = list_find(l, (long) index);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1015 list_remove(l, li, li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1016 clear_tv(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1017 vim_free(li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1018 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1019 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1020
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1021 if (ConvertFromPyObject(obj, &tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1022 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1023
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1024 if (index == length)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1025 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1026 if (list_append_tv(l, &tv) == FAIL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1027 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1028 PyErr_SetVim(_("Failed to add item to list"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1029 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1030 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1031 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1032 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1033 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1034 li = list_find(l, (long) index);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1035 clear_tv(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1036 copy_tv(&tv, &li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1037 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1038 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1039 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1040
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1041 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1042 ListAssSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1043 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1044 PyInt size = ListLength(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1045 Py_ssize_t i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1046 Py_ssize_t lsize;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1047 PyObject *litem;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1048 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1049 listitem_T *next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1050 typval_T v;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1051 list_T *l = ((ListObject *) (self))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1052
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1053 if (l->lv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1054 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1055 PyErr_SetVim(_("list is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1056 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1057 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1058
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1059 PROC_RANGE
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1060
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1061 if (first == size)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1062 li = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1063 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1064 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1065 li = list_find(l, (long) first);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1066 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1067 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1068 PyErr_SetVim(_("internal error: no vim list item"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1069 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1070 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1071 if (last > first)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1072 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1073 i = last - first;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1074 while (i-- && li != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1075 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1076 next = li->li_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1077 listitem_remove(l, li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1078 li = next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1079 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1080 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1081 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1082
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1083 if (obj == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1084 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1085
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1086 if (!PyList_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1087 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1088 PyErr_SetString(PyExc_TypeError, _("can only assign lists to slice"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1089 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1090 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1091
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1092 lsize = PyList_Size(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1093
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1094 for(i=0; i<lsize; i++)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1095 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1096 litem = PyList_GetItem(obj, i);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1097 if (litem == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1098 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1099 if (ConvertFromPyObject(litem, &v) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1100 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1101 if (list_insert_tv(l, &v, li) == FAIL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1102 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1103 PyErr_SetVim(_("internal error: failed to add item to list"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1104 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1105 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1106 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1107 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1108 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1109
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1110 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1111 ListConcatInPlace(PyObject *self, PyObject *obj)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1112 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1113 list_T *l = ((ListObject *) (self))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1114 PyObject *lookup_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1115
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1116 if (l->lv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1117 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1118 PyErr_SetVim(_("list is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1119 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1120 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1121
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1122 if (!PySequence_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1123 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1124 PyErr_SetString(PyExc_TypeError, _("can only concatenate with lists"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1125 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1126 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1127
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1128 lookup_dict = PyDict_New();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1129 if (list_py_concat(l, obj, lookup_dict) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1130 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1131 Py_DECREF(lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1132 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1133 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1134 Py_DECREF(lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1135
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1136 Py_INCREF(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1137 return self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1138 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1139
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1140 static int
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1141 ListSetattr(PyObject *self, char *name, PyObject *val)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1142 {
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1143 ListObject *this = (ListObject *)(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1144
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1145 if (val == NULL)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1146 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1147 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1148 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1149 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1150
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1151 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1152 {
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1153 if (this->list->lv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1154 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1155 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed list"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1156 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1157 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1158 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1159 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1160 if (!PyBool_Check(val))
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1161 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1162 PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1163 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1164 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1165
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1166 if (val == Py_True)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1167 this->list->lv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1168 else
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1169 this->list->lv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1170 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1171 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1172 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1173 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1174 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1175 PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1176 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1177 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1178 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1179
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1180 static struct PyMethodDef ListMethods[] = {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1181 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1182 { NULL, NULL, 0, NULL }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1183 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1184
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1185 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1186 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1187 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1188 char_u *name;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1189 } FunctionObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1190
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1191 static PyTypeObject FunctionType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1192
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1193 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1194 FunctionNew(char_u *name)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1195 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1196 FunctionObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1197
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1198 self = PyObject_NEW(FunctionObject, &FunctionType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1199 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1200 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1201 self->name = PyMem_New(char_u, STRLEN(name) + 1);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1202 if (self->name == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1203 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1204 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1205 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1206 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1207 STRCPY(self->name, name);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1208 func_ref(name);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1209 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1210 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1211
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1212 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1213 FunctionDestructor(PyObject *self)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1214 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1215 FunctionObject *this = (FunctionObject *) (self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1216
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1217 func_unref(this->name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1218 PyMem_Del(this->name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1219
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1220 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1221 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1222
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1223 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1224 FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1225 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1226 FunctionObject *this = (FunctionObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1227 char_u *name = this->name;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1228 typval_T args;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1229 typval_T selfdicttv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1230 typval_T rettv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1231 dict_T *selfdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1232 PyObject *selfdictObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1233 PyObject *result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1234 int error;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1235
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1236 if (ConvertFromPyObject(argsObject, &args) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1237 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1238
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1239 if (kwargs != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1240 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1241 selfdictObject = PyDict_GetItemString(kwargs, "self");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1242 if (selfdictObject != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1243 {
3703
e13f2f3568e1 updated for version 7.3.611
Bram Moolenaar <bram@vim.org>
parents: 3648
diff changeset
1244 if (!PyMapping_Check(selfdictObject))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1245 {
3703
e13f2f3568e1 updated for version 7.3.611
Bram Moolenaar <bram@vim.org>
parents: 3648
diff changeset
1246 PyErr_SetString(PyExc_TypeError,
e13f2f3568e1 updated for version 7.3.611
Bram Moolenaar <bram@vim.org>
parents: 3648
diff changeset
1247 _("'self' argument must be a dictionary"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1248 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1249 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1250 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1251 if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1252 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1253 selfdict = selfdicttv.vval.v_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1254 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1255 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1256
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1257 error = func_call(name, &args, selfdict, &rettv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1258 if (error != OK)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1259 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1260 result = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1261 PyErr_SetVim(_("failed to run function"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1262 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1263 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1264 result = ConvertToPyObject(&rettv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1265
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1266 /* FIXME Check what should really be cleared. */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1267 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1268 clear_tv(&rettv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1269 /*
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1270 * if (selfdict!=NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1271 * clear_tv(selfdicttv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1272 */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1273
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1274 return result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1275 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1276
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1277 static struct PyMethodDef FunctionMethods[] = {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1278 {"__call__", (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1279 { NULL, NULL, 0, NULL }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1280 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1281
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1282 /*
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1283 * Options object
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1284 */
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1285
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1286 static PyTypeObject OptionsType;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1287
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1288 typedef int (*checkfun)(void *);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1289
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1290 typedef struct
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1291 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1292 PyObject_HEAD
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1293 int opt_type;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1294 void *from;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1295 checkfun Check;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1296 PyObject *fromObj;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1297 } OptionsObject;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1298
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1299 static PyObject *
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1300 OptionsItem(OptionsObject *this, PyObject *keyObject)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1301 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1302 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1303 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1304 long numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1305 char_u *stringval;
4359
6d45e6f97415 updated for version 7.3.928
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
1306 DICTKEY_DECL
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1307
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1308 if (this->Check(this->from))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1309 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1310
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1311 DICTKEY_GET_NOTEMPTY(NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1312
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1313 flags = get_option_value_strict(key, &numval, &stringval,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1314 this->opt_type, this->from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1315
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1316 DICTKEY_UNREF
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1317
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1318 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1319 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1320 PyErr_SetString(PyExc_KeyError, "Option does not exist in given scope");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1321 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1322 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1323
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1324 if (flags & SOPT_UNSET)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1325 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1326 Py_INCREF(Py_None);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1327 return Py_None;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1328 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1329 else if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1330 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1331 PyObject *r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1332 r = numval ? Py_True : Py_False;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1333 Py_INCREF(r);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1334 return r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1335 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1336 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1337 return PyInt_FromLong(numval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1338 else if (flags & SOPT_STRING)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1339 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1340 if (stringval)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1341 return PyBytes_FromString((char *) stringval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1342 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1343 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1344 PyErr_SetString(PyExc_ValueError, "Unable to get option value");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1345 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1346 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1347 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1348 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1349 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1350 PyErr_SetVim("Internal error: unknown option type. Should not happen");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1351 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1352 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1353 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1354
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1355 static int
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1356 set_option_value_for(key, numval, stringval, opt_flags, opt_type, from)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1357 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1358 int numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1359 char_u *stringval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1360 int opt_flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1361 int opt_type;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1362 void *from;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1363 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1364 win_T *save_curwin;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1365 tabpage_T *save_curtab;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1366 aco_save_T aco;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1367 int r = 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1368
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1369 switch (opt_type)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1370 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1371 case SREQ_WIN:
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1372 if (switch_win(&save_curwin, &save_curtab, (win_T *) from, curtab)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1373 == FAIL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1374 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1375 PyErr_SetVim("Problem while switching windows.");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1376 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1377 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1378 set_option_value(key, numval, stringval, opt_flags);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1379 restore_win(save_curwin, save_curtab);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1380 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1381 case SREQ_BUF:
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1382 aucmd_prepbuf(&aco, (buf_T *) from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1383 set_option_value(key, numval, stringval, opt_flags);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1384 aucmd_restbuf(&aco);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1385 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1386 case SREQ_GLOBAL:
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1387 set_option_value(key, numval, stringval, opt_flags);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1388 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1389 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1390 return r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1391 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1392
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1393 static int
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1394 OptionsAssItem(OptionsObject *this, PyObject *keyObject, PyObject *valObject)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1395 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1396 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1397 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1398 int opt_flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1399 int r = 0;
4359
6d45e6f97415 updated for version 7.3.928
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
1400 DICTKEY_DECL
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1401
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1402 if (this->Check(this->from))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1403 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1404
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1405 DICTKEY_GET_NOTEMPTY(-1)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1406
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1407 flags = get_option_value_strict(key, NULL, NULL,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1408 this->opt_type, this->from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1409
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1410 DICTKEY_UNREF
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1411
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1412 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1413 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1414 PyErr_SetString(PyExc_KeyError, "Option does not exist in given scope");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1415 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1416 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1417
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1418 if (valObject == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1419 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1420 if (this->opt_type == SREQ_GLOBAL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1421 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1422 PyErr_SetString(PyExc_ValueError, "Unable to unset global option");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1423 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1424 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1425 else if (!(flags & SOPT_GLOBAL))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1426 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1427 PyErr_SetString(PyExc_ValueError, "Unable to unset option without "
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1428 "global value");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1429 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1430 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1431 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1432 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1433 unset_global_local_option(key, this->from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1434 return 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1435 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1436 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1437
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1438 opt_flags = (this->opt_type ? OPT_LOCAL : OPT_GLOBAL);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1439
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1440 if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1441 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1442 if (!PyBool_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1443 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1444 PyErr_SetString(PyExc_ValueError, "Object must be boolean");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1445 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1446 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1447
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1448 r = set_option_value_for(key, (valObject == Py_True), NULL, opt_flags,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1449 this->opt_type, this->from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1450 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1451 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1452 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1453 int val;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1454
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1455 #if PY_MAJOR_VERSION < 3
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1456 if (PyInt_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1457 val = PyInt_AsLong(valObject);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1458 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1459 #endif
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1460 if (PyLong_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1461 val = PyLong_AsLong(valObject);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1462 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1463 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1464 PyErr_SetString(PyExc_ValueError, "Object must be integer");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1465 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1466 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1467
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1468 r = set_option_value_for(key, val, NULL, opt_flags,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1469 this->opt_type, this->from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1470 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1471 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1472 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1473 char_u *val;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1474 if (PyBytes_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1475 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1476
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1477 if (PyString_AsStringAndSize(valObject, (char **) &val, NULL) == -1)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1478 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1479 if (val == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1480 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1481
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1482 val = vim_strsave(val);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1483 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1484 else if (PyUnicode_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1485 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1486 PyObject *bytes;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1487
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1488 bytes = PyUnicode_AsEncodedString(valObject, (char *)ENC_OPT, NULL);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1489 if (bytes == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1490 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1491
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1492 if(PyString_AsStringAndSize(bytes, (char **) &val, NULL) == -1)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1493 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1494 if (val == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1495 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1496
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1497 val = vim_strsave(val);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1498 Py_XDECREF(bytes);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1499 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1500 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1501 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1502 PyErr_SetString(PyExc_ValueError, "Object must be string");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1503 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1504 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1505
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1506 r = set_option_value_for(key, 0, val, opt_flags,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1507 this->opt_type, this->from);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1508 vim_free(val);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1509 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1510
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1511 return r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1512 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1513
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1514 static int
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1515 dummy_check(void *arg UNUSED)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1516 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1517 return 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1518 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1519
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1520 static PyObject *
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1521 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1522 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1523 OptionsObject *self;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1524
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1525 self = PyObject_NEW(OptionsObject, &OptionsType);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1526 if (self == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1527 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1528
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1529 self->opt_type = opt_type;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1530 self->from = from;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1531 self->Check = Check;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1532 self->fromObj = fromObj;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1533 if (fromObj)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1534 Py_INCREF(fromObj);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1535
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1536 return (PyObject *)(self);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1537 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1538
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1539 static void
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1540 OptionsDestructor(PyObject *self)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1541 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1542 if (((OptionsObject *)(self))->fromObj)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1543 Py_DECREF(((OptionsObject *)(self))->fromObj);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1544 DESTRUCTOR_FINISH(self);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1545 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1546
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1547 static PyMappingMethods OptionsAsMapping = {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1548 (lenfunc) NULL,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1549 (binaryfunc) OptionsItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1550 (objobjargproc) OptionsAssItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1551 };
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1552
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1553 /* Window object
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1554 */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1555
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1556 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1557 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1558 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1559 win_T *win;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1560 } WindowObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1561
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1562 static int WindowSetattr(PyObject *, char *, PyObject *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1563 static PyObject *WindowRepr(PyObject *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1564 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
1565
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1566 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1567 CheckWindow(WindowObject *this)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1568 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1569 if (this->win == INVALID_WINDOW_VALUE)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1570 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1571 PyErr_SetVim(_("attempt to refer to deleted window"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1572 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1573 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1574
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1575 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1576 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1577
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1578 static PyObject *
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1579 WindowNew(win_T *win)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1580 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1581 /* 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
1582 * 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
1583 * 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
1584 * 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
1585 * 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
1586 * 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
1587 * the window is stored in "w_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1588 * 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
1589 * 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
1590 * 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
1591 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1592 * 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
1593 * 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
1594 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1595
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1596 WindowObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1597
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1598 if (WIN_PYTHON_REF(win))
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1599 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1600 self = WIN_PYTHON_REF(win);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1601 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1602 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1603 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1604 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1605 self = PyObject_NEW(WindowObject, &WindowType);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1606 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1607 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1608 self->win = win;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1609 WIN_PYTHON_REF(win) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1610 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1611
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1612 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1613 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1614
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1615 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1616 WindowDestructor(PyObject *self)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1617 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1618 WindowObject *this = (WindowObject *)(self);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1619
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1620 if (this->win && this->win != INVALID_WINDOW_VALUE)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1621 WIN_PYTHON_REF(this->win) = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1622
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1623 DESTRUCTOR_FINISH(self);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1624 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1625
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1626 static PyObject *
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1627 WindowAttr(WindowObject *this, char *name)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1628 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1629 if (strcmp(name, "buffer") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1630 return (PyObject *)BufferNew(this->win->w_buffer);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1631 else if (strcmp(name, "cursor") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1632 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1633 pos_T *pos = &this->win->w_cursor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1634
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1635 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
1636 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1637 else if (strcmp(name, "height") == 0)
4381
48a22f36ff45 updated for version 7.3.939
Bram Moolenaar <bram@vim.org>
parents: 4379
diff changeset
1638 return PyLong_FromLong((long)(this->win->w_height));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1639 #ifdef FEAT_WINDOWS
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1640 else if (strcmp(name, "row") == 0)
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1641 return PyLong_FromLong((long)(this->win->w_winrow));
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1642 #endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1643 #ifdef FEAT_VERTSPLIT
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1644 else if (strcmp(name, "width") == 0)
4381
48a22f36ff45 updated for version 7.3.939
Bram Moolenaar <bram@vim.org>
parents: 4379
diff changeset
1645 return PyLong_FromLong((long)(W_WIDTH(this->win)));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1646 else if (strcmp(name, "col") == 0)
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1647 return PyLong_FromLong((long)(W_WINCOL(this->win)));
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1648 #endif
4323
f1eab4f77a6f updated for version 7.3.911
Bram Moolenaar <bram@vim.org>
parents: 4321
diff changeset
1649 else if (strcmp(name, "vars") == 0)
f1eab4f77a6f updated for version 7.3.911
Bram Moolenaar <bram@vim.org>
parents: 4321
diff changeset
1650 return DictionaryNew(this->win->w_vars);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1651 else if (strcmp(name, "options") == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1652 return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1653 (PyObject *) this);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1654 else if (strcmp(name, "number") == 0)
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1655 return PyLong_FromLong((long) get_win_number(this->win));
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1656 else if (strcmp(name,"__members__") == 0)
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1657 return Py_BuildValue("[ssssssss]", "buffer", "cursor", "height", "vars",
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1658 "options", "number", "row", "col");
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1659 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1660 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1661 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1662
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1663 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1664 WindowSetattr(PyObject *self, char *name, PyObject *val)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1665 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1666 WindowObject *this = (WindowObject *)(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1667
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1668 if (CheckWindow(this))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1669 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1670
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1671 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
1672 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1673 PyErr_SetString(PyExc_TypeError, _("readonly attribute"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1674 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1675 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1676 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
1677 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1678 long lnum;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1679 long col;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1680
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1681 if (!PyArg_Parse(val, "(ll)", &lnum, &col))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1682 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1683
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1684 if (lnum <= 0 || lnum > this->win->w_buffer->b_ml.ml_line_count)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1685 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1686 PyErr_SetVim(_("cursor position outside buffer"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1687 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1688 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1689
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1690 /* Check for keyboard interrupts */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1691 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1692 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1693
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1694 this->win->w_cursor.lnum = lnum;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1695 this->win->w_cursor.col = col;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1696 #ifdef FEAT_VIRTUALEDIT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1697 this->win->w_cursor.coladd = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1698 #endif
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
1699 /* When column is out of range silently correct it. */
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
1700 check_cursor_col_win(this->win);
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
1701
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1702 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1703 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1704 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1705 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
1706 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1707 int height;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1708 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1709
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1710 if (!PyArg_Parse(val, "i", &height))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1711 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1712
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1713 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1714 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
1715 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1716 savewin = curwin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1717 curwin = this->win;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1718 win_setheight(height);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1719 curwin = savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1720
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1721 /* Check for keyboard interrupts */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1722 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1723 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1724
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1725 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1726 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1727 #ifdef FEAT_VERTSPLIT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1728 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
1729 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1730 int width;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1731 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1732
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1733 if (!PyArg_Parse(val, "i", &width))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1734 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1735
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1736 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1737 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
1738 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1739 savewin = curwin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1740 curwin = this->win;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1741 win_setwidth(width);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1742 curwin = savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1743
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1744 /* Check for keyboard interrupts */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1745 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1746 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1747
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1748 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1749 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1750 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1751 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1752 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1753 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
1754 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1755 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1756 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1757
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1758 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1759 WindowRepr(PyObject *self)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1760 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1761 static char repr[100];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1762 WindowObject *this = (WindowObject *)(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1763
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1764 if (this->win == INVALID_WINDOW_VALUE)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1765 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1766 vim_snprintf(repr, 100, _("<window object (deleted) at %p>"), (self));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1767 return PyString_FromString(repr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1768 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1769 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1770 {
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1771 int w = get_win_number(this->win);
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1772
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1773 if (w == 0)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1774 vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1775 (self));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1776 else
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1777 vim_snprintf(repr, 100, _("<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
1778
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1779 return PyString_FromString(repr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1780 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1781 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1782
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1783 static struct PyMethodDef WindowMethods[] = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1784 /* name, function, calling, documentation */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1785 { NULL, NULL, 0, NULL }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1786 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1787
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1788 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1789 * 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
1790 */
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1791
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1792 static PyTypeObject WinListType;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1793 static PySequenceMethods WinListAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1794
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1795 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1796 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1797 PyObject_HEAD
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1798 } WinListObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1799
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1800 static PyInt
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1801 WinListLength(PyObject *self UNUSED)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1802 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1803 win_T *w = firstwin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1804 PyInt n = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1805
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1806 while (w != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1807 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1808 ++n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1809 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
1810 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1811
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1812 return n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1813 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1814
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1815 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1816 WinListItem(PyObject *self UNUSED, PyInt n)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1817 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1818 win_T *w;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1819
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1820 for (w = firstwin; w != NULL; w = W_NEXT(w), --n)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1821 if (n == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1822 return WindowNew(w);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1823
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1824 PyErr_SetString(PyExc_IndexError, _("no such window"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1825 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1826 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1827
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1828 /* 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
1829 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1830 * 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
1831 * 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
1832 * characters.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1833 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1834 * 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
1835 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1836 static char *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1837 StringToLine(PyObject *obj)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1838 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1839 const char *str;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1840 char *save;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1841 PyObject *bytes;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1842 PyInt len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1843 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1844 char *p;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1845
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1846 if (obj == NULL || !PyString_Check(obj))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1847 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1848 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1849 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1850 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1851
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1852 bytes = PyString_AsBytes(obj); /* for Python 2 this does nothing */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1853 str = PyString_AsString(bytes);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1854 len = PyString_Size(bytes);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1855
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1856 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1857 * 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
1858 * 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
1859 * a single line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1860 * 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
1861 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1862 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
1863 if (p != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1864 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1865 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
1866 --len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1867 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1868 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1869 PyErr_SetVim(_("string cannot contain newlines"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1870 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1871 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1872 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1873
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1874 /* 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
1875 * 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
1876 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1877 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
1878 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1879 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1880 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1881 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1882 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1883
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1884 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
1885 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1886 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
1887 save[i] = '\n';
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1888 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1889 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
1890 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1891
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1892 save[i] = '\0';
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1893 PyString_FreeBytes(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
1894
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1895 return save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1896 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1897
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1898 /* 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
1899 * 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
1900 * string object.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1901 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1902 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1903 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
1904 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1905 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
1906 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1907
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1908
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1909 /* 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
1910 * 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
1911 * 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
1912 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1913 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1914 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
1915 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1916 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1917 PyInt n = hi - lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1918 PyObject *list = PyList_New(n);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1919
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1920 if (list == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1921 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1922
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1923 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
1924 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1925 PyObject *str = LineToString((char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1926
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1927 /* Error check - was the Python string creation OK? */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1928 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1929 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1930 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1931 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1932 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1933
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1934 /* Set the list item */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1935 if (PyList_SetItem(list, i, str))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1936 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1937 Py_DECREF(str);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1938 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1939 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1940 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1941 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1942
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1943 /* 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
1944 * 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
1945 * with it).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1946 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1947
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1948 return list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1949 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1950
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1951 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1952 * 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
1953 * 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
1954 * deleted).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1955 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1956 static void
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1957 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
1958 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1959 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
1960 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1961 /* 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
1962 * lines. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1963 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
1964 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1965 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
1966 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1967 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1968 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
1969 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1970 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
1971 check_cursor();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1972 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1973 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1974 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1975 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
1976 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1977 invalidate_botline();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1978 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1979
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1980 /*
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
1981 * 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
1982 * 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
1983 * 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
1984 * 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
1985 * 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
1986 * 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
1987 * 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
1988 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1989 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1990 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
1991 {
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
1992 /* 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
1993 * 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
1994 * 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
1995 * 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
1996 * 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
1997 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1998 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
1999 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2000 buf_T *savebuf = curbuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2001
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2002 PyErr_Clear();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2003 curbuf = buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2004
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2005 if (u_savedel((linenr_T)n, 1L) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2006 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2007 else if (ml_delete((linenr_T)n, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2008 PyErr_SetVim(_("cannot delete line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2009 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2010 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2011 if (buf == curwin->w_buffer)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2012 py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2013 deleted_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
2014 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2015
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2016 curbuf = savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2017
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2018 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2019 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2020
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2021 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2022 *len_change = -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2023
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2024 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2025 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2026 else if (PyString_Check(line))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2027 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2028 char *save = StringToLine(line);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2029 buf_T *savebuf = curbuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2030
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2031 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2032 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2033
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2034 /* 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
2035 PyErr_Clear();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2036 curbuf = buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2037
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2038 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
2039 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2040 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2041 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2042 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2043 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
2044 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2045 PyErr_SetVim(_("cannot replace line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2046 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2047 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2048 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2049 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
2050
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2051 curbuf = savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2052
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2053 /* Check that the cursor is not beyond the end of the line now. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2054 if (buf == curwin->w_buffer)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2055 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2056
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2057 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2058 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2059
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2060 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2061 *len_change = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2062
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2063 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2064 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2065 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2066 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2067 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2068 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2069 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2070 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2071
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2072 /* 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
2073 * 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
2074 * 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
2075 * 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
2076 * 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
2077 * 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
2078 * 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
2079 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2080 static int
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2081 SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2082 {
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
2083 /* 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
2084 * There are three cases:
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2085 * 1. NULL, or None - this is a deletion.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2086 * 2. A list - this is a replacement.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2087 * 3. Anything else - this is an error.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2088 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2089 if (list == Py_None || list == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2090 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2091 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2092 PyInt n = (int)(hi - lo);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2093 buf_T *savebuf = curbuf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2094
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2095 PyErr_Clear();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2096 curbuf = buf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2097
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2098 if (u_savedel((linenr_T)lo, (long)n) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2099 PyErr_SetVim(_("cannot save undo information"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2100 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2101 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2102 for (i = 0; i < n; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2103 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2104 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2105 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2106 PyErr_SetVim(_("cannot delete line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2107 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2108 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2109 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2110 if (buf == curwin->w_buffer)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2111 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2112 deleted_lines_mark((linenr_T)lo, (long)i);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2113 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2114
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2115 curbuf = savebuf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2116
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2117 if (PyErr_Occurred() || VimErrorCheck())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2118 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2119
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2120 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2121 *len_change = -n;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2122
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2123 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2124 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2125 else if (PyList_Check(list))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2126 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2127 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2128 PyInt new_len = PyList_Size(list);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2129 PyInt old_len = hi - lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2130 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
2131 char **array;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2132 buf_T *savebuf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2133
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2134 if (new_len == 0) /* avoid allocating zero bytes */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2135 array = NULL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2136 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2137 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2138 array = (char **)alloc((unsigned)(new_len * sizeof(char *)));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2139 if (array == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2140 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2141 PyErr_NoMemory();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2142 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2143 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2144 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2145
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2146 for (i = 0; i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2147 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2148 PyObject *line = PyList_GetItem(list, i);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2149
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2150 array[i] = StringToLine(line);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2151 if (array[i] == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2152 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2153 while (i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2154 vim_free(array[--i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2155 vim_free(array);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2156 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2157 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2158 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2159
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2160 savebuf = curbuf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2161
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2162 PyErr_Clear();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2163 curbuf = buf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2164
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2165 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2166 PyErr_SetVim(_("cannot save undo information"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2167
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2168 /* 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
2169 * 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
2170 * repeatedly deleting line "lo".
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2171 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2172 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2173 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2174 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
2175 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2176 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2177 PyErr_SetVim(_("cannot delete line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2178 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2179 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2180 extra -= i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2181 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2182
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2183 /* 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
2184 * 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
2185 * less memory allocation and freeing.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2186 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2187 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2188 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2189 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
2190 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
2191 == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2192 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2193 PyErr_SetVim(_("cannot replace line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2194 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2195 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2196 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2197 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2198 i = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2199
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2200 /* 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
2201 * 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
2202 * responsibility to vim in this case).
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2203 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2204 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2205 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2206 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2207 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2208 if (ml_append((linenr_T)(lo + i - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2209 (char_u *)array[i], 0, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2210 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2211 PyErr_SetVim(_("cannot insert line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2212 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2213 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2214 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2215 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2216 ++extra;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2217 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2218 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2219
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2220 /* 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
2221 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2222 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2223 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2224 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2225 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2226
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2227 /* 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
2228 * 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
2229 * to vim.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2230 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2231 vim_free(array);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2232
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2233 /* Adjust marks. Invalidate any which lie in the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2234 * changed range, and move any in the remainder of the buffer.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2235 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2236 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2237 (long)MAXLNUM, (long)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2238 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
2239
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2240 if (buf == curwin->w_buffer)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2241 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
2242
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2243 curbuf = savebuf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2244
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2245 if (PyErr_Occurred() || VimErrorCheck())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2246 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2247
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2248 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2249 *len_change = new_len - old_len;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2250
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2251 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2252 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2253 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2254 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2255 PyErr_BadArgument();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2256 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2257 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2258 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2259
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
2260 /* 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
2261 * 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
2262 * 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
2263 * 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
2264 * 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
2265 * 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
2266 * 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
2267 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2268 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2269 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
2270 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2271 /* 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
2272 * 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
2273 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2274 if (PyString_Check(lines))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2275 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2276 char *str = StringToLine(lines);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2277 buf_T *savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2278
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2279 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2280 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2281
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2282 savebuf = curbuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2283
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2284 PyErr_Clear();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2285 curbuf = buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2286
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2287 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2288 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2289 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2290 PyErr_SetVim(_("cannot insert line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2291 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2292 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
2293
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2294 vim_free(str);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2295 curbuf = savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2296 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2297
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2298 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2299 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2300
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2301 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2302 *len_change = 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2303
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2304 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2305 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2306 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
2307 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2308 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2309 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
2310 char **array;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2311 buf_T *savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2312
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2313 array = (char **)alloc((unsigned)(size * sizeof(char *)));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2314 if (array == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2315 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2316 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2317 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2318 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2319
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2320 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
2321 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2322 PyObject *line = PyList_GetItem(lines, i);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2323 array[i] = StringToLine(line);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2324
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2325 if (array[i] == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2326 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2327 while (i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2328 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
2329 vim_free(array);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2330 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2331 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2332 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2333
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2334 savebuf = curbuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2335
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2336 PyErr_Clear();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2337 curbuf = buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2338
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2339 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2340 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2341 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2342 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2343 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
2344 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2345 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
2346 (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
2347 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2348 PyErr_SetVim(_("cannot insert line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2349
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2350 /* 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
2351 while (i < size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2352 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
2353
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2354 break;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2355 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2356 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
2357 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2358 if (i > 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2359 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
2360 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2361
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2362 /* Free the array of lines. All of its contents have now
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2363 * been freed.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2364 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2365 vim_free(array);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2366
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2367 curbuf = savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2368 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2369
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2370 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2371 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2372
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2373 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2374 *len_change = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2375
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2376 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2377 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2378 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2379 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2380 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2381 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2382 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2383 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2384
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2385 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2386 * 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
2387 * -------------------------------------------
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2388 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2389
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2390 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2391 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2392 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2393 buf_T *buf;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2394 } BufferObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2395
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2396 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2397 CheckBuffer(BufferObject *this)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2398 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2399 if (this->buf == INVALID_BUFFER_VALUE)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2400 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2401 PyErr_SetVim(_("attempt to refer to deleted buffer"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2402 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2403 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2404
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2405 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2406 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2407
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2408 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2409 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
2410 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2411 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2412 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2413
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2414 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2415 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2416
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2417 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2418 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2419
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2420 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
2421 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2422 PyErr_SetString(PyExc_IndexError, _("line number out of range"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2423 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2424 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2425
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2426 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
2427 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2428
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2429 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2430 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
2431 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2432 PyInt size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2433
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2434 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2435 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2436
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2437 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2438 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2439
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2440 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
2441
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2442 if (lo < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2443 lo = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2444 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
2445 lo = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2446 if (hi < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2447 hi = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2448 if (hi < lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2449 hi = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2450 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
2451 hi = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2452
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2453 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
2454 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2455
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2456 static PyInt
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2457 RBAsItem(BufferObject *self, PyInt n, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2458 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2459 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2460
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2461 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2462 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2463
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2464 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2465 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2466
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2467 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2468 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2469
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2470 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
2471 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2472 PyErr_SetString(PyExc_IndexError, _("line number out of range"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2473 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2474 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2475
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2476 if (SetBufferLine(self->buf, n+start, val, &len_change) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2477 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2478
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2479 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2480 *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
2481
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2482 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2483 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2484
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2485 static PyInt
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2486 RBAsSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2487 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2488 PyInt size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2489 PyInt len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2490
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2491 /* Self must be a valid buffer */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2492 if (CheckBuffer(self))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2493 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2494
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2495 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2496 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2497
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2498 /* Sort out the slice range */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2499 size = end - start + 1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2500
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2501 if (lo < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2502 lo = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2503 else if (lo > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2504 lo = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2505 if (hi < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2506 hi = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2507 if (hi < lo)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2508 hi = lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2509 else if (hi > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2510 hi = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2511
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2512 if (SetBufferLineList(self->buf, lo + start, hi + start,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2513 val, &len_change) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2514 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2515
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2516 if (new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2517 *new_end = end + len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2518
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2519 return 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2520 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2521
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2522
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2523 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2524 RBAppend(BufferObject *self, PyObject *args, PyInt start, PyInt end, PyInt *new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2525 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2526 PyObject *lines;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2527 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2528 PyInt max;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2529 PyInt n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2530
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2531 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2532 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2533
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2534 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2535 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2536
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2537 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
2538
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2539 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
2540 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2541
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2542 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
2543 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2544 PyErr_SetString(PyExc_ValueError, _("line number out of range"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2545 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2546 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2547
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2548 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
2549 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2550
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2551 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2552 *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
2553
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2554 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
2555 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2556 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2557
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2558 /* Range object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2559 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2560
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2561 static PyTypeObject RangeType;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2562 static PySequenceMethods RangeAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2563 static PyMappingMethods RangeAsMapping;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2564
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2565 typedef struct
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2566 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2567 PyObject_HEAD
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2568 BufferObject *buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2569 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2570 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2571 } RangeObject;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2572
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2573 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2574 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
2575 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2576 BufferObject *bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2577 RangeObject *self;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2578 self = PyObject_NEW(RangeObject, &RangeType);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2579 if (self == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2580 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2581
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2582 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
2583 if (bufr == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2584 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2585 Py_DECREF(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2586 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2587 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2588 Py_INCREF(bufr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2589
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2590 self->buf = bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2591 self->start = start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2592 self->end = end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2593
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2594 return (PyObject *)(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2595 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2596
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2597 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2598 RangeDestructor(PyObject *self)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2599 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2600 Py_DECREF(((RangeObject *)(self))->buf);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2601 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2602 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2603
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2604 static PyInt
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2605 RangeLength(PyObject *self)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2606 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2607 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2608 if (CheckBuffer(((RangeObject *)(self))->buf))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2609 return -1; /* ??? */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2610
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2611 return (((RangeObject *)(self))->end - ((RangeObject *)(self))->start + 1);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2612 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2613
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2614 static PyObject *
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2615 RangeItem(PyObject *self, PyInt n)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2616 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2617 return RBItem(((RangeObject *)(self))->buf, n,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2618 ((RangeObject *)(self))->start,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2619 ((RangeObject *)(self))->end);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2620 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2621
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2622 static PyObject *
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2623 RangeSlice(PyObject *self, PyInt lo, PyInt hi)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2624 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2625 return RBSlice(((RangeObject *)(self))->buf, lo, hi,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2626 ((RangeObject *)(self))->start,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2627 ((RangeObject *)(self))->end);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2628 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2629
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2630 static PyObject *
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2631 RangeAppend(PyObject *self, PyObject *args)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2632 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2633 return RBAppend(((RangeObject *)(self))->buf, args,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2634 ((RangeObject *)(self))->start,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2635 ((RangeObject *)(self))->end,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2636 &((RangeObject *)(self))->end);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2637 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2638
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2639 static PyObject *
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2640 RangeRepr(PyObject *self)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2641 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2642 static char repr[100];
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2643 RangeObject *this = (RangeObject *)(self);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2644
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2645 if (this->buf->buf == INVALID_BUFFER_VALUE)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2646 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2647 vim_snprintf(repr, 100, "<range object (for deleted buffer) at %p>",
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2648 (self));
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2649 return PyString_FromString(repr);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2650 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2651 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2652 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2653 char *name = (char *)this->buf->buf->b_fname;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2654 int len;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2655
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2656 if (name == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2657 name = "";
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2658 len = (int)strlen(name);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2659
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2660 if (len > 45)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2661 name = name + (45 - len);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2662
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2663 vim_snprintf(repr, 100, "<range %s%s (%d:%d)>",
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2664 len > 45 ? "..." : "", name,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2665 this->start, this->end);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2666
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2667 return PyString_FromString(repr);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2668 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2669 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2670
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2671 static struct PyMethodDef RangeMethods[] = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2672 /* name, function, calling, documentation */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2673 {"append", RangeAppend, 1, "Append data to the Vim range" },
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2674 { NULL, NULL, 0, NULL }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2675 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2676
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2677 static PyTypeObject BufferType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2678 static PySequenceMethods BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2679 static PyMappingMethods BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2680
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2681 static PyObject *
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2682 BufferNew(buf_T *buf)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2683 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2684 /* 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
2685 * 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
2686 * 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
2687 * 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
2688 * 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
2689 * 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
2690 * the buffer is stored in "b_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2691 * 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
2692 * 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
2693 * 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
2694 * 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
2695 * 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
2696 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2697 * 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
2698 * 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
2699 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2700
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2701 BufferObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2702
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2703 if (BUF_PYTHON_REF(buf) != NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2704 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2705 self = BUF_PYTHON_REF(buf);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2706 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2707 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2708 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2709 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2710 self = PyObject_NEW(BufferObject, &BufferType);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2711 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2712 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2713 self->buf = buf;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2714 BUF_PYTHON_REF(buf) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2715 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2716
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2717 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2718 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2719
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2720 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2721 BufferDestructor(PyObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2722 {
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2723 BufferObject *this = (BufferObject *)(self);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2724
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2725 if (this->buf && this->buf != INVALID_BUFFER_VALUE)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2726 BUF_PYTHON_REF(this->buf) = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2727
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2728 DESTRUCTOR_FINISH(self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2729 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2730
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2731 static PyInt
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2732 BufferLength(PyObject *self)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2733 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2734 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2735 if (CheckBuffer((BufferObject *)(self)))
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2736 return -1; /* ??? */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2737
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2738 return (PyInt)(((BufferObject *)(self))->buf->b_ml.ml_line_count);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2739 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2740
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2741 static PyObject *
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2742 BufferItem(PyObject *self, PyInt n)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2743 {
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2744 return RBItem((BufferObject *)(self), n, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2745 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2746
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2747 static PyObject *
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2748 BufferSlice(PyObject *self, PyInt lo, PyInt hi)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2749 {
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2750 return RBSlice((BufferObject *)(self), lo, hi, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2751 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2752
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2753 static PyObject *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2754 BufferAttr(BufferObject *this, char *name)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2755 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2756 if (strcmp(name, "name") == 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2757 return Py_BuildValue("s", this->buf->b_ffname);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2758 else if (strcmp(name, "number") == 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2759 return Py_BuildValue(Py_ssize_t_fmt, this->buf->b_fnum);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2760 else if (strcmp(name, "vars") == 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2761 return DictionaryNew(this->buf->b_vars);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2762 else if (strcmp(name, "options") == 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2763 return OptionsNew(SREQ_BUF, this->buf, (checkfun) CheckBuffer,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2764 (PyObject *) this);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2765 else if (strcmp(name,"__members__") == 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2766 return Py_BuildValue("[ssss]", "name", "number", "vars", "options");
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2767 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2768 return NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2769 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2770
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2771 static PyObject *
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2772 BufferAppend(PyObject *self, PyObject *args)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2773 {
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2774 return RBAppend((BufferObject *)(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
2775 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2776
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2777 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2778 BufferMark(PyObject *self, PyObject *args)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2779 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2780 pos_T *posp;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2781 char *pmark;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2782 char mark;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2783 buf_T *curbuf_save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2784
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2785 if (CheckBuffer((BufferObject *)(self)))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2786 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2787
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2788 if (!PyArg_ParseTuple(args, "s", &pmark))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2789 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2790 mark = *pmark;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2791
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2792 curbuf_save = curbuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2793 curbuf = ((BufferObject *)(self))->buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2794 posp = getmark(mark, FALSE);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2795 curbuf = curbuf_save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2796
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2797 if (posp == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2798 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2799 PyErr_SetVim(_("invalid mark name"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2800 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2801 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2802
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
2803 /* Check for keyboard interrupt */
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2804 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2805 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2806
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2807 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
2808 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2809 /* 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
2810 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
2811 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2812 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2813
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2814 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
2815 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2816
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2817 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2818 BufferRange(PyObject *self, PyObject *args)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2819 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2820 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2821 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2822
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2823 if (CheckBuffer((BufferObject *)(self)))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2824 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2825
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2826 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
2827 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2828
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2829 return RangeNew(((BufferObject *)(self))->buf, start, end);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2830 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2831
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2832 static PyObject *
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2833 BufferRepr(PyObject *self)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2834 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2835 static char repr[100];
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2836 BufferObject *this = (BufferObject *)(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2837
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2838 if (this->buf == INVALID_BUFFER_VALUE)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2839 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2840 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2841 return PyString_FromString(repr);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2842 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2843 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2844 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2845 char *name = (char *)this->buf->b_fname;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2846 PyInt len;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2847
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2848 if (name == NULL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2849 name = "";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2850 len = strlen(name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2851
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2852 if (len > 35)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2853 name = name + (35 - len);
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 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name);
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 return PyString_FromString(repr);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2858 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2859 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2860
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2861 static struct PyMethodDef BufferMethods[] = {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2862 /* name, function, calling, documentation */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2863 {"append", BufferAppend, 1, "Append data to Vim buffer" },
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2864 {"mark", BufferMark, 1, "Return (row,col) representing position of named mark" },
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2865 {"range", BufferRange, 1, "Return a range object which represents the part of the given buffer between line numbers s and e" },
3310
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3056
diff changeset
2866 #if PY_VERSION_HEX >= 0x03000000
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3056
diff changeset
2867 {"__dir__", BufferDir, 4, "List its attributes" },
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3056
diff changeset
2868 #endif
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2869 { NULL, NULL, 0, NULL }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2870 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2871
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2872 /* 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
2873 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2874
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2875 static PyObject *
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2876 CurrentGetattr(PyObject *self UNUSED, char *name)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2877 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2878 if (strcmp(name, "buffer") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2879 return (PyObject *)BufferNew(curbuf);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2880 else if (strcmp(name, "window") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2881 return (PyObject *)WindowNew(curwin);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2882 else if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2883 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2884 else if (strcmp(name, "range") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2885 return RangeNew(curbuf, RangeStart, RangeEnd);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2886 else if (strcmp(name,"__members__") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2887 return Py_BuildValue("[ssss]", "buffer", "window", "line", "range");
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2888 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2889 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2890 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2891 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2892 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2893 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2894
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2895 static int
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2896 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *value)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2897 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2898 if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2899 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2900 if (SetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum, value, NULL) == FAIL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2901 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2902
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2903 return 0;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2904 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2905 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2906 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2907 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2908 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2909 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2910 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2911
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2912 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2913 set_ref_in_py(const int copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2914 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2915 pylinkedlist_T *cur;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2916 dict_T *dd;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2917 list_T *ll;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2918
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2919 if (lastdict != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2920 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
2921 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2922 dd = ((DictionaryObject *) (cur->pll_obj))->dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2923 if (dd->dv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2924 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2925 dd->dv_copyID = copyID;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2926 set_ref_in_ht(&dd->dv_hashtab, copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2927 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2928 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2929
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2930 if (lastlist != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2931 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
2932 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2933 ll = ((ListObject *) (cur->pll_obj))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2934 if (ll->lv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2935 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2936 ll->lv_copyID = copyID;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2937 set_ref_in_list(ll, copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2938 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2939 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2940 }
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 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2943 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
2944 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2945 tv->vval.v_string = vim_strsave(str);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2946 if (tv->vval.v_string == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2947 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2948 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2949 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2950 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2951 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2952 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
2953
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2954 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2955 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2956 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2957 dict_T *d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2958 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2959 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2960 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2961 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2962 Py_ssize_t iter = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2963
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2964 d = dict_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2965 if (d == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2966 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2967 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2968 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2969 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2970
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2971 tv->v_type = VAR_DICT;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2972 tv->vval.v_dict = d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2973
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2974 while (PyDict_Next(obj, &iter, &keyObject, &valObject))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2975 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2976 DICTKEY_DECL
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2977
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2978 if (keyObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2979 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2980 if (valObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2981 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2982
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2983 DICTKEY_GET_NOTEMPTY(-1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2984
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2985 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2986
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2987 DICTKEY_UNREF
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2988
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2989 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2990 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2991 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2992 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2993 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2994 di->di_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2995
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2996 if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2997 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2998 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2999 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3000 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3001 if (dict_add(d, di) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3002 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3003 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3004 PyErr_SetVim(_("failed to add key to dictionary"));
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3005 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3006 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3007 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3008 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3009 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3010
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3011 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3012 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3013 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3014 dict_T *d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3015 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3016 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3017 PyObject *list;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3018 PyObject *litem;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3019 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3020 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3021 Py_ssize_t lsize;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3022
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3023 d = dict_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3024 if (d == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3025 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3026 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3027 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3028 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3029
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3030 tv->v_type = VAR_DICT;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3031 tv->vval.v_dict = d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3032
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3033 list = PyMapping_Items(obj);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3034 if (list == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3035 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3036 lsize = PyList_Size(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3037 while (lsize--)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3038 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3039 DICTKEY_DECL
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3040
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3041 litem = PyList_GetItem(list, lsize);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3042 if (litem == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3043 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3044 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3045 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3046 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3047
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3048 keyObject = PyTuple_GetItem(litem, 0);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3049 if (keyObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3050 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3051 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3052 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3053 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3054 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3055
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3056 DICTKEY_GET_NOTEMPTY(-1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3057
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3058 valObject = PyTuple_GetItem(litem, 1);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3059 if (valObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3060 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3061 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3062 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3063 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3064 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3065
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3066 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3067
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3068 DICTKEY_UNREF
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3069
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3070 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3071 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3072 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3073 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3074 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3075 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3076 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3077 di->di_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3078
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3079 if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3080 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3081 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3082 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3083 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3084 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3085 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3086 if (dict_add(d, di) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3087 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3088 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3089 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3090 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3091 PyErr_SetVim(_("failed to add key to dictionary"));
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3092 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3093 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3094 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3095 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3096 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3097 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3098 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3099
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3100 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3101 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3102 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3103 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3104
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3105 l = list_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3106 if (l == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3107 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3108 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3109 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3110 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3111
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3112 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3113 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3114
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3115 if (list_py_concat(l, obj, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3116 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3117
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3118 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3119 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3120
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3121 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3122 pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3123 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3124 PyObject *iterator = PyObject_GetIter(obj);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3125 PyObject *item;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3126 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3127 listitem_T *li;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3128
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3129 l = list_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3130
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3131 if (l == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3132 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3133 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3134 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3135 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3136
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3137 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3138 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3139
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3140
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3141 if (iterator == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3142 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3143
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3144 while ((item = PyIter_Next(obj)))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3145 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3146 li = listitem_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3147 if (li == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3148 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3149 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3150 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3151 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3152 li->li_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3153
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3154 if (_ConvertFromPyObject(item, &li->li_tv, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3155 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3156
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3157 list_append(l, li);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3158
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3159 Py_DECREF(item);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3160 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3161
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3162 Py_DECREF(iterator);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3163 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3164 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3165
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3166 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3167
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3168 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3169 convert_dl(PyObject *obj, typval_T *tv,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3170 pytotvfunc py_to_tv, PyObject *lookupDict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3171 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3172 PyObject *capsule;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3173 char hexBuf[sizeof(void *) * 2 + 3];
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3174
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3175 sprintf(hexBuf, "%p", obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3176
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3177 # ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3178 capsule = PyDict_GetItemString(lookupDict, hexBuf);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3179 # else
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3180 capsule = (PyObject *)PyDict_GetItemString(lookupDict, hexBuf);
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3181 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3182 if (capsule == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3183 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3184 # ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3185 capsule = PyCapsule_New(tv, NULL, NULL);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3186 # else
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3187 capsule = PyCObject_FromVoidPtr(tv, NULL);
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3188 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3189 PyDict_SetItemString(lookupDict, hexBuf, capsule);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3190 Py_DECREF(capsule);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3191 if (py_to_tv(obj, tv, lookupDict) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3192 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3193 tv->v_type = VAR_UNKNOWN;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3194 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3195 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3196 /* 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
3197 * do it ourself. */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3198 switch(tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3199 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3200 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
3201 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
3202 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3203 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3204 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3205 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3206 typval_T *v;
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3207
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3208 # ifdef PY_USE_CAPSULE
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3209 v = PyCapsule_GetPointer(capsule, NULL);
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3210 # else
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3211 v = PyCObject_AsVoidPtr(capsule);
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3212 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3213 copy_tv(v, tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3214 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3215 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3216 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3217
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3218 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3219 ConvertFromPyObject(PyObject *obj, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3220 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3221 PyObject *lookup_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3222 int r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3223
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3224 lookup_dict = PyDict_New();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3225 r = _ConvertFromPyObject(obj, tv, lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3226 Py_DECREF(lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3227 return r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3228 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3229
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3230 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3231 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3232 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3233 if (obj->ob_type == &DictionaryType)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3234 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3235 tv->v_type = VAR_DICT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3236 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3237 ++tv->vval.v_dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3238 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3239 else if (obj->ob_type == &ListType)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3240 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3241 tv->v_type = VAR_LIST;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3242 tv->vval.v_list = (((ListObject *)(obj))->list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3243 ++tv->vval.v_list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3244 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3245 else if (obj->ob_type == &FunctionType)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3246 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3247 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
3248 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3249
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3250 tv->v_type = VAR_FUNC;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3251 func_ref(tv->vval.v_string);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3252 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3253 else if (PyBytes_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3254 {
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3255 char_u *result;
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3256
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3257 if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3258 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3259 if (result == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3260 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3261
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3262 if (set_string_copy(result, tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3263 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3264
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3265 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3266 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3267 else if (PyUnicode_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3268 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3269 PyObject *bytes;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3270 char_u *result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3271
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3272 bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3273 if (bytes == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3274 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3275
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3276 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3277 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3278 if (result == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3279 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3280
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3281 if (set_string_copy(result, tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3282 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3283 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3284 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3285 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3286 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3287
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3288 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3289 }
4321
d8d9c591c50f updated for version 7.3.910
Bram Moolenaar <bram@vim.org>
parents: 4319
diff changeset
3290 #if PY_MAJOR_VERSION < 3
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3291 else if (PyInt_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3292 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3293 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3294 tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3295 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3296 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3297 else if (PyLong_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3298 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3299 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3300 tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3301 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3302 else if (PyDict_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3303 return convert_dl(obj, tv, pydict_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3304 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3305 else if (PyFloat_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3306 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3307 tv->v_type = VAR_FLOAT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3308 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
3309 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3310 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3311 else if (PyIter_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3312 return convert_dl(obj, tv, pyiter_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3313 else if (PySequence_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3314 return convert_dl(obj, tv, pyseq_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3315 else if (PyMapping_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3316 return convert_dl(obj, tv, pymap_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3317 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3318 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3319 PyErr_SetString(PyExc_TypeError, _("unable to convert to vim structure"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3320 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3321 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3322 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3323 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3324
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3325 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3326 ConvertToPyObject(typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3327 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3328 if (tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3329 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3330 PyErr_SetVim(_("NULL reference passed"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3331 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3332 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3333 switch (tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3334 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3335 case VAR_STRING:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3336 return PyBytes_FromString(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3337 ? "" : (char *)tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3338 case VAR_NUMBER:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3339 return PyLong_FromLong((long) tv->vval.v_number);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3340 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3341 case VAR_FLOAT:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3342 return PyFloat_FromDouble((double) tv->vval.v_float);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3343 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3344 case VAR_LIST:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3345 return ListNew(tv->vval.v_list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3346 case VAR_DICT:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3347 return DictionaryNew(tv->vval.v_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3348 case VAR_FUNC:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3349 return FunctionNew(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3350 ? (char_u *)"" : tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3351 case VAR_UNKNOWN:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3352 Py_INCREF(Py_None);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3353 return Py_None;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3354 default:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3355 PyErr_SetVim(_("internal error: invalid value type"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3356 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3357 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3358 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3359
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3360 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3361 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3362 PyObject_HEAD
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3363 } CurrentObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3364 static PyTypeObject CurrentType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3365
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3366 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3367 init_structs(void)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3368 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3369 vim_memset(&OutputType, 0, sizeof(OutputType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3370 OutputType.tp_name = "vim.message";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3371 OutputType.tp_basicsize = sizeof(OutputObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3372 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3373 OutputType.tp_doc = "vim message object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3374 OutputType.tp_methods = OutputMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3375 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3376 OutputType.tp_getattro = OutputGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3377 OutputType.tp_setattro = OutputSetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3378 OutputType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3379 OutputType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3380 OutputType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3381 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3382 OutputType.tp_getattr = OutputGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3383 OutputType.tp_setattr = OutputSetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3384 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3385
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3386 vim_memset(&BufferType, 0, sizeof(BufferType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3387 BufferType.tp_name = "vim.buffer";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3388 BufferType.tp_basicsize = sizeof(BufferType);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3389 BufferType.tp_dealloc = BufferDestructor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3390 BufferType.tp_repr = BufferRepr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3391 BufferType.tp_as_sequence = &BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3392 BufferType.tp_as_mapping = &BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3393 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3394 BufferType.tp_doc = "vim buffer object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3395 BufferType.tp_methods = BufferMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3396 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3397 BufferType.tp_getattro = BufferGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3398 BufferType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3399 BufferType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3400 BufferType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3401 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3402 BufferType.tp_getattr = BufferGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3403 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3404
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3405 vim_memset(&WindowType, 0, sizeof(WindowType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3406 WindowType.tp_name = "vim.window";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3407 WindowType.tp_basicsize = sizeof(WindowObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3408 WindowType.tp_dealloc = WindowDestructor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3409 WindowType.tp_repr = WindowRepr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3410 WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3411 WindowType.tp_doc = "vim Window object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3412 WindowType.tp_methods = WindowMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3413 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3414 WindowType.tp_getattro = WindowGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3415 WindowType.tp_setattro = WindowSetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3416 WindowType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3417 WindowType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3418 WindowType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3419 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3420 WindowType.tp_getattr = WindowGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3421 WindowType.tp_setattr = WindowSetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3422 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3423
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
3424 vim_memset(&BufMapType, 0, sizeof(BufMapType));
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
3425 BufMapType.tp_name = "vim.bufferlist";
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
3426 BufMapType.tp_basicsize = sizeof(BufMapObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
3427 BufMapType.tp_as_mapping = &BufMapAsMapping;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
3428 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3429 BufferType.tp_doc = "vim buffer list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3430
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3431 vim_memset(&WinListType, 0, sizeof(WinListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3432 WinListType.tp_name = "vim.windowlist";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3433 WinListType.tp_basicsize = sizeof(WinListType);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3434 WinListType.tp_as_sequence = &WinListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3435 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3436 WinListType.tp_doc = "vim window list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3437
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3438 vim_memset(&RangeType, 0, sizeof(RangeType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3439 RangeType.tp_name = "vim.range";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3440 RangeType.tp_basicsize = sizeof(RangeObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3441 RangeType.tp_dealloc = RangeDestructor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3442 RangeType.tp_repr = RangeRepr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3443 RangeType.tp_as_sequence = &RangeAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3444 RangeType.tp_as_mapping = &RangeAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3445 RangeType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3446 RangeType.tp_doc = "vim Range object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3447 RangeType.tp_methods = RangeMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3448 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3449 RangeType.tp_getattro = RangeGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3450 RangeType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3451 RangeType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3452 RangeType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3453 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3454 RangeType.tp_getattr = RangeGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3455 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3456
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3457 vim_memset(&CurrentType, 0, sizeof(CurrentType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3458 CurrentType.tp_name = "vim.currentdata";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3459 CurrentType.tp_basicsize = sizeof(CurrentObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3460 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3461 CurrentType.tp_doc = "vim current object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3462 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3463 CurrentType.tp_getattro = CurrentGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3464 CurrentType.tp_setattro = CurrentSetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3465 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3466 CurrentType.tp_getattr = CurrentGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3467 CurrentType.tp_setattr = CurrentSetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3468 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3469
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3470 vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3471 DictionaryType.tp_name = "vim.dictionary";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3472 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3473 DictionaryType.tp_dealloc = DictionaryDestructor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3474 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3475 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3476 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
3477 DictionaryType.tp_methods = DictionaryMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3478 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3479 DictionaryType.tp_getattro = DictionaryGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3480 DictionaryType.tp_setattro = DictionarySetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3481 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3482 DictionaryType.tp_getattr = DictionaryGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3483 DictionaryType.tp_setattr = DictionarySetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3484 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3485
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3486 vim_memset(&ListType, 0, sizeof(ListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3487 ListType.tp_name = "vim.list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3488 ListType.tp_dealloc = ListDestructor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3489 ListType.tp_basicsize = sizeof(ListObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3490 ListType.tp_as_sequence = &ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3491 ListType.tp_as_mapping = &ListAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3492 ListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3493 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
3494 ListType.tp_methods = ListMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3495 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3496 ListType.tp_getattro = ListGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3497 ListType.tp_setattro = ListSetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3498 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3499 ListType.tp_getattr = ListGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3500 ListType.tp_setattr = ListSetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3501 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3502
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3503 vim_memset(&FunctionType, 0, sizeof(FunctionType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3504 FunctionType.tp_name = "vim.list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3505 FunctionType.tp_basicsize = sizeof(FunctionObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3506 FunctionType.tp_dealloc = FunctionDestructor;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3507 FunctionType.tp_call = FunctionCall;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3508 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3509 FunctionType.tp_doc = "object that calls vim function";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3510 FunctionType.tp_methods = FunctionMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3511 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3512 FunctionType.tp_getattro = FunctionGetattro;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3513 #else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3514 FunctionType.tp_getattr = FunctionGetattr;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3515 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3516
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3517 vim_memset(&OptionsType, 0, sizeof(OptionsType));
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3518 OptionsType.tp_name = "vim.options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3519 OptionsType.tp_basicsize = sizeof(OptionsObject);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3520 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3521 OptionsType.tp_doc = "object for manipulating options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3522 OptionsType.tp_as_mapping = &OptionsAsMapping;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3523 OptionsType.tp_dealloc = OptionsDestructor;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
3524
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3525 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3526 vim_memset(&vimmodule, 0, sizeof(vimmodule));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3527 vimmodule.m_name = "vim";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3528 vimmodule.m_doc = "Vim Python interface\n";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3529 vimmodule.m_size = -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3530 vimmodule.m_methods = VimMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3531 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3532 }