]>
Commit | Line | Data |
---|---|---|
5a088057 KK |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.672 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.3.672 | |
11 | Problem: Not possible to lock/unlock lists in Python interface. | |
12 | Solution: Add .locked and .scope attributes. (ZyX) | |
13 | Files: runtime/doc/if_pyth.txt, src/if_py_both.h, src/if_python.c, | |
14 | src/if_python3.c, src/testdir/test86.in, src/testdir/test86.ok, | |
15 | src/testdir/test87.in, src/testdir/test87.ok | |
16 | ||
17 | ||
18 | *** ../vim-7.3.671/runtime/doc/if_pyth.txt 2012-06-29 12:54:32.000000000 +0200 | |
19 | --- runtime/doc/if_pyth.txt 2012-09-21 13:49:14.000000000 +0200 | |
20 | *************** | |
21 | *** 27,33 **** | |
22 | ||
23 | *:python* *:py* *E205* *E263* *E264* | |
24 | :[range]py[thon] {stmt} | |
25 | ! Execute Python statement {stmt}. | |
26 | ||
27 | :[range]py[thon] << {endmarker} | |
28 | {script} | |
29 | --- 27,35 ---- | |
30 | ||
31 | *:python* *:py* *E205* *E263* *E264* | |
32 | :[range]py[thon] {stmt} | |
33 | ! Execute Python statement {stmt}. A simple check if | |
34 | ! the `:python` command is working: > | |
35 | ! :python print "Hello" | |
36 | ||
37 | :[range]py[thon] << {endmarker} | |
38 | {script} | |
39 | *************** | |
40 | *** 157,162 **** | |
41 | --- 159,184 ---- | |
42 | vimlist or vimdictionary python type that are connected to original | |
43 | list or dictionary. Thus modifications to these objects imply | |
44 | modifications of the original. | |
45 | + | |
46 | + Additionally, vimlist and vimdictionary type have read-write | |
47 | + `.locked` attribute that returns | |
48 | + Value Meaning ~ | |
49 | + zero Variable is not locked | |
50 | + vim.VAR_LOCKED Variable is locked, but can be unlocked | |
51 | + vim.VAR_FIXED Variable is locked and can’t be unlocked | |
52 | + integer constants. If variable is not fixed, you can do | |
53 | + `var.locked=True` to lock it and `var.locked=False` to unlock. | |
54 | + There is no recursive locking like |:lockvar|! does. There is also | |
55 | + no way to lock a specific key or check whether it is locked (in any | |
56 | + case these locks are ignored by anything except |:let|: |extend()| | |
57 | + does not care, neither does python interface). | |
58 | + | |
59 | + Vimdictionary type also supports `.scope` attribute which is one of | |
60 | + Value Meaning ~ | |
61 | + zero Dictionary is not a scope one | |
62 | + vim.VAR_DEF_SCOPE Function-local or global scope dictionary | |
63 | + vim.VAR_SCOPE Other scope dictionary | |
64 | + | |
65 | 2. if expression evaluates to a function reference, then it returns | |
66 | callable vimfunction object. Use self keyword argument to assign | |
67 | |self| object for dictionary functions. | |
68 | *************** | |
69 | *** 362,369 **** | |
70 | 8. Python 3 *python3* | |
71 | ||
72 | *:py3* *:python3* | |
73 | ! The |:py3| and |:python3| commands work similar to |:python|. | |
74 | ! *:py3file* | |
75 | The |:py3file| command works similar to |:pyfile|. | |
76 | ||
77 | ||
78 | --- 384,393 ---- | |
79 | 8. Python 3 *python3* | |
80 | ||
81 | *:py3* *:python3* | |
82 | ! The |:py3| and |:python3| commands work similar to |:python|. A simple check | |
83 | ! if the `:py3` command is wrong: > | |
84 | ! :py3 print("Hello") | |
85 | ! < *:py3file* | |
86 | The |:py3file| command works similar to |:pyfile|. | |
87 | ||
88 | ||
89 | *** ../vim-7.3.671/src/if_py_both.h 2012-09-21 13:45:57.000000000 +0200 | |
90 | --- src/if_py_both.h 2012-09-21 13:49:14.000000000 +0200 | |
91 | *************** | |
92 | *** 808,813 **** | |
93 | --- 808,851 ---- | |
94 | } | |
95 | ||
96 | static PyInt | |
97 | + DictionarySetattr(DictionaryObject *self, char *name, PyObject *val) | |
98 | + { | |
99 | + if (val == NULL) | |
100 | + { | |
101 | + PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes")); | |
102 | + return -1; | |
103 | + } | |
104 | + | |
105 | + if (strcmp(name, "locked") == 0) | |
106 | + { | |
107 | + if (self->dict->dv_lock == VAR_FIXED) | |
108 | + { | |
109 | + PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary")); | |
110 | + return -1; | |
111 | + } | |
112 | + else | |
113 | + { | |
114 | + if (!PyBool_Check(val)) | |
115 | + { | |
116 | + PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed")); | |
117 | + return -1; | |
118 | + } | |
119 | + | |
120 | + if (val == Py_True) | |
121 | + self->dict->dv_lock = VAR_LOCKED; | |
122 | + else | |
123 | + self->dict->dv_lock = 0; | |
124 | + } | |
125 | + return 0; | |
126 | + } | |
127 | + else | |
128 | + { | |
129 | + PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute")); | |
130 | + return -1; | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + static PyInt | |
135 | DictionaryLength(PyObject *self) | |
136 | { | |
137 | return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used))); | |
138 | *************** | |
139 | *** 1271,1276 **** | |
140 | --- 1309,1352 ---- | |
141 | return self; | |
142 | } | |
143 | ||
144 | + static int | |
145 | + ListSetattr(ListObject *self, char *name, PyObject *val) | |
146 | + { | |
147 | + if (val == NULL) | |
148 | + { | |
149 | + PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes")); | |
150 | + return -1; | |
151 | + } | |
152 | + | |
153 | + if (strcmp(name, "locked") == 0) | |
154 | + { | |
155 | + if (self->list->lv_lock == VAR_FIXED) | |
156 | + { | |
157 | + PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed list")); | |
158 | + return -1; | |
159 | + } | |
160 | + else | |
161 | + { | |
162 | + if (!PyBool_Check(val)) | |
163 | + { | |
164 | + PyErr_SetString(PyExc_TypeError, _("Only boolean objects are allowed")); | |
165 | + return -1; | |
166 | + } | |
167 | + | |
168 | + if (val == Py_True) | |
169 | + self->list->lv_lock = VAR_LOCKED; | |
170 | + else | |
171 | + self->list->lv_lock = 0; | |
172 | + } | |
173 | + return 0; | |
174 | + } | |
175 | + else | |
176 | + { | |
177 | + PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute")); | |
178 | + return -1; | |
179 | + } | |
180 | + } | |
181 | + | |
182 | static struct PyMethodDef ListMethods[] = { | |
183 | {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""}, | |
184 | { NULL, NULL, 0, NULL } | |
185 | *** ../vim-7.3.671/src/if_python.c 2012-09-21 13:45:57.000000000 +0200 | |
186 | --- src/if_python.c 2012-09-21 13:49:14.000000000 +0200 | |
187 | *************** | |
188 | *** 163,168 **** | |
189 | --- 163,169 ---- | |
190 | # define PyInt_FromLong dll_PyInt_FromLong | |
191 | # define PyLong_AsLong dll_PyLong_AsLong | |
192 | # define PyLong_FromLong dll_PyLong_FromLong | |
193 | + # define PyBool_Type (*dll_PyBool_Type) | |
194 | # define PyInt_Type (*dll_PyInt_Type) | |
195 | # define PyLong_Type (*dll_PyLong_Type) | |
196 | # define PyList_GetItem dll_PyList_GetItem | |
197 | *************** | |
198 | *** 221,226 **** | |
199 | --- 222,229 ---- | |
200 | # define _PyObject_NextNotImplemented (*dll__PyObject_NextNotImplemented) | |
201 | # endif | |
202 | # define _Py_NoneStruct (*dll__Py_NoneStruct) | |
203 | + # define _Py_ZeroStruct (*dll__Py_ZeroStruct) | |
204 | + # define _Py_TrueStruct (*dll__Py_TrueStruct) | |
205 | # define PyObject_Init dll__PyObject_Init | |
206 | # define PyObject_GetIter dll_PyObject_GetIter | |
207 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 | |
208 | *************** | |
209 | *** 263,268 **** | |
210 | --- 266,272 ---- | |
211 | static PyObject*(*dll_PyInt_FromLong)(long); | |
212 | static long(*dll_PyLong_AsLong)(PyObject *); | |
213 | static PyObject*(*dll_PyLong_FromLong)(long); | |
214 | + static PyTypeObject* dll_PyBool_Type; | |
215 | static PyTypeObject* dll_PyInt_Type; | |
216 | static PyTypeObject* dll_PyLong_Type; | |
217 | static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt); | |
218 | *************** | |
219 | *** 320,325 **** | |
220 | --- 324,331 ---- | |
221 | static iternextfunc dll__PyObject_NextNotImplemented; | |
222 | # endif | |
223 | static PyObject* dll__Py_NoneStruct; | |
224 | + static PyObject* _Py_ZeroStruct; | |
225 | + static PyObject* dll__Py_TrueStruct; | |
226 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 | |
227 | static int (*dll_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *); | |
228 | # endif | |
229 | *************** | |
230 | *** 389,394 **** | |
231 | --- 395,401 ---- | |
232 | {"PyInt_FromLong", (PYTHON_PROC*)&dll_PyInt_FromLong}, | |
233 | {"PyLong_AsLong", (PYTHON_PROC*)&dll_PyLong_AsLong}, | |
234 | {"PyLong_FromLong", (PYTHON_PROC*)&dll_PyLong_FromLong}, | |
235 | + {"PyBool_Type", (PYTHON_PROC*)&dll_PyBool_Type}, | |
236 | {"PyInt_Type", (PYTHON_PROC*)&dll_PyInt_Type}, | |
237 | {"PyLong_Type", (PYTHON_PROC*)&dll_PyLong_Type}, | |
238 | {"PyList_GetItem", (PYTHON_PROC*)&dll_PyList_GetItem}, | |
239 | *************** | |
240 | *** 449,454 **** | |
241 | --- 456,463 ---- | |
242 | {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented}, | |
243 | # endif | |
244 | {"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct}, | |
245 | + {"_Py_ZeroStruct", (PYTHON_PROC*)&dll__Py_ZeroStruct}, | |
246 | + {"_Py_TrueStruct", (PYTHON_PROC*)&dll__Py_TrueStruct}, | |
247 | # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000 | |
248 | {"PyType_IsSubtype", (PYTHON_PROC*)&dll_PyType_IsSubtype}, | |
249 | # endif | |
250 | *************** | |
251 | *** 1563,1568 **** | |
252 | --- 1572,1581 ---- | |
253 | PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferList); | |
254 | PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent); | |
255 | PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList); | |
256 | + PyDict_SetItemString(dict, "VAR_LOCKED", PyInt_FromLong(VAR_LOCKED)); | |
257 | + PyDict_SetItemString(dict, "VAR_FIXED", PyInt_FromLong(VAR_FIXED)); | |
258 | + PyDict_SetItemString(dict, "VAR_SCOPE", PyInt_FromLong(VAR_SCOPE)); | |
259 | + PyDict_SetItemString(dict, "VAR_DEF_SCOPE", PyInt_FromLong(VAR_DEF_SCOPE)); | |
260 | ||
261 | if (PyErr_Occurred()) | |
262 | return -1; | |
263 | *************** | |
264 | *** 1629,1635 **** | |
265 | (destructor) DictionaryDestructor, | |
266 | (printfunc) 0, | |
267 | (getattrfunc) DictionaryGetattr, | |
268 | ! (setattrfunc) 0, | |
269 | (cmpfunc) 0, | |
270 | (reprfunc) 0, | |
271 | ||
272 | --- 1642,1648 ---- | |
273 | (destructor) DictionaryDestructor, | |
274 | (printfunc) 0, | |
275 | (getattrfunc) DictionaryGetattr, | |
276 | ! (setattrfunc) DictionarySetattr, | |
277 | (cmpfunc) 0, | |
278 | (reprfunc) 0, | |
279 | ||
280 | *************** | |
281 | *** 1656,1661 **** | |
282 | --- 1669,1681 ---- | |
283 | static PyObject * | |
284 | DictionaryGetattr(PyObject *self, char *name) | |
285 | { | |
286 | + DictionaryObject *this = ((DictionaryObject *) (self)); | |
287 | + | |
288 | + if (strcmp(name, "locked") == 0) | |
289 | + return PyInt_FromLong(this->dict->dv_lock); | |
290 | + else if (strcmp(name, "scope") == 0) | |
291 | + return PyInt_FromLong(this->dict->dv_scope); | |
292 | + | |
293 | return Py_FindMethod(DictionaryMethods, self, name); | |
294 | } | |
295 | ||
296 | *************** | |
297 | *** 1687,1693 **** | |
298 | (destructor) ListDestructor, | |
299 | (printfunc) 0, | |
300 | (getattrfunc) ListGetattr, | |
301 | ! (setattrfunc) 0, | |
302 | (cmpfunc) 0, | |
303 | (reprfunc) 0, | |
304 | ||
305 | --- 1707,1713 ---- | |
306 | (destructor) ListDestructor, | |
307 | (printfunc) 0, | |
308 | (getattrfunc) ListGetattr, | |
309 | ! (setattrfunc) ListSetattr, | |
310 | (cmpfunc) 0, | |
311 | (reprfunc) 0, | |
312 | ||
313 | *************** | |
314 | *** 1714,1719 **** | |
315 | --- 1734,1742 ---- | |
316 | static PyObject * | |
317 | ListGetattr(PyObject *self, char *name) | |
318 | { | |
319 | + if (strcmp(name, "locked") == 0) | |
320 | + return PyInt_FromLong(((ListObject *)(self))->list->lv_lock); | |
321 | + | |
322 | return Py_FindMethod(ListMethods, self, name); | |
323 | } | |
324 | ||
325 | *** ../vim-7.3.671/src/if_python3.c 2012-09-21 13:45:57.000000000 +0200 | |
326 | --- src/if_python3.c 2012-09-21 13:49:14.000000000 +0200 | |
327 | *************** | |
328 | *** 161,167 **** | |
329 | # define PyRun_String py3_PyRun_String | |
330 | # define PySys_SetObject py3_PySys_SetObject | |
331 | # define PySys_SetArgv py3_PySys_SetArgv | |
332 | - # define PyType_Type (*py3_PyType_Type) | |
333 | # define PyType_Ready py3_PyType_Ready | |
334 | #undef Py_BuildValue | |
335 | # define Py_BuildValue py3_Py_BuildValue | |
336 | --- 161,166 ---- | |
337 | *************** | |
338 | *** 170,175 **** | |
339 | --- 169,176 ---- | |
340 | # define Py_Finalize py3_Py_Finalize | |
341 | # define Py_IsInitialized py3_Py_IsInitialized | |
342 | # define _Py_NoneStruct (*py3__Py_NoneStruct) | |
343 | + # define _Py_FalseStruct (*py3__Py_FalseStruct) | |
344 | + # define _Py_TrueStruct (*py3__Py_TrueStruct) | |
345 | # define _PyObject_NextNotImplemented (*py3__PyObject_NextNotImplemented) | |
346 | # define PyModule_AddObject py3_PyModule_AddObject | |
347 | # define PyImport_AppendInittab py3_PyImport_AppendInittab | |
348 | *************** | |
349 | *** 184,191 **** | |
350 | --- 185,194 ---- | |
351 | # define PyFloat_FromDouble py3_PyFloat_FromDouble | |
352 | # define PyFloat_AsDouble py3_PyFloat_AsDouble | |
353 | # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr | |
354 | + # define PyType_Type (*py3_PyType_Type) | |
355 | # define PySlice_Type (*py3_PySlice_Type) | |
356 | # define PyFloat_Type (*py3_PyFloat_Type) | |
357 | + # define PyBool_Type (*py3_PyBool_Type) | |
358 | # define PyErr_NewException py3_PyErr_NewException | |
359 | # ifdef Py_DEBUG | |
360 | # define _Py_NegativeRefcount py3__Py_NegativeRefcount | |
361 | *************** | |
362 | *** 245,251 **** | |
363 | static PyObject* (*py3_PyImport_ImportModule)(const char *); | |
364 | static PyObject* (*py3_PyImport_AddModule)(const char *); | |
365 | static int (*py3_PyErr_BadArgument)(void); | |
366 | - static PyTypeObject* py3_PyType_Type; | |
367 | static PyObject* (*py3_PyErr_Occurred)(void); | |
368 | static PyObject* (*py3_PyModule_GetDict)(PyObject *); | |
369 | static int (*py3_PyList_SetItem)(PyObject *, Py_ssize_t, PyObject *); | |
370 | --- 248,253 ---- | |
371 | *************** | |
372 | *** 275,280 **** | |
373 | --- 277,284 ---- | |
374 | static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *); | |
375 | static iternextfunc py3__PyObject_NextNotImplemented; | |
376 | static PyObject* py3__Py_NoneStruct; | |
377 | + static PyObject* py3__Py_FalseStruct; | |
378 | + static PyObject* py3__Py_TrueStruct; | |
379 | static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o); | |
380 | static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void)); | |
381 | static char* (*py3__PyUnicode_AsString)(PyObject *unicode); | |
382 | *************** | |
383 | *** 288,295 **** | |
384 | --- 292,301 ---- | |
385 | static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version); | |
386 | static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems); | |
387 | static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds); | |
388 | + static PyTypeObject* py3_PyType_Type; | |
389 | static PyTypeObject* py3_PySlice_Type; | |
390 | static PyTypeObject* py3_PyFloat_Type; | |
391 | + static PyTypeObject* py3_PyBool_Type; | |
392 | static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict); | |
393 | static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor); | |
394 | static void* (*py3_PyCapsule_GetPointer)(PyObject *, char *); | |
395 | *************** | |
396 | *** 363,369 **** | |
397 | {"PyImport_ImportModule", (PYTHON_PROC*)&py3_PyImport_ImportModule}, | |
398 | {"PyImport_AddModule", (PYTHON_PROC*)&py3_PyImport_AddModule}, | |
399 | {"PyErr_BadArgument", (PYTHON_PROC*)&py3_PyErr_BadArgument}, | |
400 | - {"PyType_Type", (PYTHON_PROC*)&py3_PyType_Type}, | |
401 | {"PyErr_Occurred", (PYTHON_PROC*)&py3_PyErr_Occurred}, | |
402 | {"PyModule_GetDict", (PYTHON_PROC*)&py3_PyModule_GetDict}, | |
403 | {"PyList_SetItem", (PYTHON_PROC*)&py3_PyList_SetItem}, | |
404 | --- 369,374 ---- | |
405 | *************** | |
406 | *** 386,391 **** | |
407 | --- 391,398 ---- | |
408 | {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized}, | |
409 | {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&py3__PyObject_NextNotImplemented}, | |
410 | {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct}, | |
411 | + {"_Py_FalseStruct", (PYTHON_PROC*)&py3__Py_FalseStruct}, | |
412 | + {"_Py_TrueStruct", (PYTHON_PROC*)&py3__Py_TrueStruct}, | |
413 | {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear}, | |
414 | {"PyObject_Init", (PYTHON_PROC*)&py3__PyObject_Init}, | |
415 | {"PyModule_AddObject", (PYTHON_PROC*)&py3_PyModule_AddObject}, | |
416 | *************** | |
417 | *** 400,407 **** | |
418 | --- 407,416 ---- | |
419 | {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2}, | |
420 | {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc}, | |
421 | {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew}, | |
422 | + {"PyType_Type", (PYTHON_PROC*)&py3_PyType_Type}, | |
423 | {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type}, | |
424 | {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type}, | |
425 | + {"PyBool_Type", (PYTHON_PROC*)&py3_PyBool_Type}, | |
426 | {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException}, | |
427 | # ifdef Py_DEBUG | |
428 | {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount}, | |
429 | *************** | |
430 | *** 1534,1539 **** | |
431 | --- 1543,1570 ---- | |
432 | /* mp_ass_subscript */ (objobjargproc) DictionaryAssItem, | |
433 | }; | |
434 | ||
435 | + static PyObject * | |
436 | + DictionaryGetattro(PyObject *self, PyObject *nameobj) | |
437 | + { | |
438 | + DictionaryObject *this = ((DictionaryObject *) (self)); | |
439 | + | |
440 | + GET_ATTR_STRING(name, nameobj); | |
441 | + | |
442 | + if (strcmp(name, "locked") == 0) | |
443 | + return PyLong_FromLong(this->dict->dv_lock); | |
444 | + else if (strcmp(name, "scope") == 0) | |
445 | + return PyLong_FromLong(this->dict->dv_scope); | |
446 | + | |
447 | + return PyObject_GenericGetAttr(self, nameobj); | |
448 | + } | |
449 | + | |
450 | + static int | |
451 | + DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val) | |
452 | + { | |
453 | + GET_ATTR_STRING(name, nameobj); | |
454 | + return DictionarySetattr((DictionaryObject *) self, name, val); | |
455 | + } | |
456 | + | |
457 | static PyTypeObject DictionaryType; | |
458 | ||
459 | static void | |
460 | *************** | |
461 | *** 1625,1630 **** | |
462 | --- 1656,1679 ---- | |
463 | } | |
464 | } | |
465 | ||
466 | + static PyObject * | |
467 | + ListGetattro(PyObject *self, PyObject *nameobj) | |
468 | + { | |
469 | + GET_ATTR_STRING(name, nameobj); | |
470 | + | |
471 | + if (strcmp(name, "locked") == 0) | |
472 | + return PyLong_FromLong(((ListObject *) (self))->list->lv_lock); | |
473 | + | |
474 | + return PyObject_GenericGetAttr(self, nameobj); | |
475 | + } | |
476 | + | |
477 | + static int | |
478 | + ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val) | |
479 | + { | |
480 | + GET_ATTR_STRING(name, nameobj); | |
481 | + return ListSetattr((ListObject *) self, name, val); | |
482 | + } | |
483 | + | |
484 | static void | |
485 | ListDestructor(PyObject *self) | |
486 | { | |
487 | *************** | |
488 | *** 1713,1718 **** | |
489 | --- 1762,1768 ---- | |
490 | PyMODINIT_FUNC Py3Init_vim(void) | |
491 | { | |
492 | PyObject *mod; | |
493 | + PyObject *tmp; | |
494 | /* The special value is removed from sys.path in Python3_Init(). */ | |
495 | static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL}; | |
496 | ||
497 | *************** | |
498 | *** 1744,1749 **** | |
499 | --- 1794,1809 ---- | |
500 | Py_INCREF((PyObject *)(void *)&TheWindowList); | |
501 | PyModule_AddObject(mod, "windows", (PyObject *)(void *)&TheWindowList); | |
502 | ||
503 | + #define ADD_INT_CONSTANT(name, value) \ | |
504 | + tmp = PyLong_FromLong(value); \ | |
505 | + Py_INCREF(tmp); \ | |
506 | + PyModule_AddObject(mod, name, tmp) | |
507 | + | |
508 | + ADD_INT_CONSTANT("VAR_LOCKED", VAR_LOCKED); | |
509 | + ADD_INT_CONSTANT("VAR_FIXED", VAR_FIXED); | |
510 | + ADD_INT_CONSTANT("VAR_SCOPE", VAR_SCOPE); | |
511 | + ADD_INT_CONSTANT("VAR_DEF_SCOPE", VAR_DEF_SCOPE); | |
512 | + | |
513 | if (PyErr_Occurred()) | |
514 | return NULL; | |
515 | ||
516 | *************** | |
517 | *** 1899,1904 **** | |
518 | --- 1959,1966 ---- | |
519 | vim_memset(&DictionaryType, 0, sizeof(DictionaryType)); | |
520 | DictionaryType.tp_name = "vim.dictionary"; | |
521 | DictionaryType.tp_basicsize = sizeof(DictionaryObject); | |
522 | + DictionaryType.tp_getattro = DictionaryGetattro; | |
523 | + DictionaryType.tp_setattro = DictionarySetattro; | |
524 | DictionaryType.tp_dealloc = DictionaryDestructor; | |
525 | DictionaryType.tp_as_mapping = &DictionaryAsMapping; | |
526 | DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT; | |
527 | *************** | |
528 | *** 1909,1914 **** | |
529 | --- 1971,1978 ---- | |
530 | ListType.tp_name = "vim.list"; | |
531 | ListType.tp_dealloc = ListDestructor; | |
532 | ListType.tp_basicsize = sizeof(ListObject); | |
533 | + ListType.tp_getattro = ListGetattro; | |
534 | + ListType.tp_setattro = ListSetattro; | |
535 | ListType.tp_as_sequence = &ListAsSeq; | |
536 | ListType.tp_as_mapping = &ListAsMapping; | |
537 | ListType.tp_flags = Py_TPFLAGS_DEFAULT; | |
538 | *** ../vim-7.3.671/src/testdir/test86.in 2012-09-05 19:17:37.000000000 +0200 | |
539 | --- src/testdir/test86.in 2012-09-21 13:49:14.000000000 +0200 | |
540 | *************** | |
541 | *** 211,216 **** | |
542 | --- 211,251 ---- | |
543 | m.extend([e.__class__.__name__]) | |
544 | EOF | |
545 | :$put =messages | |
546 | + :unlet messages | |
547 | + :" locked and scope attributes | |
548 | + :let d={} | let dl={} | lockvar dl | |
549 | + :for s in split("d dl v: g:") | |
550 | + : let name=tr(s, ':', 's') | |
551 | + : execute 'py '.name.'=vim.bindeval("'.s.'")' | |
552 | + : let toput=s.' : '.join(map(['locked', 'scope'], 'v:val.":".pyeval(name.".".v:val)'), ';') | |
553 | + : $put =toput | |
554 | + :endfor | |
555 | + :silent! let d.abc=1 | |
556 | + :silent! let dl.abc=1 | |
557 | + :py d.locked=True | |
558 | + :py dl.locked=False | |
559 | + :silent! let d.def=1 | |
560 | + :silent! let dl.def=1 | |
561 | + :put ='d:'.string(d) | |
562 | + :put ='dl:'.string(dl) | |
563 | + :unlet d dl | |
564 | + : | |
565 | + :let l=[] | let ll=[] | lockvar ll | |
566 | + :for s in split("l ll") | |
567 | + : let name=tr(s, ':', 's') | |
568 | + : execute 'py '.name.'=vim.bindeval("'.s.'")' | |
569 | + : let toput=s.' : locked:'.pyeval(name.'.locked') | |
570 | + : $put =toput | |
571 | + :endfor | |
572 | + :silent! call extend(l, [0]) | |
573 | + :silent! call extend(ll, [0]) | |
574 | + :py l.locked=True | |
575 | + :py ll.locked=False | |
576 | + :silent! call extend(l, [1]) | |
577 | + :silent! call extend(ll, [1]) | |
578 | + :put ='l:'.string(l) | |
579 | + :put ='ll:'.string(ll) | |
580 | + :unlet l ll | |
581 | :" | |
582 | :" pyeval() | |
583 | :let l=pyeval('range(3)') | |
584 | *************** | |
585 | *** 240,245 **** | |
586 | --- 275,281 ---- | |
587 | :call garbagecollect(1) | |
588 | :" | |
589 | :/^start:/,$wq! test.out | |
590 | + :call getchar() | |
591 | ENDTEST | |
592 | ||
593 | start: | |
594 | *** ../vim-7.3.671/src/testdir/test86.ok 2012-09-05 19:17:37.000000000 +0200 | |
595 | --- src/testdir/test86.ok 2012-09-21 13:49:14.000000000 +0200 | |
596 | *************** | |
597 | *** 44,49 **** | |
598 | --- 44,59 ---- | |
599 | ValueError | |
600 | TypeError | |
601 | TypeError | |
602 | + d : locked:0;scope:0 | |
603 | + dl : locked:1;scope:0 | |
604 | + v: : locked:2;scope:1 | |
605 | + g: : locked:0;scope:2 | |
606 | + d:{'abc': 1} | |
607 | + dl:{'def': 1} | |
608 | + l : locked:0 | |
609 | + ll : locked:1 | |
610 | + l:[0] | |
611 | + ll:[1] | |
612 | [0, 1, 2] | |
613 | ['a', 'b'] | |
614 | ['c', 1] | |
615 | *** ../vim-7.3.671/src/testdir/test87.in 2012-09-05 19:17:37.000000000 +0200 | |
616 | --- src/testdir/test87.in 2012-09-21 13:49:14.000000000 +0200 | |
617 | *************** | |
618 | *** 211,216 **** | |
619 | --- 211,251 ---- | |
620 | m.extend([e.__class__.__name__]) | |
621 | EOF | |
622 | :$put =messages | |
623 | + :unlet messages | |
624 | + :" locked and scope attributes | |
625 | + :let d={} | let dl={} | lockvar dl | |
626 | + :for s in split("d dl v: g:") | |
627 | + : let name=tr(s, ':', 's') | |
628 | + : execute 'py3 '.name.'=vim.bindeval("'.s.'")' | |
629 | + : let toput=s.' : '.join(map(['locked', 'scope'], 'v:val.":".py3eval(name.".".v:val)'), ';') | |
630 | + : $put =toput | |
631 | + :endfor | |
632 | + :silent! let d.abc=1 | |
633 | + :silent! let dl.abc=1 | |
634 | + :py3 d.locked=True | |
635 | + :py3 dl.locked=False | |
636 | + :silent! let d.def=1 | |
637 | + :silent! let dl.def=1 | |
638 | + :put ='d:'.string(d) | |
639 | + :put ='dl:'.string(dl) | |
640 | + :unlet d dl | |
641 | + : | |
642 | + :let l=[] | let ll=[] | lockvar ll | |
643 | + :for s in split("l ll") | |
644 | + : let name=tr(s, ':', 's') | |
645 | + : execute 'py3 '.name.'=vim.bindeval("'.s.'")' | |
646 | + : let toput=s.' : locked:'.py3eval(name.'.locked') | |
647 | + : $put =toput | |
648 | + :endfor | |
649 | + :silent! call extend(l, [0]) | |
650 | + :silent! call extend(ll, [0]) | |
651 | + :py3 l.locked=True | |
652 | + :py3 ll.locked=False | |
653 | + :silent! call extend(l, [1]) | |
654 | + :silent! call extend(ll, [1]) | |
655 | + :put ='l:'.string(l) | |
656 | + :put ='ll:'.string(ll) | |
657 | + :unlet l ll | |
658 | :" | |
659 | :" py3eval() | |
660 | :let l=py3eval('[0, 1, 2]') | |
661 | *** ../vim-7.3.671/src/testdir/test87.ok 2012-09-05 19:17:37.000000000 +0200 | |
662 | --- src/testdir/test87.ok 2012-09-21 13:49:14.000000000 +0200 | |
663 | *************** | |
664 | *** 44,49 **** | |
665 | --- 44,59 ---- | |
666 | ValueError | |
667 | TypeError | |
668 | TypeError | |
669 | + d : locked:0;scope:0 | |
670 | + dl : locked:1;scope:0 | |
671 | + v: : locked:2;scope:1 | |
672 | + g: : locked:0;scope:2 | |
673 | + d:{'abc': 1} | |
674 | + dl:{'def': 1} | |
675 | + l : locked:0 | |
676 | + ll : locked:1 | |
677 | + l:[0] | |
678 | + ll:[1] | |
679 | [0, 1, 2] | |
680 | ['a', 'b'] | |
681 | ['c', 1] | |
682 | *** ../vim-7.3.671/src/version.c 2012-09-21 13:45:57.000000000 +0200 | |
683 | --- src/version.c 2012-09-21 13:48:18.000000000 +0200 | |
684 | *************** | |
685 | *** 721,722 **** | |
686 | --- 721,724 ---- | |
687 | { /* Add new patch number below this line */ | |
688 | + /**/ | |
689 | + 672, | |
690 | /**/ | |
691 | ||
692 | -- | |
693 | Vi beats Emacs to death, and then again! | |
694 | http://linuxtoday.com/stories/5764.html | |
695 | ||
696 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
697 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
698 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
699 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |