]> git.pld-linux.org Git - packages/vim.git/blob - 7.3.569
- add patches 7.3.619-743
[packages/vim.git] / 7.3.569
1 To: vim_dev@googlegroups.com
2 Subject: Patch 7.3.569
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.3.569
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
21
22
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
25 ***************
26 *** 1836,1844 ****
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}]])
36 --- 1847,1857 ----
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}]]])
43 !                               String or 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}]])
48 ***************
49 *** 1867,1872 ****
50 --- 1880,1887 ----
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}]])
59 ***************
60 *** 3980,3985 ****
61 --- 4003,4022 ----
62   <                     -2.0
63                 {only available when compiled with the |+float| feature}
64                 
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 
74 +               as-is.
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}
78
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
82 ***************
83 *** 4574,4579 ****
84 --- 4612,4640 ----
85                 This can be used to avoid some things that would remove the
86                 popup menu.
87   
88 +                                                       *E860* *E861*
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 
94 +               'encoding').
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}
99
100 +                                                       *E858* *E859*
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 
105 +               copied though).
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}
110
111                                                         *E726* *E727*
112   range({expr} [, {max} [, {stride}]])                          *range()*
113                 Returns a |List| with Numbers:
114 ***************
115 *** 4807,4812 ****
116 --- 4868,4877 ----
117                 Search for regexp pattern {pattern}.  The search starts at the
118                 cursor position (you can use |cursor()| to set it).
119   
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.
123
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
129 ***************
130 *** 1,4 ****
131 ! *if_pyth.txt*   For Vim version 7.3.  Last change: 2010 Aug 13
132   
133   
134                   VIM REFERENCE MANUAL    by Paul Moore
135 --- 1,4 ----
136 ! *if_pyth.txt*   For Vim version 7.3.  Last change: 2012 Feb 04
137   
138   
139                   VIM REFERENCE MANUAL    by Paul Moore
140 ***************
141 *** 6,18 ****
142   
143   The Python Interface to Vim                           *python* *Python*
144   
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|
152   
153   {Vi does not have any of these commands}
154   
155 --- 6,19 ----
156   
157   The Python Interface to Vim                           *python* *Python*
158   
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|
167   
168   {Vi does not have any of these commands}
169   
170 ***************
171 *** 150,155 ****
172 --- 151,172 ----
173         [{'cmd': '/^eval_expr(arg, nextcmd)$/', 'static': 0, 'name':
174         'eval_expr', 'kind': 'f', 'filename': './src/eval.c'}]
175   
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.
185
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.
191
192   
193   
194   Error object of the "vim" module
195 ***************
196 *** 222,229 ****
197         - from indexing vim.buffers (|python-buffers|)
198         - from the "buffer" attribute of a window (|python-window|)
199   
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).
202   
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
205 --- 239,247 ----
206         - from indexing vim.buffers (|python-buffers|)
207         - from the "buffer" attribute of a window (|python-window|)
208   
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).
212   
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
215 ***************
216 *** 318,324 ****
217   The width attribute is writable only if the screen is split vertically.
218   
219   ==============================================================================
220 ! 6. Dynamic loading                                    *python-dynamic*
221   
222   On MS-Windows the Python library can be loaded dynamically.  The |:version|
223   output then includes |+python/dyn|.
224 --- 336,348 ----
225   The width attribute is writable only if the screen is split vertically.
226   
227   ==============================================================================
228 ! 6. pyeval() and py3eval() Vim functions                       *python-pyeval*
229
230 ! To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()| 
231 ! functions to evaluate Python expressions and pass their values to VimL.
232
233 ! ==============================================================================
234 ! 7. Dynamic loading                                    *python-dynamic*
235   
236   On MS-Windows the Python library can be loaded dynamically.  The |:version|
237   output then includes |+python/dyn|.
238 ***************
239 *** 335,347 ****
240   sure edit "gvim.exe" and search for "python\d*.dll\c".
241   
242   ==============================================================================
243 ! 7. Python 3                                           *python3*
244   
245                                                         *:py3* *:python3*
246   The |:py3| and |:python3| commands work similar to |:python|.
247                                                         *:py3file*
248   The |:py3file| command works similar to |:pyfile|.
249   
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)
253 --- 359,372 ----
254   sure edit "gvim.exe" and search for "python\d*.dll\c".
255   
256   ==============================================================================
257 ! 8. Python 3                                           *python3*
258   
259                                                         *:py3* *:python3*
260   The |:py3| and |:python3| commands work similar to |:python|.
261                                                         *:py3file*
262   The |:py3file| command works similar to |:pyfile|.
263   
264
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)
268 ***************
269 *** 355,361 ****
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.
275                                                         *E836* *E837*
276   Vim's configuration script makes a guess for all libraries based on one
277 --- 380,386 ----
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.
283                                                         *E836* *E837*
284   Vim's configuration script makes a guess for all libraries based on one
285 ***************
286 *** 377,382 ****
287 --- 402,419 ----
288   3. You undefine PY_NO_RTLD_GLOBAL in auto/config.h after configuration.  This
289      may crash Vim though.
290   
291 +                                                       *has-python*
292 + You can test what Python version is available with: >
293 +       if has('python')
294 +         echo 'there is Python 2.x'
295 +       elseif has('python3')
296 +         echo 'there is Python 3.x'
297 +       endif
298
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.
303   
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
308 ***************
309 *** 424,453 ****
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));
340 --- 424,444 ----
341 ***************
342 *** 654,659 ****
343 --- 645,656 ----
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));
349 + #endif
350 + #ifdef FEAT_PYTHON
351 + static void f_pyeval __ARGS((typval_T *argvars, typval_T *rettv));
352 + #endif
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));
356 ***************
357 *** 824,831 ****
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));
366 --- 821,826 ----
367 ***************
368 *** 5927,5933 ****
369   /*
370    * Allocate a list item.
371    */
372 !     static listitem_T *
373   listitem_alloc()
374   {
375       return (listitem_T *)alloc(sizeof(listitem_T));
376 --- 5922,5928 ----
377   /*
378    * Allocate a list item.
379    */
380 !     listitem_T *
381   listitem_alloc()
382   {
383       return (listitem_T *)alloc(sizeof(listitem_T));
384 ***************
385 *** 5947,5953 ****
386   /*
387    * Remove a list item from a List and free it.  Also clears the value.
388    */
389 !     static void
390   listitem_remove(l, item)
391       list_T  *l;
392       listitem_T *item;
393 --- 5942,5948 ----
394   /*
395    * Remove a list item from a List and free it.  Also clears the value.
396    */
397 !     void
398   listitem_remove(l, item)
399       list_T  *l;
400       listitem_T *item;
401 ***************
402 *** 6123,6129 ****
403    * A negative index is counted from the end; -1 is the last item.
404    * Returns NULL when "n" is out of range.
405    */
406 !     static listitem_T *
407   list_find(l, n)
408       list_T    *l;
409       long      n;
410 --- 6118,6124 ----
411    * A negative index is counted from the end; -1 is the last item.
412    * Returns NULL when "n" is out of range.
413    */
414 !     listitem_T *
415   list_find(l, n)
416       list_T    *l;
417       long      n;
418 ***************
419 *** 6265,6271 ****
420   /*
421    * Append item "item" to the end of list "l".
422    */
423 !     static void
424   list_append(l, item)
425       list_T    *l;
426       listitem_T        *item;
427 --- 6260,6266 ----
428   /*
429    * Append item "item" to the end of list "l".
430    */
431 !     void
432   list_append(l, item)
433       list_T    *l;
434       listitem_T        *item;
435 ***************
436 *** 6378,6384 ****
437    * If "item" is NULL append at the end.
438    * Return FAIL when out of memory.
439    */
440 !     static int
441   list_insert_tv(l, tv, item)
442       list_T    *l;
443       typval_T  *tv;
444 --- 6373,6379 ----
445    * If "item" is NULL append at the end.
446    * Return FAIL when out of memory.
447    */
448 !     int
449   list_insert_tv(l, tv, item)
450       list_T    *l;
451       typval_T  *tv;
452 ***************
453 *** 6523,6529 ****
454    * Remove items "item" to "item2" from list "l".
455    * Does not free the listitem or the value!
456    */
457 !     static void
458   list_remove(l, item, item2)
459       list_T    *l;
460       listitem_T        *item;
461 --- 6518,6524 ----
462    * Remove items "item" to "item2" from list "l".
463    * Does not free the listitem or the value!
464    */
465 !     void
466   list_remove(l, item, item2)
467       list_T    *l;
468       listitem_T        *item;
469 ***************
470 *** 6785,6790 ****
471 --- 6780,6793 ----
472       set_ref_in_lua(copyID);
473   #endif
474   
475 + #ifdef FEAT_PYTHON
476 +     set_ref_in_python(copyID);
477 + #endif
478
479 + #ifdef FEAT_PYTHON3
480 +     set_ref_in_python3(copyID);
481 + #endif
482
483       /*
484        * 2. Free lists and dictionaries that are not referenced.
485        */
486 ***************
487 *** 6870,6876 ****
488   /*
489    * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
490    */
491 !     static void
492   set_ref_in_ht(ht, copyID)
493       hashtab_T *ht;
494       int               copyID;
495 --- 6873,6879 ----
496   /*
497    * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
498    */
499 !     void
500   set_ref_in_ht(ht, copyID)
501       hashtab_T *ht;
502       int               copyID;
503 ***************
504 *** 6890,6896 ****
505   /*
506    * Mark all lists and dicts referenced through list "l" with "copyID".
507    */
508 !     static void
509   set_ref_in_list(l, copyID)
510       list_T    *l;
511       int               copyID;
512 --- 6893,6899 ----
513   /*
514    * Mark all lists and dicts referenced through list "l" with "copyID".
515    */
516 !     void
517   set_ref_in_list(l, copyID)
518       list_T    *l;
519       int               copyID;
520 ***************
521 *** 6904,6910 ****
522   /*
523    * Mark all lists and dicts referenced through typval "tv" with "copyID".
524    */
525 !     static void
526   set_ref_in_item(tv, copyID)
527       typval_T  *tv;
528       int               copyID;
529 --- 6907,6913 ----
530   /*
531    * Mark all lists and dicts referenced through typval "tv" with "copyID".
532    */
533 !     void
534   set_ref_in_item(tv, copyID)
535       typval_T  *tv;
536       int               copyID;
537 ***************
538 *** 7986,7991 ****
539 --- 7989,8000 ----
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},
545 + #endif
546 + #ifdef FEAT_PYTHON
547 +     {"pyeval",                1, 1, f_pyeval},
548 + #endif
549       {"range",         1, 3, f_range},
550       {"readfile",      1, 3, f_readfile},
551       {"reltime",               0, 2, f_reltime},
552 ***************
553 *** 9150,9155 ****
554 --- 9159,9203 ----
555   #endif
556   }
557   
558 +     int
559 + func_call(name, args, selfdict, rettv)
560 +     char_u    *name;
561 +     typval_T  *args;
562 +     dict_T    *selfdict;
563 +     typval_T  *rettv;
564 + {
565 +     listitem_T        *item;
566 +     typval_T  argv[MAX_FUNC_ARGS + 1];
567 +     int               argc = 0;
568 +     int               dummy;
569 +     int               r = 0;
570
571 +     for (item = args->vval.v_list->lv_first; item != NULL;
572 +                                                        item = item->li_next)
573 +     {
574 +       if (argc == MAX_FUNC_ARGS)
575 +       {
576 +           EMSG(_("E699: Too many arguments"));
577 +           break;
578 +       }
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.
581 +        */
582 +       copy_tv(&item->li_tv, &argv[argc++]);
583 +     }
584
585 +     if (item == NULL)
586 +       r = call_func(name, (int)STRLEN(name), rettv, argc, argv,
587 +                                curwin->w_cursor.lnum, curwin->w_cursor.lnum,
588 +                                                     &dummy, TRUE, selfdict);
589
590 +     /* Free the arguments. */
591 +     while (argc > 0)
592 +       clear_tv(&argv[--argc]);
593
594 +     return r;
595 + }
596
597   /*
598    * "call(func, arglist)" function
599    */
600 ***************
601 *** 9159,9168 ****
602       typval_T  *rettv;
603   {
604       char_u    *func;
605 -     typval_T  argv[MAX_FUNC_ARGS + 1];
606 -     int               argc = 0;
607 -     listitem_T        *item;
608 -     int               dummy;
609       dict_T    *selfdict = NULL;
610   
611       if (argvars[1].v_type != VAR_LIST)
612 --- 9207,9212 ----
613 ***************
614 *** 9190,9217 ****
615         selfdict = argvars[2].vval.v_dict;
616       }
617   
618 !     for (item = argvars[1].vval.v_list->lv_first; item != NULL;
619 !                                                        item = item->li_next)
620 !     {
621 !       if (argc == MAX_FUNC_ARGS)
622 !       {
623 !           EMSG(_("E699: Too many arguments"));
624 !           break;
625 !       }
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.
628 !        */
629 !       copy_tv(&item->li_tv, &argv[argc++]);
630 !     }
631
632 !     if (item == NULL)
633 !       (void)call_func(func, (int)STRLEN(func), rettv, argc, argv,
634 !                                curwin->w_cursor.lnum, curwin->w_cursor.lnum,
635 !                                                     &dummy, TRUE, selfdict);
636
637 !     /* Free the arguments. */
638 !     while (argc > 0)
639 !       clear_tv(&argv[--argc]);
640   }
641   
642   #ifdef FEAT_FLOAT
643 --- 9234,9240 ----
644         selfdict = argvars[2].vval.v_dict;
645       }
646   
647 !     (void)func_call(func, &argvars[1], selfdict, rettv);
648   }
649   
650   #ifdef FEAT_FLOAT
651 ***************
652 *** 14424,14429 ****
653 --- 14447,14486 ----
654   #endif
655   }
656   
657 + #ifdef FEAT_PYTHON3
658 + /*
659 +  * "py3eval()" function
660 +  */
661 +     static void
662 + f_py3eval(argvars, rettv)
663 +     typval_T  *argvars;
664 +     typval_T  *rettv;
665 + {
666 +     char_u    *str;
667 +     char_u    buf[NUMBUFLEN];
668
669 +     str = get_tv_string_buf(&argvars[0], buf);
670 +     do_py3eval(str, rettv);
671 + }
672 + #endif
673
674 + #ifdef FEAT_PYTHON
675 + /*
676 +  * "pyeval()" function
677 +  */
678 +     static void
679 + f_pyeval(argvars, rettv)
680 +     typval_T  *argvars;
681 +     typval_T  *rettv;
682 + {
683 +     char_u    *str;
684 +     char_u    buf[NUMBUFLEN];
685
686 +     str = get_tv_string_buf(&argvars[0], buf);
687 +     do_pyeval(str, rettv);
688 + }
689 + #endif
690
691   /*
692    * "range()" function
693    */
694 ***************
695 *** 22139,22145 ****
696    * Unreference a Function: decrement the reference count and free it when it
697    * becomes zero.  Only for numbered functions.
698    */
699 !     static void
700   func_unref(name)
701       char_u    *name;
702   {
703 --- 22196,22202 ----
704    * Unreference a Function: decrement the reference count and free it when it
705    * becomes zero.  Only for numbered functions.
706    */
707 !     void
708   func_unref(name)
709       char_u    *name;
710   {
711 ***************
712 *** 22163,22169 ****
713   /*
714    * Count a reference to a Function.
715    */
716 !     static void
717   func_ref(name)
718       char_u    *name;
719   {
720 --- 22220,22226 ----
721   /*
722    * Count a reference to a Function.
723    */
724 !     void
725   func_ref(name)
726       char_u    *name;
727   {
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
730 ***************
731 *** 199,207 ****
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,
735 !         lua_CFunction k);
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);
740   #endif
741 --- 199,207 ----
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,
745 !       lua_CFunction k);
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);
750   #endif
751 ***************
752 *** 394,400 ****
753   luaL_typeerror (lua_State *L, int narg, const char *tname)
754   {
755       const char *msg = lua_pushfstring(L, "%s expected, got %s",
756 !             tname, luaL_typename(L, narg));
757       return luaL_argerror(L, narg, msg);
758   }
759   #endif
760 --- 394,400 ----
761   luaL_typeerror (lua_State *L, int narg, const char *tname)
762   {
763       const char *msg = lua_pushfstring(L, "%s expected, got %s",
764 !           tname, luaL_typename(L, narg));
765       return luaL_argerror(L, narg, msg);
766   }
767   #endif
768 ***************
769 *** 646,786 ****
770         return 1; \
771       }
772   
773
774 - /* adapted from eval.c */
775
776 - #define listitem_alloc() (listitem_T *)alloc(sizeof(listitem_T))
777
778 -     static listitem_T *
779 - list_find (list_T *l, long n)
780 - {
781 -     listitem_T *li;
782 -     if (l == NULL || n < -l->lv_len || n >= l->lv_len)
783 -       return NULL;
784 -     if (n < 0) /* search backward? */
785 -       for (li = l->lv_last; n < -1; li = li->li_prev)
786 -           n++;
787 -     else /* search forward */
788 -       for (li = l->lv_first; n > 0; li = li->li_next)
789 -           n--;
790 -     return li;
791 - }
792
793 -     static void
794 - list_remove (list_T *l, listitem_T *li)
795 - {
796 -     listwatch_T *lw;
797 -     --l->lv_len;
798 -     /* fix watchers */
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;
805 -     else
806 -       li->li_next->li_prev = li->li_prev;
807 -     if (li->li_prev == NULL) /* first? */
808 -       l->lv_first = li->li_next;
809 -     else
810 -       li->li_prev->li_next = li->li_next;
811 -     l->lv_idx_item = NULL;
812 - }
813
814 -     static void
815 - list_append(list_T *l, listitem_T *item)
816 - {
817 -     if (l->lv_last == NULL) /* empty list? */
818 -       l->lv_first = item;
819 -     else
820 -       l->lv_last->li_next = item;
821 -     item->li_prev = l->lv_last;
822 -     item->li_next = NULL;
823 -     l->lv_last = item;
824 -     ++l->lv_len;
825 - }
826
827 -     static int
828 - list_insert_tv(list_T *l, typval_T *tv, listitem_T *item)
829 - {
830 -     listitem_T        *ni = listitem_alloc();
831
832 -     if (ni == NULL)
833 -       return FAIL;
834 -     copy_tv(tv, &ni->li_tv);
835 -     if (item == NULL)
836 -       list_append(l, ni);
837 -     else
838 -     {
839 -       ni->li_prev = item->li_prev;
840 -       ni->li_next = item;
841 -       if (item->li_prev == NULL)
842 -       {
843 -           l->lv_first = ni;
844 -           ++l->lv_idx;
845 -       }
846 -       else
847 -       {
848 -           item->li_prev->li_next = ni;
849 -           l->lv_idx_item = NULL;
850 -       }
851 -       item->li_prev = ni;
852 -       ++l->lv_len;
853 -     }
854 -     return OK;
855 - }
856
857 - /* set references */
858
859 - static void set_ref_in_tv (typval_T *tv, int copyID);
860
861 -     static void
862 - set_ref_in_dict(dict_T *d, int copyID)
863 - {
864 -     hashtab_T *ht = &d->dv_hashtab;
865 -     int n = ht->ht_used;
866 -     hashitem_T *hi;
867 -     for (hi = ht->ht_array; n > 0; ++hi)
868 -       if (!HASHITEM_EMPTY(hi))
869 -       {
870 -           dictitem_T *di = dict_lookup(hi);
871 -           set_ref_in_tv(&di->di_tv, copyID);
872 -           --n;
873 -       }
874 - }
875
876 -     static void
877 - set_ref_in_list(list_T *l, int copyID)
878 - {
879 -     listitem_T *li;
880 -     for (li = l->lv_first; li != NULL; li = li->li_next)
881 -       set_ref_in_tv(&li->li_tv, copyID);
882 - }
883
884 -     static void
885 - set_ref_in_tv(typval_T *tv, int copyID)
886 - {
887 -     if (tv->v_type == VAR_LIST)
888 -     {
889 -       list_T *l = tv->vval.v_list;
890 -       if (l != NULL && l->lv_copyID != copyID)
891 -       {
892 -           l->lv_copyID = copyID;
893 -           set_ref_in_list(l, copyID);
894 -       }
895 -     }
896 -     else if (tv->v_type == VAR_DICT)
897 -     {
898 -       dict_T *d = tv->vval.v_dict;
899 -       if (d != NULL && d->dv_copyID != copyID)
900 -       {
901 -           d->dv_copyID = copyID;
902 -           set_ref_in_dict(d, copyID);
903 -       }
904 -     }
905 - }
906
907
908   /* =======   List type   ======= */
909   
910       static luaV_List *
911 --- 646,651 ----
912 ***************
913 *** 876,882 ****
914       if (li == NULL) return 0;
915       if (lua_isnil(L, 3)) /* remove? */
916       {
917 !       list_remove(l, li);
918         clear_tv(&li->li_tv);
919         vim_free(li);
920       }
921 --- 741,747 ----
922       if (li == NULL) return 0;
923       if (lua_isnil(L, 3)) /* remove? */
924       {
925 !       list_remove(l, li, li);
926         clear_tv(&li->li_tv);
927         vim_free(li);
928       }
929 ***************
930 *** 904,911 ****
931         typval_T v;
932         lua_settop(L, 2);
933         luaV_totypval(L, 2, &v);
934 !       copy_tv(&v, &li->li_tv);
935 !       list_append(l, li);
936       }
937       lua_settop(L, 1);
938       return 1;
939 --- 769,775 ----
940         typval_T v;
941         lua_settop(L, 2);
942         luaV_totypval(L, 2, &v);
943 !       list_append_tv(l, &v);
944       }
945       lua_settop(L, 1);
946       return 1;
947 ***************
948 *** 1682,1688 ****
949             tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
950         }
951         lua_pop(L, 2); /* metatable and value */
952 !       set_ref_in_tv(&tv, copyID);
953       }
954       return 0;
955   }
956 --- 1546,1552 ----
957             tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
958         }
959         lua_pop(L, 2); /* metatable and value */
960 !       set_ref_in_item(&tv, copyID);
961       }
962       return 0;
963   }
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
966 ***************
967 *** 1,4 ****
968 ! /* vi:set ts=8 sts=4 sw=4:
969    *
970    * VIM - Vi IMproved  by Bram Moolenaar
971    *
972 --- 1,4 ----
973 ! /* vi:set ts=8 sts=4 sw=4 noet:
974    *
975    * VIM - Vi IMproved  by Bram Moolenaar
976    *
977 ***************
978 *** 105,111 ****
979         return NULL;
980       Py_INCREF(list);
981   
982 !     if (!PyList_Check(list)) {
983         PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
984         Py_DECREF(list);
985         return NULL;
986 --- 105,112 ----
987         return NULL;
988       Py_INCREF(list);
989   
990 !     if (!PyList_Check(list))
991 !     {
992         PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
993         Py_DECREF(list);
994         return NULL;
995 ***************
996 *** 119,125 ****
997         char *str = NULL;
998         PyInt len;
999   
1000 !       if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len)) {
1001             PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
1002             Py_DECREF(list);
1003             return NULL;
1004 --- 120,127 ----
1005         char *str = NULL;
1006         PyInt len;
1007   
1008 !       if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len))
1009 !       {
1010             PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
1011             Py_DECREF(list);
1012             return NULL;
1013 ***************
1014 *** 297,303 ****
1015   {
1016       PyObject  *result;
1017       PyObject  *newObj;
1018 !     char      ptrBuf[NUMBUFLEN];
1019   
1020       /* Avoid infinite recursion */
1021       if (depth > 100)
1022 --- 299,305 ----
1023   {
1024       PyObject  *result;
1025       PyObject  *newObj;
1026 !     char      ptrBuf[sizeof(void *) * 2 + 3];
1027   
1028       /* Avoid infinite recursion */
1029       if (depth > 100)
1030 ***************
1031 *** 312,320 ****
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))
1034       {
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);
1039         if (result != NULL)
1040         {
1041 --- 314,322 ----
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))
1044       {
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);
1049         if (result != NULL)
1050         {
1051 ***************
1052 *** 374,509 ****
1053             hashitem_T  *hi;
1054             dictitem_T  *di;
1055   
1056 !           PyDict_SetItemString(lookupDict, ptrBuf, result);
1057   
1058 !           for (hi = ht->ht_array; todo > 0; ++hi)
1059             {
1060 !               if (!HASHITEM_EMPTY(hi))
1061 !               {
1062 !                   --todo;
1063
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);
1068 !               }
1069             }
1070         }
1071       }
1072 !     else
1073       {
1074 !       Py_INCREF(Py_None);
1075 !       result = Py_None;
1076       }
1077   
1078 !     return result;
1079   }
1080 - #endif
1081   
1082       static PyObject *
1083 ! VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
1084   {
1085 ! #ifdef FEAT_EVAL
1086 !     char      *expr;
1087 !     typval_T  *our_tv;
1088 !     PyObject  *result;
1089 !     PyObject    *lookup_dict;
1090   
1091 !     if (!PyArg_ParseTuple(args, "s", &expr))
1092         return NULL;
1093   
1094 !     Py_BEGIN_ALLOW_THREADS
1095 !     Python_Lock_Vim();
1096 !     our_tv = eval_expr((char_u *)expr, NULL);
1097
1098 !     Python_Release_Vim();
1099 !     Py_END_ALLOW_THREADS
1100
1101 !     if (our_tv == NULL)
1102       {
1103 !       PyErr_SetVim(_("invalid expression"));
1104         return NULL;
1105       }
1106   
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);
1112   
1113
1114 !     Py_BEGIN_ALLOW_THREADS
1115 !     Python_Lock_Vim();
1116 !     free_tv(our_tv);
1117 !     Python_Release_Vim();
1118 !     Py_END_ALLOW_THREADS
1119
1120 !     return result;
1121 ! #else
1122 !     PyErr_SetVim(_("expressions disabled at compile time"));
1123 !     return NULL;
1124 ! #endif
1125   }
1126   
1127 ! /*
1128 !  * Vim module - Definitions
1129 !  */
1130
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 }
1136   };
1137   
1138   typedef struct
1139   {
1140       PyObject_HEAD
1141 !     buf_T *buf;
1142 ! }
1143 ! BufferObject;
1144   
1145 ! #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
1146
1147 ! /*
1148 !  * Buffer list object - Implementation
1149 !  */
1150   
1151 !     static PyInt
1152 ! BufListLength(PyObject *self UNUSED)
1153   {
1154 !     buf_T     *b = firstbuf;
1155 !     PyInt     n = 0;
1156   
1157 !     while (b)
1158       {
1159 !       ++n;
1160 !       b = b->b_next;
1161       }
1162
1163 !     return n;
1164   }
1165   
1166       static PyObject *
1167 ! BufListItem(PyObject *self UNUSED, PyInt n)
1168   {
1169 !     buf_T *b;
1170   
1171 !     for (b = firstbuf; b; b = b->b_next, --n)
1172       {
1173 !       if (n == 0)
1174 !           return BufferNew(b);
1175       }
1176   
1177 !     PyErr_SetString(PyExc_IndexError, _("no such buffer"));
1178 !     return NULL;
1179   }
1180   
1181 ! typedef struct
1182 ! {
1183 !     PyObject_HEAD
1184 !     win_T     *win;
1185 ! } WindowObject;
1186   
1187   #define INVALID_WINDOW_VALUE ((win_T *)(-1))
1188   
1189 --- 376,1325 ----
1190             hashitem_T  *hi;
1191             dictitem_T  *di;
1192   
1193 !           PyDict_SetItemString(lookupDict, ptrBuf, result);
1194
1195 !           for (hi = ht->ht_array; todo > 0; ++hi)
1196 !           {
1197 !               if (!HASHITEM_EMPTY(hi))
1198 !               {
1199 !                   --todo;
1200
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);
1205 !               }
1206 !           }
1207 !       }
1208 !     }
1209 !     else
1210 !     {
1211 !       Py_INCREF(Py_None);
1212 !       result = Py_None;
1213 !     }
1214
1215 !     return result;
1216 ! }
1217 ! #endif
1218
1219 !     static PyObject *
1220 ! VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
1221 ! {
1222 ! #ifdef FEAT_EVAL
1223 !     char      *expr;
1224 !     typval_T  *our_tv;
1225 !     PyObject  *result;
1226 !     PyObject    *lookup_dict;
1227
1228 !     if (!PyArg_ParseTuple(args, "s", &expr))
1229 !       return NULL;
1230
1231 !     Py_BEGIN_ALLOW_THREADS
1232 !     Python_Lock_Vim();
1233 !     our_tv = eval_expr((char_u *)expr, NULL);
1234
1235 !     Python_Release_Vim();
1236 !     Py_END_ALLOW_THREADS
1237
1238 !     if (our_tv == NULL)
1239 !     {
1240 !       PyErr_SetVim(_("invalid expression"));
1241 !       return NULL;
1242 !     }
1243
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);
1249
1250
1251 !     Py_BEGIN_ALLOW_THREADS
1252 !     Python_Lock_Vim();
1253 !     free_tv(our_tv);
1254 !     Python_Release_Vim();
1255 !     Py_END_ALLOW_THREADS
1256
1257 !     return result;
1258 ! #else
1259 !     PyErr_SetVim(_("expressions disabled at compile time"));
1260 !     return NULL;
1261 ! #endif
1262 ! }
1263
1264 ! static PyObject *ConvertToPyObject(typval_T *);
1265
1266 !     static PyObject *
1267 ! VimEvalPy(PyObject *self UNUSED, PyObject *args UNUSED)
1268 ! {
1269 ! #ifdef FEAT_EVAL
1270 !     char      *expr;
1271 !     typval_T  *our_tv;
1272 !     PyObject  *result;
1273
1274 !     if (!PyArg_ParseTuple(args, "s", &expr))
1275 !       return NULL;
1276
1277 !     Py_BEGIN_ALLOW_THREADS
1278 !     Python_Lock_Vim();
1279 !     our_tv = eval_expr((char_u *)expr, NULL);
1280
1281 !     Python_Release_Vim();
1282 !     Py_END_ALLOW_THREADS
1283
1284 !     if (our_tv == NULL)
1285 !     {
1286 !       PyErr_SetVim(_("invalid expression"));
1287 !       return NULL;
1288 !     }
1289
1290 !     result = ConvertToPyObject(our_tv);
1291 !     Py_BEGIN_ALLOW_THREADS
1292 !     Python_Lock_Vim();
1293 !     free_tv(our_tv);
1294 !     Python_Release_Vim();
1295 !     Py_END_ALLOW_THREADS
1296
1297 !     return result;
1298 ! #else
1299 !     PyErr_SetVim(_("expressions disabled at compile time"));
1300 !     return NULL;
1301 ! #endif
1302 ! }
1303
1304 !     static PyObject *
1305 ! VimStrwidth(PyObject *self UNUSED, PyObject *args)
1306 ! {
1307 !     char      *expr;
1308
1309 !     if (!PyArg_ParseTuple(args, "s", &expr))
1310 !       return NULL;
1311
1312 !     return PyLong_FromLong(mb_string2cells((char_u *)expr, STRLEN(expr)));
1313 ! }
1314
1315 ! /*
1316 !  * Vim module - Definitions
1317 !  */
1318
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 }
1326 ! };
1327
1328 ! typedef struct
1329 ! {
1330 !     PyObject_HEAD
1331 !     buf_T *buf;
1332 ! } BufferObject;
1333
1334 ! #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
1335
1336 ! /*
1337 !  * Buffer list object - Implementation
1338 !  */
1339
1340 !     static PyInt
1341 ! BufListLength(PyObject *self UNUSED)
1342 ! {
1343 !     buf_T     *b = firstbuf;
1344 !     PyInt     n = 0;
1345
1346 !     while (b)
1347 !     {
1348 !       ++n;
1349 !       b = b->b_next;
1350 !     }
1351
1352 !     return n;
1353 ! }
1354
1355 !     static PyObject *
1356 ! BufListItem(PyObject *self UNUSED, PyInt n)
1357 ! {
1358 !     buf_T *b;
1359
1360 !     for (b = firstbuf; b; b = b->b_next, --n)
1361 !     {
1362 !       if (n == 0)
1363 !           return BufferNew(b);
1364 !     }
1365
1366 !     PyErr_SetString(PyExc_IndexError, _("no such buffer"));
1367 !     return NULL;
1368 ! }
1369
1370 ! typedef struct
1371 ! {
1372 !     PyObject_HEAD
1373 !     win_T     *win;
1374 ! } WindowObject;
1375
1376 ! static int ConvertFromPyObject(PyObject *, typval_T *);
1377 ! static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
1378
1379 ! typedef struct pylinkedlist_S {
1380 !     struct pylinkedlist_S     *pll_next;
1381 !     struct pylinkedlist_S     *pll_prev;
1382 !     PyObject                  *pll_obj;
1383 ! } pylinkedlist_T;
1384
1385 ! static pylinkedlist_T *lastdict = NULL;
1386 ! static pylinkedlist_T *lastlist = NULL;
1387
1388 !     static void
1389 ! pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
1390 ! {
1391 !     if (ref->pll_prev == NULL)
1392 !     {
1393 !       if (ref->pll_next == NULL)
1394 !       {
1395 !           *last = NULL;
1396 !           return;
1397 !       }
1398 !     }
1399 !     else
1400 !       ref->pll_prev->pll_next = ref->pll_next;
1401
1402 !     if (ref->pll_next == NULL)
1403 !       *last = ref->pll_prev;
1404 !     else
1405 !       ref->pll_next->pll_prev = ref->pll_prev;
1406 ! }
1407
1408 !     static void
1409 ! pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
1410 ! {
1411 !     if (*last == NULL)
1412 !       ref->pll_prev = NULL;
1413 !     else
1414 !     {
1415 !       (*last)->pll_next = ref;
1416 !       ref->pll_prev = *last;
1417 !     }
1418 !     ref->pll_next = NULL;
1419 !     ref->pll_obj = self;
1420 !     *last = ref;
1421 ! }
1422
1423 ! static PyTypeObject DictionaryType;
1424
1425 ! typedef struct
1426 ! {
1427 !     PyObject_HEAD
1428 !     dict_T    *dict;
1429 !     pylinkedlist_T    ref;
1430 ! } DictionaryObject;
1431
1432 !     static PyObject *
1433 ! DictionaryNew(dict_T *dict)
1434 ! {
1435 !     DictionaryObject  *self;
1436
1437 !     self = PyObject_NEW(DictionaryObject, &DictionaryType);
1438 !     if (self == NULL)
1439 !       return NULL;
1440 !     self->dict = dict;
1441 !     ++dict->dv_refcount;
1442
1443 !     pyll_add((PyObject *)(self), &self->ref, &lastdict);
1444
1445 !     return (PyObject *)(self);
1446 ! }
1447
1448 !     static int
1449 ! pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1450 ! {
1451 !     dict_T    *d;
1452 !     char_u    *key;
1453 !     dictitem_T        *di;
1454 !     PyObject  *keyObject;
1455 !     PyObject  *valObject;
1456 !     Py_ssize_t        iter = 0;
1457
1458 !     d = dict_alloc();
1459 !     if (d == NULL)
1460 !     {
1461 !       PyErr_NoMemory();
1462 !       return -1;
1463 !     }
1464
1465 !     tv->v_type = VAR_DICT;
1466 !     tv->vval.v_dict = d;
1467
1468 !     while (PyDict_Next(obj, &iter, &keyObject, &valObject))
1469 !     {
1470 !       DICTKEY_DECL
1471
1472 !       if (keyObject == NULL)
1473 !           return -1;
1474 !       if (valObject == NULL)
1475 !           return -1;
1476
1477 !       DICTKEY_GET(-1)
1478
1479 !       di = dictitem_alloc(key);
1480
1481 !       DICTKEY_UNREF
1482
1483 !       if (di == NULL)
1484 !       {
1485 !           PyErr_NoMemory();
1486 !           return -1;
1487 !       }
1488 !       di->di_tv.v_lock = 0;
1489
1490 !       if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
1491 !       {
1492 !           vim_free(di);
1493 !           return -1;
1494 !       }
1495 !       if (dict_add(d, di) == FAIL)
1496 !       {
1497 !           vim_free(di);
1498 !           PyErr_SetVim(_("failed to add key to dictionary"));
1499 !           return -1;
1500 !       }
1501 !     }
1502 !     return 0;
1503 ! }
1504
1505 !     static int
1506 ! pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1507 ! {
1508 !     dict_T    *d;
1509 !     char_u    *key;
1510 !     dictitem_T        *di;
1511 !     PyObject  *list;
1512 !     PyObject  *litem;
1513 !     PyObject  *keyObject;
1514 !     PyObject  *valObject;
1515 !     Py_ssize_t        lsize;
1516
1517 !     d = dict_alloc();
1518 !     if (d == NULL)
1519 !     {
1520 !       PyErr_NoMemory();
1521 !       return -1;
1522 !     }
1523
1524 !     tv->v_type = VAR_DICT;
1525 !     tv->vval.v_dict = d;
1526
1527 !     list = PyMapping_Items(obj);
1528 !     lsize = PyList_Size(list);
1529 !     while (lsize--)
1530 !     {
1531 !       DICTKEY_DECL
1532
1533 !       litem = PyList_GetItem(list, lsize);
1534 !       if (litem == NULL)
1535 !       {
1536 !           Py_DECREF(list);
1537 !           return -1;
1538 !       }
1539
1540 !       keyObject = PyTuple_GetItem(litem, 0);
1541 !       if (keyObject == NULL)
1542 !       {
1543 !           Py_DECREF(list);
1544 !           Py_DECREF(litem);
1545 !           return -1;
1546 !       }
1547
1548 !       DICTKEY_GET(-1)
1549
1550 !       valObject = PyTuple_GetItem(litem, 1);
1551 !       if (valObject == NULL)
1552 !       {
1553 !           Py_DECREF(list);
1554 !           Py_DECREF(litem);
1555 !           return -1;
1556 !       }
1557
1558 !       di = dictitem_alloc(key);
1559
1560 !       DICTKEY_UNREF
1561
1562 !       if (di == NULL)
1563 !       {
1564 !           Py_DECREF(list);
1565 !           Py_DECREF(litem);
1566 !           PyErr_NoMemory();
1567 !           return -1;
1568 !       }
1569 !       di->di_tv.v_lock = 0;
1570
1571 !       if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
1572 !       {
1573 !           vim_free(di);
1574 !           Py_DECREF(list);
1575 !           Py_DECREF(litem);
1576 !           return -1;
1577 !       }
1578 !       if (dict_add(d, di) == FAIL)
1579 !       {
1580 !           vim_free(di);
1581 !           Py_DECREF(list);
1582 !           Py_DECREF(litem);
1583 !           PyErr_SetVim(_("failed to add key to dictionary"));
1584 !           return -1;
1585 !       }
1586 !       Py_DECREF(litem);
1587 !     }
1588 !     Py_DECREF(list);
1589 !     return 0;
1590 ! }
1591
1592 !     static PyInt
1593 ! DictionaryLength(PyObject *self)
1594 ! {
1595 !     return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used)));
1596 ! }
1597
1598 !     static PyObject *
1599 ! DictionaryItem(PyObject *self, PyObject *keyObject)
1600 ! {
1601 !     char_u    *key;
1602 !     dictitem_T        *val;
1603 !     DICTKEY_DECL
1604
1605 !     DICTKEY_GET(NULL)
1606
1607 !     val = dict_find(((DictionaryObject *) (self))->dict, key, -1);
1608
1609 !     DICTKEY_UNREF
1610
1611 !     return ConvertToPyObject(&val->di_tv);
1612 ! }
1613
1614 !     static PyInt
1615 ! DictionaryAssItem(PyObject *self, PyObject *keyObject, PyObject *valObject)
1616 ! {
1617 !     char_u    *key;
1618 !     typval_T  tv;
1619 !     dict_T    *d = ((DictionaryObject *)(self))->dict;
1620 !     dictitem_T        *di;
1621 !     DICTKEY_DECL
1622
1623 !     if (d->dv_lock)
1624 !     {
1625 !       PyErr_SetVim(_("dict is locked"));
1626 !       return -1;
1627 !     }
1628
1629 !     DICTKEY_GET(-1)
1630
1631 !     di = dict_find(d, key, -1);
1632
1633 !     if (valObject == NULL)
1634 !     {
1635 !       if (di == NULL)
1636 !       {
1637 !           PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
1638 !           return -1;
1639 !       }
1640 !       hashitem_T      *hi = hash_find(&d->dv_hashtab, di->di_key);
1641 !       hash_remove(&d->dv_hashtab, hi);
1642 !       dictitem_free(di);
1643 !       return 0;
1644 !     }
1645
1646 !     if (ConvertFromPyObject(valObject, &tv) == -1)
1647 !     {
1648 !       return -1;
1649 !     }
1650
1651 !     if (di == NULL)
1652 !     {
1653 !       di = dictitem_alloc(key);
1654 !       if (di == NULL)
1655 !       {
1656 !           PyErr_NoMemory();
1657 !           return -1;
1658 !       }
1659 !       di->di_tv.v_lock = 0;
1660
1661 !       if (dict_add(d, di) == FAIL)
1662 !       {
1663 !           vim_free(di);
1664 !           PyErr_SetVim(_("failed to add key to dictionary"));
1665 !           return -1;
1666 !       }
1667 !     }
1668 !     else
1669 !       clear_tv(&di->di_tv);
1670
1671 !     DICTKEY_UNREF
1672
1673 !     copy_tv(&tv, &di->di_tv);
1674 !     return 0;
1675 ! }
1676
1677 !     static PyObject *
1678 ! DictionaryListKeys(PyObject *self)
1679 ! {
1680 !     dict_T    *dict = ((DictionaryObject *)(self))->dict;
1681 !     long_u    todo = dict->dv_hashtab.ht_used;
1682 !     Py_ssize_t        i = 0;
1683 !     PyObject  *r;
1684 !     hashitem_T        *hi;
1685
1686 !     r = PyList_New(todo);
1687 !     for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
1688 !     {
1689 !       if (!HASHITEM_EMPTY(hi))
1690 !       {
1691 !           PyList_SetItem(r, i, PyBytes_FromString((char *)(hi->hi_key)));
1692 !           --todo;
1693 !           ++i;
1694 !       }
1695 !     }
1696 !     return r;
1697 ! }
1698
1699 ! static struct PyMethodDef DictionaryMethods[] = {
1700 !     {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
1701 !     { NULL,       NULL,               0,          NULL }
1702 ! };
1703
1704 ! static PyTypeObject ListType;
1705
1706 ! typedef struct
1707 ! {
1708 !     PyObject_HEAD
1709 !     list_T    *list;
1710 !     pylinkedlist_T    ref;
1711 ! } ListObject;
1712
1713 !     static PyObject *
1714 ! ListNew(list_T *list)
1715 ! {
1716 !     ListObject        *self;
1717
1718 !     self = PyObject_NEW(ListObject, &ListType);
1719 !     if (self == NULL)
1720 !       return NULL;
1721 !     self->list = list;
1722 !     ++list->lv_refcount;
1723
1724 !     pyll_add((PyObject *)(self), &self->ref, &lastlist);
1725
1726 !     return (PyObject *)(self);
1727 ! }
1728
1729 !     static int
1730 ! list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict)
1731 ! {
1732 !     Py_ssize_t        i;
1733 !     Py_ssize_t        lsize = PySequence_Size(obj);
1734 !     PyObject  *litem;
1735 !     listitem_T        *li;
1736
1737 !     for(i=0; i<lsize; i++)
1738 !     {
1739 !       li = listitem_alloc();
1740 !       if (li == NULL)
1741 !       {
1742 !           PyErr_NoMemory();
1743 !           return -1;
1744 !       }
1745 !       li->li_tv.v_lock = 0;
1746
1747 !       litem = PySequence_GetItem(obj, i);
1748 !       if (litem == NULL)
1749 !           return -1;
1750 !       if (_ConvertFromPyObject(litem, &li->li_tv, lookupDict) == -1)
1751 !           return -1;
1752
1753 !       list_append(l, li);
1754 !     }
1755 !     return 0;
1756 ! }
1757
1758 !     static int
1759 ! pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1760 ! {
1761 !     list_T    *l;
1762
1763 !     l = list_alloc();
1764 !     if (l == NULL)
1765 !     {
1766 !       PyErr_NoMemory();
1767 !       return -1;
1768 !     }
1769
1770 !     tv->v_type = VAR_LIST;
1771 !     tv->vval.v_list = l;
1772
1773 !     if (list_py_concat(l, obj, lookupDict) == -1)
1774 !       return -1;
1775
1776 !     return 0;
1777 ! }
1778
1779 !     static int
1780 ! pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
1781 ! {
1782 !     PyObject  *iterator = PyObject_GetIter(obj);
1783 !     PyObject  *item;
1784 !     list_T    *l;
1785 !     listitem_T        *li;
1786
1787 !     l = list_alloc();
1788
1789 !     if (l == NULL)
1790 !     {
1791 !       PyErr_NoMemory();
1792 !       return -1;
1793 !     }
1794
1795 !     tv->vval.v_list = l;
1796 !     tv->v_type = VAR_LIST;
1797
1798
1799 !     if (iterator == NULL)
1800 !       return -1;
1801
1802 !     while ((item = PyIter_Next(obj)))
1803 !     {
1804 !       li = listitem_alloc();
1805 !       if (li == NULL)
1806 !       {
1807 !           PyErr_NoMemory();
1808 !           return -1;
1809 !       }
1810 !       li->li_tv.v_lock = 0;
1811
1812 !       if (_ConvertFromPyObject(item, &li->li_tv, lookupDict) == -1)
1813 !           return -1;
1814
1815 !       list_append(l, li);
1816
1817 !       Py_DECREF(item);
1818 !     }
1819
1820 !     Py_DECREF(iterator);
1821 !     return 0;
1822 ! }
1823
1824 !     static PyInt
1825 ! ListLength(PyObject *self)
1826 ! {
1827 !     return ((PyInt) (((ListObject *) (self))->list->lv_len));
1828 ! }
1829
1830 !     static PyObject *
1831 ! ListItem(PyObject *self, Py_ssize_t index)
1832 ! {
1833 !     listitem_T        *li;
1834
1835 !     if (index>=ListLength(self))
1836 !     {
1837 !       PyErr_SetString(PyExc_IndexError, "list index out of range");
1838 !       return NULL;
1839 !     }
1840 !     li = list_find(((ListObject *) (self))->list, (long) index);
1841 !     if (li == NULL)
1842 !     {
1843 !       PyErr_SetVim(_("internal error: failed to get vim list item"));
1844 !       return NULL;
1845 !     }
1846 !     return ConvertToPyObject(&li->li_tv);
1847 ! }
1848
1849 ! #define PROC_RANGE \
1850 !     if (last < 0) {\
1851 !       if (last < -size) \
1852 !           last = 0; \
1853 !       else \
1854 !           last += size; \
1855 !     } \
1856 !     if (first < 0) \
1857 !       first = 0; \
1858 !     if (first > size) \
1859 !       first = size; \
1860 !     if (last > size) \
1861 !       last = size;
1862
1863 !     static PyObject *
1864 ! ListSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last)
1865 ! {
1866 !     PyInt     i;
1867 !     PyInt     size = ListLength(self);
1868 !     PyInt     n;
1869 !     PyObject  *list;
1870 !     int               reversed = 0;
1871
1872 !     PROC_RANGE
1873 !     if (first >= last)
1874 !       first = last;
1875
1876 !     n = last-first;
1877 !     list = PyList_New(n);
1878 !     if (list == NULL)
1879 !       return NULL;
1880
1881 !     for (i = 0; i < n; ++i)
1882 !     {
1883 !       PyObject        *item = ListItem(self, i);
1884 !       if (item == NULL)
1885 !       {
1886 !           Py_DECREF(list);
1887 !           return NULL;
1888 !       }
1889
1890 !       if ((PyList_SetItem(list, ((reversed)?(n-i-1):(i)), item)))
1891 !       {
1892 !           Py_DECREF(item);
1893 !           Py_DECREF(list);
1894 !           return NULL;
1895 !       }
1896 !     }
1897
1898 !     return list;
1899 ! }
1900
1901 !     static int
1902 ! ListAssItem(PyObject *self, Py_ssize_t index, PyObject *obj)
1903 ! {
1904 !     typval_T  tv;
1905 !     list_T    *l = ((ListObject *) (self))->list;
1906 !     listitem_T        *li;
1907 !     Py_ssize_t        length = ListLength(self);
1908
1909 !     if (l->lv_lock)
1910 !     {
1911 !       PyErr_SetVim(_("list is locked"));
1912 !       return -1;
1913 !     }
1914 !     if (index>length || (index==length && obj==NULL))
1915 !     {
1916 !       PyErr_SetString(PyExc_IndexError, "list index out of range");
1917 !       return -1;
1918 !     }
1919
1920 !     if (obj == NULL)
1921 !     {
1922 !       li = list_find(l, (long) index);
1923 !       list_remove(l, li, li);
1924 !       clear_tv(&li->li_tv);
1925 !       vim_free(li);
1926 !       return 0;
1927 !     }
1928
1929 !     if (ConvertFromPyObject(obj, &tv) == -1)
1930 !       return -1;
1931
1932 !     if (index == length)
1933 !     {
1934 !       if (list_append_tv(l, &tv) == FAIL)
1935 !       {
1936 !           PyErr_SetVim(_("Failed to add item to list"));
1937 !           return -1;
1938 !       }
1939 !     }
1940 !     else
1941 !     {
1942 !       li = list_find(l, (long) index);
1943 !       clear_tv(&li->li_tv);
1944 !       copy_tv(&tv, &li->li_tv);
1945 !     }
1946 !     return 0;
1947 ! }
1948
1949 !     static int
1950 ! ListAssSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
1951 ! {
1952 !     PyInt     size = ListLength(self);
1953 !     Py_ssize_t        i;
1954 !     Py_ssize_t        lsize;
1955 !     PyObject  *litem;
1956 !     listitem_T        *li;
1957 !     listitem_T        *next;
1958 !     typval_T  v;
1959 !     list_T    *l = ((ListObject *) (self))->list;
1960
1961 !     if (l->lv_lock)
1962 !     {
1963 !       PyErr_SetVim(_("list is locked"));
1964 !       return -1;
1965 !     }
1966
1967 !     PROC_RANGE
1968   
1969 !     if (first == size)
1970 !       li = NULL;
1971 !     else
1972 !     {
1973 !       li = list_find(l, (long) first);
1974 !       if (li == NULL)
1975 !       {
1976 !           PyErr_SetVim(_("internal error: no vim list item"));
1977 !           return -1;
1978 !       }
1979 !       if (last > first)
1980 !       {
1981 !           i = last - first;
1982 !           while (i-- && li != NULL)
1983             {
1984 !               next = li->li_next;
1985 !               listitem_remove(l, li);
1986 !               li = next;
1987             }
1988         }
1989       }
1990
1991 !     if (obj == NULL)
1992 !       return 0;
1993
1994 !     if (!PyList_Check(obj))
1995       {
1996 !       PyErr_SetString(PyExc_TypeError, _("can only assign lists to slice"));
1997 !       return -1;
1998       }
1999   
2000 !     lsize = PyList_Size(obj);
2001
2002 !     for(i=0; i<lsize; i++)
2003 !     {
2004 !       litem = PyList_GetItem(obj, i);
2005 !       if (litem == NULL)
2006 !           return -1;
2007 !       if (ConvertFromPyObject(litem, &v) == -1)
2008 !           return -1;
2009 !       if (list_insert_tv(l, &v, li) == FAIL)
2010 !       {
2011 !           PyErr_SetVim(_("internal error: failed to add item to list"));
2012 !           return -1;
2013 !       }
2014 !     }
2015 !     return 0;
2016   }
2017   
2018       static PyObject *
2019 ! ListConcatInPlace(PyObject *self, PyObject *obj)
2020   {
2021 !     list_T    *l = ((ListObject *) (self))->list;
2022 !     PyObject  *lookup_dict;
2023   
2024 !     if (l->lv_lock)
2025 !     {
2026 !       PyErr_SetVim(_("list is locked"));
2027         return NULL;
2028 +     }
2029   
2030 !     if (!PySequence_Check(obj))
2031       {
2032 !       PyErr_SetString(PyExc_TypeError, _("can only concatenate with lists"));
2033         return NULL;
2034       }
2035   
2036       lookup_dict = PyDict_New();
2037 !     if (list_py_concat(l, obj, lookup_dict) == -1)
2038 !     {
2039 !       Py_DECREF(lookup_dict);
2040 !       return NULL;
2041 !     }
2042       Py_DECREF(lookup_dict);
2043   
2044 !     Py_INCREF(self);
2045 !     return self;
2046   }
2047   
2048 ! static struct PyMethodDef ListMethods[] = {
2049 !     {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
2050 !     { NULL,       NULL,               0,          NULL }
2051   };
2052   
2053   typedef struct
2054   {
2055       PyObject_HEAD
2056 !     char_u    *name;
2057 ! } FunctionObject;
2058   
2059 ! static PyTypeObject FunctionType;
2060   
2061 !     static PyObject *
2062 ! FunctionNew(char_u *name)
2063   {
2064 !     FunctionObject    *self;
2065   
2066 !     self = PyObject_NEW(FunctionObject, &FunctionType);
2067 !     if (self == NULL)
2068 !       return NULL;
2069 !     self->name = PyMem_New(char_u, STRLEN(name) + 1);
2070 !     if (self->name == NULL)
2071       {
2072 !       PyErr_NoMemory();
2073 !       return NULL;
2074       }
2075 !     STRCPY(self->name, name);
2076 !     func_ref(name);
2077 !     return (PyObject *)(self);
2078   }
2079   
2080       static PyObject *
2081 ! FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs)
2082   {
2083 !     FunctionObject    *this = (FunctionObject *)(self);
2084 !     char_u    *name = this->name;
2085 !     typval_T  args;
2086 !     typval_T  selfdicttv;
2087 !     typval_T  rettv;
2088 !     dict_T    *selfdict = NULL;
2089 !     PyObject  *selfdictObject;
2090 !     PyObject  *result;
2091 !     int               error;
2092   
2093 !     if (ConvertFromPyObject(argsObject, &args) == -1)
2094 !       return NULL;
2095
2096 !     if (kwargs != NULL)
2097       {
2098 !       selfdictObject = PyDict_GetItemString(kwargs, "self");
2099 !       if (selfdictObject != NULL)
2100 !       {
2101 !           if (!PyDict_Check(selfdictObject))
2102 !           {
2103 !               PyErr_SetString(PyExc_TypeError, _("'self' argument must be a dictionary"));
2104 !               clear_tv(&args);
2105 !               return NULL;
2106 !           }
2107 !           if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
2108 !               return NULL;
2109 !           selfdict = selfdicttv.vval.v_dict;
2110 !       }
2111       }
2112   
2113 !     error = func_call(name, &args, selfdict, &rettv);
2114 !     if (error != OK)
2115 !     {
2116 !       result = NULL;
2117 !       PyErr_SetVim(_("failed to run function"));
2118 !     }
2119 !     else
2120 !       result = ConvertToPyObject(&rettv);
2121
2122 !     /* FIXME Check what should really be cleared. */
2123 !     clear_tv(&args);
2124 !     clear_tv(&rettv);
2125 !     /*
2126 !      * if (selfdict!=NULL)
2127 !      *     clear_tv(selfdicttv);
2128 !      */
2129
2130 !     return result;
2131   }
2132   
2133 ! static struct PyMethodDef FunctionMethods[] = {
2134 !     {"__call__",    (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
2135 !     { NULL,       NULL,               0,          NULL }
2136 ! };
2137   
2138   #define INVALID_WINDOW_VALUE ((win_T *)(-1))
2139   
2140 ***************
2141 *** 1567,1569 ****
2142 --- 2383,2638 ----
2143       { NULL,       NULL,               0,          NULL }
2144   };
2145   
2146 +     static void
2147 + set_ref_in_py(const int copyID)
2148 + {
2149 +     pylinkedlist_T    *cur;
2150 +     dict_T    *dd;
2151 +     list_T    *ll;
2152
2153 +     if (lastdict != NULL)
2154 +       for(cur = lastdict ; cur != NULL ; cur = cur->pll_prev)
2155 +       {
2156 +           dd = ((DictionaryObject *) (cur->pll_obj))->dict;
2157 +           if (dd->dv_copyID != copyID)
2158 +           {
2159 +               dd->dv_copyID = copyID;
2160 +               set_ref_in_ht(&dd->dv_hashtab, copyID);
2161 +           }
2162 +       }
2163
2164 +     if (lastlist != NULL)
2165 +       for(cur = lastlist ; cur != NULL ; cur = cur->pll_prev)
2166 +       {
2167 +           ll = ((ListObject *) (cur->pll_obj))->list;
2168 +           if (ll->lv_copyID != copyID)
2169 +           {
2170 +               ll->lv_copyID = copyID;
2171 +               set_ref_in_list(ll, copyID);
2172 +           }
2173 +       }
2174 + }
2175
2176 +     static int
2177 + set_string_copy(char_u *str, typval_T *tv)
2178 + {
2179 +     tv->vval.v_string = vim_strsave(str);
2180 +     if (tv->vval.v_string == NULL)
2181 +     {
2182 +       PyErr_NoMemory();
2183 +       return -1;
2184 +     }
2185 +     return 0;
2186 + }
2187
2188 + #ifdef FEAT_EVAL
2189 + typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
2190
2191 +     static int
2192 + convert_dl(PyObject *obj, typval_T *tv,
2193 +                                   pytotvfunc py_to_tv, PyObject *lookupDict)
2194 + {
2195 +     PyObject  *capsule;
2196 +     char      hexBuf[sizeof(void *) * 2 + 3];
2197
2198 +     sprintf(hexBuf, "%p", obj);
2199
2200 +     capsule = PyDict_GetItemString(lookupDict, hexBuf);
2201 +     if (capsule == NULL)
2202 +     {
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)
2207 +       {
2208 +           tv->v_type = VAR_UNKNOWN;
2209 +           return -1;
2210 +       }
2211 +       /* As we are not using copy_tv which increments reference count we must
2212 +        * do it ourself. */
2213 +       switch(tv->v_type)
2214 +       {
2215 +           case VAR_DICT: ++tv->vval.v_dict->dv_refcount; break;
2216 +           case VAR_LIST: ++tv->vval.v_list->lv_refcount; break;
2217 +       }
2218 +     }
2219 +     else
2220 +     {
2221 +       typval_T        *v = PyCapsule_GetPointer(capsule, NULL);
2222 +       copy_tv(v, tv);
2223 +     }
2224 +     return 0;
2225 + }
2226
2227 +     static int
2228 + ConvertFromPyObject(PyObject *obj, typval_T *tv)
2229 + {
2230 +     PyObject  *lookup_dict;
2231 +     int               r;
2232
2233 +     lookup_dict = PyDict_New();
2234 +     r = _ConvertFromPyObject(obj, tv, lookup_dict);
2235 +     Py_DECREF(lookup_dict);
2236 +     return r;
2237 + }
2238
2239 +     static int
2240 + _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
2241 + {
2242 +     if (obj->ob_type == &DictionaryType)
2243 +     {
2244 +       tv->v_type = VAR_DICT;
2245 +       tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
2246 +       ++tv->vval.v_dict->dv_refcount;
2247 +     }
2248 +     else if (obj->ob_type == &ListType)
2249 +     {
2250 +       tv->v_type = VAR_LIST;
2251 +       tv->vval.v_list = (((ListObject *)(obj))->list);
2252 +       ++tv->vval.v_list->lv_refcount;
2253 +     }
2254 +     else if (obj->ob_type == &FunctionType)
2255 +     {
2256 +       if (set_string_copy(((FunctionObject *) (obj))->name, tv) == -1)
2257 +           return -1;
2258
2259 +       tv->v_type = VAR_FUNC;
2260 +       func_ref(tv->vval.v_string);
2261 +     }
2262 + #if PY_MAJOR_VERSION >= 3
2263 +     else if (PyBytes_Check(obj))
2264 +     {
2265 +       char_u  *result = (char_u *) PyBytes_AsString(obj);
2266
2267 +       if (result == NULL)
2268 +           return -1;
2269
2270 +       if (set_string_copy(result, tv) == -1)
2271 +           return -1;
2272
2273 +       tv->v_type = VAR_STRING;
2274 +     }
2275 +     else if (PyUnicode_Check(obj))
2276 +     {
2277 +       PyObject        *bytes;
2278 +       char_u  *result;
2279
2280 +       bytes = PyString_AsBytes(obj);
2281 +       if (bytes == NULL)
2282 +           return -1;
2283
2284 +       result = (char_u *) PyBytes_AsString(bytes);
2285 +       if (result == NULL)
2286 +           return -1;
2287
2288 +       if (set_string_copy(result, tv) == -1)
2289 +       {
2290 +           Py_XDECREF(bytes);
2291 +           return -1;
2292 +       }
2293 +       Py_XDECREF(bytes);
2294
2295 +       tv->v_type = VAR_STRING;
2296 +     }
2297 + #else
2298 +     else if (PyUnicode_Check(obj))
2299 +     {
2300 +       PyObject        *bytes;
2301 +       char_u  *result;
2302
2303 +       bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
2304 +       if (bytes == NULL)
2305 +           return -1;
2306
2307 +       result=(char_u *) PyString_AsString(bytes);
2308 +       if (result == NULL)
2309 +           return -1;
2310
2311 +       if (set_string_copy(result, tv) == -1)
2312 +       {
2313 +           Py_XDECREF(bytes);
2314 +           return -1;
2315 +       }
2316 +       Py_XDECREF(bytes);
2317
2318 +       tv->v_type = VAR_STRING;
2319 +     }
2320 +     else if (PyString_Check(obj))
2321 +     {
2322 +       char_u  *result = (char_u *) PyString_AsString(obj);
2323
2324 +       if (result == NULL)
2325 +           return -1;
2326
2327 +       if (set_string_copy(result, tv) == -1)
2328 +           return -1;
2329
2330 +       tv->v_type = VAR_STRING;
2331 +     }
2332 +     else if (PyInt_Check(obj))
2333 +     {
2334 +       tv->v_type = VAR_NUMBER;
2335 +       tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
2336 +     }
2337 + #endif
2338 +     else if (PyLong_Check(obj))
2339 +     {
2340 +       tv->v_type = VAR_NUMBER;
2341 +       tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
2342 +     }
2343 +     else if (PyDict_Check(obj))
2344 +       return convert_dl(obj, tv, pydict_to_tv, lookupDict);
2345 + #ifdef FEAT_FLOAT
2346 +     else if (PyFloat_Check(obj))
2347 +     {
2348 +       tv->v_type = VAR_FLOAT;
2349 +       tv->vval.v_float = (float_T) PyFloat_AsDouble(obj);
2350 +     }
2351 + #endif
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);
2358 +     else
2359 +     {
2360 +       PyErr_SetString(PyExc_TypeError, _("unable to convert to vim structure"));
2361 +       return -1;
2362 +     }
2363 +     return 0;
2364 + }
2365
2366 +     static PyObject *
2367 + ConvertToPyObject(typval_T *tv)
2368 + {
2369 +     if (tv == NULL)
2370 +     {
2371 +       PyErr_SetVim(_("NULL reference passed"));
2372 +       return NULL;
2373 +     }
2374 +     switch (tv->v_type)
2375 +     {
2376 +       case VAR_STRING:
2377 +           return PyBytes_FromString((char *) tv->vval.v_string);
2378 +       case VAR_NUMBER:
2379 +           return PyLong_FromLong((long) tv->vval.v_number);
2380 + #ifdef FEAT_FLOAT
2381 +       case VAR_FLOAT:
2382 +           return PyFloat_FromDouble((double) tv->vval.v_float);
2383 + #endif
2384 +       case VAR_LIST:
2385 +           return ListNew(tv->vval.v_list);
2386 +       case VAR_DICT:
2387 +           return DictionaryNew(tv->vval.v_dict);
2388 +       case VAR_FUNC:
2389 +           return FunctionNew(tv->vval.v_string);
2390 +       case VAR_UNKNOWN:
2391 +           Py_INCREF(Py_None);
2392 +           return Py_None;
2393 +       default:
2394 +           PyErr_SetVim(_("internal error: invalid value type"));
2395 +           return NULL;
2396 +     }
2397 + }
2398 + #endif
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
2401 ***************
2402 *** 1,4 ****
2403 ! /* vi:set ts=8 sts=4 sw=4:
2404    *
2405    * VIM - Vi IMproved  by Bram Moolenaar
2406    *
2407 --- 1,4 ----
2408 ! /* vi:set ts=8 sts=4 sw=4 noet:
2409    *
2410    * VIM - Vi IMproved  by Bram Moolenaar
2411    *
2412 ***************
2413 *** 56,61 ****
2414 --- 56,63 ----
2415   
2416   static void init_structs(void);
2417   
2418 + #define PyBytes_FromString PyString_FromString
2419
2420   /* No-op conversion functions, use with care! */
2421   #define PyString_AsBytes(obj) (obj)
2422   #define PyString_FreeBytes(obj)
2423 ***************
2424 *** 122,132 ****
2425 --- 124,136 ----
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
2430   # undef PyArg_Parse
2431   # undef PyArg_ParseTuple
2432   # undef Py_BuildValue
2433   # undef Py_InitModule4
2434   # undef Py_InitModule4_64
2435 + # undef PyObject_CallMethod
2436   
2437   /*
2438    * Wrapper defines
2439 ***************
2440 *** 134,139 ****
2441 --- 138,144 ----
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
2449 ***************
2450 *** 150,172 ****
2451 --- 155,202 ----
2452   # endif
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
2477 + # else
2478 + #  define PyMapping_Items dll_PyMapping_Items
2479 + # endif
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)
2500 ***************
2501 *** 179,186 ****
2502 --- 209,218 ----
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
2512   # endif
2513 ***************
2514 *** 188,193 ****
2515 --- 220,227 ----
2516   #  define PyObject_Malloc dll_PyObject_Malloc
2517   #  define PyObject_Free dll_PyObject_Free
2518   # endif
2519 + # define PyCapsule_New dll_PyCapsule_New
2520 + # define PyCapsule_GetPointer dll_PyCapsule_GetPointer
2521   
2522   /*
2523    * Pointers for dynamic link
2524 ***************
2525 *** 195,200 ****
2526 --- 229,235 ----
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);
2534 ***************
2535 *** 208,233 ****
2536   # ifdef PY_CAN_RECURSE
2537   static PyGILState_STATE       (*dll_PyGILState_Ensure)(void);
2538   static void (*dll_PyGILState_Release)(PyGILState_STATE);
2539 ! #endif
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;
2562 --- 243,290 ----
2563   # ifdef PY_CAN_RECURSE
2564   static PyGILState_STATE       (*dll_PyGILState_Ensure)(void);
2565   static void (*dll_PyGILState_Release)(PyGILState_STATE);
2566 ! # endif
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 *);
2591 + # endif
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;
2611 ***************
2612 *** 235,246 ****
2613 --- 292,306 ----
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 *);
2629 ***************
2630 *** 249,254 ****
2631 --- 309,316 ----
2632   static void* (*dll_PyObject_Malloc)(size_t);
2633   static void (*dll_PyObject_Free)(void*);
2634   # endif
2635 + static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
2636 + static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *);
2637   
2638   static HINSTANCE hinstPython = 0; /* Instance of python.dll */
2639   
2640 ***************
2641 *** 278,283 ****
2642 --- 340,346 ----
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},
2650 ***************
2651 *** 294,316 ****
2652 --- 357,402 ----
2653   # endif
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},
2678 + # endif
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},
2699 ***************
2700 *** 328,333 ****
2701 --- 414,421 ----
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},
2710 ***************
2711 *** 336,341 ****
2712 --- 424,431 ----
2713       {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc},
2714       {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free},
2715   # endif
2716 +     {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New},
2717 +     {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer},
2718       {"", NULL},
2719   };
2720   
2721 ***************
2722 *** 434,443 ****
2723 --- 524,548 ----
2724   
2725   static PyObject *BufferNew (buf_T *);
2726   static PyObject *WindowNew(win_T *);
2727 + static PyObject *DictionaryNew(dict_T *);
2728   static PyObject *LineToString(const char *);
2729   
2730   static PyTypeObject RangeType;
2731   
2732 + static int initialised = 0;
2733 + #define PYINITIALISED initialised
2734
2735 + /* Add conversion from PyInt? */
2736 + #define DICTKEY_GET(err) \
2737 +     if (!PyString_Check(keyObject)) \
2738 +     { \
2739 +       PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
2740 +       return err; \
2741 +     } \
2742 +     key = (char_u *) PyString_AsString(keyObject);
2743 + #define DICTKEY_UNREF
2744 + #define DICTKEY_DECL
2745
2746   /*
2747    * Include the code shared with if_python3.c
2748    */
2749 ***************
2750 *** 451,456 ****
2751 --- 556,563 ----
2752   static PyInt RangeStart;
2753   static PyInt RangeEnd;
2754   
2755 + static PyObject *globals;
2756
2757   static void PythonIO_Flush(void);
2758   static int PythonIO_Init(void);
2759   static int PythonMod_Init(void);
2760 ***************
2761 *** 466,473 ****
2762    * 1. Python interpreter main program.
2763    */
2764   
2765 - static int initialised = 0;
2766
2767   #if PYTHON_API_VERSION < 1007 /* Python 1.4 */
2768   typedef PyObject PyThreadState;
2769   #endif
2770 --- 573,578 ----
2771 ***************
2772 *** 581,586 ****
2773 --- 686,693 ----
2774         if (PythonMod_Init())
2775             goto fail;
2776   
2777 +       globals = PyModule_GetDict(PyImport_AddModule("__main__"));
2778
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
2782 ***************
2783 *** 609,615 ****
2784    * External interface
2785    */
2786       static void
2787 ! DoPythonCommand(exarg_T *eap, const char *cmd)
2788   {
2789   #ifndef PY_CAN_RECURSE
2790       static int                recursive = 0;
2791 --- 716,722 ----
2792    * External interface
2793    */
2794       static void
2795 ! DoPythonCommand(exarg_T *eap, const char *cmd, typval_T *rettv)
2796   {
2797   #ifndef PY_CAN_RECURSE
2798       static int                recursive = 0;
2799 ***************
2800 *** 639,646 ****
2801       if (Python_Init())
2802         goto theend;
2803   
2804 !     RangeStart = eap->line1;
2805 !     RangeEnd = eap->line2;
2806       Python_Release_Vim();         /* leave vim */
2807   
2808   #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
2809 --- 746,761 ----
2810       if (Python_Init())
2811         goto theend;
2812   
2813 !     if (rettv == NULL)
2814 !     {
2815 !       RangeStart = eap->line1;
2816 !       RangeEnd = eap->line2;
2817 !     }
2818 !     else
2819 !     {
2820 !       RangeStart = (PyInt) curwin->w_cursor.lnum;
2821 !       RangeEnd = RangeStart;
2822 !     }
2823       Python_Release_Vim();         /* leave vim */
2824   
2825   #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
2826 ***************
2827 *** 658,664 ****
2828   
2829       Python_RestoreThread();       /* enter python */
2830   
2831 !     PyRun_SimpleString((char *)(cmd));
2832   
2833       Python_SaveThread();          /* leave python */
2834   
2835 --- 773,795 ----
2836   
2837       Python_RestoreThread();       /* enter python */
2838   
2839 !     if (rettv == NULL)
2840 !       PyRun_SimpleString((char *)(cmd));
2841 !     else
2842 !     {
2843 !       PyObject        *r;
2844
2845 !       r = PyRun_String((char *)(cmd), Py_eval_input, globals, globals);
2846 !       if (r == NULL)
2847 !           EMSG(_("E858: Eval did not return a valid python object"));
2848 !       else
2849 !       {
2850 !           if (ConvertFromPyObject(r, rettv) == -1)
2851 !               EMSG(_("E859: Failed to convert returned python object to vim value"));
2852 !           Py_DECREF(r);
2853 !       }
2854 !       PyErr_Clear();
2855 !     }
2856   
2857       Python_SaveThread();          /* leave python */
2858   
2859 ***************
2860 *** 680,686 ****
2861   #ifndef PY_CAN_RECURSE
2862       --recursive;
2863   #endif
2864 !     return;       /* keeps lint happy */
2865   }
2866   
2867   /*
2868 --- 811,817 ----
2869   #ifndef PY_CAN_RECURSE
2870       --recursive;
2871   #endif
2872 !     return;
2873   }
2874   
2875   /*
2876 ***************
2877 *** 695,703 ****
2878       if (!eap->skip)
2879       {
2880         if (script == NULL)
2881 !           DoPythonCommand(eap, (char *)eap->arg);
2882         else
2883 !           DoPythonCommand(eap, (char *)script);
2884       }
2885       vim_free(script);
2886   }
2887 --- 826,834 ----
2888       if (!eap->skip)
2889       {
2890         if (script == NULL)
2891 !           DoPythonCommand(eap, (char *)eap->arg, NULL);
2892         else
2893 !           DoPythonCommand(eap, (char *)script, NULL);
2894       }
2895       vim_free(script);
2896   }
2897 ***************
2898 *** 743,749 ****
2899       *p++ = '\0';
2900   
2901       /* Execute the file */
2902 !     DoPythonCommand(eap, buffer);
2903   }
2904   
2905   /******************************************************
2906 --- 874,880 ----
2907       *p++ = '\0';
2908   
2909       /* Execute the file */
2910 !     DoPythonCommand(eap, buffer, NULL);
2911   }
2912   
2913   /******************************************************
2914 ***************
2915 *** 765,778 ****
2916       static int
2917   OutputSetattr(PyObject *self, char *name, PyObject *val)
2918   {
2919 !     if (val == NULL) {
2920         PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
2921         return -1;
2922       }
2923   
2924       if (strcmp(name, "softspace") == 0)
2925       {
2926 !       if (!PyInt_Check(val)) {
2927             PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
2928             return -1;
2929         }
2930 --- 896,911 ----
2931       static int
2932   OutputSetattr(PyObject *self, char *name, PyObject *val)
2933   {
2934 !     if (val == NULL)
2935 !     {
2936         PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
2937         return -1;
2938       }
2939   
2940       if (strcmp(name, "softspace") == 0)
2941       {
2942 !       if (!PyInt_Check(val))
2943 !       {
2944             PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
2945             return -1;
2946         }
2947 ***************
2948 *** 800,805 ****
2949 --- 933,941 ----
2950    * 3. Implementation of the Vim module for Python
2951    */
2952   
2953 + static PyObject *ConvertToPyObject(typval_T *);
2954 + static int ConvertFromPyObject(PyObject *, typval_T *);
2955
2956   /* Window type - Implementation functions
2957    * --------------------------------------
2958    */
2959 ***************
2960 *** 1441,1446 ****
2961 --- 1577,1748 ----
2962       return result;
2963   }
2964   
2965 + static void DictionaryDestructor(PyObject *);
2966 + static PyObject *DictionaryGetattr(PyObject *, char*);
2967
2968 + static PyMappingMethods DictionaryAsMapping = {
2969 +     (PyInquiry)               DictionaryLength,
2970 +     (binaryfunc)      DictionaryItem,
2971 +     (objobjargproc)   DictionaryAssItem,
2972 + };
2973
2974 + static PyTypeObject DictionaryType = {
2975 +     PyObject_HEAD_INIT(0)
2976 +     0,
2977 +     "vimdictionary",
2978 +     sizeof(DictionaryObject),
2979 +     0,
2980
2981 +     (destructor)  DictionaryDestructor,
2982 +     (printfunc)   0,
2983 +     (getattrfunc) DictionaryGetattr,
2984 +     (setattrfunc) 0,
2985 +     (cmpfunc)     0,
2986 +     (reprfunc)    0,
2987
2988 +     0,                            /* as number */
2989 +     0,                            /* as sequence */
2990 +     &DictionaryAsMapping,   /* as mapping */
2991
2992 +     (hashfunc)    0,
2993 +     (ternaryfunc) 0,
2994 +     (reprfunc)    0,
2995 + };
2996
2997 +     static void
2998 + DictionaryDestructor(PyObject *self)
2999 + {
3000 +     DictionaryObject  *this = ((DictionaryObject *) (self));
3001
3002 +     pyll_remove(&this->ref, &lastdict);
3003 +     dict_unref(this->dict);
3004
3005 +     Py_DECREF(self);
3006 + }
3007
3008 +     static PyObject *
3009 + DictionaryGetattr(PyObject *self, char *name)
3010 + {
3011 +     return Py_FindMethod(DictionaryMethods, self, name);
3012 + }
3013
3014 + static void ListDestructor(PyObject *);
3015 + static PyObject *ListGetattr(PyObject *, char *);
3016
3017 + static PySequenceMethods ListAsSeq = {
3018 +     (PyInquiry)                       ListLength,
3019 +     (binaryfunc)              0,
3020 +     (PyIntArgFunc)            0,
3021 +     (PyIntArgFunc)            ListItem,
3022 +     (PyIntIntArgFunc)         ListSlice,
3023 +     (PyIntObjArgProc)         ListAssItem,
3024 +     (PyIntIntObjArgProc)      ListAssSlice,
3025 +     (objobjproc)              0,
3026 + #if PY_MAJOR_VERSION >= 2
3027 +     (binaryfunc)              ListConcatInPlace,
3028 +     0,
3029 + #endif
3030 + };
3031
3032 + static PyTypeObject ListType = {
3033 +     PyObject_HEAD_INIT(0)
3034 +     0,
3035 +     "vimlist",
3036 +     sizeof(ListObject),
3037 +     0,
3038
3039 +     (destructor)  ListDestructor,
3040 +     (printfunc)   0,
3041 +     (getattrfunc) ListGetattr,
3042 +     (setattrfunc) 0,
3043 +     (cmpfunc)     0,
3044 +     (reprfunc)    0,
3045
3046 +     0,                            /* as number */
3047 +     &ListAsSeq,                   /* as sequence */
3048 +     0,                            /* as mapping */
3049
3050 +     (hashfunc)    0,
3051 +     (ternaryfunc) 0,
3052 +     (reprfunc)    0,
3053 + };
3054
3055 +     static void
3056 + ListDestructor(PyObject *self)
3057 + {
3058 +     ListObject        *this = ((ListObject *) (self));
3059
3060 +     pyll_remove(&this->ref, &lastlist);
3061 +     list_unref(this->list);
3062
3063 +     Py_DECREF(self);
3064 + }
3065
3066 +     static PyObject *
3067 + ListGetattr(PyObject *self, char *name)
3068 + {
3069 +     return Py_FindMethod(ListMethods, self, name);
3070 + }
3071
3072 + static void FunctionDestructor(PyObject *);
3073 + static PyObject *FunctionGetattr(PyObject *, char *);
3074
3075 + static PyTypeObject FunctionType = {
3076 +     PyObject_HEAD_INIT(0)
3077 +     0,
3078 +     "vimfunction",
3079 +     sizeof(FunctionObject),
3080 +     0,
3081
3082 +     (destructor)  FunctionDestructor,
3083 +     (printfunc)   0,
3084 +     (getattrfunc) FunctionGetattr,
3085 +     (setattrfunc) 0,
3086 +     (cmpfunc)     0,
3087 +     (reprfunc)    0,
3088
3089 +     0,                            /* as number */
3090 +     0,                            /* as sequence */
3091 +     0,                            /* as mapping */
3092
3093 +     (hashfunc)    0,
3094 +     (ternaryfunc) FunctionCall,
3095 +     (reprfunc)    0,
3096 + };
3097
3098 +     static void
3099 + FunctionDestructor(PyObject *self)
3100 + {
3101 +     FunctionObject    *this = (FunctionObject *) (self);
3102
3103 +     func_unref(this->name);
3104 +     PyMem_Del(this->name);
3105
3106 +     Py_DECREF(self);
3107 + }
3108
3109 +     static PyObject *
3110 + FunctionGetattr(PyObject *self, char *name)
3111 + {
3112 +     FunctionObject    *this = (FunctionObject *)(self);
3113
3114 +     if (strcmp(name, "name") == 0)
3115 +       return PyString_FromString((char *)(this->name));
3116 +     else
3117 +       return Py_FindMethod(FunctionMethods, self, name);
3118 + }
3119
3120 +     void
3121 + do_pyeval (char_u *str, typval_T *rettv)
3122 + {
3123 +     DoPythonCommand(NULL, (char *) str, rettv);
3124 +     switch(rettv->v_type)
3125 +     {
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;
3129 +     }
3130 + }
3131   
3132   /* Don't generate a prototype for the next function, it generates an error on
3133    * newer Python versions. */
3134 ***************
3135 *** 1453,1458 ****
3136 --- 1755,1766 ----
3137   }
3138   #endif /* Python 1.4 */
3139   
3140 +     void
3141 + set_ref_in_python (int copyID)
3142 + {
3143 +     set_ref_in_py(copyID);
3144 + }
3145
3146       static void
3147   init_structs(void)
3148   {
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
3151 ***************
3152 *** 77,83 ****
3153   
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)
3160 --- 77,83 ----
3161   
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)
3168 ***************
3169 *** 109,114 ****
3170 --- 109,115 ----
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
3178 ***************
3179 *** 128,141 ****
3180 --- 129,155 ----
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)
3208 ***************
3209 *** 147,152 ****
3210 --- 161,167 ----
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
3218 ***************
3219 *** 154,161 ****
3220 --- 169,181 ----
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
3232   # ifdef Py_DEBUG
3233   #  define _Py_NegativeRefcount py3__Py_NegativeRefcount
3234 ***************
3235 *** 174,179 ****
3236 --- 194,202 ----
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
3243   
3244   # ifdef Py_DEBUG
3245   #  undef PyObject_NEW
3246 ***************
3247 *** 194,215 ****
3248 --- 217,250 ----
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);
3283 ***************
3284 *** 224,244 ****
3285 --- 259,287 ----
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 *);
3312   # ifdef Py_DEBUG
3313       static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op);
3314       static Py_ssize_t* py3__Py_RefTotal;
3315 ***************
3316 *** 249,254 ****
3317 --- 292,298 ----
3318       static void (*py3_PyObject_Free)(void*);
3319       static void* (*py3_PyObject_Malloc)(size_t);
3320   # endif
3321 + static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
3322   
3323   static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */
3324   
3325 ***************
3326 *** 280,304 ****
3327 --- 324,361 ----
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},
3366 ***************
3367 *** 311,316 ****
3368 --- 368,374 ----
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},
3376 ***************
3377 *** 318,328 ****
3378 --- 376,390 ----
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},
3392   # ifdef Py_DEBUG
3393       {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount},
3394 ***************
3395 *** 334,339 ****
3396 --- 396,404 ----
3397       {"PyObject_Malloc", (PYTHON_PROC*)&py3_PyObject_Malloc},
3398       {"PyObject_Free", (PYTHON_PROC*)&py3_PyObject_Free},
3399   # endif
3400 +     {"PyType_IsSubtype", (PYTHON_PROC*)&py3_PyType_IsSubtype},
3401 +     {"PyCapsule_New", (PYTHON_PROC*)&py3_PyCapsule_New},
3402 +     {"PyCapsule_GetPointer", (PYTHON_PROC*)&py3_PyCapsule_GetPointer},
3403       {"", NULL},
3404   };
3405   
3406 ***************
3407 *** 472,482 ****
3408 --- 537,577 ----
3409   
3410   static PyTypeObject RangeType;
3411   
3412 + static int py3initialised = 0;
3413
3414 + #define PYINITIALISED py3initialised
3415
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)) \
3421 +     { \
3422 +       bytes = PyString_AsBytes(keyObject); \
3423 +       if (bytes == NULL) \
3424 +           return err; \
3425 +       key = (char_u *) PyBytes_AsString(bytes); \
3426 +       if (key == NULL) \
3427 +           return err; \
3428 +     } \
3429 +     else \
3430 +     { \
3431 +       PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
3432 +       return err; \
3433 +     }
3434 + #define DICTKEY_UNREF \
3435 +     if (bytes != NULL) \
3436 +       Py_XDECREF(bytes);
3437
3438 + #define DICTKEY_DECL PyObject *bytes = NULL;
3439
3440   /*
3441    * Include the code shared with if_python.c
3442    */
3443   #include "if_py_both.h"
3444   
3445 + #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
3446
3447       static void
3448   call_PyObject_Free(void *p)
3449   {
3450 ***************
3451 *** 506,511 ****
3452 --- 601,608 ----
3453   static Py_ssize_t RangeStart;
3454   static Py_ssize_t RangeEnd;
3455   
3456 + static PyObject *globals;
3457
3458   static int PythonIO_Init(void);
3459   static void PythonIO_Fini(void);
3460   PyMODINIT_FUNC Py3Init_vim(void);
3461 ***************
3462 *** 514,521 ****
3463    * 1. Python interpreter main program.
3464    */
3465   
3466 - static int py3initialised = 0;
3467
3468   static PyGILState_STATE pygilstate = PyGILState_UNLOCKED;
3469   
3470       void
3471 --- 611,616 ----
3472 ***************
3473 *** 593,598 ****
3474 --- 688,695 ----
3475   
3476         PyImport_AppendInittab("vim", Py3Init_vim);
3477   
3478 +       globals = PyModule_GetDict(PyImport_AddModule("__main__"));
3479
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
3483 ***************
3484 *** 629,635 ****
3485    * External interface
3486    */
3487       static void
3488 ! DoPy3Command(exarg_T *eap, const char *cmd)
3489   {
3490   #if defined(MACOS) && !defined(MACOS_X_UNIX)
3491       GrafPtr           oldPort;
3492 --- 726,732 ----
3493    * External interface
3494    */
3495       static void
3496 ! DoPy3Command(exarg_T *eap, const char *cmd, typval_T *rettv)
3497   {
3498   #if defined(MACOS) && !defined(MACOS_X_UNIX)
3499       GrafPtr           oldPort;
3500 ***************
3501 *** 649,656 ****
3502       if (Python3_Init())
3503         goto theend;
3504   
3505 !     RangeStart = eap->line1;
3506 !     RangeEnd = eap->line2;
3507       Python_Release_Vim();         /* leave vim */
3508   
3509   #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3510 --- 746,761 ----
3511       if (Python3_Init())
3512         goto theend;
3513   
3514 !     if (rettv == NULL)
3515 !     {
3516 !       RangeStart = eap->line1;
3517 !       RangeEnd = eap->line2;
3518 !     }
3519 !     else
3520 !     {
3521 !       RangeStart = (PyInt) curwin->w_cursor.lnum;
3522 !       RangeEnd = RangeStart;
3523 !     }
3524       Python_Release_Vim();         /* leave vim */
3525   
3526   #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3527 ***************
3528 *** 674,680 ****
3529                                         (char *)ENC_OPT, CODEC_ERROR_HANDLER);
3530       cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
3531       Py_XDECREF(cmdstr);
3532 !     PyRun_SimpleString(PyBytes_AsString(cmdbytes));
3533       Py_XDECREF(cmdbytes);
3534   
3535       PyGILState_Release(pygilstate);
3536 --- 779,802 ----
3537                                         (char *)ENC_OPT, CODEC_ERROR_HANDLER);
3538       cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
3539       Py_XDECREF(cmdstr);
3540 !     if (rettv == NULL)
3541 !       PyRun_SimpleString(PyBytes_AsString(cmdbytes));
3542 !     else
3543 !     {
3544 !       PyObject        *r;
3545
3546 !       r = PyRun_String(PyBytes_AsString(cmdbytes), Py_eval_input,
3547 !                        globals, globals);
3548 !       if (r == NULL)
3549 !           EMSG(_("E860: Eval did not return a valid python 3 object"));
3550 !       else
3551 !       {
3552 !           if (ConvertFromPyObject(r, rettv) == -1)
3553 !               EMSG(_("E861: Failed to convert returned python 3 object to vim value"));
3554 !           Py_DECREF(r);
3555 !       }
3556 !       PyErr_Clear();
3557 !     }
3558       Py_XDECREF(cmdbytes);
3559   
3560       PyGILState_Release(pygilstate);
3561 ***************
3562 *** 709,717 ****
3563       if (!eap->skip)
3564       {
3565         if (script == NULL)
3566 !           DoPy3Command(eap, (char *)eap->arg);
3567         else
3568 !           DoPy3Command(eap, (char *)script);
3569       }
3570       vim_free(script);
3571   }
3572 --- 831,839 ----
3573       if (!eap->skip)
3574       {
3575         if (script == NULL)
3576 !           DoPy3Command(eap, (char *)eap->arg, NULL);
3577         else
3578 !           DoPy3Command(eap, (char *)script, NULL);
3579       }
3580       vim_free(script);
3581   }
3582 ***************
3583 *** 772,778 ****
3584   
3585   
3586       /* Execute the file */
3587 !     DoPy3Command(eap, buffer);
3588   }
3589   
3590   /******************************************************
3591 --- 894,900 ----
3592   
3593   
3594       /* Execute the file */
3595 !     DoPy3Command(eap, buffer, NULL);
3596   }
3597   
3598   /******************************************************
3599 ***************
3600 *** 802,815 ****
3601       if (PyUnicode_Check(nameobj))
3602         name = _PyUnicode_AsString(nameobj);
3603   
3604 !     if (val == NULL) {
3605         PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
3606         return -1;
3607       }
3608   
3609       if (strcmp(name, "softspace") == 0)
3610       {
3611 !       if (!PyLong_Check(val)) {
3612             PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
3613             return -1;
3614         }
3615 --- 924,939 ----
3616       if (PyUnicode_Check(nameobj))
3617         name = _PyUnicode_AsString(nameobj);
3618   
3619 !     if (val == NULL)
3620 !     {
3621         PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
3622         return -1;
3623       }
3624   
3625       if (strcmp(name, "softspace") == 0)
3626       {
3627 !       if (!PyLong_Check(val))
3628 !       {
3629             PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
3630             return -1;
3631         }
3632 ***************
3633 *** 1030,1049 ****
3634       static PyObject *
3635   BufferSubscript(PyObject *self, PyObject* idx)
3636   {
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;
3642   
3643         if (PySlice_GetIndicesEx((PyObject *)idx,
3644               (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3645               &start, &stop,
3646 !             &step, &slicelen) < 0) {
3647             return NULL;
3648         }
3649         return BufferSlice(self, start, stop);
3650 !     } else {
3651         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3652         return NULL;
3653       }
3654 --- 1154,1178 ----
3655       static PyObject *
3656   BufferSubscript(PyObject *self, PyObject* idx)
3657   {
3658 !     if (PyLong_Check(idx))
3659 !     {
3660         long _idx = PyLong_AsLong(idx);
3661         return BufferItem(self,_idx);
3662 !     } else if (PySlice_Check(idx))
3663 !     {
3664         Py_ssize_t start, stop, step, slicelen;
3665   
3666         if (PySlice_GetIndicesEx((PyObject *)idx,
3667               (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3668               &start, &stop,
3669 !             &step, &slicelen) < 0)
3670 !       {
3671             return NULL;
3672         }
3673         return BufferSlice(self, start, stop);
3674 !     }
3675 !     else
3676 !     {
3677         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3678         return NULL;
3679       }
3680 ***************
3681 *** 1052,1075 ****
3682       static Py_ssize_t
3683   BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
3684   {
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,
3689                     NULL);
3690 !     } else if (PySlice_Check(idx)) {
3691         Py_ssize_t start, stop, step, slicelen;
3692   
3693         if (PySlice_GetIndicesEx((PyObject *)idx,
3694               (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3695               &start, &stop,
3696 !             &step, &slicelen) < 0) {
3697             return -1;
3698         }
3699         return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
3700                           (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
3701                           NULL);
3702 !     } else {
3703         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3704         return -1;
3705       }
3706 --- 1181,1209 ----
3707       static Py_ssize_t
3708   BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
3709   {
3710 !     if (PyLong_Check(idx))
3711 !     {
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,
3715                     NULL);
3716 !     } else if (PySlice_Check(idx))
3717 !     {
3718         Py_ssize_t start, stop, step, slicelen;
3719   
3720         if (PySlice_GetIndicesEx((PyObject *)idx,
3721               (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
3722               &start, &stop,
3723 !             &step, &slicelen) < 0)
3724 !       {
3725             return -1;
3726         }
3727         return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
3728                           (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
3729                           NULL);
3730 !     }
3731 !     else
3732 !     {
3733         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3734         return -1;
3735       }
3736 ***************
3737 *** 1142,1161 ****
3738       static PyObject *
3739   RangeSubscript(PyObject *self, PyObject* idx)
3740   {
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;
3746   
3747         if (PySlice_GetIndicesEx((PyObject *)idx,
3748                 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3749                 &start, &stop,
3750 !               &step, &slicelen) < 0) {
3751             return NULL;
3752         }
3753         return RangeSlice(self, start, stop);
3754 !     } else {
3755         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3756         return NULL;
3757       }
3758 --- 1276,1300 ----
3759       static PyObject *
3760   RangeSubscript(PyObject *self, PyObject* idx)
3761   {
3762 !     if (PyLong_Check(idx))
3763 !     {
3764         long _idx = PyLong_AsLong(idx);
3765         return RangeItem(self,_idx);
3766 !     } else if (PySlice_Check(idx))
3767 !     {
3768         Py_ssize_t start, stop, step, slicelen;
3769   
3770         if (PySlice_GetIndicesEx((PyObject *)idx,
3771                 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3772                 &start, &stop,
3773 !               &step, &slicelen) < 0)
3774 !       {
3775             return NULL;
3776         }
3777         return RangeSlice(self, start, stop);
3778 !     }
3779 !     else
3780 !     {
3781         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3782         return NULL;
3783       }
3784 ***************
3785 *** 1164,1183 ****
3786       static Py_ssize_t
3787   RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
3788   {
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;
3794   
3795         if (PySlice_GetIndicesEx((PyObject *)idx,
3796                 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3797                 &start, &stop,
3798 !               &step, &slicelen) < 0) {
3799             return -1;
3800         }
3801         return RangeAsSlice(self, start, stop, val);
3802 !     } else {
3803         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3804         return -1;
3805       }
3806 --- 1303,1327 ----
3807       static Py_ssize_t
3808   RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
3809   {
3810 !     if (PyLong_Check(idx))
3811 !     {
3812         long n = PyLong_AsLong(idx);
3813         return RangeAsItem(self, n, val);
3814 !     } else if (PySlice_Check(idx))
3815 !     {
3816         Py_ssize_t start, stop, step, slicelen;
3817   
3818         if (PySlice_GetIndicesEx((PyObject *)idx,
3819                 ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
3820                 &start, &stop,
3821 !               &step, &slicelen) < 0)
3822 !       {
3823             return -1;
3824         }
3825         return RangeAsSlice(self, start, stop, val);
3826 !     }
3827 !     else
3828 !     {
3829         PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3830         return -1;
3831       }
3832 ***************
3833 *** 1390,1395 ****
3834 --- 1534,1680 ----
3835       }
3836   }
3837   
3838 + /* Dictionary object - Definitions
3839 +  */
3840
3841 + static PyInt DictionaryLength(PyObject *);
3842
3843 + static PyMappingMethods DictionaryAsMapping = {
3844 +     /* mp_length      */ (lenfunc) DictionaryLength,
3845 +     /* mp_subscript     */ (binaryfunc) DictionaryItem,
3846 +     /* mp_ass_subscript */ (objobjargproc) DictionaryAssItem,
3847 + };
3848
3849 + static PyTypeObject DictionaryType;
3850
3851 +     static void
3852 + DictionaryDestructor(PyObject *self)
3853 + {
3854 +     DictionaryObject *this = (DictionaryObject *)(self);
3855
3856 +     pyll_remove(&this->ref, &lastdict);
3857 +     dict_unref(this->dict);
3858
3859 +     Py_TYPE(self)->tp_free((PyObject*)self);
3860 + }
3861
3862 + /* List object - Definitions
3863 +  */
3864
3865 + static PyInt ListLength(PyObject *);
3866 + static PyObject *ListItem(PyObject *, Py_ssize_t);
3867
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 */
3879 + };
3880
3881 + static PyObject *ListSubscript(PyObject *, PyObject *);
3882 + static Py_ssize_t ListAsSubscript(PyObject *, PyObject *, PyObject *);
3883
3884 + static PyMappingMethods ListAsMapping = {
3885 +     /* mp_length      */ (lenfunc) ListLength,
3886 +     /* mp_subscript     */ (binaryfunc) ListSubscript,
3887 +     /* mp_ass_subscript */ (objobjargproc) ListAsSubscript,
3888 + };
3889
3890 + static PyTypeObject ListType;
3891
3892 +     static PyObject *
3893 + ListSubscript(PyObject *self, PyObject* idxObject)
3894 + {
3895 +     if (PyLong_Check(idxObject))
3896 +     {
3897 +       long idx = PyLong_AsLong(idxObject);
3898 +       return ListItem(self, idx);
3899 +     }
3900 +     else if (PySlice_Check(idxObject))
3901 +     {
3902 +       Py_ssize_t start, stop, step, slicelen;
3903
3904 +       if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
3905 +                                &step, &slicelen) < 0)
3906 +           return NULL;
3907 +       return ListSlice(self, start, stop);
3908 +     }
3909 +     else
3910 +     {
3911 +       PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3912 +       return NULL;
3913 +     }
3914 + }
3915
3916 +     static Py_ssize_t
3917 + ListAsSubscript(PyObject *self, PyObject *idxObject, PyObject *obj)
3918 + {
3919 +     if (PyLong_Check(idxObject))
3920 +     {
3921 +       long idx = PyLong_AsLong(idxObject);
3922 +       return ListAssItem(self, idx, obj);
3923 +     }
3924 +     else if (PySlice_Check(idxObject))
3925 +     {
3926 +       Py_ssize_t start, stop, step, slicelen;
3927
3928 +       if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
3929 +                                &step, &slicelen) < 0)
3930 +           return -1;
3931 +       return ListAssSlice(self, start, stop, obj);
3932 +     }
3933 +     else
3934 +     {
3935 +       PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
3936 +       return -1;
3937 +     }
3938 + }
3939
3940 +     static void
3941 + ListDestructor(PyObject *self)
3942 + {
3943 +     ListObject *this = (ListObject *)(self);
3944
3945 +     pyll_remove(&this->ref, &lastlist);
3946 +     list_unref(this->list);
3947
3948 +     Py_TYPE(self)->tp_free((PyObject*)self);
3949 + }
3950
3951 + /* Function object - Definitions
3952 +  */
3953
3954 +     static void
3955 + FunctionDestructor(PyObject *self)
3956 + {
3957 +     FunctionObject    *this = (FunctionObject *) (self);
3958
3959 +     func_unref(this->name);
3960 +     PyMem_Del(this->name);
3961
3962 +     Py_TYPE(self)->tp_free((PyObject*)self);
3963 + }
3964
3965 +     static PyObject *
3966 + FunctionGetattro(PyObject *self, PyObject *nameobj)
3967 + {
3968 +     FunctionObject    *this = (FunctionObject *)(self);
3969 +     char      *name = "";
3970 +     if (PyUnicode_Check(nameobj))
3971 +       name = _PyUnicode_AsString(nameobj);
3972
3973 +     if (strcmp(name, "name") == 0)
3974 +       return PyUnicode_FromString((char *)(this->name));
3975
3976 +     return PyObject_GenericGetAttr(self, nameobj);
3977 + }
3978
3979   /* External interface
3980    */
3981   
3982 ***************
3983 *** 1449,1454 ****
3984 --- 1734,1742 ----
3985       PyType_Ready(&BufListType);
3986       PyType_Ready(&WinListType);
3987       PyType_Ready(&CurrentType);
3988 +     PyType_Ready(&DictionaryType);
3989 +     PyType_Ready(&ListType);
3990 +     PyType_Ready(&FunctionType);
3991   
3992       /* Set sys.argv[] to avoid a crash in warn(). */
3993       PySys_SetArgv(1, argv);
3994 ***************
3995 *** 1517,1522 ****
3996 --- 1805,1828 ----
3997       return result;
3998   }
3999   
4000 +     void
4001 + do_py3eval (char_u *str, typval_T *rettv)
4002 + {
4003 +     DoPy3Command(NULL, (char *) str, rettv);
4004 +     switch(rettv->v_type)
4005 +     {
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;
4009 +     }
4010 + }
4011
4012 +     void
4013 + set_ref_in_python3 (int copyID)
4014 + {
4015 +     set_ref_in_py(copyID);
4016 + }
4017
4018       static void
4019   init_structs(void)
4020   {
4021 ***************
4022 *** 1598,1603 ****
4023 --- 1904,1938 ----
4024       CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
4025       CurrentType.tp_doc = "vim current object";
4026   
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;
4035
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;
4045
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;
4055
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
4061 ***************
4062 *** 46,57 ****
4063 --- 46,66 ----
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));
4085 ***************
4086 *** 64,69 ****
4087 --- 73,79 ----
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));
4095 ***************
4096 *** 94,99 ****
4097 --- 104,111 ----
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
4108 ***************
4109 *** 6,9 ****
4110 --- 6,11 ----
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
4119 ***************
4120 *** 6,9 ****
4121 --- 6,11 ----
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
4130 ***************
4131 *** 14,19 ****
4132 --- 14,20 ----
4133   # test27      can't edit file with "*"
4134   # test52      only for Win32
4135   # test85      no Lua interface
4136 + # test86, 87  no Python interface
4137   
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
4142 ***************
4143 *** 30,36 ****
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
4148   
4149   SCRIPTS32 =   test50.out test70.out
4150   
4151 --- 30,36 ----
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
4156   
4157   SCRIPTS32 =   test50.out test70.out
4158   
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
4161 ***************
4162 *** 50,56 ****
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
4167   
4168   SCRIPTS32 =   test50.out test70.out
4169   
4170 --- 50,56 ----
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
4175   
4176   SCRIPTS32 =   test50.out test70.out
4177   
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
4180 ***************
4181 *** 14,19 ****
4182 --- 14,20 ----
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
4187   
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
4192 ***************
4193 *** 27,33 ****
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
4198   
4199   SCRIPTS_GUI = test16.out
4200   
4201 --- 27,33 ----
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
4206   
4207   SCRIPTS_GUI = test16.out
4208   
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
4211 ***************
4212 *** 0 ****
4213 --- 1,211 ----
4214 + Tests for various python features.     vim: set ft=vim :
4215
4216 + STARTTEST
4217 + :so small.vim
4218 + :if !has('python') | e! test.ok | wq! test.out | endif
4219 + :py import vim
4220 + :fun Test()
4221 + :let l = []
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}]])
4226 + :$put =string(l)
4227 + :$put =string(l[-1])
4228 + :try
4229 + :  $put =string(l[-4])
4230 + :catch
4231 + :  $put =v:exception[:13]
4232 + :endtry
4233 + :" List assignment
4234 + :py l[0]=0
4235 + :$put =string(l)
4236 + :py l[-2]=f
4237 + :$put =string(l)
4238 + :"
4239 + :" Extending Dictionary directly with different types
4240 + :let d = {}
4241 + :py d=vim.bindeval('d')
4242 + :py d['1']='asd'
4243 + :py d['b']=[1, 2, f]
4244 + :py d['-1']={'a': 1}
4245 + :let dkeys = []
4246 + :py dk=vim.bindeval('dkeys')
4247 + :py dkeys=d.keys()
4248 + :py dkeys.sort()
4249 + :py dk.extend(dkeys)
4250 + :$put =string(dkeys)
4251 + :for [key, val] in sort(items(d))
4252 + :  $put =string(key) . ' : ' . string(val)
4253 + :  unlet key val
4254 + :endfor
4255 + :"
4256 + :" removing items with del
4257 + :py del l[2]
4258 + :$put =string(l)
4259 + :let l = range(8)
4260 + :py l=vim.bindeval('l')
4261 + :try
4262 + :   py del l[:3]
4263 + :   py del l[1:]
4264 + :catch
4265 + :   $put =v:exception
4266 + :endtry
4267 + :$put =string(l)
4268 + :"
4269 + :py del d['-1']
4270 + :$put =string(d)
4271 + :"
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:
4276 + :py del l[2:1]
4277 + :$put =string(l)
4278 + :py del l[2:2]
4279 + :$put =string(l)
4280 + :py del l[2:3]
4281 + :$put =string(l)
4282 + :let l = [0, 1, 2, 3]
4283 + :py l=vim.bindeval('l')
4284 + :py del l[2:4]
4285 + :$put =string(l)
4286 + :let l = [0, 1, 2, 3]
4287 + :py l=vim.bindeval('l')
4288 + :py del l[2:5]
4289 + :$put =string(l)
4290 + :let l = [0, 1, 2, 3]
4291 + :py l=vim.bindeval('l')
4292 + :py del l[2:6]
4293 + :$put =string(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:
4297 + :py del l[-1:2]
4298 + :$put =string(l)
4299 + :py del l[-2:2]
4300 + :$put =string(l)
4301 + :py del l[-3:2]
4302 + :$put =string(l)
4303 + :let l = [0, 1, 2, 3]
4304 + :py l=vim.bindeval('l')
4305 + :py del l[-4:2]
4306 + :$put =string(l)
4307 + :let l = [0, 1, 2, 3]
4308 + :py l=vim.bindeval('l')
4309 + :py del l[-5:2]
4310 + :$put =string(l)
4311 + :let l = [0, 1, 2, 3]
4312 + :py l=vim.bindeval('l')
4313 + :py del l[-6:2]
4314 + :$put =string(l)
4315 + :"
4316 + :" Slice assignment to a list
4317 + :let l = [0, 1, 2, 3]
4318 + :py l=vim.bindeval('l')
4319 + :py l[0:0]=['a']
4320 + :$put =string(l)
4321 + :let l = [0, 1, 2, 3]
4322 + :py l=vim.bindeval('l')
4323 + :py l[1:2]=['b']
4324 + :$put =string(l)
4325 + :let l = [0, 1, 2, 3]
4326 + :py l=vim.bindeval('l')
4327 + :py l[2:4]=['c']
4328 + :$put =string(l)
4329 + :let l = [0, 1, 2, 3]
4330 + :py l=vim.bindeval('l')
4331 + :py l[4:4]=['d']
4332 + :$put =string(l)
4333 + :let l = [0, 1, 2, 3]
4334 + :py l=vim.bindeval('l')
4335 + :py l[-1:2]=['e']
4336 + :$put =string(l)
4337 + :let l = [0, 1, 2, 3]
4338 + :py l=vim.bindeval('l')
4339 + :py l[-10:2]=['f']
4340 + :$put =string(l)
4341 + :let l = [0, 1, 2, 3]
4342 + :py l=vim.bindeval('l')
4343 + :py l[2:-10]=['g']
4344 + :$put =string(l)
4345 + :let l = []
4346 + :py l=vim.bindeval('l')
4347 + :py l[0:0]=['h']
4348 + :$put =string(l)
4349 + :"
4350 + :" Locked variables
4351 + :let l = [0, 1, 2, 3]
4352 + :py l=vim.bindeval('l')
4353 + :lockvar! l
4354 + :py l[2]='i'
4355 + :$put =string(l)
4356 + :unlockvar! l
4357 + :"
4358 + :" Function calls
4359 + :function New(...)
4360 + :return ['NewStart']+a:000+['NewEnd']
4361 + :endfunction
4362 + :function DictNew(...) dict
4363 + :return ['DictNewStart']+a:000+['DictNewEnd', self]
4364 + :endfunction
4365 + :let l=[function('New'), function('DictNew')]
4366 + :py l=vim.bindeval('l')
4367 + :py l.extend(list(l[0](1, 2, 3)))
4368 + :$put =string(l)
4369 + :py l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
4370 + :$put =string(l)
4371 + :py l.extend([l[0].name])
4372 + :$put =string(l)
4373 + :try
4374 + :   py l[1](1, 2, 3)
4375 + :catch
4376 + :   $put =v:exception[:16]
4377 + :endtry
4378 + :delfunction New
4379 + :try
4380 + :   py l[0](1, 2, 3)
4381 + :catch
4382 + :   $put =v:exception[:16]
4383 + :endtry
4384 + :if has('float')
4385 + :   let l=[0.0]
4386 + :   py l=vim.bindeval('l')
4387 + :   py l.extend([0.0])
4388 + :   $put =string(l)
4389 + :else
4390 + :   $put ='[0.0, 0.0]'
4391 + :endif
4392 + :"
4393 + :" pyeval()
4394 + :let l=pyeval('range(3)')
4395 + :$put =string(l)
4396 + :let d=pyeval('{"a": "b", "c": 1, "d": ["e"]}')
4397 + :$put =sort(items(d))
4398 + :try
4399 + :   let undef=pyeval('undefined_name')
4400 + :catch
4401 + :   $put =v:exception[:13]
4402 + :endtry
4403 + :try
4404 + :   let vim=pyeval('vim')
4405 + :catch
4406 + :   $put =v:exception[:13]
4407 + :endtry
4408 + :if has('float')
4409 + :   let f=pyeval('0.0')
4410 + :   $put =string(f)
4411 + :else
4412 + :   $put ='0.0'
4413 + :endif
4414 + :endfun
4415 + :"
4416 + :call Test()
4417 + :"
4418 + :delfunc Test
4419 + :call garbagecollect(1)
4420 + :"
4421 + :/^start:/,$wq! test.out
4422 + ENDTEST
4423
4424 + start:
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
4427 ***************
4428 *** 0 ****
4429 --- 1,47 ----
4430 + start:
4431 + [1, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4432 + [1, 2, function('strlen'), {'a': 1}]
4433 + Vim(put):E684:
4434 + [0, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4435 + [0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]]
4436 + ['-1', '1', 'b']
4437 + '-1' : {'a': 1}
4438 + '1' : 'asd'
4439 + 'b' : [1, 2, function('strlen')]
4440 + [0, function('strlen')]
4441 + [3]
4442 + {'1': 'asd', 'b': [1, 2, function('strlen')]}
4443 + [0, 1, 2, 3]
4444 + [0, 1, 2, 3]
4445 + [0, 1, 3]
4446 + [0, 1]
4447 + [0, 1]
4448 + [0, 1]
4449 + [0, 1, 2, 3]
4450 + [0, 1, 2, 3]
4451 + [0, 2, 3]
4452 + [2, 3]
4453 + [2, 3]
4454 + [2, 3]
4455 + ['a', 0, 1, 2, 3]
4456 + [0, 'b', 2, 3]
4457 + [0, 1, 'c']
4458 + [0, 1, 2, 3, 'd']
4459 + [0, 1, 2, 'e', 3]
4460 + ['f', 2, 3]
4461 + [0, 1, 'g', 2, 3]
4462 + ['h']
4463 + [0, 1, 2, 3]
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']
4467 + Vim(python):E725:
4468 + Vim(python):E117:
4469 + [0.0, 0.0]
4470 + [0, 1, 2]
4471 + ['a', 'b']
4472 + ['c', 1]
4473 + ['d', ['e']]
4474 + Vim(let):E858:
4475 + Vim(let):E859:
4476 + 0.0
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
4479 ***************
4480 *** 0 ****
4481 --- 1,211 ----
4482 + Tests for various python features.     vim: set ft=vim :
4483
4484 + STARTTEST
4485 + :so small.vim
4486 + :if !has('python3') | e! test.ok | wq! test.out | endif
4487 + :py3 import vim
4488 + :fun Test()
4489 + :let l = []
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}]]
4494 + :$put =string(l)
4495 + :$put =string(l[-1])
4496 + :try
4497 + :  $put =string(l[-4])
4498 + :catch
4499 + :  $put =v:exception[:13]
4500 + :endtry
4501 + :" List assignment
4502 + :py3 l[0]=0
4503 + :$put =string(l)
4504 + :py3 l[-2]=f
4505 + :$put =string(l)
4506 + :"
4507 + :" Extending Dictionary directly with different types
4508 + :let d = {}
4509 + :py3 d=vim.bindeval('d')
4510 + :py3 d['1']='asd'
4511 + :py3 d['b']=[1, 2, f]
4512 + :py3 d['-1']={'a': 1}
4513 + :let dkeys = []
4514 + :py3 dk=vim.bindeval('dkeys')
4515 + :py3 dkeys=d.keys()
4516 + :py3 dkeys.sort()
4517 + :py3 dk+=dkeys
4518 + :$put =string(dkeys)
4519 + :for [key, val] in sort(items(d))
4520 + :  $put =string(key) . ' : ' . string(val)
4521 + :  unlet key val
4522 + :endfor
4523 + :"
4524 + :" removing items with del
4525 + :py3 del l[2]
4526 + :$put =string(l)
4527 + :let l = range(8)
4528 + :py3 l=vim.bindeval('l')
4529 + :try
4530 + :   py3 del l[:3]
4531 + :   py3 del l[1:]
4532 + :catch
4533 + :   $put =v:exception
4534 + :endtry
4535 + :$put =string(l)
4536 + :"
4537 + :py3 del d['-1']
4538 + :$put =string(d)
4539 + :"
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:
4544 + :py3 del l[2:1]
4545 + :$put =string(l)
4546 + :py3 del l[2:2]
4547 + :$put =string(l)
4548 + :py3 del l[2:3]
4549 + :$put =string(l)
4550 + :let l = [0, 1, 2, 3]
4551 + :py3 l=vim.bindeval('l')
4552 + :py3 del l[2:4]
4553 + :$put =string(l)
4554 + :let l = [0, 1, 2, 3]
4555 + :py3 l=vim.bindeval('l')
4556 + :py3 del l[2:5]
4557 + :$put =string(l)
4558 + :let l = [0, 1, 2, 3]
4559 + :py3 l=vim.bindeval('l')
4560 + :py3 del l[2:6]
4561 + :$put =string(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:
4565 + :py3 del l[-1:2]
4566 + :$put =string(l)
4567 + :py3 del l[-2:2]
4568 + :$put =string(l)
4569 + :py3 del l[-3:2]
4570 + :$put =string(l)
4571 + :let l = [0, 1, 2, 3]
4572 + :py3 l=vim.bindeval('l')
4573 + :py3 del l[-4:2]
4574 + :$put =string(l)
4575 + :let l = [0, 1, 2, 3]
4576 + :py3 l=vim.bindeval('l')
4577 + :py3 del l[-5:2]
4578 + :$put =string(l)
4579 + :let l = [0, 1, 2, 3]
4580 + :py3 l=vim.bindeval('l')
4581 + :py3 del l[-6:2]
4582 + :$put =string(l)
4583 + :"
4584 + :" Slice assignment to a list
4585 + :let l = [0, 1, 2, 3]
4586 + :py3 l=vim.bindeval('l')
4587 + :py3 l[0:0]=['a']
4588 + :$put =string(l)
4589 + :let l = [0, 1, 2, 3]
4590 + :py3 l=vim.bindeval('l')
4591 + :py3 l[1:2]=['b']
4592 + :$put =string(l)
4593 + :let l = [0, 1, 2, 3]
4594 + :py3 l=vim.bindeval('l')
4595 + :py3 l[2:4]=['c']
4596 + :$put =string(l)
4597 + :let l = [0, 1, 2, 3]
4598 + :py3 l=vim.bindeval('l')
4599 + :py3 l[4:4]=['d']
4600 + :$put =string(l)
4601 + :let l = [0, 1, 2, 3]
4602 + :py3 l=vim.bindeval('l')
4603 + :py3 l[-1:2]=['e']
4604 + :$put =string(l)
4605 + :let l = [0, 1, 2, 3]
4606 + :py3 l=vim.bindeval('l')
4607 + :py3 l[-10:2]=['f']
4608 + :$put =string(l)
4609 + :let l = [0, 1, 2, 3]
4610 + :py3 l=vim.bindeval('l')
4611 + :py3 l[2:-10]=['g']
4612 + :$put =string(l)
4613 + :let l = []
4614 + :py3 l=vim.bindeval('l')
4615 + :py3 l[0:0]=['h']
4616 + :$put =string(l)
4617 + :"
4618 + :" Locked variables
4619 + :let l = [0, 1, 2, 3]
4620 + :py3 l=vim.bindeval('l')
4621 + :lockvar! l
4622 + :py3 l[2]='i'
4623 + :$put =string(l)
4624 + :unlockvar! l
4625 + :"
4626 + :" Function calls
4627 + :function New(...)
4628 + :return ['NewStart']+a:000+['NewEnd']
4629 + :endfunction
4630 + :function DictNew(...) dict
4631 + :return ['DictNewStart']+a:000+['DictNewEnd', self]
4632 + :endfunction
4633 + :let l=[function('New'), function('DictNew')]
4634 + :py3 l=vim.bindeval('l')
4635 + :py3 l.extend(list(l[0](1, 2, 3)))
4636 + :$put =string(l)
4637 + :py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
4638 + :$put =string(l)
4639 + :py3 l+=[l[0].name]
4640 + :$put =string(l)
4641 + :try
4642 + :   py3 l[1](1, 2, 3)
4643 + :catch
4644 + :   $put =v:exception[:13]
4645 + :endtry
4646 + :delfunction New
4647 + :try
4648 + :   py3 l[0](1, 2, 3)
4649 + :catch
4650 + :   $put =v:exception[:13]
4651 + :endtry
4652 + :if has('float')
4653 + :   let l=[0.0]
4654 + :   py3 l=vim.bindeval('l')
4655 + :   py3 l.extend([0.0])
4656 + :   $put =string(l)
4657 + :else
4658 + :   $put ='[0.0, 0.0]'
4659 + :endif
4660 + :"
4661 + :" py3eval()
4662 + :let l=py3eval('[0, 1, 2]')
4663 + :$put =string(l)
4664 + :let d=py3eval('{"a": "b", "c": 1, "d": ["e"]}')
4665 + :$put =sort(items(d))
4666 + :try
4667 + :   let undef=py3eval('undefined_name')
4668 + :catch
4669 + :   $put =v:exception[:13]
4670 + :endtry
4671 + :try
4672 + :   let vim=py3eval('vim')
4673 + :catch
4674 + :   $put =v:exception[:13]
4675 + :endtry
4676 + :if has('float')
4677 + :   let f=py3eval('0.0')
4678 + :   $put =string(f)
4679 + :else
4680 + :   $put ='0.0'
4681 + :endif
4682 + :endfun
4683 + :"
4684 + :call Test()
4685 + :"
4686 + :delfunc Test
4687 + :call garbagecollect(1)
4688 + :"
4689 + :/^start:/,$wq! test.out
4690 + ENDTEST
4691
4692 + start:
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
4695 ***************
4696 *** 0 ****
4697 --- 1,47 ----
4698 + start:
4699 + [1, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4700 + [1, 2, function('strlen'), {'a': 1}]
4701 + Vim(put):E684:
4702 + [0, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
4703 + [0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]]
4704 + ['-1', '1', 'b']
4705 + '-1' : {'a': 1}
4706 + '1' : 'asd'
4707 + 'b' : [1, 2, function('strlen')]
4708 + [0, function('strlen')]
4709 + [3]
4710 + {'1': 'asd', 'b': [1, 2, function('strlen')]}
4711 + [0, 1, 2, 3]
4712 + [0, 1, 2, 3]
4713 + [0, 1, 3]
4714 + [0, 1]
4715 + [0, 1]
4716 + [0, 1]
4717 + [0, 1, 2, 3]
4718 + [0, 1, 2, 3]
4719 + [0, 2, 3]
4720 + [2, 3]
4721 + [2, 3]
4722 + [2, 3]
4723 + ['a', 0, 1, 2, 3]
4724 + [0, 'b', 2, 3]
4725 + [0, 1, 'c']
4726 + [0, 1, 2, 3, 'd']
4727 + [0, 1, 2, 'e', 3]
4728 + ['f', 2, 3]
4729 + [0, 1, 'g', 2, 3]
4730 + ['h']
4731 + [0, 1, 2, 3]
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']
4735 + Vim(py3):E725:
4736 + Vim(py3):E117:
4737 + [0.0, 0.0]
4738 + [0, 1, 2]
4739 + ['a', 'b']
4740 + ['c', 1]
4741 + ['d', ['e']]
4742 + Vim(let):E860:
4743 + Vim(let):E861:
4744 + 0.0
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
4747 ***************
4748 *** 716,717 ****
4749 --- 716,719 ----
4750   {   /* Add new patch number below this line */
4751 + /**/
4752 +     569,
4753   /**/
4754
4755 -- 
4756 hundred-and-one symptoms of being an internet addict:
4757 69. Yahoo welcomes you with your own start page
4758
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    ///
This page took 3.674478 seconds and 3 git commands to generate.