1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Evaluating Vim expression in Python is insufficient.
12 Solution: Add vim.bindeval(). Also add pyeval() and py3eval(). (ZyX)
13 Files: runtime/doc/eval.txt, runtime/doc/if_pyth.txt, src/eval.c,
14 src/if_lua.c, src/if_py_both.h, src/if_python.c, src/if_python3.c,
15 src/proto/eval.pro, src/proto/if_python.pro,
16 src/proto/if_python3.pro, src/testdir/Make_amiga.mak,
17 src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
18 src/testdir/Make_os2.mak, src/testdir/Makefile,
19 src/testdir/test86.in, src/testdir/test86.ok,
20 src/testdir/test87.in, src/testdir/test87.ok
23 *** ../vim-7.3.568/runtime/doc/eval.txt 2012-03-07 19:16:49.000000000 +0100
24 --- runtime/doc/eval.txt 2012-06-20 18:01:02.000000000 +0200
27 localtime() Number current time
28 log( {expr}) Float natural logarithm (base e) of {expr}
29 log10( {expr}) Float logarithm of Float {expr} to base 10
30 map( {expr}, {string}) List/Dict change each item in {expr} to {expr}
31 maparg( {name}[, {mode} [, {abbr} [, {dict}]]])
32 ! String rhs of mapping {name} in mode {mode}
33 mapcheck( {name}[, {mode} [, {abbr}]])
34 String check for mappings matching {name}
35 match( {expr}, {pat}[, {start}[, {count}]])
37 localtime() Number current time
38 log( {expr}) Float natural logarithm (base e) of {expr}
39 log10( {expr}) Float logarithm of Float {expr} to base 10
40 + luaeval( {expr}[, {expr}]) any evaluate |Lua| expression
41 map( {expr}, {string}) List/Dict change each item in {expr} to {expr}
42 maparg( {name}[, {mode} [, {abbr} [, {dict}]]])
44 ! rhs of mapping {name} in mode {mode}
45 mapcheck( {name}[, {mode} [, {abbr}]])
46 String check for mappings matching {name}
47 match( {expr}, {pat}[, {start}[, {count}]])
51 prevnonblank( {lnum}) Number line nr of non-blank line <= {lnum}
52 printf( {fmt}, {expr1}...) String format text
53 pumvisible() Number whether popup menu is visible
54 + pyeval( {expr}) any evaluate |Python| expression
55 + py3eval( {expr}) any evaluate |python3| expression
56 range( {expr} [, {max} [, {stride}]])
57 List items from {expr} to {max}
58 readfile( {fname} [, {binary} [, {max}]])
63 {only available when compiled with the |+float| feature}
65 + luaeval({expr}[, {expr}]) *luaeval()*
66 + Evaluate Lua expression {expr} and return its result converted
67 + to Vim data structures. Second {expr} may hold additional
68 + argument accessible as _A inside first {expr}.
69 + Strings are returned as they are.
70 + Boolean objects are converted to numbers.
71 + Numbers are converted to |Float| values if vim was compiled
72 + with |+float| and to numbers otherwise.
73 + Dictionaries and lists obtained by vim.eval() are returned
75 + Other objects are returned as zero without any errors.
76 + See |lua-luaeval| for more details.
77 + {only available when compiled with the |+lua| feature}
79 map({expr}, {string}) *map()*
80 {expr} must be a |List| or a |Dictionary|.
81 Replace each item in {expr} with the result of evaluating
85 This can be used to avoid some things that would remove the
89 + py3eval({expr}) *py3eval()*
90 + Evaluate Python expression {expr} and return its result
91 + converted to Vim data structures.
92 + Numbers and strings are returned as they are (strings are
93 + copied though, unicode strings are additionally converted to
95 + Lists are represented as Vim |List| type.
96 + Dictionaries are represented as Vim |Dictionary| type with
97 + keys converted to strings.
98 + {only available when compiled with the |+python3| feature}
101 + pyeval({expr}) *pyeval()*
102 + Evaluate Python expression {expr} and return its result
103 + converted to Vim data structures.
104 + Numbers and strings are returned as they are (strings are
106 + Lists are represented as Vim |List| type.
107 + Dictionaries are represented as Vim |Dictionary| type with
108 + keys converted to strings.
109 + {only available when compiled with the |+python| feature}
112 range({expr} [, {max} [, {stride}]]) *range()*
113 Returns a |List| with Numbers:
117 Search for regexp pattern {pattern}. The search starts at the
118 cursor position (you can use |cursor()| to set it).
120 + If there is no match a 0 is returned and the cursor doesn't
121 + move. No error message is given.
122 + When a match has been found its line number is returned.
124 {flags} is a String, which can contain these character flags:
125 'b' search backward instead of forward
126 'c' accept a match at the cursor position
127 *** ../vim-7.3.568/runtime/doc/if_pyth.txt 2010-08-15 21:57:12.000000000 +0200
128 --- runtime/doc/if_pyth.txt 2012-06-20 18:01:02.000000000 +0200
131 ! *if_pyth.txt* For Vim version 7.3. Last change: 2010 Aug 13
134 VIM REFERENCE MANUAL by Paul Moore
136 ! *if_pyth.txt* For Vim version 7.3. Last change: 2012 Feb 04
139 VIM REFERENCE MANUAL by Paul Moore
143 The Python Interface to Vim *python* *Python*
145 ! 1. Commands |python-commands|
146 ! 2. The vim module |python-vim|
147 ! 3. Buffer objects |python-buffer|
148 ! 4. Range objects |python-range|
149 ! 5. Window objects |python-window|
150 ! 6. Dynamic loading |python-dynamic|
151 ! 7. Python 3 |python3|
153 {Vi does not have any of these commands}
157 The Python Interface to Vim *python* *Python*
159 ! 1. Commands |python-commands|
160 ! 2. The vim module |python-vim|
161 ! 3. Buffer objects |python-buffer|
162 ! 4. Range objects |python-range|
163 ! 5. Window objects |python-window|
164 ! 6. pyeval(), py3eval() Vim functions |python-pyeval|
165 ! 7. Dynamic loading |python-dynamic|
166 ! 8. Python 3 |python3|
168 {Vi does not have any of these commands}
173 [{'cmd': '/^eval_expr(arg, nextcmd)$/', 'static': 0, 'name':
174 'eval_expr', 'kind': 'f', 'filename': './src/eval.c'}]
176 + vim.bindeval(str) *python-bindeval*
177 + Like |python-eval|, but
178 + 1. if expression evaluates to |List| or |Dictionary| it is returned as
179 + vimlist or vimdictionary python type that are connected to original
180 + list or dictionary. Thus modifications to these objects imply
181 + modifications of the original.
182 + 2. if expression evaluates to a function reference, then it returns
183 + callable vimfunction object. Use self keyword argument to assign
184 + |self| object for dictionary functions.
186 + Note: this function has the same behavior as |lua-eval| (except that
187 + lua does not support running vim functions), |python-eval| is
188 + kept for backwards compatibility in order not to make scripts
189 + relying on outputs of vim.eval() being a copy of original or
190 + vim.eval("1") returning a string.
194 Error object of the "vim" module
197 - from indexing vim.buffers (|python-buffers|)
198 - from the "buffer" attribute of a window (|python-window|)
200 ! Buffer objects have one read-only attribute - name - the full file name for
201 ! the buffer. They also have three methods (append, mark, and range; see below).
203 You can also treat buffer objects as sequence objects. In this context, they
204 act as if they were lists (yes, they are mutable) of strings, with each
206 - from indexing vim.buffers (|python-buffers|)
207 - from the "buffer" attribute of a window (|python-window|)
209 ! Buffer objects have two read-only attributes - name - the full file name for
210 ! the buffer, and number - the buffer number. They also have three methods
211 ! (append, mark, and range; see below).
213 You can also treat buffer objects as sequence objects. In this context, they
214 act as if they were lists (yes, they are mutable) of strings, with each
217 The width attribute is writable only if the screen is split vertically.
219 ==============================================================================
220 ! 6. Dynamic loading *python-dynamic*
222 On MS-Windows the Python library can be loaded dynamically. The |:version|
223 output then includes |+python/dyn|.
225 The width attribute is writable only if the screen is split vertically.
227 ==============================================================================
228 ! 6. pyeval() and py3eval() Vim functions *python-pyeval*
230 ! To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()|
231 ! functions to evaluate Python expressions and pass their values to VimL.
233 ! ==============================================================================
234 ! 7. Dynamic loading *python-dynamic*
236 On MS-Windows the Python library can be loaded dynamically. The |:version|
237 output then includes |+python/dyn|.
240 sure edit "gvim.exe" and search for "python\d*.dll\c".
242 ==============================================================================
243 ! 7. Python 3 *python3*
246 The |:py3| and |:python3| commands work similar to |:python|.
248 The |:py3file| command works similar to |:pyfile|.
250 Vim can be built in four ways (:version output):
251 1. No Python support (-python, -python3)
252 2. Python 2 support only (+python or +python/dyn, -python3)
254 sure edit "gvim.exe" and search for "python\d*.dll\c".
256 ==============================================================================
257 ! 8. Python 3 *python3*
260 The |:py3| and |:python3| commands work similar to |:python|.
262 The |:py3file| command works similar to |:pyfile|.
265 Vim can be built in four ways (:version output):
266 1. No Python support (-python, -python3)
267 2. Python 2 support only (+python or +python/dyn, -python3)
270 When doing this on Linux/Unix systems and importing global symbols, this leads
271 to a crash when the second Python version is used. So either global symbols
272 are loaded but only one Python version is activated, or no global symbols are
273 ! loaded. The latter makes Python's "import" fail on libaries that expect the
274 symbols to be provided by Vim.
276 Vim's configuration script makes a guess for all libraries based on one
278 When doing this on Linux/Unix systems and importing global symbols, this leads
279 to a crash when the second Python version is used. So either global symbols
280 are loaded but only one Python version is activated, or no global symbols are
281 ! loaded. The latter makes Python's "import" fail on libraries that expect the
282 symbols to be provided by Vim.
284 Vim's configuration script makes a guess for all libraries based on one
288 3. You undefine PY_NO_RTLD_GLOBAL in auto/config.h after configuration. This
289 may crash Vim though.
292 + You can test what Python version is available with: >
294 + echo 'there is Python 2.x'
295 + elseif has('python3')
296 + echo 'there is Python 3.x'
299 + Note however, that when Python 2 and 3 are both available and loaded
300 + dynamically, these has() calls will try to load them. If only one can be
301 + loaded at a time, just checking if Python 2 or 3 are available will prevent
302 + the other one from being available.
304 ==============================================================================
305 vim:tw=78:ts=8:ft=help:norl:
306 *** ../vim-7.3.568/src/eval.c 2012-06-20 14:13:02.000000000 +0200
307 --- src/eval.c 2012-06-20 18:29:15.000000000 +0200
310 static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
311 static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
312 static int rettv_list_alloc __ARGS((typval_T *rettv));
313 - static listitem_T *listitem_alloc __ARGS((void));
314 static void listitem_free __ARGS((listitem_T *item));
315 - static void listitem_remove __ARGS((list_T *l, listitem_T *item));
316 static long list_len __ARGS((list_T *l));
317 static int list_equal __ARGS((list_T *l1, list_T *l2, int ic, int recursive));
318 static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic, int recursive));
319 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic, int recursive));
320 - static listitem_T *list_find __ARGS((list_T *l, long n));
321 static long list_find_nr __ARGS((list_T *l, long idx, int *errorp));
322 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
323 - static void list_append __ARGS((list_T *l, listitem_T *item));
324 static int list_append_number __ARGS((list_T *l, varnumber_T n));
325 - static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
326 static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef));
327 static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv));
328 static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID));
329 - static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
330 static char_u *list2string __ARGS((typval_T *tv, int copyID));
331 static int list_join_inner __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo_style, int copyID, garray_T *join_gap));
332 static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID));
333 static int free_unref_items __ARGS((int copyID));
334 - static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
335 - static void set_ref_in_list __ARGS((list_T *l, int copyID));
336 - static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
337 static int rettv_dict_alloc __ARGS((typval_T *rettv));
338 static void dict_free __ARGS((dict_T *d, int recurse));
339 static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
344 static void f_prevnonblank __ARGS((typval_T *argvars, typval_T *rettv));
345 static void f_printf __ARGS((typval_T *argvars, typval_T *rettv));
346 static void f_pumvisible __ARGS((typval_T *argvars, typval_T *rettv));
347 + #ifdef FEAT_PYTHON3
348 + static void f_py3eval __ARGS((typval_T *argvars, typval_T *rettv));
351 + static void f_pyeval __ARGS((typval_T *argvars, typval_T *rettv));
353 static void f_range __ARGS((typval_T *argvars, typval_T *rettv));
354 static void f_readfile __ARGS((typval_T *argvars, typval_T *rettv));
355 static void f_reltime __ARGS((typval_T *argvars, typval_T *rettv));
358 static char_u *autoload_name __ARGS((char_u *name));
359 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
360 static void func_free __ARGS((ufunc_T *fp));
361 - static void func_unref __ARGS((char_u *name));
362 - static void func_ref __ARGS((char_u *name));
363 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
364 static int can_free_funccal __ARGS((funccall_T *fc, int copyID)) ;
365 static void free_funccal __ARGS((funccall_T *fc, int free_val));
370 * Allocate a list item.
372 ! static listitem_T *
375 return (listitem_T *)alloc(sizeof(listitem_T));
378 * Allocate a list item.
383 return (listitem_T *)alloc(sizeof(listitem_T));
387 * Remove a list item from a List and free it. Also clears the value.
390 listitem_remove(l, item)
395 * Remove a list item from a List and free it. Also clears the value.
398 listitem_remove(l, item)
403 * A negative index is counted from the end; -1 is the last item.
404 * Returns NULL when "n" is out of range.
406 ! static listitem_T *
411 * A negative index is counted from the end; -1 is the last item.
412 * Returns NULL when "n" is out of range.
421 * Append item "item" to the end of list "l".
429 * Append item "item" to the end of list "l".
437 * If "item" is NULL append at the end.
438 * Return FAIL when out of memory.
441 list_insert_tv(l, tv, item)
445 * If "item" is NULL append at the end.
446 * Return FAIL when out of memory.
449 list_insert_tv(l, tv, item)
454 * Remove items "item" to "item2" from list "l".
455 * Does not free the listitem or the value!
458 list_remove(l, item, item2)
462 * Remove items "item" to "item2" from list "l".
463 * Does not free the listitem or the value!
466 list_remove(l, item, item2)
472 set_ref_in_lua(copyID);
476 + set_ref_in_python(copyID);
479 + #ifdef FEAT_PYTHON3
480 + set_ref_in_python3(copyID);
484 * 2. Free lists and dictionaries that are not referenced.
489 * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
492 set_ref_in_ht(ht, copyID)
497 * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
500 set_ref_in_ht(ht, copyID)
506 * Mark all lists and dicts referenced through list "l" with "copyID".
509 set_ref_in_list(l, copyID)
514 * Mark all lists and dicts referenced through list "l" with "copyID".
517 set_ref_in_list(l, copyID)
523 * Mark all lists and dicts referenced through typval "tv" with "copyID".
526 set_ref_in_item(tv, copyID)
531 * Mark all lists and dicts referenced through typval "tv" with "copyID".
534 set_ref_in_item(tv, copyID)
540 {"prevnonblank", 1, 1, f_prevnonblank},
541 {"printf", 2, 19, f_printf},
542 {"pumvisible", 0, 0, f_pumvisible},
543 + #ifdef FEAT_PYTHON3
544 + {"py3eval", 1, 1, f_py3eval},
547 + {"pyeval", 1, 1, f_pyeval},
549 {"range", 1, 3, f_range},
550 {"readfile", 1, 3, f_readfile},
551 {"reltime", 0, 2, f_reltime},
559 + func_call(name, args, selfdict, rettv)
566 + typval_T argv[MAX_FUNC_ARGS + 1];
571 + for (item = args->vval.v_list->lv_first; item != NULL;
572 + item = item->li_next)
574 + if (argc == MAX_FUNC_ARGS)
576 + EMSG(_("E699: Too many arguments"));
579 + /* Make a copy of each argument. This is needed to be able to set
580 + * v_lock to VAR_FIXED in the copy without changing the original list.
582 + copy_tv(&item->li_tv, &argv[argc++]);
586 + r = call_func(name, (int)STRLEN(name), rettv, argc, argv,
587 + curwin->w_cursor.lnum, curwin->w_cursor.lnum,
588 + &dummy, TRUE, selfdict);
590 + /* Free the arguments. */
592 + clear_tv(&argv[--argc]);
598 * "call(func, arglist)" function
605 - typval_T argv[MAX_FUNC_ARGS + 1];
609 dict_T *selfdict = NULL;
611 if (argvars[1].v_type != VAR_LIST)
615 selfdict = argvars[2].vval.v_dict;
618 ! for (item = argvars[1].vval.v_list->lv_first; item != NULL;
619 ! item = item->li_next)
621 ! if (argc == MAX_FUNC_ARGS)
623 ! EMSG(_("E699: Too many arguments"));
626 ! /* Make a copy of each argument. This is needed to be able to set
627 ! * v_lock to VAR_FIXED in the copy without changing the original list.
629 ! copy_tv(&item->li_tv, &argv[argc++]);
633 ! (void)call_func(func, (int)STRLEN(func), rettv, argc, argv,
634 ! curwin->w_cursor.lnum, curwin->w_cursor.lnum,
635 ! &dummy, TRUE, selfdict);
637 ! /* Free the arguments. */
639 ! clear_tv(&argv[--argc]);
644 selfdict = argvars[2].vval.v_dict;
647 ! (void)func_call(func, &argvars[1], selfdict, rettv);
657 + #ifdef FEAT_PYTHON3
659 + * "py3eval()" function
662 + f_py3eval(argvars, rettv)
667 + char_u buf[NUMBUFLEN];
669 + str = get_tv_string_buf(&argvars[0], buf);
670 + do_py3eval(str, rettv);
676 + * "pyeval()" function
679 + f_pyeval(argvars, rettv)
684 + char_u buf[NUMBUFLEN];
686 + str = get_tv_string_buf(&argvars[0], buf);
687 + do_pyeval(str, rettv);
696 * Unreference a Function: decrement the reference count and free it when it
697 * becomes zero. Only for numbered functions.
704 * Unreference a Function: decrement the reference count and free it when it
705 * becomes zero. Only for numbered functions.
714 * Count a reference to a Function.
722 * Count a reference to a Function.
728 *** ../vim-7.3.568/src/if_lua.c 2012-04-06 14:30:55.000000000 +0200
729 --- src/if_lua.c 2012-06-20 18:16:33.000000000 +0200
732 lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
733 lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
734 void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
736 int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
737 ! int ctx, lua_CFunction k);
738 void (*dll_lua_getglobal) (lua_State *L, const char *var);
739 void (*dll_lua_setglobal) (lua_State *L, const char *var);
742 lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
743 lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
744 void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
746 int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
747 ! int ctx, lua_CFunction k);
748 void (*dll_lua_getglobal) (lua_State *L, const char *var);
749 void (*dll_lua_setglobal) (lua_State *L, const char *var);
753 luaL_typeerror (lua_State *L, int narg, const char *tname)
755 const char *msg = lua_pushfstring(L, "%s expected, got %s",
756 ! tname, luaL_typename(L, narg));
757 return luaL_argerror(L, narg, msg);
761 luaL_typeerror (lua_State *L, int narg, const char *tname)
763 const char *msg = lua_pushfstring(L, "%s expected, got %s",
764 ! tname, luaL_typename(L, narg));
765 return luaL_argerror(L, narg, msg);
774 - /* adapted from eval.c */
776 - #define listitem_alloc() (listitem_T *)alloc(sizeof(listitem_T))
778 - static listitem_T *
779 - list_find (list_T *l, long n)
782 - if (l == NULL || n < -l->lv_len || n >= l->lv_len)
784 - if (n < 0) /* search backward? */
785 - for (li = l->lv_last; n < -1; li = li->li_prev)
787 - else /* search forward */
788 - for (li = l->lv_first; n > 0; li = li->li_next)
794 - list_remove (list_T *l, listitem_T *li)
799 - for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
800 - if (lw->lw_item == li)
801 - lw->lw_item = li->li_next;
802 - /* fix list pointers */
803 - if (li->li_next == NULL) /* last? */
804 - l->lv_last = li->li_prev;
806 - li->li_next->li_prev = li->li_prev;
807 - if (li->li_prev == NULL) /* first? */
808 - l->lv_first = li->li_next;
810 - li->li_prev->li_next = li->li_next;
811 - l->lv_idx_item = NULL;
815 - list_append(list_T *l, listitem_T *item)
817 - if (l->lv_last == NULL) /* empty list? */
818 - l->lv_first = item;
820 - l->lv_last->li_next = item;
821 - item->li_prev = l->lv_last;
822 - item->li_next = NULL;
828 - list_insert_tv(list_T *l, typval_T *tv, listitem_T *item)
830 - listitem_T *ni = listitem_alloc();
834 - copy_tv(tv, &ni->li_tv);
836 - list_append(l, ni);
839 - ni->li_prev = item->li_prev;
840 - ni->li_next = item;
841 - if (item->li_prev == NULL)
848 - item->li_prev->li_next = ni;
849 - l->lv_idx_item = NULL;
851 - item->li_prev = ni;
857 - /* set references */
859 - static void set_ref_in_tv (typval_T *tv, int copyID);
862 - set_ref_in_dict(dict_T *d, int copyID)
864 - hashtab_T *ht = &d->dv_hashtab;
865 - int n = ht->ht_used;
867 - for (hi = ht->ht_array; n > 0; ++hi)
868 - if (!HASHITEM_EMPTY(hi))
870 - dictitem_T *di = dict_lookup(hi);
871 - set_ref_in_tv(&di->di_tv, copyID);
877 - set_ref_in_list(list_T *l, int copyID)
880 - for (li = l->lv_first; li != NULL; li = li->li_next)
881 - set_ref_in_tv(&li->li_tv, copyID);
885 - set_ref_in_tv(typval_T *tv, int copyID)
887 - if (tv->v_type == VAR_LIST)
889 - list_T *l = tv->vval.v_list;
890 - if (l != NULL && l->lv_copyID != copyID)
892 - l->lv_copyID = copyID;
893 - set_ref_in_list(l, copyID);
896 - else if (tv->v_type == VAR_DICT)
898 - dict_T *d = tv->vval.v_dict;
899 - if (d != NULL && d->dv_copyID != copyID)
901 - d->dv_copyID = copyID;
902 - set_ref_in_dict(d, copyID);
908 /* ======= List type ======= */
914 if (li == NULL) return 0;
915 if (lua_isnil(L, 3)) /* remove? */
917 ! list_remove(l, li);
918 clear_tv(&li->li_tv);
922 if (li == NULL) return 0;
923 if (lua_isnil(L, 3)) /* remove? */
925 ! list_remove(l, li, li);
926 clear_tv(&li->li_tv);
933 luaV_totypval(L, 2, &v);
934 ! copy_tv(&v, &li->li_tv);
935 ! list_append(l, li);
942 luaV_totypval(L, 2, &v);
943 ! list_append_tv(l, &v);
949 tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
951 lua_pop(L, 2); /* metatable and value */
952 ! set_ref_in_tv(&tv, copyID);
957 tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
959 lua_pop(L, 2); /* metatable and value */
960 ! set_ref_in_item(&tv, copyID);
964 *** ../vim-7.3.568/src/if_py_both.h 2012-04-20 13:31:16.000000000 +0200
965 --- src/if_py_both.h 2012-06-29 12:03:52.000000000 +0200
968 ! /* vi:set ts=8 sts=4 sw=4:
970 * VIM - Vi IMproved by Bram Moolenaar
973 ! /* vi:set ts=8 sts=4 sw=4 noet:
975 * VIM - Vi IMproved by Bram Moolenaar
982 ! if (!PyList_Check(list)) {
983 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
990 ! if (!PyList_Check(list))
992 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
1000 ! if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len)) {
1001 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
1008 ! if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len))
1010 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
1018 ! char ptrBuf[NUMBUFLEN];
1020 /* Avoid infinite recursion */
1026 ! char ptrBuf[sizeof(void *) * 2 + 3];
1028 /* Avoid infinite recursion */
1032 if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
1033 || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
1035 ! sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U,
1036 ! our_tv->v_type == VAR_LIST ? (long_u)our_tv->vval.v_list
1037 ! : (long_u)our_tv->vval.v_dict);
1038 result = PyDict_GetItemString(lookupDict, ptrBuf);
1042 if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
1043 || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
1045 ! sprintf(ptrBuf, "%p",
1046 ! our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
1047 ! : (void *)our_tv->vval.v_dict);
1048 result = PyDict_GetItemString(lookupDict, ptrBuf);
1056 ! PyDict_SetItemString(lookupDict, ptrBuf, result);
1058 ! for (hi = ht->ht_array; todo > 0; ++hi)
1060 ! if (!HASHITEM_EMPTY(hi))
1064 ! di = dict_lookup(hi);
1065 ! newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
1066 ! PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
1067 ! Py_DECREF(newObj);
1074 ! Py_INCREF(Py_None);
1083 ! VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
1089 ! PyObject *lookup_dict;
1091 ! if (!PyArg_ParseTuple(args, "s", &expr))
1094 ! Py_BEGIN_ALLOW_THREADS
1095 ! Python_Lock_Vim();
1096 ! our_tv = eval_expr((char_u *)expr, NULL);
1098 ! Python_Release_Vim();
1099 ! Py_END_ALLOW_THREADS
1101 ! if (our_tv == NULL)
1103 ! PyErr_SetVim(_("invalid expression"));
1107 - /* Convert the Vim type into a Python type. Create a dictionary that's
1108 - * used to check for recursive loops. */
1109 lookup_dict = PyDict_New();
1110 ! result = VimToPython(our_tv, 1, lookup_dict);
1111 Py_DECREF(lookup_dict);
1114 ! Py_BEGIN_ALLOW_THREADS
1115 ! Python_Lock_Vim();
1117 ! Python_Release_Vim();
1118 ! Py_END_ALLOW_THREADS
1122 ! PyErr_SetVim(_("expressions disabled at compile time"));
1128 ! * Vim module - Definitions
1131 ! static struct PyMethodDef VimMethods[] = {
1132 ! /* name, function, calling, documentation */
1133 ! {"command", VimCommand, 1, "Execute a Vim ex-mode command" },
1134 ! {"eval", VimEval, 1, "Evaluate an expression using Vim evaluator" },
1135 ! { NULL, NULL, 0, NULL }
1145 ! #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
1148 ! * Buffer list object - Implementation
1152 ! BufListLength(PyObject *self UNUSED)
1154 ! buf_T *b = firstbuf;
1167 ! BufListItem(PyObject *self UNUSED, PyInt n)
1171 ! for (b = firstbuf; b; b = b->b_next, --n)
1174 ! return BufferNew(b);
1177 ! PyErr_SetString(PyExc_IndexError, _("no such buffer"));
1187 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
1193 ! PyDict_SetItemString(lookupDict, ptrBuf, result);
1195 ! for (hi = ht->ht_array; todo > 0; ++hi)
1197 ! if (!HASHITEM_EMPTY(hi))
1201 ! di = dict_lookup(hi);
1202 ! newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
1203 ! PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
1204 ! Py_DECREF(newObj);
1211 ! Py_INCREF(Py_None);
1220 ! VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
1226 ! PyObject *lookup_dict;
1228 ! if (!PyArg_ParseTuple(args, "s", &expr))
1231 ! Py_BEGIN_ALLOW_THREADS
1232 ! Python_Lock_Vim();
1233 ! our_tv = eval_expr((char_u *)expr, NULL);
1235 ! Python_Release_Vim();
1236 ! Py_END_ALLOW_THREADS
1238 ! if (our_tv == NULL)
1240 ! PyErr_SetVim(_("invalid expression"));
1244 ! /* Convert the Vim type into a Python type. Create a dictionary that's
1245 ! * used to check for recursive loops. */
1246 ! lookup_dict = PyDict_New();
1247 ! result = VimToPython(our_tv, 1, lookup_dict);
1248 ! Py_DECREF(lookup_dict);
1251 ! Py_BEGIN_ALLOW_THREADS
1252 ! Python_Lock_Vim();
1254 ! Python_Release_Vim();
1255 ! Py_END_ALLOW_THREADS
1259 ! PyErr_SetVim(_("expressions disabled at compile time"));
1264 ! static PyObject *ConvertToPyObject(typval_T *);
1267 ! VimEvalPy(PyObject *self UNUSED, PyObject *args UNUSED)
1274 ! if (!PyArg_ParseTuple(args, "s", &expr))
1277 ! Py_BEGIN_ALLOW_THREADS
1278 ! Python_Lock_Vim();
1279 ! our_tv = eval_expr((char_u *)expr, NULL);
1281 ! Python_Release_Vim();
1282 ! Py_END_ALLOW_THREADS
1284 ! if (our_tv == NULL)
1286 ! PyErr_SetVim(_("invalid expression"));
1290 ! result = ConvertToPyObject(our_tv);
1291 ! Py_BEGIN_ALLOW_THREADS
1292 ! Python_Lock_Vim();
1294 ! Python_Release_Vim();
1295 ! Py_END_ALLOW_THREADS
1299 ! PyErr_SetVim(_("expressions disabled at compile time"));
1305 ! VimStrwidth(PyObject *self UNUSED, PyObject *args)
1309 ! if (!PyArg_ParseTuple(args, "s", &expr))
1312 ! return PyLong_FromLong(mb_string2cells((char_u *)expr, STRLEN(expr)));
1316 ! * Vim module - Definitions
1319 ! static struct PyMethodDef VimMethods[] = {
1320 ! /* name, function, calling, documentation */
1321 ! {"command", VimCommand, 1, "Execute a Vim ex-mode command" },
1322 ! {"eval", VimEval, 1, "Evaluate an expression using Vim evaluator" },
1323 ! {"bindeval", VimEvalPy, 1, "Like eval(), but returns objects attached to vim ones"},
1324 ! {"strwidth", VimStrwidth, 1, "Screen string width, counts <Tab> as having width 1"},
1325 ! { NULL, NULL, 0, NULL }
1334 ! #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
1337 ! * Buffer list object - Implementation
1341 ! BufListLength(PyObject *self UNUSED)
1343 ! buf_T *b = firstbuf;
1356 ! BufListItem(PyObject *self UNUSED, PyInt n)
1360 ! for (b = firstbuf; b; b = b->b_next, --n)
1363 ! return BufferNew(b);
1366 ! PyErr_SetString(PyExc_IndexError, _("no such buffer"));
1376 ! static int ConvertFromPyObject(PyObject *, typval_T *);
1377 ! static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
1379 ! typedef struct pylinkedlist_S {
1380 ! struct pylinkedlist_S *pll_next;
1381 ! struct pylinkedlist_S *pll_prev;
1382 ! PyObject *pll_obj;
1385 ! static pylinkedlist_T *lastdict = NULL;
1386 ! static pylinkedlist_T *lastlist = NULL;
1389 ! pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
1391 ! if (ref->pll_prev == NULL)
1393 ! if (ref->pll_next == NULL)
1400 ! ref->pll_prev->pll_next = ref->pll_next;
1402 ! if (ref->pll_next == NULL)
1403 ! *last = ref->pll_prev;
1405 ! ref->pll_next->pll_prev = ref->pll_prev;
1409 ! pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
1411 ! if (*last == NULL)
1412 ! ref->pll_prev = NULL;
1415 ! (*last)->pll_next = ref;
1416 ! ref->pll_prev = *last;
1418 ! ref->pll_next = NULL;
1419 ! ref->pll_obj = self;
1423 ! static PyTypeObject DictionaryType;
1429 ! pylinkedlist_T ref;
1430 ! } DictionaryObject;
1433 ! DictionaryNew(dict_T *dict)
1435 ! DictionaryObject *self;
1437 ! self = PyObject_NEW(DictionaryObject, &DictionaryType);
1440 ! self->dict = dict;
1441 ! ++dict->dv_refcount;
1443 ! pyll_add((PyObject *)(self), &self->ref, &lastdict);
1445 ! return (PyObject *)(self);
1449 ! pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1454 ! PyObject *keyObject;
1455 ! PyObject *valObject;
1456 ! Py_ssize_t iter = 0;
1465 ! tv->v_type = VAR_DICT;
1466 ! tv->vval.v_dict = d;
1468 ! while (PyDict_Next(obj, &iter, &keyObject, &valObject))
1472 ! if (keyObject == NULL)
1474 ! if (valObject == NULL)
1479 ! di = dictitem_alloc(key);
1488 ! di->di_tv.v_lock = 0;
1490 ! if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
1495 ! if (dict_add(d, di) == FAIL)
1498 ! PyErr_SetVim(_("failed to add key to dictionary"));
1506 ! pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1513 ! PyObject *keyObject;
1514 ! PyObject *valObject;
1524 ! tv->v_type = VAR_DICT;
1525 ! tv->vval.v_dict = d;
1527 ! list = PyMapping_Items(obj);
1528 ! lsize = PyList_Size(list);
1533 ! litem = PyList_GetItem(list, lsize);
1534 ! if (litem == NULL)
1540 ! keyObject = PyTuple_GetItem(litem, 0);
1541 ! if (keyObject == NULL)
1550 ! valObject = PyTuple_GetItem(litem, 1);
1551 ! if (valObject == NULL)
1558 ! di = dictitem_alloc(key);
1569 ! di->di_tv.v_lock = 0;
1571 ! if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
1578 ! if (dict_add(d, di) == FAIL)
1583 ! PyErr_SetVim(_("failed to add key to dictionary"));
1593 ! DictionaryLength(PyObject *self)
1595 ! return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used)));
1599 ! DictionaryItem(PyObject *self, PyObject *keyObject)
1607 ! val = dict_find(((DictionaryObject *) (self))->dict, key, -1);
1611 ! return ConvertToPyObject(&val->di_tv);
1615 ! DictionaryAssItem(PyObject *self, PyObject *keyObject, PyObject *valObject)
1619 ! dict_T *d = ((DictionaryObject *)(self))->dict;
1625 ! PyErr_SetVim(_("dict is locked"));
1631 ! di = dict_find(d, key, -1);
1633 ! if (valObject == NULL)
1637 ! PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
1640 ! hashitem_T *hi = hash_find(&d->dv_hashtab, di->di_key);
1641 ! hash_remove(&d->dv_hashtab, hi);
1642 ! dictitem_free(di);
1646 ! if (ConvertFromPyObject(valObject, &tv) == -1)
1653 ! di = dictitem_alloc(key);
1659 ! di->di_tv.v_lock = 0;
1661 ! if (dict_add(d, di) == FAIL)
1664 ! PyErr_SetVim(_("failed to add key to dictionary"));
1669 ! clear_tv(&di->di_tv);
1673 ! copy_tv(&tv, &di->di_tv);
1678 ! DictionaryListKeys(PyObject *self)
1680 ! dict_T *dict = ((DictionaryObject *)(self))->dict;
1681 ! long_u todo = dict->dv_hashtab.ht_used;
1686 ! r = PyList_New(todo);
1687 ! for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
1689 ! if (!HASHITEM_EMPTY(hi))
1691 ! PyList_SetItem(r, i, PyBytes_FromString((char *)(hi->hi_key)));
1699 ! static struct PyMethodDef DictionaryMethods[] = {
1700 ! {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
1701 ! { NULL, NULL, 0, NULL }
1704 ! static PyTypeObject ListType;
1710 ! pylinkedlist_T ref;
1714 ! ListNew(list_T *list)
1718 ! self = PyObject_NEW(ListObject, &ListType);
1721 ! self->list = list;
1722 ! ++list->lv_refcount;
1724 ! pyll_add((PyObject *)(self), &self->ref, &lastlist);
1726 ! return (PyObject *)(self);
1730 ! list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict)
1733 ! Py_ssize_t lsize = PySequence_Size(obj);
1737 ! for(i=0; i<lsize; i++)
1739 ! li = listitem_alloc();
1745 ! li->li_tv.v_lock = 0;
1747 ! litem = PySequence_GetItem(obj, i);
1748 ! if (litem == NULL)
1750 ! if (_ConvertFromPyObject(litem, &li->li_tv, lookupDict) == -1)
1753 ! list_append(l, li);
1759 ! pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1770 ! tv->v_type = VAR_LIST;
1771 ! tv->vval.v_list = l;
1773 ! if (list_py_concat(l, obj, lookupDict) == -1)
1780 ! pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1782 ! PyObject *iterator = PyObject_GetIter(obj);
1795 ! tv->vval.v_list = l;
1796 ! tv->v_type = VAR_LIST;
1799 ! if (iterator == NULL)
1802 ! while ((item = PyIter_Next(obj)))
1804 ! li = listitem_alloc();
1810 ! li->li_tv.v_lock = 0;
1812 ! if (_ConvertFromPyObject(item, &li->li_tv, lookupDict) == -1)
1815 ! list_append(l, li);
1820 ! Py_DECREF(iterator);
1825 ! ListLength(PyObject *self)
1827 ! return ((PyInt) (((ListObject *) (self))->list->lv_len));
1831 ! ListItem(PyObject *self, Py_ssize_t index)
1835 ! if (index>=ListLength(self))
1837 ! PyErr_SetString(PyExc_IndexError, "list index out of range");
1840 ! li = list_find(((ListObject *) (self))->list, (long) index);
1843 ! PyErr_SetVim(_("internal error: failed to get vim list item"));
1846 ! return ConvertToPyObject(&li->li_tv);
1849 ! #define PROC_RANGE \
1851 ! if (last < -size) \
1858 ! if (first > size) \
1860 ! if (last > size) \
1864 ! ListSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last)
1867 ! PyInt size = ListLength(self);
1873 ! if (first >= last)
1877 ! list = PyList_New(n);
1881 ! for (i = 0; i < n; ++i)
1883 ! PyObject *item = ListItem(self, i);
1890 ! if ((PyList_SetItem(list, ((reversed)?(n-i-1):(i)), item)))
1902 ! ListAssItem(PyObject *self, Py_ssize_t index, PyObject *obj)
1905 ! list_T *l = ((ListObject *) (self))->list;
1907 ! Py_ssize_t length = ListLength(self);
1911 ! PyErr_SetVim(_("list is locked"));
1914 ! if (index>length || (index==length && obj==NULL))
1916 ! PyErr_SetString(PyExc_IndexError, "list index out of range");
1922 ! li = list_find(l, (long) index);
1923 ! list_remove(l, li, li);
1924 ! clear_tv(&li->li_tv);
1929 ! if (ConvertFromPyObject(obj, &tv) == -1)
1932 ! if (index == length)
1934 ! if (list_append_tv(l, &tv) == FAIL)
1936 ! PyErr_SetVim(_("Failed to add item to list"));
1942 ! li = list_find(l, (long) index);
1943 ! clear_tv(&li->li_tv);
1944 ! copy_tv(&tv, &li->li_tv);
1950 ! ListAssSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
1952 ! PyInt size = ListLength(self);
1959 ! list_T *l = ((ListObject *) (self))->list;
1963 ! PyErr_SetVim(_("list is locked"));
1969 ! if (first == size)
1973 ! li = list_find(l, (long) first);
1976 ! PyErr_SetVim(_("internal error: no vim list item"));
1982 ! while (i-- && li != NULL)
1984 ! next = li->li_next;
1985 ! listitem_remove(l, li);
1994 ! if (!PyList_Check(obj))
1996 ! PyErr_SetString(PyExc_TypeError, _("can only assign lists to slice"));
2000 ! lsize = PyList_Size(obj);
2002 ! for(i=0; i<lsize; i++)
2004 ! litem = PyList_GetItem(obj, i);
2005 ! if (litem == NULL)
2007 ! if (ConvertFromPyObject(litem, &v) == -1)
2009 ! if (list_insert_tv(l, &v, li) == FAIL)
2011 ! PyErr_SetVim(_("internal error: failed to add item to list"));
2019 ! ListConcatInPlace(PyObject *self, PyObject *obj)
2021 ! list_T *l = ((ListObject *) (self))->list;
2022 ! PyObject *lookup_dict;
2026 ! PyErr_SetVim(_("list is locked"));
2030 ! if (!PySequence_Check(obj))
2032 ! PyErr_SetString(PyExc_TypeError, _("can only concatenate with lists"));
2036 lookup_dict = PyDict_New();
2037 ! if (list_py_concat(l, obj, lookup_dict) == -1)
2039 ! Py_DECREF(lookup_dict);
2042 Py_DECREF(lookup_dict);
2048 ! static struct PyMethodDef ListMethods[] = {
2049 ! {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
2050 ! { NULL, NULL, 0, NULL }
2059 ! static PyTypeObject FunctionType;
2062 ! FunctionNew(char_u *name)
2064 ! FunctionObject *self;
2066 ! self = PyObject_NEW(FunctionObject, &FunctionType);
2069 ! self->name = PyMem_New(char_u, STRLEN(name) + 1);
2070 ! if (self->name == NULL)
2075 ! STRCPY(self->name, name);
2077 ! return (PyObject *)(self);
2081 ! FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs)
2083 ! FunctionObject *this = (FunctionObject *)(self);
2084 ! char_u *name = this->name;
2086 ! typval_T selfdicttv;
2088 ! dict_T *selfdict = NULL;
2089 ! PyObject *selfdictObject;
2093 ! if (ConvertFromPyObject(argsObject, &args) == -1)
2096 ! if (kwargs != NULL)
2098 ! selfdictObject = PyDict_GetItemString(kwargs, "self");
2099 ! if (selfdictObject != NULL)
2101 ! if (!PyDict_Check(selfdictObject))
2103 ! PyErr_SetString(PyExc_TypeError, _("'self' argument must be a dictionary"));
2107 ! if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
2109 ! selfdict = selfdicttv.vval.v_dict;
2113 ! error = func_call(name, &args, selfdict, &rettv);
2117 ! PyErr_SetVim(_("failed to run function"));
2120 ! result = ConvertToPyObject(&rettv);
2122 ! /* FIXME Check what should really be cleared. */
2126 ! * if (selfdict!=NULL)
2127 ! * clear_tv(selfdicttv);
2133 ! static struct PyMethodDef FunctionMethods[] = {
2134 ! {"__call__", (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
2135 ! { NULL, NULL, 0, NULL }
2138 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
2143 { NULL, NULL, 0, NULL }
2147 + set_ref_in_py(const int copyID)
2149 + pylinkedlist_T *cur;
2153 + if (lastdict != NULL)
2154 + for(cur = lastdict ; cur != NULL ; cur = cur->pll_prev)
2156 + dd = ((DictionaryObject *) (cur->pll_obj))->dict;
2157 + if (dd->dv_copyID != copyID)
2159 + dd->dv_copyID = copyID;
2160 + set_ref_in_ht(&dd->dv_hashtab, copyID);
2164 + if (lastlist != NULL)
2165 + for(cur = lastlist ; cur != NULL ; cur = cur->pll_prev)
2167 + ll = ((ListObject *) (cur->pll_obj))->list;
2168 + if (ll->lv_copyID != copyID)
2170 + ll->lv_copyID = copyID;
2171 + set_ref_in_list(ll, copyID);
2177 + set_string_copy(char_u *str, typval_T *tv)
2179 + tv->vval.v_string = vim_strsave(str);
2180 + if (tv->vval.v_string == NULL)
2189 + typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
2192 + convert_dl(PyObject *obj, typval_T *tv,
2193 + pytotvfunc py_to_tv, PyObject *lookupDict)
2195 + PyObject *capsule;
2196 + char hexBuf[sizeof(void *) * 2 + 3];
2198 + sprintf(hexBuf, "%p", obj);
2200 + capsule = PyDict_GetItemString(lookupDict, hexBuf);
2201 + if (capsule == NULL)
2203 + capsule = PyCapsule_New(tv, NULL, NULL);
2204 + PyDict_SetItemString(lookupDict, hexBuf, capsule);
2205 + Py_DECREF(capsule);
2206 + if (py_to_tv(obj, tv, lookupDict) == -1)
2208 + tv->v_type = VAR_UNKNOWN;
2211 + /* As we are not using copy_tv which increments reference count we must
2212 + * do it ourself. */
2213 + switch(tv->v_type)
2215 + case VAR_DICT: ++tv->vval.v_dict->dv_refcount; break;
2216 + case VAR_LIST: ++tv->vval.v_list->lv_refcount; break;
2221 + typval_T *v = PyCapsule_GetPointer(capsule, NULL);
2228 + ConvertFromPyObject(PyObject *obj, typval_T *tv)
2230 + PyObject *lookup_dict;
2233 + lookup_dict = PyDict_New();
2234 + r = _ConvertFromPyObject(obj, tv, lookup_dict);
2235 + Py_DECREF(lookup_dict);
2240 + _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
2242 + if (obj->ob_type == &DictionaryType)
2244 + tv->v_type = VAR_DICT;
2245 + tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
2246 + ++tv->vval.v_dict->dv_refcount;
2248 + else if (obj->ob_type == &ListType)
2250 + tv->v_type = VAR_LIST;
2251 + tv->vval.v_list = (((ListObject *)(obj))->list);
2252 + ++tv->vval.v_list->lv_refcount;
2254 + else if (obj->ob_type == &FunctionType)
2256 + if (set_string_copy(((FunctionObject *) (obj))->name, tv) == -1)
2259 + tv->v_type = VAR_FUNC;
2260 + func_ref(tv->vval.v_string);
2262 + #if PY_MAJOR_VERSION >= 3
2263 + else if (PyBytes_Check(obj))
2265 + char_u *result = (char_u *) PyBytes_AsString(obj);
2267 + if (result == NULL)
2270 + if (set_string_copy(result, tv) == -1)
2273 + tv->v_type = VAR_STRING;
2275 + else if (PyUnicode_Check(obj))
2280 + bytes = PyString_AsBytes(obj);
2281 + if (bytes == NULL)
2284 + result = (char_u *) PyBytes_AsString(bytes);
2285 + if (result == NULL)
2288 + if (set_string_copy(result, tv) == -1)
2290 + Py_XDECREF(bytes);
2293 + Py_XDECREF(bytes);
2295 + tv->v_type = VAR_STRING;
2298 + else if (PyUnicode_Check(obj))
2303 + bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
2304 + if (bytes == NULL)
2307 + result=(char_u *) PyString_AsString(bytes);
2308 + if (result == NULL)
2311 + if (set_string_copy(result, tv) == -1)
2313 + Py_XDECREF(bytes);
2316 + Py_XDECREF(bytes);
2318 + tv->v_type = VAR_STRING;
2320 + else if (PyString_Check(obj))
2322 + char_u *result = (char_u *) PyString_AsString(obj);
2324 + if (result == NULL)
2327 + if (set_string_copy(result, tv) == -1)
2330 + tv->v_type = VAR_STRING;
2332 + else if (PyInt_Check(obj))
2334 + tv->v_type = VAR_NUMBER;
2335 + tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
2338 + else if (PyLong_Check(obj))
2340 + tv->v_type = VAR_NUMBER;
2341 + tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
2343 + else if (PyDict_Check(obj))
2344 + return convert_dl(obj, tv, pydict_to_tv, lookupDict);
2346 + else if (PyFloat_Check(obj))
2348 + tv->v_type = VAR_FLOAT;
2349 + tv->vval.v_float = (float_T) PyFloat_AsDouble(obj);
2352 + else if (PyIter_Check(obj))
2353 + return convert_dl(obj, tv, pyiter_to_tv, lookupDict);
2354 + else if (PySequence_Check(obj))
2355 + return convert_dl(obj, tv, pyseq_to_tv, lookupDict);
2356 + else if (PyMapping_Check(obj))
2357 + return convert_dl(obj, tv, pymap_to_tv, lookupDict);
2360 + PyErr_SetString(PyExc_TypeError, _("unable to convert to vim structure"));
2367 + ConvertToPyObject(typval_T *tv)
2371 + PyErr_SetVim(_("NULL reference passed"));
2374 + switch (tv->v_type)
2377 + return PyBytes_FromString((char *) tv->vval.v_string);
2379 + return PyLong_FromLong((long) tv->vval.v_number);
2382 + return PyFloat_FromDouble((double) tv->vval.v_float);
2385 + return ListNew(tv->vval.v_list);
2387 + return DictionaryNew(tv->vval.v_dict);
2389 + return FunctionNew(tv->vval.v_string);
2391 + Py_INCREF(Py_None);
2394 + PyErr_SetVim(_("internal error: invalid value type"));
2399 *** ../vim-7.3.568/src/if_python.c 2011-08-28 16:00:14.000000000 +0200
2400 --- src/if_python.c 2012-06-29 12:47:48.000000000 +0200
2403 ! /* vi:set ts=8 sts=4 sw=4:
2405 * VIM - Vi IMproved by Bram Moolenaar
2408 ! /* vi:set ts=8 sts=4 sw=4 noet:
2410 * VIM - Vi IMproved by Bram Moolenaar
2416 static void init_structs(void);
2418 + #define PyBytes_FromString PyString_FromString
2420 /* No-op conversion functions, use with care! */
2421 #define PyString_AsBytes(obj) (obj)
2422 #define PyString_FreeBytes(obj)
2426 /* This makes if_python.c compile without warnings against Python 2.5
2427 * on Win32 and Win64. */
2428 # undef PyRun_SimpleString
2429 + # undef PyRun_String
2431 # undef PyArg_ParseTuple
2432 # undef Py_BuildValue
2433 # undef Py_InitModule4
2434 # undef Py_InitModule4_64
2435 + # undef PyObject_CallMethod
2442 # define PyArg_Parse dll_PyArg_Parse
2443 # define PyArg_ParseTuple dll_PyArg_ParseTuple
2444 # define PyMem_Free dll_PyMem_Free
2445 + # define PyMem_Malloc dll_PyMem_Malloc
2446 # define PyDict_SetItemString dll_PyDict_SetItemString
2447 # define PyErr_BadArgument dll_PyErr_BadArgument
2448 # define PyErr_Clear dll_PyErr_Clear
2453 # define PyInt_AsLong dll_PyInt_AsLong
2454 # define PyInt_FromLong dll_PyInt_FromLong
2455 + # define PyLong_AsLong dll_PyLong_AsLong
2456 + # define PyLong_FromLong dll_PyLong_FromLong
2457 # define PyInt_Type (*dll_PyInt_Type)
2458 + # define PyLong_Type (*dll_PyLong_Type)
2459 # define PyList_GetItem dll_PyList_GetItem
2460 # define PyList_Append dll_PyList_Append
2461 # define PyList_New dll_PyList_New
2462 # define PyList_SetItem dll_PyList_SetItem
2463 # define PyList_Size dll_PyList_Size
2464 # define PyList_Type (*dll_PyList_Type)
2465 + # define PySequence_Check dll_PySequence_Check
2466 + # define PySequence_Size dll_PySequence_Size
2467 + # define PySequence_GetItem dll_PySequence_GetItem
2468 + # define PyTuple_Size dll_PyTuple_Size
2469 + # define PyTuple_GetItem dll_PyTuple_GetItem
2470 + # define PyTuple_Type (*dll_PyTuple_Type)
2471 # define PyImport_ImportModule dll_PyImport_ImportModule
2472 # define PyDict_New dll_PyDict_New
2473 # define PyDict_GetItemString dll_PyDict_GetItemString
2474 + # define PyDict_Next dll_PyDict_Next
2475 + # ifdef PyMapping_Items
2476 + # define PY_NO_MAPPING_ITEMS
2478 + # define PyMapping_Items dll_PyMapping_Items
2480 + # define PyObject_CallMethod dll_PyObject_CallMethod
2481 + # define PyMapping_Check dll_PyMapping_Check
2482 + # define PyIter_Next dll_PyIter_Next
2483 # define PyModule_GetDict dll_PyModule_GetDict
2484 # define PyRun_SimpleString dll_PyRun_SimpleString
2485 + # define PyRun_String dll_PyRun_String
2486 # define PyString_AsString dll_PyString_AsString
2487 # define PyString_FromString dll_PyString_FromString
2488 # define PyString_FromStringAndSize dll_PyString_FromStringAndSize
2489 # define PyString_Size dll_PyString_Size
2490 # define PyString_Type (*dll_PyString_Type)
2491 + # define PyUnicode_Type (*dll_PyUnicode_Type)
2492 + # define PyUnicodeUCS4_AsEncodedString (*dll_PyUnicodeUCS4_AsEncodedString)
2493 + # define PyFloat_AsDouble dll_PyFloat_AsDouble
2494 + # define PyFloat_FromDouble dll_PyFloat_FromDouble
2495 + # define PyFloat_Type (*dll_PyFloat_Type)
2496 + # define PyImport_AddModule (*dll_PyImport_AddModule)
2497 # define PySys_SetObject dll_PySys_SetObject
2498 # define PySys_SetArgv dll_PySys_SetArgv
2499 # define PyType_Type (*dll_PyType_Type)
2503 # define Py_Finalize dll_Py_Finalize
2504 # define Py_IsInitialized dll_Py_IsInitialized
2505 # define _PyObject_New dll__PyObject_New
2506 + # define _PyObject_NextNotImplemented (*dll__PyObject_NextNotImplemented)
2507 # define _Py_NoneStruct (*dll__Py_NoneStruct)
2508 # define PyObject_Init dll__PyObject_Init
2509 + # define PyObject_GetIter dll_PyObject_GetIter
2510 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
2511 # define PyType_IsSubtype dll_PyType_IsSubtype
2516 # define PyObject_Malloc dll_PyObject_Malloc
2517 # define PyObject_Free dll_PyObject_Free
2519 + # define PyCapsule_New dll_PyCapsule_New
2520 + # define PyCapsule_GetPointer dll_PyCapsule_GetPointer
2523 * Pointers for dynamic link
2527 static int(*dll_PyArg_Parse)(PyObject *, char *, ...);
2528 static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...);
2529 static int(*dll_PyMem_Free)(void *);
2530 + static void* (*dll_PyMem_Malloc)(size_t);
2531 static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
2532 static int(*dll_PyErr_BadArgument)(void);
2533 static void(*dll_PyErr_Clear)(void);
2536 # ifdef PY_CAN_RECURSE
2537 static PyGILState_STATE (*dll_PyGILState_Ensure)(void);
2538 static void (*dll_PyGILState_Release)(PyGILState_STATE);
2540 static long(*dll_PyInt_AsLong)(PyObject *);
2541 static PyObject*(*dll_PyInt_FromLong)(long);
2542 static PyTypeObject* dll_PyInt_Type;
2543 static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt);
2544 static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *);
2545 static PyObject*(*dll_PyList_New)(PyInt size);
2546 static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *);
2547 static PyInt(*dll_PyList_Size)(PyObject *);
2548 static PyTypeObject* dll_PyList_Type;
2549 static PyObject*(*dll_PyImport_ImportModule)(const char *);
2550 static PyObject*(*dll_PyDict_New)(void);
2551 static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *);
2552 static PyObject*(*dll_PyModule_GetDict)(PyObject *);
2553 static int(*dll_PyRun_SimpleString)(char *);
2554 static char*(*dll_PyString_AsString)(PyObject *);
2555 static PyObject*(*dll_PyString_FromString)(const char *);
2556 static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
2557 static PyInt(*dll_PyString_Size)(PyObject *);
2558 static PyTypeObject* dll_PyString_Type;
2559 static int(*dll_PySys_SetObject)(char *, PyObject *);
2560 static int(*dll_PySys_SetArgv)(int, char **);
2561 static PyTypeObject* dll_PyType_Type;
2563 # ifdef PY_CAN_RECURSE
2564 static PyGILState_STATE (*dll_PyGILState_Ensure)(void);
2565 static void (*dll_PyGILState_Release)(PyGILState_STATE);
2567 static long(*dll_PyInt_AsLong)(PyObject *);
2568 static PyObject*(*dll_PyInt_FromLong)(long);
2569 + static long(*dll_PyLong_AsLong)(PyObject *);
2570 + static PyObject*(*dll_PyLong_FromLong)(long);
2571 static PyTypeObject* dll_PyInt_Type;
2572 + static PyTypeObject* dll_PyLong_Type;
2573 static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt);
2574 static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *);
2575 static PyObject*(*dll_PyList_New)(PyInt size);
2576 static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *);
2577 static PyInt(*dll_PyList_Size)(PyObject *);
2578 static PyTypeObject* dll_PyList_Type;
2579 + static int (*dll_PySequence_Check)(PyObject *);
2580 + static PyInt(*dll_PySequence_Size)(PyObject *);
2581 + static PyObject*(*dll_PySequence_GetItem)(PyObject *, PyInt);
2582 + static PyInt(*dll_PyTuple_Size)(PyObject *);
2583 + static PyObject*(*dll_PyTuple_GetItem)(PyObject *, PyInt);
2584 + static PyTypeObject* dll_PyTuple_Type;
2585 static PyObject*(*dll_PyImport_ImportModule)(const char *);
2586 static PyObject*(*dll_PyDict_New)(void);
2587 static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *);
2588 + static int (*dll_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **);
2589 + # ifndef PY_NO_MAPPING_ITEMS
2590 + static PyObject* (*dll_PyMapping_Items)(PyObject *);
2592 + static PyObject* (*dll_PyObject_CallMethod)(PyObject *, char *, PyObject *);
2593 + static int (*dll_PyMapping_Check)(PyObject *);
2594 + static PyObject* (*dll_PyIter_Next)(PyObject *);
2595 static PyObject*(*dll_PyModule_GetDict)(PyObject *);
2596 static int(*dll_PyRun_SimpleString)(char *);
2597 + static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *);
2598 static char*(*dll_PyString_AsString)(PyObject *);
2599 static PyObject*(*dll_PyString_FromString)(const char *);
2600 static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
2601 static PyInt(*dll_PyString_Size)(PyObject *);
2602 static PyTypeObject* dll_PyString_Type;
2603 + static PyTypeObject* dll_PyUnicode_Type;
2604 + static PyObject *(*PyUnicodeUCS4_AsEncodedString)(PyObject *, char *, char *);
2605 + static double(*dll_PyFloat_AsDouble)(PyObject *);
2606 + static PyObject*(*dll_PyFloat_FromDouble)(double);
2607 + static PyTypeObject* dll_PyFloat_Type;
2608 static int(*dll_PySys_SetObject)(char *, PyObject *);
2609 static int(*dll_PySys_SetArgv)(int, char **);
2610 static PyTypeObject* dll_PyType_Type;
2614 static PyObject*(*dll_Py_BuildValue)(char *, ...);
2615 static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *);
2616 static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int);
2617 + static PyObject*(*dll_PyImport_AddModule)(char *);
2618 static void(*dll_Py_SetPythonHome)(char *home);
2619 static void(*dll_Py_Initialize)(void);
2620 static void(*dll_Py_Finalize)(void);
2621 static int(*dll_Py_IsInitialized)(void);
2622 static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *);
2623 static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *);
2624 + static PyObject* (*dll_PyObject_GetIter)(PyObject *);
2625 + static iternextfunc dll__PyObject_NextNotImplemented;
2626 static PyObject* dll__Py_NoneStruct;
2627 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
2628 static int (*dll_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
2632 static void* (*dll_PyObject_Malloc)(size_t);
2633 static void (*dll_PyObject_Free)(void*);
2635 + static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
2636 + static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *);
2638 static HINSTANCE hinstPython = 0; /* Instance of python.dll */
2643 {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse},
2644 {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple},
2645 {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free},
2646 + {"PyMem_Malloc", (PYTHON_PROC*)&dll_PyMem_Malloc},
2647 {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString},
2648 {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument},
2649 {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear},
2654 {"PyInt_AsLong", (PYTHON_PROC*)&dll_PyInt_AsLong},
2655 {"PyInt_FromLong", (PYTHON_PROC*)&dll_PyInt_FromLong},
2656 + {"PyLong_AsLong", (PYTHON_PROC*)&dll_PyLong_AsLong},
2657 + {"PyLong_FromLong", (PYTHON_PROC*)&dll_PyLong_FromLong},
2658 {"PyInt_Type", (PYTHON_PROC*)&dll_PyInt_Type},
2659 + {"PyLong_Type", (PYTHON_PROC*)&dll_PyLong_Type},
2660 {"PyList_GetItem", (PYTHON_PROC*)&dll_PyList_GetItem},
2661 {"PyList_Append", (PYTHON_PROC*)&dll_PyList_Append},
2662 {"PyList_New", (PYTHON_PROC*)&dll_PyList_New},
2663 {"PyList_SetItem", (PYTHON_PROC*)&dll_PyList_SetItem},
2664 {"PyList_Size", (PYTHON_PROC*)&dll_PyList_Size},
2665 {"PyList_Type", (PYTHON_PROC*)&dll_PyList_Type},
2666 + {"PySequence_GetItem", (PYTHON_PROC*)&dll_PySequence_GetItem},
2667 + {"PySequence_Size", (PYTHON_PROC*)&dll_PySequence_Size},
2668 + {"PySequence_Check", (PYTHON_PROC*)&dll_PySequence_Check},
2669 + {"PyTuple_GetItem", (PYTHON_PROC*)&dll_PyTuple_GetItem},
2670 + {"PyTuple_Size", (PYTHON_PROC*)&dll_PyTuple_Size},
2671 + {"PyTuple_Type", (PYTHON_PROC*)&dll_PyTuple_Type},
2672 {"PyImport_ImportModule", (PYTHON_PROC*)&dll_PyImport_ImportModule},
2673 {"PyDict_GetItemString", (PYTHON_PROC*)&dll_PyDict_GetItemString},
2674 + {"PyDict_Next", (PYTHON_PROC*)&dll_PyDict_Next},
2675 {"PyDict_New", (PYTHON_PROC*)&dll_PyDict_New},
2676 + # ifndef PY_NO_MAPPING_ITEMS
2677 + {"PyMapping_Items", (PYTHON_PROC*)&dll_PyMapping_Items},
2679 + {"PyObject_CallMethod", (PYTHON_PROC*)&dll_PyObject_CallMethod},
2680 + {"PyMapping_Check", (PYTHON_PROC*)&dll_PyMapping_Check},
2681 + {"PyIter_Next", (PYTHON_PROC*)&dll_PyIter_Next},
2682 {"PyModule_GetDict", (PYTHON_PROC*)&dll_PyModule_GetDict},
2683 {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString},
2684 + {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String},
2685 {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString},
2686 {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString},
2687 {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize},
2688 {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size},
2689 {"PyString_Type", (PYTHON_PROC*)&dll_PyString_Type},
2690 + {"PyUnicode_Type", (PYTHON_PROC*)&dll_PyUnicode_Type},
2691 + {"PyUnicodeUCS4_AsEncodedString", (PYTHON_PROC*)&dll_PyUnicodeUCS4_AsEncodedString},
2692 + {"PyFloat_Type", (PYTHON_PROC*)&dll_PyFloat_Type},
2693 + {"PyFloat_AsDouble", (PYTHON_PROC*)&dll_PyFloat_AsDouble},
2694 + {"PyFloat_FromDouble", (PYTHON_PROC*)&dll_PyFloat_FromDouble},
2695 + {"PyImport_AddModule", (PYTHON_PROC*)&dll_PyImport_AddModule},
2696 {"PySys_SetObject", (PYTHON_PROC*)&dll_PySys_SetObject},
2697 {"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv},
2698 {"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type},
2702 {"Py_IsInitialized", (PYTHON_PROC*)&dll_Py_IsInitialized},
2703 {"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New},
2704 {"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init},
2705 + {"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter},
2706 + {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented},
2707 {"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct},
2708 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
2709 {"PyType_IsSubtype", (PYTHON_PROC*)&dll_PyType_IsSubtype},
2713 {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc},
2714 {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free},
2716 + {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New},
2717 + {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer},
2725 static PyObject *BufferNew (buf_T *);
2726 static PyObject *WindowNew(win_T *);
2727 + static PyObject *DictionaryNew(dict_T *);
2728 static PyObject *LineToString(const char *);
2730 static PyTypeObject RangeType;
2732 + static int initialised = 0;
2733 + #define PYINITIALISED initialised
2735 + /* Add conversion from PyInt? */
2736 + #define DICTKEY_GET(err) \
2737 + if (!PyString_Check(keyObject)) \
2739 + PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
2742 + key = (char_u *) PyString_AsString(keyObject);
2743 + #define DICTKEY_UNREF
2744 + #define DICTKEY_DECL
2747 * Include the code shared with if_python3.c
2752 static PyInt RangeStart;
2753 static PyInt RangeEnd;
2755 + static PyObject *globals;
2757 static void PythonIO_Flush(void);
2758 static int PythonIO_Init(void);
2759 static int PythonMod_Init(void);
2762 * 1. Python interpreter main program.
2765 - static int initialised = 0;
2767 #if PYTHON_API_VERSION < 1007 /* Python 1.4 */
2768 typedef PyObject PyThreadState;
2774 if (PythonMod_Init())
2777 + globals = PyModule_GetDict(PyImport_AddModule("__main__"));
2779 /* Remove the element from sys.path that was added because of our
2780 * argv[0] value in PythonMod_Init(). Previously we used an empty
2781 * string, but dependinding on the OS we then get an empty entry or
2784 * External interface
2787 ! DoPythonCommand(exarg_T *eap, const char *cmd)
2789 #ifndef PY_CAN_RECURSE
2790 static int recursive = 0;
2792 * External interface
2795 ! DoPythonCommand(exarg_T *eap, const char *cmd, typval_T *rettv)
2797 #ifndef PY_CAN_RECURSE
2798 static int recursive = 0;
2804 ! RangeStart = eap->line1;
2805 ! RangeEnd = eap->line2;
2806 Python_Release_Vim(); /* leave vim */
2808 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
2813 ! if (rettv == NULL)
2815 ! RangeStart = eap->line1;
2816 ! RangeEnd = eap->line2;
2820 ! RangeStart = (PyInt) curwin->w_cursor.lnum;
2821 ! RangeEnd = RangeStart;
2823 Python_Release_Vim(); /* leave vim */
2825 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
2829 Python_RestoreThread(); /* enter python */
2831 ! PyRun_SimpleString((char *)(cmd));
2833 Python_SaveThread(); /* leave python */
2837 Python_RestoreThread(); /* enter python */
2839 ! if (rettv == NULL)
2840 ! PyRun_SimpleString((char *)(cmd));
2845 ! r = PyRun_String((char *)(cmd), Py_eval_input, globals, globals);
2847 ! EMSG(_("E858: Eval did not return a valid python object"));
2850 ! if (ConvertFromPyObject(r, rettv) == -1)
2851 ! EMSG(_("E859: Failed to convert returned python object to vim value"));
2857 Python_SaveThread(); /* leave python */
2861 #ifndef PY_CAN_RECURSE
2864 ! return; /* keeps lint happy */
2869 #ifndef PY_CAN_RECURSE
2881 ! DoPythonCommand(eap, (char *)eap->arg);
2883 ! DoPythonCommand(eap, (char *)script);
2891 ! DoPythonCommand(eap, (char *)eap->arg, NULL);
2893 ! DoPythonCommand(eap, (char *)script, NULL);
2901 /* Execute the file */
2902 ! DoPythonCommand(eap, buffer);
2905 /******************************************************
2909 /* Execute the file */
2910 ! DoPythonCommand(eap, buffer, NULL);
2913 /******************************************************
2917 OutputSetattr(PyObject *self, char *name, PyObject *val)
2919 ! if (val == NULL) {
2920 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
2924 if (strcmp(name, "softspace") == 0)
2926 ! if (!PyInt_Check(val)) {
2927 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
2932 OutputSetattr(PyObject *self, char *name, PyObject *val)
2936 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
2940 if (strcmp(name, "softspace") == 0)
2942 ! if (!PyInt_Check(val))
2944 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
2950 * 3. Implementation of the Vim module for Python
2953 + static PyObject *ConvertToPyObject(typval_T *);
2954 + static int ConvertFromPyObject(PyObject *, typval_T *);
2956 /* Window type - Implementation functions
2957 * --------------------------------------
2965 + static void DictionaryDestructor(PyObject *);
2966 + static PyObject *DictionaryGetattr(PyObject *, char*);
2968 + static PyMappingMethods DictionaryAsMapping = {
2969 + (PyInquiry) DictionaryLength,
2970 + (binaryfunc) DictionaryItem,
2971 + (objobjargproc) DictionaryAssItem,
2974 + static PyTypeObject DictionaryType = {
2975 + PyObject_HEAD_INIT(0)
2978 + sizeof(DictionaryObject),
2981 + (destructor) DictionaryDestructor,
2983 + (getattrfunc) DictionaryGetattr,
2988 + 0, /* as number */
2989 + 0, /* as sequence */
2990 + &DictionaryAsMapping, /* as mapping */
2998 + DictionaryDestructor(PyObject *self)
3000 + DictionaryObject *this = ((DictionaryObject *) (self));
3002 + pyll_remove(&this->ref, &lastdict);
3003 + dict_unref(this->dict);
3009 + DictionaryGetattr(PyObject *self, char *name)
3011 + return Py_FindMethod(DictionaryMethods, self, name);
3014 + static void ListDestructor(PyObject *);
3015 + static PyObject *ListGetattr(PyObject *, char *);
3017 + static PySequenceMethods ListAsSeq = {
3018 + (PyInquiry) ListLength,
3021 + (PyIntArgFunc) ListItem,
3022 + (PyIntIntArgFunc) ListSlice,
3023 + (PyIntObjArgProc) ListAssItem,
3024 + (PyIntIntObjArgProc) ListAssSlice,
3026 + #if PY_MAJOR_VERSION >= 2
3027 + (binaryfunc) ListConcatInPlace,
3032 + static PyTypeObject ListType = {
3033 + PyObject_HEAD_INIT(0)
3036 + sizeof(ListObject),
3039 + (destructor) ListDestructor,
3041 + (getattrfunc) ListGetattr,
3046 + 0, /* as number */
3047 + &ListAsSeq, /* as sequence */
3048 + 0, /* as mapping */
3056 + ListDestructor(PyObject *self)
3058 + ListObject *this = ((ListObject *) (self));
3060 + pyll_remove(&this->ref, &lastlist);
3061 + list_unref(this->list);
3067 + ListGetattr(PyObject *self, char *name)
3069 + return Py_FindMethod(ListMethods, self, name);
3072 + static void FunctionDestructor(PyObject *);
3073 + static PyObject *FunctionGetattr(PyObject *, char *);
3075 + static PyTypeObject FunctionType = {
3076 + PyObject_HEAD_INIT(0)
3079 + sizeof(FunctionObject),
3082 + (destructor) FunctionDestructor,
3084 + (getattrfunc) FunctionGetattr,
3089 + 0, /* as number */
3090 + 0, /* as sequence */
3091 + 0, /* as mapping */
3094 + (ternaryfunc) FunctionCall,
3099 + FunctionDestructor(PyObject *self)
3101 + FunctionObject *this = (FunctionObject *) (self);
3103 + func_unref(this->name);
3104 + PyMem_Del(this->name);
3110 + FunctionGetattr(PyObject *self, char *name)
3112 + FunctionObject *this = (FunctionObject *)(self);
3114 + if (strcmp(name, "name") == 0)
3115 + return PyString_FromString((char *)(this->name));
3117 + return Py_FindMethod(FunctionMethods, self, name);
3121 + do_pyeval (char_u *str, typval_T *rettv)
3123 + DoPythonCommand(NULL, (char *) str, rettv);
3124 + switch(rettv->v_type)
3126 + case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
3127 + case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
3128 + case VAR_FUNC: func_ref(rettv->vval.v_string); break;
3132 /* Don't generate a prototype for the next function, it generates an error on
3133 * newer Python versions. */
3138 #endif /* Python 1.4 */
3141 + set_ref_in_python (int copyID)
3143 + set_ref_in_py(copyID);
3149 *** ../vim-7.3.568/src/if_python3.c 2012-02-04 20:17:21.000000000 +0100
3150 --- src/if_python3.c 2012-06-29 11:54:10.000000000 +0200
3154 #define PyInt Py_ssize_t
3155 #define PyString_Check(obj) PyUnicode_Check(obj)
3156 ! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
3157 #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
3158 #define PyString_AsString(obj) PyBytes_AsString(obj)
3159 #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
3162 #define PyInt Py_ssize_t
3163 #define PyString_Check(obj) PyUnicode_Check(obj)
3164 ! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER)
3165 #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
3166 #define PyString_AsString(obj) PyBytes_AsString(obj)
3167 #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
3171 # undef PyArg_ParseTuple
3172 # define PyArg_ParseTuple py3_PyArg_ParseTuple
3173 # define PyMem_Free py3_PyMem_Free
3174 + # define PyMem_Malloc py3_PyMem_Malloc
3175 # define PyDict_SetItemString py3_PyDict_SetItemString
3176 # define PyErr_BadArgument py3_PyErr_BadArgument
3177 # define PyErr_Clear py3_PyErr_Clear
3181 # define PyList_New py3_PyList_New
3182 # define PyList_SetItem py3_PyList_SetItem
3183 # define PyList_Size py3_PyList_Size
3184 + # define PySequence_Check py3_PySequence_Check
3185 + # define PySequence_Size py3_PySequence_Size
3186 + # define PySequence_GetItem py3_PySequence_GetItem
3187 + # define PyTuple_Size py3_PyTuple_Size
3188 + # define PyTuple_GetItem py3_PyTuple_GetItem
3189 # define PySlice_GetIndicesEx py3_PySlice_GetIndicesEx
3190 # define PyImport_ImportModule py3_PyImport_ImportModule
3191 + # define PyImport_AddModule py3_PyImport_AddModule
3192 # define PyObject_Init py3__PyObject_Init
3193 # define PyDict_New py3_PyDict_New
3194 # define PyDict_GetItemString py3_PyDict_GetItemString
3195 + # define PyDict_Next py3_PyDict_Next
3196 + # define PyMapping_Check py3_PyMapping_Check
3197 + # define PyMapping_Items py3_PyMapping_Items
3198 + # define PyIter_Next py3_PyIter_Next
3199 + # define PyObject_GetIter py3_PyObject_GetIter
3200 # define PyModule_GetDict py3_PyModule_GetDict
3201 #undef PyRun_SimpleString
3202 # define PyRun_SimpleString py3_PyRun_SimpleString
3203 + #undef PyRun_String
3204 + # define PyRun_String py3_PyRun_String
3205 # define PySys_SetObject py3_PySys_SetObject
3206 # define PySys_SetArgv py3_PySys_SetArgv
3207 # define PyType_Type (*py3_PyType_Type)
3211 # define Py_Finalize py3_Py_Finalize
3212 # define Py_IsInitialized py3_Py_IsInitialized
3213 # define _Py_NoneStruct (*py3__Py_NoneStruct)
3214 + # define _PyObject_NextNotImplemented (*py3__PyObject_NextNotImplemented)
3215 # define PyModule_AddObject py3_PyModule_AddObject
3216 # define PyImport_AppendInittab py3_PyImport_AppendInittab
3217 # define _PyUnicode_AsString py3__PyUnicode_AsString
3221 # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString
3222 # undef PyBytes_AsString
3223 # define PyBytes_AsString py3_PyBytes_AsString
3224 + # undef PyBytes_FromString
3225 + # define PyBytes_FromString py3_PyBytes_FromString
3226 + # define PyFloat_FromDouble py3_PyFloat_FromDouble
3227 + # define PyFloat_AsDouble py3_PyFloat_AsDouble
3228 # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr
3229 # define PySlice_Type (*py3_PySlice_Type)
3230 + # define PyFloat_Type (*py3_PyFloat_Type)
3231 # define PyErr_NewException py3_PyErr_NewException
3233 # define _Py_NegativeRefcount py3__Py_NegativeRefcount
3237 # define PyUnicode_FromString py3_PyUnicode_FromString
3238 # undef PyUnicode_Decode
3239 # define PyUnicode_Decode py3_PyUnicode_Decode
3240 + # define PyType_IsSubtype py3_PyType_IsSubtype
3241 + # define PyCapsule_New py3_PyCapsule_New
3242 + # define PyCapsule_GetPointer py3_PyCapsule_GetPointer
3245 # undef PyObject_NEW
3249 static int (*py3_PySys_SetObject)(char *, PyObject *);
3250 static PyObject* (*py3_PyList_Append)(PyObject *, PyObject *);
3251 static Py_ssize_t (*py3_PyList_Size)(PyObject *);
3252 + static int (*py3_PySequence_Check)(PyObject *);
3253 + static Py_ssize_t (*py3_PySequence_Size)(PyObject *);
3254 + static PyObject* (*py3_PySequence_GetItem)(PyObject *, Py_ssize_t);
3255 + static Py_ssize_t (*py3_PyTuple_Size)(PyObject *);
3256 + static PyObject* (*py3_PyTuple_GetItem)(PyObject *, Py_ssize_t);
3257 + static int (*py3_PyMapping_Check)(PyObject *);
3258 + static PyObject* (*py3_PyMapping_Items)(PyObject *);
3259 static int (*py3_PySlice_GetIndicesEx)(PyObject *r, Py_ssize_t length,
3260 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength);
3261 static PyObject* (*py3_PyErr_NoMemory)(void);
3262 static void (*py3_Py_Finalize)(void);
3263 static void (*py3_PyErr_SetString)(PyObject *, const char *);
3264 static int (*py3_PyRun_SimpleString)(char *);
3265 + static PyObject* (*py3_PyRun_String)(char *, int, PyObject *, PyObject *);
3266 static PyObject* (*py3_PyList_GetItem)(PyObject *, Py_ssize_t);
3267 static PyObject* (*py3_PyImport_ImportModule)(const char *);
3268 + static PyObject* (*py3_PyImport_AddModule)(const char *);
3269 static int (*py3_PyErr_BadArgument)(void);
3270 static PyTypeObject* py3_PyType_Type;
3271 static PyObject* (*py3_PyErr_Occurred)(void);
3272 static PyObject* (*py3_PyModule_GetDict)(PyObject *);
3273 static int (*py3_PyList_SetItem)(PyObject *, Py_ssize_t, PyObject *);
3274 static PyObject* (*py3_PyDict_GetItemString)(PyObject *, const char *);
3275 + static int (*py3_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **);
3276 static PyObject* (*py3_PyLong_FromLong)(long);
3277 static PyObject* (*py3_PyDict_New)(void);
3278 + static PyObject* (*py3_PyIter_Next)(PyObject *);
3279 + static PyObject* (*py3_PyObject_GetIter)(PyObject *);
3280 static PyObject* (*py3_Py_BuildValue)(char *, ...);
3281 static int (*py3_PyType_Ready)(PyTypeObject *type);
3282 static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
3286 static int (*py3_PyArg_Parse)(PyObject *, char *, ...);
3287 static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...);
3288 static int (*py3_PyMem_Free)(void *);
3289 + static void* (*py3_PyMem_Malloc)(size_t);
3290 static int (*py3_Py_IsInitialized)(void);
3291 static void (*py3_PyErr_Clear)(void);
3292 static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *);
3293 + static iternextfunc py3__PyObject_NextNotImplemented;
3294 static PyObject* py3__Py_NoneStruct;
3295 static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o);
3296 static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void));
3297 static char* (*py3__PyUnicode_AsString)(PyObject *unicode);
3298 static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors);
3299 static char* (*py3_PyBytes_AsString)(PyObject *bytes);
3300 + static PyObject* (*py3_PyBytes_FromString)(char *str);
3301 + static PyObject* (*py3_PyFloat_FromDouble)(double num);
3302 + static double (*py3_PyFloat_AsDouble)(PyObject *);
3303 static PyObject* (*py3_PyObject_GenericGetAttr)(PyObject *obj, PyObject *name);
3304 static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version);
3305 static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems);
3306 static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds);
3307 static PyTypeObject* py3_PySlice_Type;
3308 + static PyTypeObject* py3_PyFloat_Type;
3309 static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict);
3310 + static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
3311 + static void* (*py3_PyCapsule_GetPointer)(PyObject *, char *);
3313 static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op);
3314 static Py_ssize_t* py3__Py_RefTotal;
3318 static void (*py3_PyObject_Free)(void*);
3319 static void* (*py3_PyObject_Malloc)(size_t);
3321 + static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
3323 static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */
3328 {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize},
3329 {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
3330 {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free},
3331 + {"PyMem_Malloc", (PYTHON_PROC*)&py3_PyMem_Malloc},
3332 {"PyList_New", (PYTHON_PROC*)&py3_PyList_New},
3333 {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure},
3334 {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release},
3335 {"PySys_SetObject", (PYTHON_PROC*)&py3_PySys_SetObject},
3336 {"PyList_Append", (PYTHON_PROC*)&py3_PyList_Append},
3337 {"PyList_Size", (PYTHON_PROC*)&py3_PyList_Size},
3338 + {"PySequence_Check", (PYTHON_PROC*)&py3_PySequence_Check},
3339 + {"PySequence_Size", (PYTHON_PROC*)&py3_PySequence_Size},
3340 + {"PySequence_GetItem", (PYTHON_PROC*)&py3_PySequence_GetItem},
3341 + {"PyTuple_Size", (PYTHON_PROC*)&py3_PyTuple_Size},
3342 + {"PyTuple_GetItem", (PYTHON_PROC*)&py3_PyTuple_GetItem},
3343 {"PySlice_GetIndicesEx", (PYTHON_PROC*)&py3_PySlice_GetIndicesEx},
3344 {"PyErr_NoMemory", (PYTHON_PROC*)&py3_PyErr_NoMemory},
3345 {"Py_Finalize", (PYTHON_PROC*)&py3_Py_Finalize},
3346 {"PyErr_SetString", (PYTHON_PROC*)&py3_PyErr_SetString},
3347 {"PyRun_SimpleString", (PYTHON_PROC*)&py3_PyRun_SimpleString},
3348 + {"PyRun_String", (PYTHON_PROC*)&py3_PyRun_String},
3349 {"PyList_GetItem", (PYTHON_PROC*)&py3_PyList_GetItem},
3350 {"PyImport_ImportModule", (PYTHON_PROC*)&py3_PyImport_ImportModule},
3351 + {"PyImport_AddModule", (PYTHON_PROC*)&py3_PyImport_AddModule},
3352 {"PyErr_BadArgument", (PYTHON_PROC*)&py3_PyErr_BadArgument},
3353 {"PyType_Type", (PYTHON_PROC*)&py3_PyType_Type},
3354 {"PyErr_Occurred", (PYTHON_PROC*)&py3_PyErr_Occurred},
3355 {"PyModule_GetDict", (PYTHON_PROC*)&py3_PyModule_GetDict},
3356 {"PyList_SetItem", (PYTHON_PROC*)&py3_PyList_SetItem},
3357 {"PyDict_GetItemString", (PYTHON_PROC*)&py3_PyDict_GetItemString},
3358 + {"PyDict_Next", (PYTHON_PROC*)&py3_PyDict_Next},
3359 + {"PyMapping_Check", (PYTHON_PROC*)&py3_PyMapping_Check},
3360 + {"PyMapping_Items", (PYTHON_PROC*)&py3_PyMapping_Items},
3361 + {"PyIter_Next", (PYTHON_PROC*)&py3_PyIter_Next},
3362 + {"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter},
3363 {"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong},
3364 {"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New},
3365 {"Py_BuildValue", (PYTHON_PROC*)&py3_Py_BuildValue},
3369 {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread},
3370 {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse},
3371 {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized},
3372 + {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&py3__PyObject_NextNotImplemented},
3373 {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct},
3374 {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear},
3375 {"PyObject_Init", (PYTHON_PROC*)&py3__PyObject_Init},
3379 {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab},
3380 {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
3381 {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
3382 + {"PyBytes_FromString", (PYTHON_PROC*)&py3_PyBytes_FromString},
3383 + {"PyFloat_FromDouble", (PYTHON_PROC*)&py3_PyFloat_FromDouble},
3384 + {"PyFloat_AsDouble", (PYTHON_PROC*)&py3_PyFloat_AsDouble},
3385 {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr},
3386 {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2},
3387 {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc},
3388 {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew},
3389 {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
3390 + {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type},
3391 {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException},
3393 {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount},
3397 {"PyObject_Malloc", (PYTHON_PROC*)&py3_PyObject_Malloc},
3398 {"PyObject_Free", (PYTHON_PROC*)&py3_PyObject_Free},
3400 + {"PyType_IsSubtype", (PYTHON_PROC*)&py3_PyType_IsSubtype},
3401 + {"PyCapsule_New", (PYTHON_PROC*)&py3_PyCapsule_New},
3402 + {"PyCapsule_GetPointer", (PYTHON_PROC*)&py3_PyCapsule_GetPointer},
3410 static PyTypeObject RangeType;
3412 + static int py3initialised = 0;
3414 + #define PYINITIALISED py3initialised
3416 + /* Add conversion from PyInt? */
3417 + #define DICTKEY_GET(err) \
3418 + if (PyBytes_Check(keyObject)) \
3419 + key = (char_u *) PyBytes_AsString(keyObject); \
3420 + else if (PyUnicode_Check(keyObject)) \
3422 + bytes = PyString_AsBytes(keyObject); \
3423 + if (bytes == NULL) \
3425 + key = (char_u *) PyBytes_AsString(bytes); \
3426 + if (key == NULL) \
3431 + PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
3434 + #define DICTKEY_UNREF \
3435 + if (bytes != NULL) \
3436 + Py_XDECREF(bytes);
3438 + #define DICTKEY_DECL PyObject *bytes = NULL;
3441 * Include the code shared with if_python.c
3443 #include "if_py_both.h"
3445 + #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
3448 call_PyObject_Free(void *p)
3453 static Py_ssize_t RangeStart;
3454 static Py_ssize_t RangeEnd;
3456 + static PyObject *globals;
3458 static int PythonIO_Init(void);
3459 static void PythonIO_Fini(void);
3460 PyMODINIT_FUNC Py3Init_vim(void);
3463 * 1. Python interpreter main program.
3466 - static int py3initialised = 0;
3468 static PyGILState_STATE pygilstate = PyGILState_UNLOCKED;
3476 PyImport_AppendInittab("vim", Py3Init_vim);
3478 + globals = PyModule_GetDict(PyImport_AddModule("__main__"));
3480 /* Remove the element from sys.path that was added because of our
3481 * argv[0] value in Py3Init_vim(). Previously we used an empty
3482 * string, but dependinding on the OS we then get an empty entry or
3485 * External interface
3488 ! DoPy3Command(exarg_T *eap, const char *cmd)
3490 #if defined(MACOS) && !defined(MACOS_X_UNIX)
3493 * External interface
3496 ! DoPy3Command(exarg_T *eap, const char *cmd, typval_T *rettv)
3498 #if defined(MACOS) && !defined(MACOS_X_UNIX)
3505 ! RangeStart = eap->line1;
3506 ! RangeEnd = eap->line2;
3507 Python_Release_Vim(); /* leave vim */
3509 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3514 ! if (rettv == NULL)
3516 ! RangeStart = eap->line1;
3517 ! RangeEnd = eap->line2;
3521 ! RangeStart = (PyInt) curwin->w_cursor.lnum;
3522 ! RangeEnd = RangeStart;
3524 Python_Release_Vim(); /* leave vim */
3526 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3529 (char *)ENC_OPT, CODEC_ERROR_HANDLER);
3530 cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
3532 ! PyRun_SimpleString(PyBytes_AsString(cmdbytes));
3533 Py_XDECREF(cmdbytes);
3535 PyGILState_Release(pygilstate);
3537 (char *)ENC_OPT, CODEC_ERROR_HANDLER);
3538 cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
3540 ! if (rettv == NULL)
3541 ! PyRun_SimpleString(PyBytes_AsString(cmdbytes));
3546 ! r = PyRun_String(PyBytes_AsString(cmdbytes), Py_eval_input,
3547 ! globals, globals);
3549 ! EMSG(_("E860: Eval did not return a valid python 3 object"));
3552 ! if (ConvertFromPyObject(r, rettv) == -1)
3553 ! EMSG(_("E861: Failed to convert returned python 3 object to vim value"));
3558 Py_XDECREF(cmdbytes);
3560 PyGILState_Release(pygilstate);
3566 ! DoPy3Command(eap, (char *)eap->arg);
3568 ! DoPy3Command(eap, (char *)script);
3576 ! DoPy3Command(eap, (char *)eap->arg, NULL);
3578 ! DoPy3Command(eap, (char *)script, NULL);
3586 /* Execute the file */
3587 ! DoPy3Command(eap, buffer);
3590 /******************************************************
3594 /* Execute the file */
3595 ! DoPy3Command(eap, buffer, NULL);
3598 /******************************************************
3601 if (PyUnicode_Check(nameobj))
3602 name = _PyUnicode_AsString(nameobj);
3604 ! if (val == NULL) {
3605 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
3609 if (strcmp(name, "softspace") == 0)
3611 ! if (!PyLong_Check(val)) {
3612 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
3616 if (PyUnicode_Check(nameobj))
3617 name = _PyUnicode_AsString(nameobj);
3621 PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
3625 if (strcmp(name, "softspace") == 0)
3627 ! if (!PyLong_Check(val))
3629 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
3635 BufferSubscript(PyObject *self, PyObject* idx)
3637 ! if (PyLong_Check(idx)) {
3638 long _idx = PyLong_AsLong(idx);
3639 return BufferItem(self,_idx);
3640 ! } else if (PySlice_Check(idx)) {
3641 Py_ssize_t start, stop, step, slicelen;
3643 if (PySlice_GetIndicesEx((PyObject *)idx,
3644 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3646 ! &step, &slicelen) < 0) {
3649 return BufferSlice(self, start, stop);
3651 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3656 BufferSubscript(PyObject *self, PyObject* idx)
3658 ! if (PyLong_Check(idx))
3660 long _idx = PyLong_AsLong(idx);
3661 return BufferItem(self,_idx);
3662 ! } else if (PySlice_Check(idx))
3664 Py_ssize_t start, stop, step, slicelen;
3666 if (PySlice_GetIndicesEx((PyObject *)idx,
3667 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3669 ! &step, &slicelen) < 0)
3673 return BufferSlice(self, start, stop);
3677 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3683 BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
3685 ! if (PyLong_Check(idx)) {
3686 long n = PyLong_AsLong(idx);
3687 return RBAsItem((BufferObject *)(self), n, val, 1,
3688 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
3690 ! } else if (PySlice_Check(idx)) {
3691 Py_ssize_t start, stop, step, slicelen;
3693 if (PySlice_GetIndicesEx((PyObject *)idx,
3694 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3696 ! &step, &slicelen) < 0) {
3699 return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
3700 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
3703 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3708 BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
3710 ! if (PyLong_Check(idx))
3712 long n = PyLong_AsLong(idx);
3713 return RBAsItem((BufferObject *)(self), n, val, 1,
3714 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
3716 ! } else if (PySlice_Check(idx))
3718 Py_ssize_t start, stop, step, slicelen;
3720 if (PySlice_GetIndicesEx((PyObject *)idx,
3721 (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3723 ! &step, &slicelen) < 0)
3727 return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
3728 (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
3733 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3739 RangeSubscript(PyObject *self, PyObject* idx)
3741 ! if (PyLong_Check(idx)) {
3742 long _idx = PyLong_AsLong(idx);
3743 return RangeItem(self,_idx);
3744 ! } else if (PySlice_Check(idx)) {
3745 Py_ssize_t start, stop, step, slicelen;
3747 if (PySlice_GetIndicesEx((PyObject *)idx,
3748 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3750 ! &step, &slicelen) < 0) {
3753 return RangeSlice(self, start, stop);
3755 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3760 RangeSubscript(PyObject *self, PyObject* idx)
3762 ! if (PyLong_Check(idx))
3764 long _idx = PyLong_AsLong(idx);
3765 return RangeItem(self,_idx);
3766 ! } else if (PySlice_Check(idx))
3768 Py_ssize_t start, stop, step, slicelen;
3770 if (PySlice_GetIndicesEx((PyObject *)idx,
3771 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3773 ! &step, &slicelen) < 0)
3777 return RangeSlice(self, start, stop);
3781 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3787 RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
3789 ! if (PyLong_Check(idx)) {
3790 long n = PyLong_AsLong(idx);
3791 return RangeAsItem(self, n, val);
3792 ! } else if (PySlice_Check(idx)) {
3793 Py_ssize_t start, stop, step, slicelen;
3795 if (PySlice_GetIndicesEx((PyObject *)idx,
3796 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3798 ! &step, &slicelen) < 0) {
3801 return RangeAsSlice(self, start, stop, val);
3803 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3808 RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
3810 ! if (PyLong_Check(idx))
3812 long n = PyLong_AsLong(idx);
3813 return RangeAsItem(self, n, val);
3814 ! } else if (PySlice_Check(idx))
3816 Py_ssize_t start, stop, step, slicelen;
3818 if (PySlice_GetIndicesEx((PyObject *)idx,
3819 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3821 ! &step, &slicelen) < 0)
3825 return RangeAsSlice(self, start, stop, val);
3829 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3838 + /* Dictionary object - Definitions
3841 + static PyInt DictionaryLength(PyObject *);
3843 + static PyMappingMethods DictionaryAsMapping = {
3844 + /* mp_length */ (lenfunc) DictionaryLength,
3845 + /* mp_subscript */ (binaryfunc) DictionaryItem,
3846 + /* mp_ass_subscript */ (objobjargproc) DictionaryAssItem,
3849 + static PyTypeObject DictionaryType;
3852 + DictionaryDestructor(PyObject *self)
3854 + DictionaryObject *this = (DictionaryObject *)(self);
3856 + pyll_remove(&this->ref, &lastdict);
3857 + dict_unref(this->dict);
3859 + Py_TYPE(self)->tp_free((PyObject*)self);
3862 + /* List object - Definitions
3865 + static PyInt ListLength(PyObject *);
3866 + static PyObject *ListItem(PyObject *, Py_ssize_t);
3868 + static PySequenceMethods ListAsSeq = {
3869 + (lenfunc) ListLength, /* sq_length, len(x) */
3870 + (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
3871 + (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */
3872 + (ssizeargfunc) ListItem, /* sq_item, x[i] */
3873 + (void *) 0, /* was_sq_slice, x[i:j] */
3874 + (ssizeobjargproc) ListAssItem, /* sq_as_item, x[i]=v */
3875 + (void *) 0, /* was_sq_ass_slice, x[i:j]=v */
3876 + 0, /* sq_contains */
3877 + (binaryfunc) ListConcatInPlace,/* sq_inplace_concat */
3878 + 0, /* sq_inplace_repeat */
3881 + static PyObject *ListSubscript(PyObject *, PyObject *);
3882 + static Py_ssize_t ListAsSubscript(PyObject *, PyObject *, PyObject *);
3884 + static PyMappingMethods ListAsMapping = {
3885 + /* mp_length */ (lenfunc) ListLength,
3886 + /* mp_subscript */ (binaryfunc) ListSubscript,
3887 + /* mp_ass_subscript */ (objobjargproc) ListAsSubscript,
3890 + static PyTypeObject ListType;
3893 + ListSubscript(PyObject *self, PyObject* idxObject)
3895 + if (PyLong_Check(idxObject))
3897 + long idx = PyLong_AsLong(idxObject);
3898 + return ListItem(self, idx);
3900 + else if (PySlice_Check(idxObject))
3902 + Py_ssize_t start, stop, step, slicelen;
3904 + if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
3905 + &step, &slicelen) < 0)
3907 + return ListSlice(self, start, stop);
3911 + PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3917 + ListAsSubscript(PyObject *self, PyObject *idxObject, PyObject *obj)
3919 + if (PyLong_Check(idxObject))
3921 + long idx = PyLong_AsLong(idxObject);
3922 + return ListAssItem(self, idx, obj);
3924 + else if (PySlice_Check(idxObject))
3926 + Py_ssize_t start, stop, step, slicelen;
3928 + if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
3929 + &step, &slicelen) < 0)
3931 + return ListAssSlice(self, start, stop, obj);
3935 + PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3941 + ListDestructor(PyObject *self)
3943 + ListObject *this = (ListObject *)(self);
3945 + pyll_remove(&this->ref, &lastlist);
3946 + list_unref(this->list);
3948 + Py_TYPE(self)->tp_free((PyObject*)self);
3951 + /* Function object - Definitions
3955 + FunctionDestructor(PyObject *self)
3957 + FunctionObject *this = (FunctionObject *) (self);
3959 + func_unref(this->name);
3960 + PyMem_Del(this->name);
3962 + Py_TYPE(self)->tp_free((PyObject*)self);
3966 + FunctionGetattro(PyObject *self, PyObject *nameobj)
3968 + FunctionObject *this = (FunctionObject *)(self);
3970 + if (PyUnicode_Check(nameobj))
3971 + name = _PyUnicode_AsString(nameobj);
3973 + if (strcmp(name, "name") == 0)
3974 + return PyUnicode_FromString((char *)(this->name));
3976 + return PyObject_GenericGetAttr(self, nameobj);
3979 /* External interface
3985 PyType_Ready(&BufListType);
3986 PyType_Ready(&WinListType);
3987 PyType_Ready(&CurrentType);
3988 + PyType_Ready(&DictionaryType);
3989 + PyType_Ready(&ListType);
3990 + PyType_Ready(&FunctionType);
3992 /* Set sys.argv[] to avoid a crash in warn(). */
3993 PySys_SetArgv(1, argv);
4001 + do_py3eval (char_u *str, typval_T *rettv)
4003 + DoPy3Command(NULL, (char *) str, rettv);
4004 + switch(rettv->v_type)
4006 + case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
4007 + case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
4008 + case VAR_FUNC: func_ref(rettv->vval.v_string); break;
4013 + set_ref_in_python3 (int copyID)
4015 + set_ref_in_py(copyID);
4024 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
4025 CurrentType.tp_doc = "vim current object";
4027 + vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
4028 + DictionaryType.tp_name = "vim.dictionary";
4029 + DictionaryType.tp_basicsize = sizeof(DictionaryObject);
4030 + DictionaryType.tp_dealloc = DictionaryDestructor;
4031 + DictionaryType.tp_as_mapping = &DictionaryAsMapping;
4032 + DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
4033 + DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
4034 + DictionaryType.tp_methods = DictionaryMethods;
4036 + vim_memset(&ListType, 0, sizeof(ListType));
4037 + ListType.tp_name = "vim.list";
4038 + ListType.tp_dealloc = ListDestructor;
4039 + ListType.tp_basicsize = sizeof(ListObject);
4040 + ListType.tp_as_sequence = &ListAsSeq;
4041 + ListType.tp_as_mapping = &ListAsMapping;
4042 + ListType.tp_flags = Py_TPFLAGS_DEFAULT;
4043 + ListType.tp_doc = "list pushing modifications to vim structure";
4044 + ListType.tp_methods = ListMethods;
4046 + vim_memset(&FunctionType, 0, sizeof(FunctionType));
4047 + FunctionType.tp_name = "vim.list";
4048 + FunctionType.tp_basicsize = sizeof(FunctionObject);
4049 + FunctionType.tp_getattro = FunctionGetattro;
4050 + FunctionType.tp_dealloc = FunctionDestructor;
4051 + FunctionType.tp_call = FunctionCall;
4052 + FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
4053 + FunctionType.tp_doc = "object that calls vim function";
4054 + FunctionType.tp_methods = FunctionMethods;
4056 vim_memset(&vimmodule, 0, sizeof(vimmodule));
4057 vimmodule.m_name = "vim";
4058 vimmodule.m_doc = vim_module_doc;
4059 *** ../vim-7.3.568/src/proto/eval.pro 2011-09-14 16:52:02.000000000 +0200
4060 --- src/proto/eval.pro 2012-06-20 18:20:28.000000000 +0200
4064 list_T *list_alloc __ARGS((void));
4065 void list_unref __ARGS((list_T *l));
4066 void list_free __ARGS((list_T *l, int recurse));
4067 + listitem_T *listitem_alloc __ARGS((void));
4068 + void listitem_remove __ARGS((list_T *l, listitem_T *item));
4069 dictitem_T *dict_lookup __ARGS((hashitem_T *hi));
4070 + listitem_T *list_find __ARGS((list_T *l, long n));
4071 char_u *list_find_str __ARGS((list_T *l, long idx));
4072 + void list_append __ARGS((list_T *l, listitem_T *item));
4073 int list_append_tv __ARGS((list_T *l, typval_T *tv));
4074 int list_append_dict __ARGS((list_T *list, dict_T *dict));
4075 int list_append_string __ARGS((list_T *l, char_u *str, int len));
4076 + int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
4077 + void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
4078 int garbage_collect __ARGS((void));
4079 + void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
4080 + void set_ref_in_list __ARGS((list_T *l, int copyID));
4081 + void set_ref_in_item __ARGS((typval_T *tv, int copyID));
4082 dict_T *dict_alloc __ARGS((void));
4083 void dict_unref __ARGS((dict_T *d));
4084 dictitem_T *dictitem_alloc __ARGS((char_u *key));
4088 long get_dict_number __ARGS((dict_T *d, char_u *key));
4089 char_u *get_function_name __ARGS((expand_T *xp, int idx));
4090 char_u *get_expr_name __ARGS((expand_T *xp, int idx));
4091 + int func_call __ARGS((char_u *name, typval_T *args, dict_T *selfdict, typval_T *rettv));
4092 long do_searchpair __ARGS((char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit));
4093 void set_vim_var_nr __ARGS((int idx, long val));
4094 long get_vim_var_nr __ARGS((int idx));
4098 void func_dump_profile __ARGS((FILE *fd));
4099 char_u *get_user_func_name __ARGS((expand_T *xp, int idx));
4100 void ex_delfunction __ARGS((exarg_T *eap));
4101 + void func_unref __ARGS((char_u *name));
4102 + void func_ref __ARGS((char_u *name));
4103 void ex_return __ARGS((exarg_T *eap));
4104 int do_return __ARGS((exarg_T *eap, int reanimate, int is_cmd, void *rettv));
4105 void discard_pending_return __ARGS((void *rettv));
4106 *** ../vim-7.3.568/src/proto/if_python.pro 2010-08-15 21:57:28.000000000 +0200
4107 --- src/proto/if_python.pro 2012-06-20 18:23:06.000000000 +0200
4111 void ex_pyfile __ARGS((exarg_T *eap));
4112 void python_buffer_free __ARGS((buf_T *buf));
4113 void python_window_free __ARGS((win_T *win));
4114 + void do_pyeval __ARGS((char_u *str, typval_T *rettv));
4115 + void set_ref_in_python __ARGS((int copyID));
4116 /* vim: set ft=c : */
4117 *** ../vim-7.3.568/src/proto/if_python3.pro 2010-08-15 21:57:28.000000000 +0200
4118 --- src/proto/if_python3.pro 2012-06-20 18:34:26.000000000 +0200
4122 void ex_py3file __ARGS((exarg_T *eap));
4123 void python3_buffer_free __ARGS((buf_T *buf));
4124 void python3_window_free __ARGS((win_T *win));
4125 + void do_py3eval __ARGS((char_u *str, typval_T *rettv));
4126 + void set_ref_in_python3 __ARGS((int copyID));
4127 /* vim: set ft=c : */
4128 *** ../vim-7.3.568/src/testdir/Make_amiga.mak 2012-04-05 16:56:38.000000000 +0200
4129 --- src/testdir/Make_amiga.mak 2012-06-20 18:43:05.000000000 +0200
4133 # test27 can't edit file with "*"
4134 # test52 only for Win32
4135 # test85 no Lua interface
4136 + # test86, 87 no Python interface
4138 SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
4139 test7.out test8.out test9.out \
4140 *** ../vim-7.3.568/src/testdir/Make_dos.mak 2012-04-13 19:11:16.000000000 +0200
4141 --- src/testdir/Make_dos.mak 2012-06-20 18:43:45.000000000 +0200
4144 test68.out test69.out test71.out test72.out test73.out \
4145 test74.out test75.out test76.out test77.out test78.out \
4146 test79.out test80.out test81.out test82.out test83.out \
4147 ! test84.out test85.out
4149 SCRIPTS32 = test50.out test70.out
4152 test68.out test69.out test71.out test72.out test73.out \
4153 test74.out test75.out test76.out test77.out test78.out \
4154 test79.out test80.out test81.out test82.out test83.out \
4155 ! test84.out test85.out test86.out test87.out
4157 SCRIPTS32 = test50.out test70.out
4159 *** ../vim-7.3.568/src/testdir/Make_ming.mak 2012-04-13 19:11:16.000000000 +0200
4160 --- src/testdir/Make_ming.mak 2012-06-20 18:44:12.000000000 +0200
4163 test68.out test69.out test71.out test72.out test73.out \
4164 test74.out test75.out test76.out test77.out test78.out \
4165 test79.out test80.out test81.out test82.out test83.out \
4166 ! test84.out test85.out
4168 SCRIPTS32 = test50.out test70.out
4171 test68.out test69.out test71.out test72.out test73.out \
4172 test74.out test75.out test76.out test77.out test78.out \
4173 test79.out test80.out test81.out test82.out test83.out \
4174 ! test84.out test85.out test86.out test87.out
4176 SCRIPTS32 = test50.out test70.out
4178 *** ../vim-7.3.568/src/testdir/Make_os2.mak 2012-04-05 16:56:38.000000000 +0200
4179 --- src/testdir/Make_os2.mak 2012-06-20 18:44:32.000000000 +0200
4183 # test27 can't edit file with "*" in file name
4184 # test52 only for Win32
4185 # test85 no Lua interface
4186 + # test86, 87 no Python interface
4188 SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
4189 test7.out test8.out test9.out \
4190 *** ../vim-7.3.568/src/testdir/Makefile 2012-04-05 16:56:38.000000000 +0200
4191 --- src/testdir/Makefile 2012-06-29 11:56:00.000000000 +0200
4194 test69.out test70.out test71.out test72.out test73.out \
4195 test74.out test75.out test76.out test77.out test78.out \
4196 test79.out test80.out test81.out test82.out test83.out \
4197 ! test84.out test85.out
4199 SCRIPTS_GUI = test16.out
4202 test69.out test70.out test71.out test72.out test73.out \
4203 test74.out test75.out test76.out test77.out test78.out \
4204 test79.out test80.out test81.out test82.out test83.out \
4205 ! test84.out test85.out test86.out test87.out
4207 SCRIPTS_GUI = test16.out
4209 *** ../vim-7.3.568/src/testdir/test86.in 2012-06-20 20:19:31.000000000 +0200
4210 --- src/testdir/test86.in 2012-06-20 18:01:02.000000000 +0200
4214 + Tests for various python features. vim: set ft=vim :
4218 + :if !has('python') | e! test.ok | wq! test.out | endif
4222 + :py l=vim.bindeval('l')
4223 + :py f=vim.bindeval('function("strlen")')
4224 + :" Extending List directly with different types
4225 + :py l.extend([1, "as'd", [1, 2, f, {'a': 1}]])
4227 + :$put =string(l[-1])
4229 + : $put =string(l[-4])
4231 + : $put =v:exception[:13]
4233 + :" List assignment
4239 + :" Extending Dictionary directly with different types
4241 + :py d=vim.bindeval('d')
4243 + :py d['b']=[1, 2, f]
4244 + :py d['-1']={'a': 1}
4246 + :py dk=vim.bindeval('dkeys')
4247 + :py dkeys=d.keys()
4249 + :py dk.extend(dkeys)
4250 + :$put =string(dkeys)
4251 + :for [key, val] in sort(items(d))
4252 + : $put =string(key) . ' : ' . string(val)
4256 + :" removing items with del
4260 + :py l=vim.bindeval('l')
4265 + : $put =v:exception
4272 + :" removing items out of range: silently skip items that don't exist
4273 + :let l = [0, 1, 2, 3]
4274 + :py l=vim.bindeval('l')
4275 + :" The following two ranges delete nothing as they match empty list:
4282 + :let l = [0, 1, 2, 3]
4283 + :py l=vim.bindeval('l')
4286 + :let l = [0, 1, 2, 3]
4287 + :py l=vim.bindeval('l')
4290 + :let l = [0, 1, 2, 3]
4291 + :py l=vim.bindeval('l')
4294 + :let l = [0, 1, 2, 3]
4295 + :py l=vim.bindeval('l')
4296 + :" The following two ranges delete nothing as they match empty list:
4303 + :let l = [0, 1, 2, 3]
4304 + :py l=vim.bindeval('l')
4307 + :let l = [0, 1, 2, 3]
4308 + :py l=vim.bindeval('l')
4311 + :let l = [0, 1, 2, 3]
4312 + :py l=vim.bindeval('l')
4316 + :" Slice assignment to a list
4317 + :let l = [0, 1, 2, 3]
4318 + :py l=vim.bindeval('l')
4321 + :let l = [0, 1, 2, 3]
4322 + :py l=vim.bindeval('l')
4325 + :let l = [0, 1, 2, 3]
4326 + :py l=vim.bindeval('l')
4329 + :let l = [0, 1, 2, 3]
4330 + :py l=vim.bindeval('l')
4333 + :let l = [0, 1, 2, 3]
4334 + :py l=vim.bindeval('l')
4337 + :let l = [0, 1, 2, 3]
4338 + :py l=vim.bindeval('l')
4339 + :py l[-10:2]=['f']
4341 + :let l = [0, 1, 2, 3]
4342 + :py l=vim.bindeval('l')
4343 + :py l[2:-10]=['g']
4346 + :py l=vim.bindeval('l')
4350 + :" Locked variables
4351 + :let l = [0, 1, 2, 3]
4352 + :py l=vim.bindeval('l')
4359 + :function New(...)
4360 + :return ['NewStart']+a:000+['NewEnd']
4362 + :function DictNew(...) dict
4363 + :return ['DictNewStart']+a:000+['DictNewEnd', self]
4365 + :let l=[function('New'), function('DictNew')]
4366 + :py l=vim.bindeval('l')
4367 + :py l.extend(list(l[0](1, 2, 3)))
4369 + :py l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
4371 + :py l.extend([l[0].name])
4374 + : py l[1](1, 2, 3)
4376 + : $put =v:exception[:16]
4380 + : py l[0](1, 2, 3)
4382 + : $put =v:exception[:16]
4386 + : py l=vim.bindeval('l')
4387 + : py l.extend([0.0])
4390 + : $put ='[0.0, 0.0]'
4394 + :let l=pyeval('range(3)')
4396 + :let d=pyeval('{"a": "b", "c": 1, "d": ["e"]}')
4397 + :$put =sort(items(d))
4399 + : let undef=pyeval('undefined_name')
4401 + : $put =v:exception[:13]
4404 + : let vim=pyeval('vim')
4406 + : $put =v:exception[:13]
4409 + : let f=pyeval('0.0')
4419 + :call garbagecollect(1)
4421 + :/^start:/,$wq! test.out
4425 *** ../vim-7.3.568/src/testdir/test86.ok 2012-06-20 20:19:31.000000000 +0200
4426 --- src/testdir/test86.ok 2012-06-20 18:01:02.000000000 +0200
4431 + [1, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4432 + [1, 2, function('strlen'), {'a': 1}]
4434 + [0, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4435 + [0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]]
4439 + 'b' : [1, 2, function('strlen')]
4440 + [0, function('strlen')]
4442 + {'1': 'asd', 'b': [1, 2, function('strlen')]}
4464 + [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd']
4465 + [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}]
4466 + [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New']
4477 *** ../vim-7.3.568/src/testdir/test87.in 2012-06-20 20:19:31.000000000 +0200
4478 --- src/testdir/test87.in 2012-06-20 18:01:02.000000000 +0200
4482 + Tests for various python features. vim: set ft=vim :
4486 + :if !has('python3') | e! test.ok | wq! test.out | endif
4490 + :py3 l=vim.bindeval('l')
4491 + :py3 f=vim.bindeval('function("strlen")')
4492 + :" Extending List directly with different types
4493 + :py3 l+=[1, "as'd", [1, 2, f, {'a': 1}]]
4495 + :$put =string(l[-1])
4497 + : $put =string(l[-4])
4499 + : $put =v:exception[:13]
4501 + :" List assignment
4507 + :" Extending Dictionary directly with different types
4509 + :py3 d=vim.bindeval('d')
4511 + :py3 d['b']=[1, 2, f]
4512 + :py3 d['-1']={'a': 1}
4514 + :py3 dk=vim.bindeval('dkeys')
4515 + :py3 dkeys=d.keys()
4518 + :$put =string(dkeys)
4519 + :for [key, val] in sort(items(d))
4520 + : $put =string(key) . ' : ' . string(val)
4524 + :" removing items with del
4528 + :py3 l=vim.bindeval('l')
4533 + : $put =v:exception
4540 + :" removing items out of range: silently skip items that don't exist
4541 + :let l = [0, 1, 2, 3]
4542 + :py3 l=vim.bindeval('l')
4543 + :" The following two ranges delete nothing as they match empty list:
4550 + :let l = [0, 1, 2, 3]
4551 + :py3 l=vim.bindeval('l')
4554 + :let l = [0, 1, 2, 3]
4555 + :py3 l=vim.bindeval('l')
4558 + :let l = [0, 1, 2, 3]
4559 + :py3 l=vim.bindeval('l')
4562 + :let l = [0, 1, 2, 3]
4563 + :py3 l=vim.bindeval('l')
4564 + :" The following two ranges delete nothing as they match empty list:
4571 + :let l = [0, 1, 2, 3]
4572 + :py3 l=vim.bindeval('l')
4575 + :let l = [0, 1, 2, 3]
4576 + :py3 l=vim.bindeval('l')
4579 + :let l = [0, 1, 2, 3]
4580 + :py3 l=vim.bindeval('l')
4584 + :" Slice assignment to a list
4585 + :let l = [0, 1, 2, 3]
4586 + :py3 l=vim.bindeval('l')
4589 + :let l = [0, 1, 2, 3]
4590 + :py3 l=vim.bindeval('l')
4593 + :let l = [0, 1, 2, 3]
4594 + :py3 l=vim.bindeval('l')
4597 + :let l = [0, 1, 2, 3]
4598 + :py3 l=vim.bindeval('l')
4601 + :let l = [0, 1, 2, 3]
4602 + :py3 l=vim.bindeval('l')
4603 + :py3 l[-1:2]=['e']
4605 + :let l = [0, 1, 2, 3]
4606 + :py3 l=vim.bindeval('l')
4607 + :py3 l[-10:2]=['f']
4609 + :let l = [0, 1, 2, 3]
4610 + :py3 l=vim.bindeval('l')
4611 + :py3 l[2:-10]=['g']
4614 + :py3 l=vim.bindeval('l')
4618 + :" Locked variables
4619 + :let l = [0, 1, 2, 3]
4620 + :py3 l=vim.bindeval('l')
4627 + :function New(...)
4628 + :return ['NewStart']+a:000+['NewEnd']
4630 + :function DictNew(...) dict
4631 + :return ['DictNewStart']+a:000+['DictNewEnd', self]
4633 + :let l=[function('New'), function('DictNew')]
4634 + :py3 l=vim.bindeval('l')
4635 + :py3 l.extend(list(l[0](1, 2, 3)))
4637 + :py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
4639 + :py3 l+=[l[0].name]
4642 + : py3 l[1](1, 2, 3)
4644 + : $put =v:exception[:13]
4648 + : py3 l[0](1, 2, 3)
4650 + : $put =v:exception[:13]
4654 + : py3 l=vim.bindeval('l')
4655 + : py3 l.extend([0.0])
4658 + : $put ='[0.0, 0.0]'
4662 + :let l=py3eval('[0, 1, 2]')
4664 + :let d=py3eval('{"a": "b", "c": 1, "d": ["e"]}')
4665 + :$put =sort(items(d))
4667 + : let undef=py3eval('undefined_name')
4669 + : $put =v:exception[:13]
4672 + : let vim=py3eval('vim')
4674 + : $put =v:exception[:13]
4677 + : let f=py3eval('0.0')
4687 + :call garbagecollect(1)
4689 + :/^start:/,$wq! test.out
4693 *** ../vim-7.3.568/src/testdir/test87.ok 2012-06-20 20:19:31.000000000 +0200
4694 --- src/testdir/test87.ok 2012-06-20 18:01:02.000000000 +0200
4699 + [1, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4700 + [1, 2, function('strlen'), {'a': 1}]
4702 + [0, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4703 + [0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]]
4707 + 'b' : [1, 2, function('strlen')]
4708 + [0, function('strlen')]
4710 + {'1': 'asd', 'b': [1, 2, function('strlen')]}
4732 + [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd']
4733 + [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}]
4734 + [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New']
4745 *** ../vim-7.3.568/src/version.c 2012-06-29 12:35:40.000000000 +0200
4746 --- src/version.c 2012-06-29 12:47:03.000000000 +0200
4750 { /* Add new patch number below this line */
4756 hundred-and-one symptoms of being an internet addict:
4757 69. Yahoo welcomes you with your own start page
4759 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
4760 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
4761 \\\ an exciting new programming language -- http://www.Zimbu.org ///
4762 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///