Karsten Hopp 80c26f
To: vim_dev@googlegroups.com
Karsten Hopp 80c26f
Subject: Patch 7.3.569
Karsten Hopp 80c26f
Fcc: outbox
Karsten Hopp 80c26f
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 80c26f
Mime-Version: 1.0
Karsten Hopp 80c26f
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 80c26f
Content-Transfer-Encoding: 8bit
Karsten Hopp 80c26f
------------
Karsten Hopp 80c26f
Karsten Hopp 80c26f
Patch 7.3.569
Karsten Hopp 80c26f
Problem:    Evaluating Vim expression in Python is insufficient.
Karsten Hopp 80c26f
Solution:   Add vim.bindeval().  Also add pyeval() and py3eval(). (ZyX)
Karsten Hopp 80c26f
Files:	    runtime/doc/eval.txt, runtime/doc/if_pyth.txt, src/eval.c,
Karsten Hopp 80c26f
	    src/if_lua.c, src/if_py_both.h, src/if_python.c, src/if_python3.c,
Karsten Hopp 80c26f
	    src/proto/eval.pro, src/proto/if_python.pro,
Karsten Hopp 80c26f
	    src/proto/if_python3.pro, src/testdir/Make_amiga.mak,
Karsten Hopp 80c26f
	    src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
Karsten Hopp 80c26f
	    src/testdir/Make_os2.mak, src/testdir/Makefile,
Karsten Hopp 80c26f
	    src/testdir/test86.in, src/testdir/test86.ok,
Karsten Hopp 80c26f
	    src/testdir/test87.in, src/testdir/test87.ok
Karsten Hopp 80c26f
Karsten Hopp 80c26f
Karsten Hopp 80c26f
*** ../vim-7.3.568/runtime/doc/eval.txt	2012-03-07 19:16:49.000000000 +0100
Karsten Hopp 80c26f
--- runtime/doc/eval.txt	2012-06-20 18:01:02.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1836,1844 ****
Karsten Hopp 80c26f
  localtime()			Number	current time
Karsten Hopp 80c26f
  log( {expr})			Float	natural logarithm (base e) of {expr}
Karsten Hopp 80c26f
  log10( {expr})			Float	logarithm of Float {expr} to base 10
Karsten Hopp 80c26f
  map( {expr}, {string})		List/Dict  change each item in {expr} to {expr}
Karsten Hopp 80c26f
  maparg( {name}[, {mode} [, {abbr} [, {dict}]]])
Karsten Hopp 80c26f
! 				String	rhs of mapping {name} in mode {mode}
Karsten Hopp 80c26f
  mapcheck( {name}[, {mode} [, {abbr}]])
Karsten Hopp 80c26f
  				String	check for mappings matching {name}
Karsten Hopp 80c26f
  match( {expr}, {pat}[, {start}[, {count}]])
Karsten Hopp 80c26f
--- 1847,1857 ----
Karsten Hopp 80c26f
  localtime()			Number	current time
Karsten Hopp 80c26f
  log( {expr})			Float	natural logarithm (base e) of {expr}
Karsten Hopp 80c26f
  log10( {expr})			Float	logarithm of Float {expr} to base 10
Karsten Hopp 80c26f
+ luaeval( {expr}[, {expr}])	any	evaluate |Lua| expression
Karsten Hopp 80c26f
  map( {expr}, {string})		List/Dict  change each item in {expr} to {expr}
Karsten Hopp 80c26f
  maparg( {name}[, {mode} [, {abbr} [, {dict}]]])
Karsten Hopp 80c26f
! 				String or Dict
Karsten Hopp 80c26f
! 					rhs of mapping {name} in mode {mode}
Karsten Hopp 80c26f
  mapcheck( {name}[, {mode} [, {abbr}]])
Karsten Hopp 80c26f
  				String	check for mappings matching {name}
Karsten Hopp 80c26f
  match( {expr}, {pat}[, {start}[, {count}]])
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1867,1872 ****
Karsten Hopp 80c26f
--- 1880,1887 ----
Karsten Hopp 80c26f
  prevnonblank( {lnum})		Number	line nr of non-blank line <= {lnum}
Karsten Hopp 80c26f
  printf( {fmt}, {expr1}...)	String	format text
Karsten Hopp 80c26f
  pumvisible()			Number	whether popup menu is visible
Karsten Hopp 80c26f
+ pyeval( {expr})			any	evaluate |Python| expression
Karsten Hopp 80c26f
+ py3eval( {expr})		any	evaluate |python3| expression
Karsten Hopp 80c26f
  range( {expr} [, {max} [, {stride}]])
Karsten Hopp 80c26f
  				List	items from {expr} to {max}
Karsten Hopp 80c26f
  readfile( {fname} [, {binary} [, {max}]])
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 3980,3985 ****
Karsten Hopp 80c26f
--- 4003,4022 ----
Karsten Hopp 80c26f
  <			-2.0
Karsten Hopp 80c26f
  		{only available when compiled with the |+float| feature}
Karsten Hopp 80c26f
  		
Karsten Hopp 80c26f
+ luaeval({expr}[, {expr}])					*luaeval()*
Karsten Hopp 80c26f
+ 		Evaluate Lua expression {expr} and return its result converted 
Karsten Hopp 80c26f
+ 		to Vim data structures. Second {expr} may hold additional 
Karsten Hopp 80c26f
+ 		argument accessible as _A inside first {expr}.
Karsten Hopp 80c26f
+ 		Strings are returned as they are.
Karsten Hopp 80c26f
+ 		Boolean objects are converted to numbers.
Karsten Hopp 80c26f
+ 		Numbers are converted to |Float| values if vim was compiled 
Karsten Hopp 80c26f
+ 		with |+float| and to numbers otherwise.
Karsten Hopp 80c26f
+ 		Dictionaries and lists obtained by vim.eval() are returned 
Karsten Hopp 80c26f
+ 		as-is.
Karsten Hopp 80c26f
+ 		Other objects are returned as zero without any errors.
Karsten Hopp 80c26f
+ 		See |lua-luaeval| for more details.
Karsten Hopp 80c26f
+ 		{only available when compiled with the |+lua| feature}
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  map({expr}, {string})					*map()*
Karsten Hopp 80c26f
  		{expr} must be a |List| or a |Dictionary|.
Karsten Hopp 80c26f
  		Replace each item in {expr} with the result of evaluating
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 4574,4579 ****
Karsten Hopp 80c26f
--- 4612,4640 ----
Karsten Hopp 80c26f
  		This can be used to avoid some things that would remove the
Karsten Hopp 80c26f
  		popup menu.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ 							*E860* *E861*
Karsten Hopp 80c26f
+ py3eval({expr})						*py3eval()*
Karsten Hopp 80c26f
+ 		Evaluate Python expression {expr} and return its result
Karsten Hopp 80c26f
+ 		converted to Vim data structures.
Karsten Hopp 80c26f
+ 		Numbers and strings are returned as they are (strings are 
Karsten Hopp 80c26f
+ 		copied though, unicode strings are additionally converted to 
Karsten Hopp 80c26f
+ 		'encoding').
Karsten Hopp 80c26f
+ 		Lists are represented as Vim |List| type.
Karsten Hopp 80c26f
+ 		Dictionaries are represented as Vim |Dictionary| type with 
Karsten Hopp 80c26f
+ 		keys converted to strings.
Karsten Hopp 80c26f
+ 		{only available when compiled with the |+python3| feature}
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 							*E858* *E859*
Karsten Hopp 80c26f
+ pyeval({expr})						*pyeval()*
Karsten Hopp 80c26f
+ 		Evaluate Python expression {expr} and return its result
Karsten Hopp 80c26f
+ 		converted to Vim data structures.
Karsten Hopp 80c26f
+ 		Numbers and strings are returned as they are (strings are 
Karsten Hopp 80c26f
+ 		copied though).
Karsten Hopp 80c26f
+ 		Lists are represented as Vim |List| type.
Karsten Hopp 80c26f
+ 		Dictionaries are represented as Vim |Dictionary| type with 
Karsten Hopp 80c26f
+ 		keys converted to strings.
Karsten Hopp 80c26f
+ 		{only available when compiled with the |+python| feature}
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  							*E726* *E727*
Karsten Hopp 80c26f
  range({expr} [, {max} [, {stride}]])				*range()*
Karsten Hopp 80c26f
  		Returns a |List| with Numbers:
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 4807,4812 ****
Karsten Hopp 80c26f
--- 4868,4877 ----
Karsten Hopp 80c26f
  		Search for regexp pattern {pattern}.  The search starts at the
Karsten Hopp 80c26f
  		cursor position (you can use |cursor()| to set it).
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ 		If there is no match a 0 is returned and the cursor doesn't
Karsten Hopp 80c26f
+ 		move.  No error message is given.
Karsten Hopp 80c26f
+ 		When a match has been found its line number is returned.
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  		{flags} is a String, which can contain these character flags:
Karsten Hopp 80c26f
  		'b'	search backward instead of forward
Karsten Hopp 80c26f
  		'c'	accept a match at the cursor position
Karsten Hopp 80c26f
*** ../vim-7.3.568/runtime/doc/if_pyth.txt	2010-08-15 21:57:12.000000000 +0200
Karsten Hopp 80c26f
--- runtime/doc/if_pyth.txt	2012-06-20 18:01:02.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1,4 ****
Karsten Hopp 80c26f
! *if_pyth.txt*   For Vim version 7.3.  Last change: 2010 Aug 13
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  		  VIM REFERENCE MANUAL    by Paul Moore
Karsten Hopp 80c26f
--- 1,4 ----
Karsten Hopp 80c26f
! *if_pyth.txt*   For Vim version 7.3.  Last change: 2012 Feb 04
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  		  VIM REFERENCE MANUAL    by Paul Moore
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6,18 ****
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  The Python Interface to Vim				*python* *Python*
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 1. Commands			|python-commands|
Karsten Hopp 80c26f
! 2. The vim module		|python-vim|
Karsten Hopp 80c26f
! 3. Buffer objects		|python-buffer|
Karsten Hopp 80c26f
! 4. Range objects		|python-range|
Karsten Hopp 80c26f
! 5. Window objects		|python-window|
Karsten Hopp 80c26f
! 6. Dynamic loading		|python-dynamic|
Karsten Hopp 80c26f
! 7. Python 3			|python3|
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  {Vi does not have any of these commands}
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
--- 6,19 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  The Python Interface to Vim				*python* *Python*
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 1. Commands					|python-commands|
Karsten Hopp 80c26f
! 2. The vim module				|python-vim|
Karsten Hopp 80c26f
! 3. Buffer objects				|python-buffer|
Karsten Hopp 80c26f
! 4. Range objects				|python-range|
Karsten Hopp 80c26f
! 5. Window objects				|python-window|
Karsten Hopp 80c26f
! 6. pyeval(), py3eval() Vim functions		|python-pyeval|
Karsten Hopp 80c26f
! 7. Dynamic loading				|python-dynamic|
Karsten Hopp 80c26f
! 8. Python 3					|python3|
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  {Vi does not have any of these commands}
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 150,155 ****
Karsten Hopp 80c26f
--- 151,172 ----
Karsten Hopp 80c26f
  	[{'cmd': '/^eval_expr(arg, nextcmd)$/', 'static': 0, 'name':
Karsten Hopp 80c26f
  	'eval_expr', 'kind': 'f', 'filename': './src/eval.c'}]
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ vim.bindeval(str)					*python-bindeval*
Karsten Hopp 80c26f
+ 	Like |python-eval|, but
Karsten Hopp 80c26f
+ 	1. if expression evaluates to |List| or |Dictionary| it is returned as 
Karsten Hopp 80c26f
+ 	   vimlist or vimdictionary python type that are connected to original 
Karsten Hopp 80c26f
+ 	   list or dictionary. Thus modifications to these objects imply 
Karsten Hopp 80c26f
+ 	   modifications of the original.
Karsten Hopp 80c26f
+ 	2. if expression evaluates to a function reference, then it returns 
Karsten Hopp 80c26f
+ 	   callable vimfunction object. Use self keyword argument to assign 
Karsten Hopp 80c26f
+ 	   |self| object for dictionary functions.
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	Note: this function has the same behavior as |lua-eval| (except that 
Karsten Hopp 80c26f
+ 	      lua does not support running vim functions), |python-eval| is 
Karsten Hopp 80c26f
+ 	      kept for backwards compatibility in order not to make scripts 
Karsten Hopp 80c26f
+ 	      relying on outputs of vim.eval() being a copy of original or 
Karsten Hopp 80c26f
+ 	      vim.eval("1") returning a string.
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  Error object of the "vim" module
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 222,229 ****
Karsten Hopp 80c26f
  	- from indexing vim.buffers (|python-buffers|)
Karsten Hopp 80c26f
  	- from the "buffer" attribute of a window (|python-window|)
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! Buffer objects have one read-only attribute - name - the full file name for
Karsten Hopp 80c26f
! the buffer.  They also have three methods (append, mark, and range; see below).
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  You can also treat buffer objects as sequence objects.  In this context, they
Karsten Hopp 80c26f
  act as if they were lists (yes, they are mutable) of strings, with each
Karsten Hopp 80c26f
--- 239,247 ----
Karsten Hopp 80c26f
  	- from indexing vim.buffers (|python-buffers|)
Karsten Hopp 80c26f
  	- from the "buffer" attribute of a window (|python-window|)
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! Buffer objects have two read-only attributes - name - the full file name for
Karsten Hopp 80c26f
! the buffer, and number - the buffer number.  They also have three methods
Karsten Hopp 80c26f
! (append, mark, and range; see below).
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  You can also treat buffer objects as sequence objects.  In this context, they
Karsten Hopp 80c26f
  act as if they were lists (yes, they are mutable) of strings, with each
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 318,324 ****
Karsten Hopp 80c26f
  The width attribute is writable only if the screen is split vertically.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  ==============================================================================
Karsten Hopp 80c26f
! 6. Dynamic loading					*python-dynamic*
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  On MS-Windows the Python library can be loaded dynamically.  The |:version|
Karsten Hopp 80c26f
  output then includes |+python/dyn|.
Karsten Hopp 80c26f
--- 336,348 ----
Karsten Hopp 80c26f
  The width attribute is writable only if the screen is split vertically.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  ==============================================================================
Karsten Hopp 80c26f
! 6. pyeval() and py3eval() Vim functions			*python-pyeval*
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()| 
Karsten Hopp 80c26f
! functions to evaluate Python expressions and pass their values to VimL.
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! ==============================================================================
Karsten Hopp 80c26f
! 7. Dynamic loading					*python-dynamic*
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  On MS-Windows the Python library can be loaded dynamically.  The |:version|
Karsten Hopp 80c26f
  output then includes |+python/dyn|.
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 335,347 ****
Karsten Hopp 80c26f
  sure edit "gvim.exe" and search for "python\d*.dll\c".
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  ==============================================================================
Karsten Hopp 80c26f
! 7. Python 3						*python3*
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  							*:py3* *:python3*
Karsten Hopp 80c26f
  The |:py3| and |:python3| commands work similar to |:python|.
Karsten Hopp 80c26f
  							*:py3file*
Karsten Hopp 80c26f
  The |:py3file| command works similar to |:pyfile|.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  Vim can be built in four ways (:version output):
Karsten Hopp 80c26f
  1. No Python support	    (-python, -python3)
Karsten Hopp 80c26f
  2. Python 2 support only    (+python or +python/dyn, -python3)
Karsten Hopp 80c26f
--- 359,372 ----
Karsten Hopp 80c26f
  sure edit "gvim.exe" and search for "python\d*.dll\c".
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  ==============================================================================
Karsten Hopp 80c26f
! 8. Python 3						*python3*
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  							*:py3* *:python3*
Karsten Hopp 80c26f
  The |:py3| and |:python3| commands work similar to |:python|.
Karsten Hopp 80c26f
  							*:py3file*
Karsten Hopp 80c26f
  The |:py3file| command works similar to |:pyfile|.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  Vim can be built in four ways (:version output):
Karsten Hopp 80c26f
  1. No Python support	    (-python, -python3)
Karsten Hopp 80c26f
  2. Python 2 support only    (+python or +python/dyn, -python3)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 355,361 ****
Karsten Hopp 80c26f
  When doing this on Linux/Unix systems and importing global symbols, this leads
Karsten Hopp 80c26f
  to a crash when the second Python version is used.  So either global symbols
Karsten Hopp 80c26f
  are loaded but only one Python version is activated, or no global symbols are
Karsten Hopp 80c26f
! loaded. The latter makes Python's "import" fail on libaries that expect the
Karsten Hopp 80c26f
  symbols to be provided by Vim.
Karsten Hopp 80c26f
  							*E836* *E837*
Karsten Hopp 80c26f
  Vim's configuration script makes a guess for all libraries based on one
Karsten Hopp 80c26f
--- 380,386 ----
Karsten Hopp 80c26f
  When doing this on Linux/Unix systems and importing global symbols, this leads
Karsten Hopp 80c26f
  to a crash when the second Python version is used.  So either global symbols
Karsten Hopp 80c26f
  are loaded but only one Python version is activated, or no global symbols are
Karsten Hopp 80c26f
! loaded. The latter makes Python's "import" fail on libraries that expect the
Karsten Hopp 80c26f
  symbols to be provided by Vim.
Karsten Hopp 80c26f
  							*E836* *E837*
Karsten Hopp 80c26f
  Vim's configuration script makes a guess for all libraries based on one
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 377,382 ****
Karsten Hopp 80c26f
--- 402,419 ----
Karsten Hopp 80c26f
  3. You undefine PY_NO_RTLD_GLOBAL in auto/config.h after configuration.  This
Karsten Hopp 80c26f
     may crash Vim though.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ 							*has-python*
Karsten Hopp 80c26f
+ You can test what Python version is available with: >
Karsten Hopp 80c26f
+ 	if has('python')
Karsten Hopp 80c26f
+ 	  echo 'there is Python 2.x'
Karsten Hopp 80c26f
+   	elseif has('python3')
Karsten Hopp 80c26f
+ 	  echo 'there is Python 3.x'
Karsten Hopp 80c26f
+ 	endif
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ Note however, that when Python 2 and 3 are both available and loaded
Karsten Hopp 80c26f
+ dynamically, these has() calls will try to load them.  If only one can be
Karsten Hopp 80c26f
+ loaded at a time, just checking if Python 2 or 3 are available will prevent
Karsten Hopp 80c26f
+ the other one from being available.
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  ==============================================================================
Karsten Hopp 80c26f
   vim:tw=78:ts=8:ft=help:norl:
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/eval.c	2012-06-20 14:13:02.000000000 +0200
Karsten Hopp 80c26f
--- src/eval.c	2012-06-20 18:29:15.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 424,453 ****
Karsten Hopp 80c26f
  static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
Karsten Hopp 80c26f
  static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
Karsten Hopp 80c26f
  static int rettv_list_alloc __ARGS((typval_T *rettv));
Karsten Hopp 80c26f
- static listitem_T *listitem_alloc __ARGS((void));
Karsten Hopp 80c26f
  static void listitem_free __ARGS((listitem_T *item));
Karsten Hopp 80c26f
- static void listitem_remove __ARGS((list_T *l, listitem_T *item));
Karsten Hopp 80c26f
  static long list_len __ARGS((list_T *l));
Karsten Hopp 80c26f
  static int list_equal __ARGS((list_T *l1, list_T *l2, int ic, int recursive));
Karsten Hopp 80c26f
  static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic, int recursive));
Karsten Hopp 80c26f
  static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic, int recursive));
Karsten Hopp 80c26f
- static listitem_T *list_find __ARGS((list_T *l, long n));
Karsten Hopp 80c26f
  static long list_find_nr __ARGS((list_T *l, long idx, int *errorp));
Karsten Hopp 80c26f
  static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
Karsten Hopp 80c26f
- static void list_append __ARGS((list_T *l, listitem_T *item));
Karsten Hopp 80c26f
  static int list_append_number __ARGS((list_T *l, varnumber_T n));
Karsten Hopp 80c26f
- static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
Karsten Hopp 80c26f
  static int list_extend __ARGS((list_T	*l1, list_T *l2, listitem_T *bef));
Karsten Hopp 80c26f
  static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv));
Karsten Hopp 80c26f
  static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID));
Karsten Hopp 80c26f
- static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
Karsten Hopp 80c26f
  static char_u *list2string __ARGS((typval_T *tv, int copyID));
Karsten Hopp 80c26f
  static int list_join_inner __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo_style, int copyID, garray_T *join_gap));
Karsten Hopp 80c26f
  static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID));
Karsten Hopp 80c26f
  static int free_unref_items __ARGS((int copyID));
Karsten Hopp 80c26f
- static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
Karsten Hopp 80c26f
- static void set_ref_in_list __ARGS((list_T *l, int copyID));
Karsten Hopp 80c26f
- static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
Karsten Hopp 80c26f
  static int rettv_dict_alloc __ARGS((typval_T *rettv));
Karsten Hopp 80c26f
  static void dict_free __ARGS((dict_T *d, int recurse));
Karsten Hopp 80c26f
  static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
Karsten Hopp 80c26f
--- 424,444 ----
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 654,659 ****
Karsten Hopp 80c26f
--- 645,656 ----
Karsten Hopp 80c26f
  static void f_prevnonblank __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
  static void f_printf __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
  static void f_pumvisible __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON3
Karsten Hopp 80c26f
+ static void f_py3eval __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON
Karsten Hopp 80c26f
+ static void f_pyeval __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
  static void f_range __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
  static void f_readfile __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
  static void f_reltime __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 824,831 ****
Karsten Hopp 80c26f
  static char_u *autoload_name __ARGS((char_u *name));
Karsten Hopp 80c26f
  static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
Karsten Hopp 80c26f
  static void func_free __ARGS((ufunc_T *fp));
Karsten Hopp 80c26f
- static void func_unref __ARGS((char_u *name));
Karsten Hopp 80c26f
- static void func_ref __ARGS((char_u *name));
Karsten Hopp 80c26f
  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));
Karsten Hopp 80c26f
  static int can_free_funccal __ARGS((funccall_T *fc, int copyID)) ;
Karsten Hopp 80c26f
  static void free_funccal __ARGS((funccall_T *fc, int free_val));
Karsten Hopp 80c26f
--- 821,826 ----
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 5927,5933 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Allocate a list item.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static listitem_T *
Karsten Hopp 80c26f
  listitem_alloc()
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      return (listitem_T *)alloc(sizeof(listitem_T));
Karsten Hopp 80c26f
--- 5922,5928 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Allocate a list item.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     listitem_T *
Karsten Hopp 80c26f
  listitem_alloc()
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      return (listitem_T *)alloc(sizeof(listitem_T));
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 5947,5953 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Remove a list item from a List and free it.  Also clears the value.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  listitem_remove(l, item)
Karsten Hopp 80c26f
      list_T  *l;
Karsten Hopp 80c26f
      listitem_T *item;
Karsten Hopp 80c26f
--- 5942,5948 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Remove a list item from a List and free it.  Also clears the value.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  listitem_remove(l, item)
Karsten Hopp 80c26f
      list_T  *l;
Karsten Hopp 80c26f
      listitem_T *item;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6123,6129 ****
Karsten Hopp 80c26f
   * A negative index is counted from the end; -1 is the last item.
Karsten Hopp 80c26f
   * Returns NULL when "n" is out of range.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static listitem_T *
Karsten Hopp 80c26f
  list_find(l, n)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      long	n;
Karsten Hopp 80c26f
--- 6118,6124 ----
Karsten Hopp 80c26f
   * A negative index is counted from the end; -1 is the last item.
Karsten Hopp 80c26f
   * Returns NULL when "n" is out of range.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     listitem_T *
Karsten Hopp 80c26f
  list_find(l, n)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      long	n;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6265,6271 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Append item "item" to the end of list "l".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  list_append(l, item)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      listitem_T	*item;
Karsten Hopp 80c26f
--- 6260,6266 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Append item "item" to the end of list "l".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  list_append(l, item)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      listitem_T	*item;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6378,6384 ****
Karsten Hopp 80c26f
   * If "item" is NULL append at the end.
Karsten Hopp 80c26f
   * Return FAIL when out of memory.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
  list_insert_tv(l, tv, item)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      typval_T	*tv;
Karsten Hopp 80c26f
--- 6373,6379 ----
Karsten Hopp 80c26f
   * If "item" is NULL append at the end.
Karsten Hopp 80c26f
   * Return FAIL when out of memory.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     int
Karsten Hopp 80c26f
  list_insert_tv(l, tv, item)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      typval_T	*tv;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6523,6529 ****
Karsten Hopp 80c26f
   * Remove items "item" to "item2" from list "l".
Karsten Hopp 80c26f
   * Does not free the listitem or the value!
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  list_remove(l, item, item2)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      listitem_T	*item;
Karsten Hopp 80c26f
--- 6518,6524 ----
Karsten Hopp 80c26f
   * Remove items "item" to "item2" from list "l".
Karsten Hopp 80c26f
   * Does not free the listitem or the value!
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  list_remove(l, item, item2)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      listitem_T	*item;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6785,6790 ****
Karsten Hopp 80c26f
--- 6780,6793 ----
Karsten Hopp 80c26f
      set_ref_in_lua(copyID);
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON
Karsten Hopp 80c26f
+     set_ref_in_python(copyID);
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON3
Karsten Hopp 80c26f
+     set_ref_in_python3(copyID);
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
      /*
Karsten Hopp 80c26f
       * 2. Free lists and dictionaries that are not referenced.
Karsten Hopp 80c26f
       */
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6870,6876 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  set_ref_in_ht(ht, copyID)
Karsten Hopp 80c26f
      hashtab_T	*ht;
Karsten Hopp 80c26f
      int		copyID;
Karsten Hopp 80c26f
--- 6873,6879 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Mark all lists and dicts referenced through hashtab "ht" with "copyID".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  set_ref_in_ht(ht, copyID)
Karsten Hopp 80c26f
      hashtab_T	*ht;
Karsten Hopp 80c26f
      int		copyID;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6890,6896 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Mark all lists and dicts referenced through list "l" with "copyID".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  set_ref_in_list(l, copyID)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      int		copyID;
Karsten Hopp 80c26f
--- 6893,6899 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Mark all lists and dicts referenced through list "l" with "copyID".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  set_ref_in_list(l, copyID)
Karsten Hopp 80c26f
      list_T	*l;
Karsten Hopp 80c26f
      int		copyID;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6904,6910 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Mark all lists and dicts referenced through typval "tv" with "copyID".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  set_ref_in_item(tv, copyID)
Karsten Hopp 80c26f
      typval_T	*tv;
Karsten Hopp 80c26f
      int		copyID;
Karsten Hopp 80c26f
--- 6907,6913 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Mark all lists and dicts referenced through typval "tv" with "copyID".
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  set_ref_in_item(tv, copyID)
Karsten Hopp 80c26f
      typval_T	*tv;
Karsten Hopp 80c26f
      int		copyID;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 7986,7991 ****
Karsten Hopp 80c26f
--- 7989,8000 ----
Karsten Hopp 80c26f
      {"prevnonblank",	1, 1, f_prevnonblank},
Karsten Hopp 80c26f
      {"printf",		2, 19, f_printf},
Karsten Hopp 80c26f
      {"pumvisible",	0, 0, f_pumvisible},
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON3
Karsten Hopp 80c26f
+     {"py3eval",		1, 1, f_py3eval},
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON
Karsten Hopp 80c26f
+     {"pyeval",		1, 1, f_pyeval},
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
      {"range",		1, 3, f_range},
Karsten Hopp 80c26f
      {"readfile",	1, 3, f_readfile},
Karsten Hopp 80c26f
      {"reltime",		0, 2, f_reltime},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 9150,9155 ****
Karsten Hopp 80c26f
--- 9159,9203 ----
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+     int
Karsten Hopp 80c26f
+ func_call(name, args, selfdict, rettv)
Karsten Hopp 80c26f
+     char_u	*name;
Karsten Hopp 80c26f
+     typval_T	*args;
Karsten Hopp 80c26f
+     dict_T	*selfdict;
Karsten Hopp 80c26f
+     typval_T	*rettv;
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     listitem_T	*item;
Karsten Hopp 80c26f
+     typval_T	argv[MAX_FUNC_ARGS + 1];
Karsten Hopp 80c26f
+     int		argc = 0;
Karsten Hopp 80c26f
+     int		dummy;
Karsten Hopp 80c26f
+     int		r = 0;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     for (item = args->vval.v_list->lv_first; item != NULL;
Karsten Hopp 80c26f
+ 							 item = item->li_next)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	if (argc == MAX_FUNC_ARGS)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    EMSG(_("E699: Too many arguments"));
Karsten Hopp 80c26f
+ 	    break;
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+ 	/* Make a copy of each argument.  This is needed to be able to set
Karsten Hopp 80c26f
+ 	 * v_lock to VAR_FIXED in the copy without changing the original list.
Karsten Hopp 80c26f
+ 	 */
Karsten Hopp 80c26f
+ 	copy_tv(&item->li_tv, &argv[argc++]);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     if (item == NULL)
Karsten Hopp 80c26f
+ 	r = call_func(name, (int)STRLEN(name), rettv, argc, argv,
Karsten Hopp 80c26f
+ 				 curwin->w_cursor.lnum, curwin->w_cursor.lnum,
Karsten Hopp 80c26f
+ 						      &dummy, TRUE, selfdict);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     /* Free the arguments. */
Karsten Hopp 80c26f
+     while (argc > 0)
Karsten Hopp 80c26f
+ 	clear_tv(&argv[--argc]);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     return r;
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * "call(func, arglist)" function
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 9159,9168 ****
Karsten Hopp 80c26f
      typval_T	*rettv;
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      char_u	*func;
Karsten Hopp 80c26f
-     typval_T	argv[MAX_FUNC_ARGS + 1];
Karsten Hopp 80c26f
-     int		argc = 0;
Karsten Hopp 80c26f
-     listitem_T	*item;
Karsten Hopp 80c26f
-     int		dummy;
Karsten Hopp 80c26f
      dict_T	*selfdict = NULL;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      if (argvars[1].v_type != VAR_LIST)
Karsten Hopp 80c26f
--- 9207,9212 ----
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 9190,9217 ****
Karsten Hopp 80c26f
  	selfdict = argvars[2].vval.v_dict;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     for (item = argvars[1].vval.v_list->lv_first; item != NULL;
Karsten Hopp 80c26f
! 							 item = item->li_next)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	if (argc == MAX_FUNC_ARGS)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    EMSG(_("E699: Too many arguments"));
Karsten Hopp 80c26f
! 	    break;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	/* Make a copy of each argument.  This is needed to be able to set
Karsten Hopp 80c26f
! 	 * v_lock to VAR_FIXED in the copy without changing the original list.
Karsten Hopp 80c26f
! 	 */
Karsten Hopp 80c26f
! 	copy_tv(&item->li_tv, &argv[argc++]);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (item == NULL)
Karsten Hopp 80c26f
! 	(void)call_func(func, (int)STRLEN(func), rettv, argc, argv,
Karsten Hopp 80c26f
! 				 curwin->w_cursor.lnum, curwin->w_cursor.lnum,
Karsten Hopp 80c26f
! 						      &dummy, TRUE, selfdict);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     /* Free the arguments. */
Karsten Hopp 80c26f
!     while (argc > 0)
Karsten Hopp 80c26f
! 	clear_tv(&argv[--argc]);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #ifdef FEAT_FLOAT
Karsten Hopp 80c26f
--- 9234,9240 ----
Karsten Hopp 80c26f
  	selfdict = argvars[2].vval.v_dict;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     (void)func_call(func, &argvars[1], selfdict, rettv);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #ifdef FEAT_FLOAT
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 14424,14429 ****
Karsten Hopp 80c26f
--- 14447,14486 ----
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON3
Karsten Hopp 80c26f
+ /*
Karsten Hopp 80c26f
+  * "py3eval()" function
Karsten Hopp 80c26f
+  */
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ f_py3eval(argvars, rettv)
Karsten Hopp 80c26f
+     typval_T	*argvars;
Karsten Hopp 80c26f
+     typval_T	*rettv;
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     char_u	*str;
Karsten Hopp 80c26f
+     char_u	buf[NUMBUFLEN];
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     str = get_tv_string_buf(&argvars[0], buf);
Karsten Hopp 80c26f
+     do_py3eval(str, rettv);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ #ifdef FEAT_PYTHON
Karsten Hopp 80c26f
+ /*
Karsten Hopp 80c26f
+  * "pyeval()" function
Karsten Hopp 80c26f
+  */
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ f_pyeval(argvars, rettv)
Karsten Hopp 80c26f
+     typval_T	*argvars;
Karsten Hopp 80c26f
+     typval_T	*rettv;
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     char_u	*str;
Karsten Hopp 80c26f
+     char_u	buf[NUMBUFLEN];
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     str = get_tv_string_buf(&argvars[0], buf);
Karsten Hopp 80c26f
+     do_pyeval(str, rettv);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * "range()" function
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 22139,22145 ****
Karsten Hopp 80c26f
   * Unreference a Function: decrement the reference count and free it when it
Karsten Hopp 80c26f
   * becomes zero.  Only for numbered functions.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  func_unref(name)
Karsten Hopp 80c26f
      char_u	*name;
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
--- 22196,22202 ----
Karsten Hopp 80c26f
   * Unreference a Function: decrement the reference count and free it when it
Karsten Hopp 80c26f
   * becomes zero.  Only for numbered functions.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  func_unref(name)
Karsten Hopp 80c26f
      char_u	*name;
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 22163,22169 ****
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Count a reference to a Function.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
  func_ref(name)
Karsten Hopp 80c26f
      char_u	*name;
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
--- 22220,22226 ----
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Count a reference to a Function.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
!     void
Karsten Hopp 80c26f
  func_ref(name)
Karsten Hopp 80c26f
      char_u	*name;
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/if_lua.c	2012-04-06 14:30:55.000000000 +0200
Karsten Hopp 80c26f
--- src/if_lua.c	2012-06-20 18:16:33.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 199,207 ****
Karsten Hopp 80c26f
  lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
Karsten Hopp 80c26f
  lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
Karsten Hopp 80c26f
  void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
Karsten Hopp 80c26f
!         lua_CFunction k);
Karsten Hopp 80c26f
  int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
Karsten Hopp 80c26f
!         int ctx, lua_CFunction k);
Karsten Hopp 80c26f
  void (*dll_lua_getglobal) (lua_State *L, const char *var);
Karsten Hopp 80c26f
  void (*dll_lua_setglobal) (lua_State *L, const char *var);
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
--- 199,207 ----
Karsten Hopp 80c26f
  lua_Number (*dll_lua_tonumberx) (lua_State *L, int idx, int *isnum);
Karsten Hopp 80c26f
  lua_Integer (*dll_lua_tointegerx) (lua_State *L, int idx, int *isnum);
Karsten Hopp 80c26f
  void (*dll_lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
Karsten Hopp 80c26f
! 	lua_CFunction k);
Karsten Hopp 80c26f
  int (*dll_lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
Karsten Hopp 80c26f
! 	int ctx, lua_CFunction k);
Karsten Hopp 80c26f
  void (*dll_lua_getglobal) (lua_State *L, const char *var);
Karsten Hopp 80c26f
  void (*dll_lua_setglobal) (lua_State *L, const char *var);
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 394,400 ****
Karsten Hopp 80c26f
  luaL_typeerror (lua_State *L, int narg, const char *tname)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      const char *msg = lua_pushfstring(L, "%s expected, got %s",
Karsten Hopp 80c26f
!             tname, luaL_typename(L, narg));
Karsten Hopp 80c26f
      return luaL_argerror(L, narg, msg);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
--- 394,400 ----
Karsten Hopp 80c26f
  luaL_typeerror (lua_State *L, int narg, const char *tname)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      const char *msg = lua_pushfstring(L, "%s expected, got %s",
Karsten Hopp 80c26f
! 	    tname, luaL_typename(L, narg));
Karsten Hopp 80c26f
      return luaL_argerror(L, narg, msg);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 646,786 ****
Karsten Hopp 80c26f
  	return 1; \
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
- /* adapted from eval.c */
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
- #define listitem_alloc() (listitem_T *)alloc(sizeof(listitem_T))
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static listitem_T *
Karsten Hopp 80c26f
- list_find (list_T *l, long n)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     listitem_T *li;
Karsten Hopp 80c26f
-     if (l == NULL || n < -l->lv_len || n >= l->lv_len)
Karsten Hopp 80c26f
- 	return NULL;
Karsten Hopp 80c26f
-     if (n < 0) /* search backward? */
Karsten Hopp 80c26f
- 	for (li = l->lv_last; n < -1; li = li->li_prev)
Karsten Hopp 80c26f
- 	    n++;
Karsten Hopp 80c26f
-     else /* search forward */
Karsten Hopp 80c26f
- 	for (li = l->lv_first; n > 0; li = li->li_next)
Karsten Hopp 80c26f
- 	    n--;
Karsten Hopp 80c26f
-     return li;
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static void
Karsten Hopp 80c26f
- list_remove (list_T *l, listitem_T *li)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     listwatch_T *lw;
Karsten Hopp 80c26f
-     --l->lv_len;
Karsten Hopp 80c26f
-     /* fix watchers */
Karsten Hopp 80c26f
-     for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
Karsten Hopp 80c26f
- 	if (lw->lw_item == li)
Karsten Hopp 80c26f
- 	    lw->lw_item = li->li_next;
Karsten Hopp 80c26f
-     /* fix list pointers */
Karsten Hopp 80c26f
-     if (li->li_next == NULL) /* last? */
Karsten Hopp 80c26f
- 	l->lv_last = li->li_prev;
Karsten Hopp 80c26f
-     else
Karsten Hopp 80c26f
- 	li->li_next->li_prev = li->li_prev;
Karsten Hopp 80c26f
-     if (li->li_prev == NULL) /* first? */
Karsten Hopp 80c26f
- 	l->lv_first = li->li_next;
Karsten Hopp 80c26f
-     else
Karsten Hopp 80c26f
- 	li->li_prev->li_next = li->li_next;
Karsten Hopp 80c26f
-     l->lv_idx_item = NULL;
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static void
Karsten Hopp 80c26f
- list_append(list_T *l, listitem_T *item)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     if (l->lv_last == NULL) /* empty list? */
Karsten Hopp 80c26f
- 	l->lv_first = item;
Karsten Hopp 80c26f
-     else
Karsten Hopp 80c26f
- 	l->lv_last->li_next = item;
Karsten Hopp 80c26f
-     item->li_prev = l->lv_last;
Karsten Hopp 80c26f
-     item->li_next = NULL;
Karsten Hopp 80c26f
-     l->lv_last = item;
Karsten Hopp 80c26f
-     ++l->lv_len;
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static int
Karsten Hopp 80c26f
- list_insert_tv(list_T *l, typval_T *tv, listitem_T *item)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     listitem_T	*ni = listitem_alloc();
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     if (ni == NULL)
Karsten Hopp 80c26f
- 	return FAIL;
Karsten Hopp 80c26f
-     copy_tv(tv, &ni->li_tv);
Karsten Hopp 80c26f
-     if (item == NULL)
Karsten Hopp 80c26f
- 	list_append(l, ni);
Karsten Hopp 80c26f
-     else
Karsten Hopp 80c26f
-     {
Karsten Hopp 80c26f
- 	ni->li_prev = item->li_prev;
Karsten Hopp 80c26f
- 	ni->li_next = item;
Karsten Hopp 80c26f
- 	if (item->li_prev == NULL)
Karsten Hopp 80c26f
- 	{
Karsten Hopp 80c26f
- 	    l->lv_first = ni;
Karsten Hopp 80c26f
- 	    ++l->lv_idx;
Karsten Hopp 80c26f
- 	}
Karsten Hopp 80c26f
- 	else
Karsten Hopp 80c26f
- 	{
Karsten Hopp 80c26f
- 	    item->li_prev->li_next = ni;
Karsten Hopp 80c26f
- 	    l->lv_idx_item = NULL;
Karsten Hopp 80c26f
- 	}
Karsten Hopp 80c26f
- 	item->li_prev = ni;
Karsten Hopp 80c26f
- 	++l->lv_len;
Karsten Hopp 80c26f
-     }
Karsten Hopp 80c26f
-     return OK;
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
- /* set references */
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
- static void set_ref_in_tv (typval_T *tv, int copyID);
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static void
Karsten Hopp 80c26f
- set_ref_in_dict(dict_T *d, int copyID)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     hashtab_T *ht = &d->dv_hashtab;
Karsten Hopp 80c26f
-     int n = ht->ht_used;
Karsten Hopp 80c26f
-     hashitem_T *hi;
Karsten Hopp 80c26f
-     for (hi = ht->ht_array; n > 0; ++hi)
Karsten Hopp 80c26f
- 	if (!HASHITEM_EMPTY(hi))
Karsten Hopp 80c26f
- 	{
Karsten Hopp 80c26f
- 	    dictitem_T *di = dict_lookup(hi);
Karsten Hopp 80c26f
- 	    set_ref_in_tv(&di->di_tv, copyID);
Karsten Hopp 80c26f
- 	    --n;
Karsten Hopp 80c26f
- 	}
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static void
Karsten Hopp 80c26f
- set_ref_in_list(list_T *l, int copyID)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     listitem_T *li;
Karsten Hopp 80c26f
-     for (li = l->lv_first; li != NULL; li = li->li_next)
Karsten Hopp 80c26f
- 	set_ref_in_tv(&li->li_tv, copyID);
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
-     static void
Karsten Hopp 80c26f
- set_ref_in_tv(typval_T *tv, int copyID)
Karsten Hopp 80c26f
- {
Karsten Hopp 80c26f
-     if (tv->v_type == VAR_LIST)
Karsten Hopp 80c26f
-     {
Karsten Hopp 80c26f
- 	list_T *l = tv->vval.v_list;
Karsten Hopp 80c26f
- 	if (l != NULL && l->lv_copyID != copyID)
Karsten Hopp 80c26f
- 	{
Karsten Hopp 80c26f
- 	    l->lv_copyID = copyID;
Karsten Hopp 80c26f
- 	    set_ref_in_list(l, copyID);
Karsten Hopp 80c26f
- 	}
Karsten Hopp 80c26f
-     }
Karsten Hopp 80c26f
-     else if (tv->v_type == VAR_DICT)
Karsten Hopp 80c26f
-     {
Karsten Hopp 80c26f
- 	dict_T *d = tv->vval.v_dict;
Karsten Hopp 80c26f
- 	if (d != NULL && d->dv_copyID != copyID)
Karsten Hopp 80c26f
- 	{
Karsten Hopp 80c26f
- 	    d->dv_copyID = copyID;
Karsten Hopp 80c26f
- 	    set_ref_in_dict(d, copyID);
Karsten Hopp 80c26f
- 	}
Karsten Hopp 80c26f
-     }
Karsten Hopp 80c26f
- }
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
  /* =======   List type   ======= */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      static luaV_List *
Karsten Hopp 80c26f
--- 646,651 ----
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 876,882 ****
Karsten Hopp 80c26f
      if (li == NULL) return 0;
Karsten Hopp 80c26f
      if (lua_isnil(L, 3)) /* remove? */
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	list_remove(l, li);
Karsten Hopp 80c26f
  	clear_tv(&li->li_tv);
Karsten Hopp 80c26f
  	vim_free(li);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
--- 741,747 ----
Karsten Hopp 80c26f
      if (li == NULL) return 0;
Karsten Hopp 80c26f
      if (lua_isnil(L, 3)) /* remove? */
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	list_remove(l, li, li);
Karsten Hopp 80c26f
  	clear_tv(&li->li_tv);
Karsten Hopp 80c26f
  	vim_free(li);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 904,911 ****
Karsten Hopp 80c26f
  	typval_T v;
Karsten Hopp 80c26f
  	lua_settop(L, 2);
Karsten Hopp 80c26f
  	luaV_totypval(L, 2, &v);
Karsten Hopp 80c26f
! 	copy_tv(&v, &li->li_tv);
Karsten Hopp 80c26f
! 	list_append(l, li);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      lua_settop(L, 1);
Karsten Hopp 80c26f
      return 1;
Karsten Hopp 80c26f
--- 769,775 ----
Karsten Hopp 80c26f
  	typval_T v;
Karsten Hopp 80c26f
  	lua_settop(L, 2);
Karsten Hopp 80c26f
  	luaV_totypval(L, 2, &v);
Karsten Hopp 80c26f
! 	list_append_tv(l, &v);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      lua_settop(L, 1);
Karsten Hopp 80c26f
      return 1;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1682,1688 ****
Karsten Hopp 80c26f
  	    tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	lua_pop(L, 2); /* metatable and value */
Karsten Hopp 80c26f
! 	set_ref_in_tv(&tv, copyID);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      return 0;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
--- 1546,1552 ----
Karsten Hopp 80c26f
  	    tv.vval.v_dict = (dict_T *) lua_touserdata(L, 4); /* key */
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	lua_pop(L, 2); /* metatable and value */
Karsten Hopp 80c26f
! 	set_ref_in_item(&tv, copyID);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      return 0;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/if_py_both.h	2012-04-20 13:31:16.000000000 +0200
Karsten Hopp 80c26f
--- src/if_py_both.h	2012-06-29 12:03:52.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1,4 ****
Karsten Hopp 80c26f
! /* vi:set ts=8 sts=4 sw=4:
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
   * VIM - Vi IMproved	by Bram Moolenaar
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
--- 1,4 ----
Karsten Hopp 80c26f
! /* vi:set ts=8 sts=4 sw=4 noet:
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
   * VIM - Vi IMproved	by Bram Moolenaar
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 105,111 ****
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      Py_INCREF(list);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (!PyList_Check(list)) {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
Karsten Hopp 80c26f
  	Py_DECREF(list);
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
--- 105,112 ----
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      Py_INCREF(list);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (!PyList_Check(list))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
Karsten Hopp 80c26f
  	Py_DECREF(list);
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 119,125 ****
Karsten Hopp 80c26f
  	char *str = NULL;
Karsten Hopp 80c26f
  	PyInt len;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 	if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len)) {
Karsten Hopp 80c26f
  	    PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
Karsten Hopp 80c26f
  	    Py_DECREF(list);
Karsten Hopp 80c26f
  	    return NULL;
Karsten Hopp 80c26f
--- 120,127 ----
Karsten Hopp 80c26f
  	char *str = NULL;
Karsten Hopp 80c26f
  	PyInt len;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 	if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len))
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
Karsten Hopp 80c26f
  	    Py_DECREF(list);
Karsten Hopp 80c26f
  	    return NULL;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 297,303 ****
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      PyObject	*result;
Karsten Hopp 80c26f
      PyObject	*newObj;
Karsten Hopp 80c26f
!     char	ptrBuf[NUMBUFLEN];
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Avoid infinite recursion */
Karsten Hopp 80c26f
      if (depth > 100)
Karsten Hopp 80c26f
--- 299,305 ----
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      PyObject	*result;
Karsten Hopp 80c26f
      PyObject	*newObj;
Karsten Hopp 80c26f
!     char	ptrBuf[sizeof(void *) * 2 + 3];
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Avoid infinite recursion */
Karsten Hopp 80c26f
      if (depth > 100)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 312,320 ****
Karsten Hopp 80c26f
      if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
Karsten Hopp 80c26f
  	    || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U,
Karsten Hopp 80c26f
! 		our_tv->v_type == VAR_LIST ? (long_u)our_tv->vval.v_list
Karsten Hopp 80c26f
! 					   : (long_u)our_tv->vval.v_dict);
Karsten Hopp 80c26f
  	result = PyDict_GetItemString(lookupDict, ptrBuf);
Karsten Hopp 80c26f
  	if (result != NULL)
Karsten Hopp 80c26f
  	{
Karsten Hopp 80c26f
--- 314,322 ----
Karsten Hopp 80c26f
      if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
Karsten Hopp 80c26f
  	    || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	sprintf(ptrBuf, "%p",
Karsten Hopp 80c26f
! 		our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
Karsten Hopp 80c26f
! 					   : (void *)our_tv->vval.v_dict);
Karsten Hopp 80c26f
  	result = PyDict_GetItemString(lookupDict, ptrBuf);
Karsten Hopp 80c26f
  	if (result != NULL)
Karsten Hopp 80c26f
  	{
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 374,509 ****
Karsten Hopp 80c26f
  	    hashitem_T	*hi;
Karsten Hopp 80c26f
  	    dictitem_T	*di;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 	    PyDict_SetItemString(lookupDict, ptrBuf, result);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 	    for (hi = ht->ht_array; todo > 0; ++hi)
Karsten Hopp 80c26f
  	    {
Karsten Hopp 80c26f
! 		if (!HASHITEM_EMPTY(hi))
Karsten Hopp 80c26f
! 		{
Karsten Hopp 80c26f
! 		    --todo;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 		    di = dict_lookup(hi);
Karsten Hopp 80c26f
! 		    newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
Karsten Hopp 80c26f
! 		    PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
Karsten Hopp 80c26f
! 		    Py_DECREF(newObj);
Karsten Hopp 80c26f
! 		}
Karsten Hopp 80c26f
  	    }
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	Py_INCREF(Py_None);
Karsten Hopp 80c26f
! 	result = Py_None;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     return result;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
- #endif
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
! VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
! #ifdef FEAT_EVAL
Karsten Hopp 80c26f
!     char	*expr;
Karsten Hopp 80c26f
!     typval_T	*our_tv;
Karsten Hopp 80c26f
!     PyObject	*result;
Karsten Hopp 80c26f
!     PyObject    *lookup_dict;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (!PyArg_ParseTuple(args, "s", &expr))
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     Py_BEGIN_ALLOW_THREADS
Karsten Hopp 80c26f
!     Python_Lock_Vim();
Karsten Hopp 80c26f
!     our_tv = eval_expr((char_u *)expr, NULL);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Python_Release_Vim();
Karsten Hopp 80c26f
!     Py_END_ALLOW_THREADS
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (our_tv == NULL)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("invalid expression"));
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
-     /* Convert the Vim type into a Python type.  Create a dictionary that's
Karsten Hopp 80c26f
-      * used to check for recursive loops. */
Karsten Hopp 80c26f
      lookup_dict = PyDict_New();
Karsten Hopp 80c26f
!     result = VimToPython(our_tv, 1, lookup_dict);
Karsten Hopp 80c26f
      Py_DECREF(lookup_dict);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Py_BEGIN_ALLOW_THREADS
Karsten Hopp 80c26f
!     Python_Lock_Vim();
Karsten Hopp 80c26f
!     free_tv(our_tv);
Karsten Hopp 80c26f
!     Python_Release_Vim();
Karsten Hopp 80c26f
!     Py_END_ALLOW_THREADS
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return result;
Karsten Hopp 80c26f
! #else
Karsten Hopp 80c26f
!     PyErr_SetVim(_("expressions disabled at compile time"));
Karsten Hopp 80c26f
!     return NULL;
Karsten Hopp 80c26f
! #endif
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! /*
Karsten Hopp 80c26f
!  * Vim module - Definitions
Karsten Hopp 80c26f
!  */
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static struct PyMethodDef VimMethods[] = {
Karsten Hopp 80c26f
!     /* name,	     function,		calling,    documentation */
Karsten Hopp 80c26f
!     {"command",	     VimCommand,	1,	    "Execute a Vim ex-mode command" },
Karsten Hopp 80c26f
!     {"eval",	     VimEval,		1,	    "Evaluate an expression using Vim evaluator" },
Karsten Hopp 80c26f
!     { NULL,	     NULL,		0,	    NULL }
Karsten Hopp 80c26f
  };
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  typedef struct
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      PyObject_HEAD
Karsten Hopp 80c26f
!     buf_T *buf;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! BufferObject;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! /*
Karsten Hopp 80c26f
!  * Buffer list object - Implementation
Karsten Hopp 80c26f
!  */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     static PyInt
Karsten Hopp 80c26f
! BufListLength(PyObject *self UNUSED)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     buf_T	*b = firstbuf;
Karsten Hopp 80c26f
!     PyInt	n = 0;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     while (b)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	++n;
Karsten Hopp 80c26f
! 	b = b->b_next;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return n;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
! BufListItem(PyObject *self UNUSED, PyInt n)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     buf_T *b;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     for (b = firstbuf; b; b = b->b_next, --n)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	if (n == 0)
Karsten Hopp 80c26f
! 	    return BufferNew(b);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     PyErr_SetString(PyExc_IndexError, _("no such buffer"));
Karsten Hopp 80c26f
!     return NULL;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! typedef struct
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyObject_HEAD
Karsten Hopp 80c26f
!     win_T	*win;
Karsten Hopp 80c26f
! } WindowObject;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #define INVALID_WINDOW_VALUE ((win_T *)(-1))
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
--- 376,1325 ----
Karsten Hopp 80c26f
  	    hashitem_T	*hi;
Karsten Hopp 80c26f
  	    dictitem_T	*di;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! 	    PyDict_SetItemString(lookupDict, ptrBuf, result);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	    for (hi = ht->ht_array; todo > 0; ++hi)
Karsten Hopp 80c26f
! 	    {
Karsten Hopp 80c26f
! 		if (!HASHITEM_EMPTY(hi))
Karsten Hopp 80c26f
! 		{
Karsten Hopp 80c26f
! 		    --todo;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 		    di = dict_lookup(hi);
Karsten Hopp 80c26f
! 		    newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
Karsten Hopp 80c26f
! 		    PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
Karsten Hopp 80c26f
! 		    Py_DECREF(newObj);
Karsten Hopp 80c26f
! 		}
Karsten Hopp 80c26f
! 	    }
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	Py_INCREF(Py_None);
Karsten Hopp 80c26f
! 	result = Py_None;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return result;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! #endif
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
! #ifdef FEAT_EVAL
Karsten Hopp 80c26f
!     char	*expr;
Karsten Hopp 80c26f
!     typval_T	*our_tv;
Karsten Hopp 80c26f
!     PyObject	*result;
Karsten Hopp 80c26f
!     PyObject    *lookup_dict;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (!PyArg_ParseTuple(args, "s", &expr))
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Py_BEGIN_ALLOW_THREADS
Karsten Hopp 80c26f
!     Python_Lock_Vim();
Karsten Hopp 80c26f
!     our_tv = eval_expr((char_u *)expr, NULL);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Python_Release_Vim();
Karsten Hopp 80c26f
!     Py_END_ALLOW_THREADS
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (our_tv == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("invalid expression"));
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     /* Convert the Vim type into a Python type.  Create a dictionary that's
Karsten Hopp 80c26f
!      * used to check for recursive loops. */
Karsten Hopp 80c26f
!     lookup_dict = PyDict_New();
Karsten Hopp 80c26f
!     result = VimToPython(our_tv, 1, lookup_dict);
Karsten Hopp 80c26f
!     Py_DECREF(lookup_dict);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Py_BEGIN_ALLOW_THREADS
Karsten Hopp 80c26f
!     Python_Lock_Vim();
Karsten Hopp 80c26f
!     free_tv(our_tv);
Karsten Hopp 80c26f
!     Python_Release_Vim();
Karsten Hopp 80c26f
!     Py_END_ALLOW_THREADS
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return result;
Karsten Hopp 80c26f
! #else
Karsten Hopp 80c26f
!     PyErr_SetVim(_("expressions disabled at compile time"));
Karsten Hopp 80c26f
!     return NULL;
Karsten Hopp 80c26f
! #endif
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static PyObject *ConvertToPyObject(typval_T *);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! VimEvalPy(PyObject *self UNUSED, PyObject *args UNUSED)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
! #ifdef FEAT_EVAL
Karsten Hopp 80c26f
!     char	*expr;
Karsten Hopp 80c26f
!     typval_T	*our_tv;
Karsten Hopp 80c26f
!     PyObject	*result;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (!PyArg_ParseTuple(args, "s", &expr))
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Py_BEGIN_ALLOW_THREADS
Karsten Hopp 80c26f
!     Python_Lock_Vim();
Karsten Hopp 80c26f
!     our_tv = eval_expr((char_u *)expr, NULL);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Python_Release_Vim();
Karsten Hopp 80c26f
!     Py_END_ALLOW_THREADS
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (our_tv == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("invalid expression"));
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     result = ConvertToPyObject(our_tv);
Karsten Hopp 80c26f
!     Py_BEGIN_ALLOW_THREADS
Karsten Hopp 80c26f
!     Python_Lock_Vim();
Karsten Hopp 80c26f
!     free_tv(our_tv);
Karsten Hopp 80c26f
!     Python_Release_Vim();
Karsten Hopp 80c26f
!     Py_END_ALLOW_THREADS
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return result;
Karsten Hopp 80c26f
! #else
Karsten Hopp 80c26f
!     PyErr_SetVim(_("expressions disabled at compile time"));
Karsten Hopp 80c26f
!     return NULL;
Karsten Hopp 80c26f
! #endif
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! VimStrwidth(PyObject *self UNUSED, PyObject *args)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     char	*expr;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (!PyArg_ParseTuple(args, "s", &expr))
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return PyLong_FromLong(mb_string2cells((char_u *)expr, STRLEN(expr)));
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! /*
Karsten Hopp 80c26f
!  * Vim module - Definitions
Karsten Hopp 80c26f
!  */
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static struct PyMethodDef VimMethods[] = {
Karsten Hopp 80c26f
!     /* name,	     function,		calling,    documentation */
Karsten Hopp 80c26f
!     {"command",	     VimCommand,	1,	    "Execute a Vim ex-mode command" },
Karsten Hopp 80c26f
!     {"eval",	     VimEval,		1,	    "Evaluate an expression using Vim evaluator" },
Karsten Hopp 80c26f
!     {"bindeval",     VimEvalPy,         1,          "Like eval(), but returns objects attached to vim ones"},
Karsten Hopp 80c26f
!     {"strwidth",     VimStrwidth,       1,          "Screen string width, counts <Tab> as having width 1"},
Karsten Hopp 80c26f
!     { NULL,	     NULL,		0,	    NULL }
Karsten Hopp 80c26f
! };
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! typedef struct
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyObject_HEAD
Karsten Hopp 80c26f
!     buf_T *buf;
Karsten Hopp 80c26f
! } BufferObject;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! /*
Karsten Hopp 80c26f
!  * Buffer list object - Implementation
Karsten Hopp 80c26f
!  */
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyInt
Karsten Hopp 80c26f
! BufListLength(PyObject *self UNUSED)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     buf_T	*b = firstbuf;
Karsten Hopp 80c26f
!     PyInt	n = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     while (b)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	++n;
Karsten Hopp 80c26f
! 	b = b->b_next;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return n;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! BufListItem(PyObject *self UNUSED, PyInt n)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     buf_T *b;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     for (b = firstbuf; b; b = b->b_next, --n)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	if (n == 0)
Karsten Hopp 80c26f
! 	    return BufferNew(b);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     PyErr_SetString(PyExc_IndexError, _("no such buffer"));
Karsten Hopp 80c26f
!     return NULL;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! typedef struct
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyObject_HEAD
Karsten Hopp 80c26f
!     win_T	*win;
Karsten Hopp 80c26f
! } WindowObject;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static int ConvertFromPyObject(PyObject *, typval_T *);
Karsten Hopp 80c26f
! static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! typedef struct pylinkedlist_S {
Karsten Hopp 80c26f
!     struct pylinkedlist_S	*pll_next;
Karsten Hopp 80c26f
!     struct pylinkedlist_S	*pll_prev;
Karsten Hopp 80c26f
!     PyObject			*pll_obj;
Karsten Hopp 80c26f
! } pylinkedlist_T;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static pylinkedlist_T *lastdict = NULL;
Karsten Hopp 80c26f
! static pylinkedlist_T *lastlist = NULL;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
! pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     if (ref->pll_prev == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	if (ref->pll_next == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    *last = NULL;
Karsten Hopp 80c26f
! 	    return;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
! 	ref->pll_prev->pll_next = ref->pll_next;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (ref->pll_next == NULL)
Karsten Hopp 80c26f
! 	*last = ref->pll_prev;
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
! 	ref->pll_next->pll_prev = ref->pll_prev;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static void
Karsten Hopp 80c26f
! pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     if (*last == NULL)
Karsten Hopp 80c26f
! 	ref->pll_prev = NULL;
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	(*last)->pll_next = ref;
Karsten Hopp 80c26f
! 	ref->pll_prev = *last;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     ref->pll_next = NULL;
Karsten Hopp 80c26f
!     ref->pll_obj = self;
Karsten Hopp 80c26f
!     *last = ref;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static PyTypeObject DictionaryType;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! typedef struct
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyObject_HEAD
Karsten Hopp 80c26f
!     dict_T	*dict;
Karsten Hopp 80c26f
!     pylinkedlist_T	ref;
Karsten Hopp 80c26f
! } DictionaryObject;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! DictionaryNew(dict_T *dict)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     DictionaryObject	*self;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     self = PyObject_NEW(DictionaryObject, &DictionaryType);
Karsten Hopp 80c26f
!     if (self == NULL)
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     self->dict = dict;
Karsten Hopp 80c26f
!     ++dict->dv_refcount;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     pyll_add((PyObject *)(self), &self->ref, &lastdict);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return (PyObject *)(self);
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     dict_T	*d;
Karsten Hopp 80c26f
!     char_u	*key;
Karsten Hopp 80c26f
!     dictitem_T	*di;
Karsten Hopp 80c26f
!     PyObject	*keyObject;
Karsten Hopp 80c26f
!     PyObject	*valObject;
Karsten Hopp 80c26f
!     Py_ssize_t	iter = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     d = dict_alloc();
Karsten Hopp 80c26f
!     if (d == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_NoMemory();
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     tv->v_type = VAR_DICT;
Karsten Hopp 80c26f
!     tv->vval.v_dict = d;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     while (PyDict_Next(obj, &iter, &keyObject, &valObject))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	DICTKEY_DECL
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (keyObject == NULL)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	if (valObject == NULL)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	DICTKEY_GET(-1)
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	di = dictitem_alloc(key);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	DICTKEY_UNREF
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (di == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_NoMemory();
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	di->di_tv.v_lock = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    vim_free(di);
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	if (dict_add(d, di) == FAIL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    vim_free(di);
Karsten Hopp 80c26f
! 	    PyErr_SetVim(_("failed to add key to dictionary"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     dict_T	*d;
Karsten Hopp 80c26f
!     char_u	*key;
Karsten Hopp 80c26f
!     dictitem_T	*di;
Karsten Hopp 80c26f
!     PyObject	*list;
Karsten Hopp 80c26f
!     PyObject	*litem;
Karsten Hopp 80c26f
!     PyObject	*keyObject;
Karsten Hopp 80c26f
!     PyObject	*valObject;
Karsten Hopp 80c26f
!     Py_ssize_t	lsize;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     d = dict_alloc();
Karsten Hopp 80c26f
!     if (d == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_NoMemory();
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     tv->v_type = VAR_DICT;
Karsten Hopp 80c26f
!     tv->vval.v_dict = d;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     list = PyMapping_Items(obj);
Karsten Hopp 80c26f
!     lsize = PyList_Size(list);
Karsten Hopp 80c26f
!     while (lsize--)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	DICTKEY_DECL
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	litem = PyList_GetItem(list, lsize);
Karsten Hopp 80c26f
! 	if (litem == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	keyObject = PyTuple_GetItem(litem, 0);
Karsten Hopp 80c26f
! 	if (keyObject == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    Py_DECREF(litem);
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	DICTKEY_GET(-1)
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	valObject = PyTuple_GetItem(litem, 1);
Karsten Hopp 80c26f
! 	if (valObject == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    Py_DECREF(litem);
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	di = dictitem_alloc(key);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	DICTKEY_UNREF
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (di == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    Py_DECREF(litem);
Karsten Hopp 80c26f
! 	    PyErr_NoMemory();
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	di->di_tv.v_lock = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    vim_free(di);
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    Py_DECREF(litem);
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	if (dict_add(d, di) == FAIL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    vim_free(di);
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    Py_DECREF(litem);
Karsten Hopp 80c26f
! 	    PyErr_SetVim(_("failed to add key to dictionary"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	Py_DECREF(litem);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     Py_DECREF(list);
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyInt
Karsten Hopp 80c26f
! DictionaryLength(PyObject *self)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     return ((PyInt) ((((DictionaryObject *)(self))->dict->dv_hashtab.ht_used)));
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! DictionaryItem(PyObject *self, PyObject *keyObject)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     char_u	*key;
Karsten Hopp 80c26f
!     dictitem_T	*val;
Karsten Hopp 80c26f
!     DICTKEY_DECL
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     DICTKEY_GET(NULL)
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     val = dict_find(((DictionaryObject *) (self))->dict, key, -1);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     DICTKEY_UNREF
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return ConvertToPyObject(&val->di_tv);
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyInt
Karsten Hopp 80c26f
! DictionaryAssItem(PyObject *self, PyObject *keyObject, PyObject *valObject)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     char_u	*key;
Karsten Hopp 80c26f
!     typval_T	tv;
Karsten Hopp 80c26f
!     dict_T	*d = ((DictionaryObject *)(self))->dict;
Karsten Hopp 80c26f
!     dictitem_T	*di;
Karsten Hopp 80c26f
!     DICTKEY_DECL
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (d->dv_lock)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("dict is locked"));
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     DICTKEY_GET(-1)
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     di = dict_find(d, key, -1);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (valObject == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	if (di == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	hashitem_T	*hi = hash_find(&d->dv_hashtab, di->di_key);
Karsten Hopp 80c26f
! 	hash_remove(&d->dv_hashtab, hi);
Karsten Hopp 80c26f
! 	dictitem_free(di);
Karsten Hopp 80c26f
! 	return 0;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (ConvertFromPyObject(valObject, &tv) == -1)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (di == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	di = dictitem_alloc(key);
Karsten Hopp 80c26f
! 	if (di == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_NoMemory();
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	di->di_tv.v_lock = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (dict_add(d, di) == FAIL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    vim_free(di);
Karsten Hopp 80c26f
! 	    PyErr_SetVim(_("failed to add key to dictionary"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
! 	clear_tv(&di->di_tv);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     DICTKEY_UNREF
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     copy_tv(&tv, &di->di_tv);
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! DictionaryListKeys(PyObject *self)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     dict_T	*dict = ((DictionaryObject *)(self))->dict;
Karsten Hopp 80c26f
!     long_u	todo = dict->dv_hashtab.ht_used;
Karsten Hopp 80c26f
!     Py_ssize_t	i = 0;
Karsten Hopp 80c26f
!     PyObject	*r;
Karsten Hopp 80c26f
!     hashitem_T	*hi;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     r = PyList_New(todo);
Karsten Hopp 80c26f
!     for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	if (!HASHITEM_EMPTY(hi))
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyList_SetItem(r, i, PyBytes_FromString((char *)(hi->hi_key)));
Karsten Hopp 80c26f
! 	    --todo;
Karsten Hopp 80c26f
! 	    ++i;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     return r;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static struct PyMethodDef DictionaryMethods[] = {
Karsten Hopp 80c26f
!     {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
Karsten Hopp 80c26f
!     { NULL,	    NULL,		0,	    NULL }
Karsten Hopp 80c26f
! };
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! static PyTypeObject ListType;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! typedef struct
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyObject_HEAD
Karsten Hopp 80c26f
!     list_T	*list;
Karsten Hopp 80c26f
!     pylinkedlist_T	ref;
Karsten Hopp 80c26f
! } ListObject;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! ListNew(list_T *list)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     ListObject	*self;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     self = PyObject_NEW(ListObject, &ListType);
Karsten Hopp 80c26f
!     if (self == NULL)
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     self->list = list;
Karsten Hopp 80c26f
!     ++list->lv_refcount;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     pyll_add((PyObject *)(self), &self->ref, &lastlist);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return (PyObject *)(self);
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     Py_ssize_t	i;
Karsten Hopp 80c26f
!     Py_ssize_t	lsize = PySequence_Size(obj);
Karsten Hopp 80c26f
!     PyObject	*litem;
Karsten Hopp 80c26f
!     listitem_T	*li;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     for(i=0; i
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	li = listitem_alloc();
Karsten Hopp 80c26f
! 	if (li == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_NoMemory();
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	li->li_tv.v_lock = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	litem = PySequence_GetItem(obj, i);
Karsten Hopp 80c26f
! 	if (litem == NULL)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	if (_ConvertFromPyObject(litem, &li->li_tv, lookupDict) == -1)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	list_append(l, li);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     list_T	*l;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     l = list_alloc();
Karsten Hopp 80c26f
!     if (l == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_NoMemory();
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     tv->v_type = VAR_LIST;
Karsten Hopp 80c26f
!     tv->vval.v_list = l;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (list_py_concat(l, obj, lookupDict) == -1)
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyObject	*iterator = PyObject_GetIter(obj);
Karsten Hopp 80c26f
!     PyObject	*item;
Karsten Hopp 80c26f
!     list_T	*l;
Karsten Hopp 80c26f
!     listitem_T	*li;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     l = list_alloc();
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (l == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_NoMemory();
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     tv->vval.v_list = l;
Karsten Hopp 80c26f
!     tv->v_type = VAR_LIST;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (iterator == NULL)
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     while ((item = PyIter_Next(obj)))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	li = listitem_alloc();
Karsten Hopp 80c26f
! 	if (li == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_NoMemory();
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	li->li_tv.v_lock = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if (_ConvertFromPyObject(item, &li->li_tv, lookupDict) == -1)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	list_append(l, li);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	Py_DECREF(item);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     Py_DECREF(iterator);
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyInt
Karsten Hopp 80c26f
! ListLength(PyObject *self)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     return ((PyInt) (((ListObject *) (self))->list->lv_len));
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! ListItem(PyObject *self, Py_ssize_t index)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     listitem_T	*li;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (index>=ListLength(self))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetString(PyExc_IndexError, "list index out of range");
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     li = list_find(((ListObject *) (self))->list, (long) index);
Karsten Hopp 80c26f
!     if (li == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("internal error: failed to get vim list item"));
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     return ConvertToPyObject(&li->li_tv);
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! #define PROC_RANGE \
Karsten Hopp 80c26f
!     if (last < 0) {\
Karsten Hopp 80c26f
! 	if (last < -size) \
Karsten Hopp 80c26f
! 	    last = 0; \
Karsten Hopp 80c26f
! 	else \
Karsten Hopp 80c26f
! 	    last += size; \
Karsten Hopp 80c26f
!     } \
Karsten Hopp 80c26f
!     if (first < 0) \
Karsten Hopp 80c26f
! 	first = 0; \
Karsten Hopp 80c26f
!     if (first > size) \
Karsten Hopp 80c26f
! 	first = size; \
Karsten Hopp 80c26f
!     if (last > size) \
Karsten Hopp 80c26f
! 	last = size;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! ListSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyInt	i;
Karsten Hopp 80c26f
!     PyInt	size = ListLength(self);
Karsten Hopp 80c26f
!     PyInt	n;
Karsten Hopp 80c26f
!     PyObject	*list;
Karsten Hopp 80c26f
!     int		reversed = 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     PROC_RANGE
Karsten Hopp 80c26f
!     if (first >= last)
Karsten Hopp 80c26f
! 	first = last;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     n = last-first;
Karsten Hopp 80c26f
!     list = PyList_New(n);
Karsten Hopp 80c26f
!     if (list == NULL)
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     for (i = 0; i < n; ++i)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyObject	*item = ListItem(self, i);
Karsten Hopp 80c26f
! 	if (item == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    return NULL;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	if ((PyList_SetItem(list, ((reversed)?(n-i-1):(i)), item)))
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    Py_DECREF(item);
Karsten Hopp 80c26f
! 	    Py_DECREF(list);
Karsten Hopp 80c26f
! 	    return NULL;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return list;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! ListAssItem(PyObject *self, Py_ssize_t index, PyObject *obj)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     typval_T	tv;
Karsten Hopp 80c26f
!     list_T	*l = ((ListObject *) (self))->list;
Karsten Hopp 80c26f
!     listitem_T	*li;
Karsten Hopp 80c26f
!     Py_ssize_t	length = ListLength(self);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (l->lv_lock)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("list is locked"));
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     if (index>length || (index==length && obj==NULL))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetString(PyExc_IndexError, "list index out of range");
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (obj == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	li = list_find(l, (long) index);
Karsten Hopp 80c26f
! 	list_remove(l, li, li);
Karsten Hopp 80c26f
! 	clear_tv(&li->li_tv);
Karsten Hopp 80c26f
! 	vim_free(li);
Karsten Hopp 80c26f
! 	return 0;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (ConvertFromPyObject(obj, &tv) == -1)
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (index == length)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	if (list_append_tv(l, &tv) == FAIL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_SetVim(_("Failed to add item to list"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	li = list_find(l, (long) index);
Karsten Hopp 80c26f
! 	clear_tv(&li->li_tv);
Karsten Hopp 80c26f
! 	copy_tv(&tv, &li->li_tv);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
! }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     static int
Karsten Hopp 80c26f
! ListAssSlice(PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
Karsten Hopp 80c26f
! {
Karsten Hopp 80c26f
!     PyInt	size = ListLength(self);
Karsten Hopp 80c26f
!     Py_ssize_t	i;
Karsten Hopp 80c26f
!     Py_ssize_t	lsize;
Karsten Hopp 80c26f
!     PyObject	*litem;
Karsten Hopp 80c26f
!     listitem_T	*li;
Karsten Hopp 80c26f
!     listitem_T	*next;
Karsten Hopp 80c26f
!     typval_T	v;
Karsten Hopp 80c26f
!     list_T	*l = ((ListObject *) (self))->list;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (l->lv_lock)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("list is locked"));
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     PROC_RANGE
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (first == size)
Karsten Hopp 80c26f
! 	li = NULL;
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	li = list_find(l, (long) first);
Karsten Hopp 80c26f
! 	if (li == NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_SetVim(_("internal error: no vim list item"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	if (last > first)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    i = last - first;
Karsten Hopp 80c26f
! 	    while (i-- && li != NULL)
Karsten Hopp 80c26f
  	    {
Karsten Hopp 80c26f
! 		next = li->li_next;
Karsten Hopp 80c26f
! 		listitem_remove(l, li);
Karsten Hopp 80c26f
! 		li = next;
Karsten Hopp 80c26f
  	    }
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (obj == NULL)
Karsten Hopp 80c26f
! 	return 0;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (!PyList_Check(obj))
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	PyErr_SetString(PyExc_TypeError, _("can only assign lists to slice"));
Karsten Hopp 80c26f
! 	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     lsize = PyList_Size(obj);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     for(i=0; i
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	litem = PyList_GetItem(obj, i);
Karsten Hopp 80c26f
! 	if (litem == NULL)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	if (ConvertFromPyObject(litem, &v) == -1)
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	if (list_insert_tv(l, &v, li) == FAIL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    PyErr_SetVim(_("internal error: failed to add item to list"));
Karsten Hopp 80c26f
! 	    return -1;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     return 0;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
! ListConcatInPlace(PyObject *self, PyObject *obj)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     list_T	*l = ((ListObject *) (self))->list;
Karsten Hopp 80c26f
!     PyObject	*lookup_dict;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (l->lv_lock)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("list is locked"));
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (!PySequence_Check(obj))
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	PyErr_SetString(PyExc_TypeError, _("can only concatenate with lists"));
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      lookup_dict = PyDict_New();
Karsten Hopp 80c26f
!     if (list_py_concat(l, obj, lookup_dict) == -1)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	Py_DECREF(lookup_dict);
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
      Py_DECREF(lookup_dict);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     Py_INCREF(self);
Karsten Hopp 80c26f
!     return self;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! static struct PyMethodDef ListMethods[] = {
Karsten Hopp 80c26f
!     {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
Karsten Hopp 80c26f
!     { NULL,	    NULL,		0,	    NULL }
Karsten Hopp 80c26f
  };
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  typedef struct
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
      PyObject_HEAD
Karsten Hopp 80c26f
!     char_u	*name;
Karsten Hopp 80c26f
! } FunctionObject;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! static PyTypeObject FunctionType;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     static PyObject *
Karsten Hopp 80c26f
! FunctionNew(char_u *name)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     FunctionObject	*self;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     self = PyObject_NEW(FunctionObject, &FunctionType);
Karsten Hopp 80c26f
!     if (self == NULL)
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
!     self->name = PyMem_New(char_u, STRLEN(name) + 1);
Karsten Hopp 80c26f
!     if (self->name == NULL)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	PyErr_NoMemory();
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
!     STRCPY(self->name, name);
Karsten Hopp 80c26f
!     func_ref(name);
Karsten Hopp 80c26f
!     return (PyObject *)(self);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
! FunctionCall(PyObject *self, PyObject *argsObject, PyObject *kwargs)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     FunctionObject	*this = (FunctionObject *)(self);
Karsten Hopp 80c26f
!     char_u	*name = this->name;
Karsten Hopp 80c26f
!     typval_T	args;
Karsten Hopp 80c26f
!     typval_T	selfdicttv;
Karsten Hopp 80c26f
!     typval_T	rettv;
Karsten Hopp 80c26f
!     dict_T	*selfdict = NULL;
Karsten Hopp 80c26f
!     PyObject	*selfdictObject;
Karsten Hopp 80c26f
!     PyObject	*result;
Karsten Hopp 80c26f
!     int		error;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (ConvertFromPyObject(argsObject, &args) == -1)
Karsten Hopp 80c26f
! 	return NULL;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     if (kwargs != NULL)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	selfdictObject = PyDict_GetItemString(kwargs, "self");
Karsten Hopp 80c26f
! 	if (selfdictObject != NULL)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    if (!PyDict_Check(selfdictObject))
Karsten Hopp 80c26f
! 	    {
Karsten Hopp 80c26f
! 		PyErr_SetString(PyExc_TypeError, _("'self' argument must be a dictionary"));
Karsten Hopp 80c26f
! 		clear_tv(&args);
Karsten Hopp 80c26f
! 		return NULL;
Karsten Hopp 80c26f
! 	    }
Karsten Hopp 80c26f
! 	    if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
Karsten Hopp 80c26f
! 		return NULL;
Karsten Hopp 80c26f
! 	    selfdict = selfdicttv.vval.v_dict;
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     error = func_call(name, &args, selfdict, &rettv);
Karsten Hopp 80c26f
!     if (error != OK)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	result = NULL;
Karsten Hopp 80c26f
! 	PyErr_SetVim(_("failed to run function"));
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
! 	result = ConvertToPyObject(&rettv);
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     /* FIXME Check what should really be cleared. */
Karsten Hopp 80c26f
!     clear_tv(&args);
Karsten Hopp 80c26f
!     clear_tv(&rettv);
Karsten Hopp 80c26f
!     /*
Karsten Hopp 80c26f
!      * if (selfdict!=NULL)
Karsten Hopp 80c26f
!      *     clear_tv(selfdicttv);
Karsten Hopp 80c26f
!      */
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
!     return result;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
! static struct PyMethodDef FunctionMethods[] = {
Karsten Hopp 80c26f
!     {"__call__",    (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
Karsten Hopp 80c26f
!     { NULL,	    NULL,		0,	    NULL }
Karsten Hopp 80c26f
! };
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #define INVALID_WINDOW_VALUE ((win_T *)(-1))
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1567,1569 ****
Karsten Hopp 80c26f
--- 2383,2638 ----
Karsten Hopp 80c26f
      { NULL,	    NULL,		0,	    NULL }
Karsten Hopp 80c26f
  };
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ set_ref_in_py(const int copyID)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     pylinkedlist_T	*cur;
Karsten Hopp 80c26f
+     dict_T	*dd;
Karsten Hopp 80c26f
+     list_T	*ll;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     if (lastdict != NULL)
Karsten Hopp 80c26f
+ 	for(cur = lastdict ; cur != NULL ; cur = cur->pll_prev)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    dd = ((DictionaryObject *) (cur->pll_obj))->dict;
Karsten Hopp 80c26f
+ 	    if (dd->dv_copyID != copyID)
Karsten Hopp 80c26f
+ 	    {
Karsten Hopp 80c26f
+ 		dd->dv_copyID = copyID;
Karsten Hopp 80c26f
+ 		set_ref_in_ht(&dd->dv_hashtab, copyID);
Karsten Hopp 80c26f
+ 	    }
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     if (lastlist != NULL)
Karsten Hopp 80c26f
+ 	for(cur = lastlist ; cur != NULL ; cur = cur->pll_prev)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    ll = ((ListObject *) (cur->pll_obj))->list;
Karsten Hopp 80c26f
+ 	    if (ll->lv_copyID != copyID)
Karsten Hopp 80c26f
+ 	    {
Karsten Hopp 80c26f
+ 		ll->lv_copyID = copyID;
Karsten Hopp 80c26f
+ 		set_ref_in_list(ll, copyID);
Karsten Hopp 80c26f
+ 	    }
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static int
Karsten Hopp 80c26f
+ set_string_copy(char_u *str, typval_T *tv)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     tv->vval.v_string = vim_strsave(str);
Karsten Hopp 80c26f
+     if (tv->vval.v_string == NULL)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyErr_NoMemory();
Karsten Hopp 80c26f
+ 	return -1;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     return 0;
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ #ifdef FEAT_EVAL
Karsten Hopp 80c26f
+ typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static int
Karsten Hopp 80c26f
+ convert_dl(PyObject *obj, typval_T *tv,
Karsten Hopp 80c26f
+ 				    pytotvfunc py_to_tv, PyObject *lookupDict)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     PyObject	*capsule;
Karsten Hopp 80c26f
+     char	hexBuf[sizeof(void *) * 2 + 3];
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     sprintf(hexBuf, "%p", obj);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     capsule = PyDict_GetItemString(lookupDict, hexBuf);
Karsten Hopp 80c26f
+     if (capsule == NULL)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	capsule = PyCapsule_New(tv, NULL, NULL);
Karsten Hopp 80c26f
+ 	PyDict_SetItemString(lookupDict, hexBuf, capsule);
Karsten Hopp 80c26f
+ 	Py_DECREF(capsule);
Karsten Hopp 80c26f
+ 	if (py_to_tv(obj, tv, lookupDict) == -1)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    tv->v_type = VAR_UNKNOWN;
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+ 	/* As we are not using copy_tv which increments reference count we must
Karsten Hopp 80c26f
+ 	 * do it ourself. */
Karsten Hopp 80c26f
+ 	switch(tv->v_type)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    case VAR_DICT: ++tv->vval.v_dict->dv_refcount; break;
Karsten Hopp 80c26f
+ 	    case VAR_LIST: ++tv->vval.v_list->lv_refcount; break;
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	typval_T	*v = PyCapsule_GetPointer(capsule, NULL);
Karsten Hopp 80c26f
+ 	copy_tv(v, tv);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     return 0;
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static int
Karsten Hopp 80c26f
+ ConvertFromPyObject(PyObject *obj, typval_T *tv)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     PyObject	*lookup_dict;
Karsten Hopp 80c26f
+     int		r;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     lookup_dict = PyDict_New();
Karsten Hopp 80c26f
+     r = _ConvertFromPyObject(obj, tv, lookup_dict);
Karsten Hopp 80c26f
+     Py_DECREF(lookup_dict);
Karsten Hopp 80c26f
+     return r;
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static int
Karsten Hopp 80c26f
+ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     if (obj->ob_type == &DictionaryType)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_DICT;
Karsten Hopp 80c26f
+ 	tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
Karsten Hopp 80c26f
+ 	++tv->vval.v_dict->dv_refcount;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (obj->ob_type == &ListType)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_LIST;
Karsten Hopp 80c26f
+ 	tv->vval.v_list = (((ListObject *)(obj))->list);
Karsten Hopp 80c26f
+ 	++tv->vval.v_list->lv_refcount;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (obj->ob_type == &FunctionType)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	if (set_string_copy(((FunctionObject *) (obj))->name, tv) == -1)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_FUNC;
Karsten Hopp 80c26f
+ 	func_ref(tv->vval.v_string);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ #if PY_MAJOR_VERSION >= 3
Karsten Hopp 80c26f
+     else if (PyBytes_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	char_u	*result = (char_u *) PyBytes_AsString(obj);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (result == NULL)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (set_string_copy(result, tv) == -1)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_STRING;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (PyUnicode_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyObject	*bytes;
Karsten Hopp 80c26f
+ 	char_u	*result;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	bytes = PyString_AsBytes(obj);
Karsten Hopp 80c26f
+ 	if (bytes == NULL)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	result = (char_u *) PyBytes_AsString(bytes);
Karsten Hopp 80c26f
+ 	if (result == NULL)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (set_string_copy(result, tv) == -1)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    Py_XDECREF(bytes);
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+ 	Py_XDECREF(bytes);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_STRING;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ #else
Karsten Hopp 80c26f
+     else if (PyUnicode_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyObject	*bytes;
Karsten Hopp 80c26f
+ 	char_u	*result;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
Karsten Hopp 80c26f
+ 	if (bytes == NULL)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	result=(char_u *) PyString_AsString(bytes);
Karsten Hopp 80c26f
+ 	if (result == NULL)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (set_string_copy(result, tv) == -1)
Karsten Hopp 80c26f
+ 	{
Karsten Hopp 80c26f
+ 	    Py_XDECREF(bytes);
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 	}
Karsten Hopp 80c26f
+ 	Py_XDECREF(bytes);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_STRING;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (PyString_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	char_u	*result = (char_u *) PyString_AsString(obj);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (result == NULL)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (set_string_copy(result, tv) == -1)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_STRING;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (PyInt_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_NUMBER;
Karsten Hopp 80c26f
+ 	tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+     else if (PyLong_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_NUMBER;
Karsten Hopp 80c26f
+ 	tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (PyDict_Check(obj))
Karsten Hopp 80c26f
+ 	return convert_dl(obj, tv, pydict_to_tv, lookupDict);
Karsten Hopp 80c26f
+ #ifdef FEAT_FLOAT
Karsten Hopp 80c26f
+     else if (PyFloat_Check(obj))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	tv->v_type = VAR_FLOAT;
Karsten Hopp 80c26f
+ 	tv->vval.v_float = (float_T) PyFloat_AsDouble(obj);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+     else if (PyIter_Check(obj))
Karsten Hopp 80c26f
+ 	return convert_dl(obj, tv, pyiter_to_tv, lookupDict);
Karsten Hopp 80c26f
+     else if (PySequence_Check(obj))
Karsten Hopp 80c26f
+ 	return convert_dl(obj, tv, pyseq_to_tv, lookupDict);
Karsten Hopp 80c26f
+     else if (PyMapping_Check(obj))
Karsten Hopp 80c26f
+ 	return convert_dl(obj, tv, pymap_to_tv, lookupDict);
Karsten Hopp 80c26f
+     else
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyErr_SetString(PyExc_TypeError, _("unable to convert to vim structure"));
Karsten Hopp 80c26f
+ 	return -1;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     return 0;
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static PyObject *
Karsten Hopp 80c26f
+ ConvertToPyObject(typval_T *tv)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     if (tv == NULL)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyErr_SetVim(_("NULL reference passed"));
Karsten Hopp 80c26f
+ 	return NULL;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     switch (tv->v_type)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	case VAR_STRING:
Karsten Hopp 80c26f
+ 	    return PyBytes_FromString((char *) tv->vval.v_string);
Karsten Hopp 80c26f
+ 	case VAR_NUMBER:
Karsten Hopp 80c26f
+ 	    return PyLong_FromLong((long) tv->vval.v_number);
Karsten Hopp 80c26f
+ #ifdef FEAT_FLOAT
Karsten Hopp 80c26f
+ 	case VAR_FLOAT:
Karsten Hopp 80c26f
+ 	    return PyFloat_FromDouble((double) tv->vval.v_float);
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ 	case VAR_LIST:
Karsten Hopp 80c26f
+ 	    return ListNew(tv->vval.v_list);
Karsten Hopp 80c26f
+ 	case VAR_DICT:
Karsten Hopp 80c26f
+ 	    return DictionaryNew(tv->vval.v_dict);
Karsten Hopp 80c26f
+ 	case VAR_FUNC:
Karsten Hopp 80c26f
+ 	    return FunctionNew(tv->vval.v_string);
Karsten Hopp 80c26f
+ 	case VAR_UNKNOWN:
Karsten Hopp 80c26f
+ 	    Py_INCREF(Py_None);
Karsten Hopp 80c26f
+ 	    return Py_None;
Karsten Hopp 80c26f
+ 	default:
Karsten Hopp 80c26f
+ 	    PyErr_SetVim(_("internal error: invalid value type"));
Karsten Hopp 80c26f
+ 	    return NULL;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/if_python.c	2011-08-28 16:00:14.000000000 +0200
Karsten Hopp 80c26f
--- src/if_python.c	2012-06-29 12:47:48.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1,4 ****
Karsten Hopp 80c26f
! /* vi:set ts=8 sts=4 sw=4:
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
   * VIM - Vi IMproved	by Bram Moolenaar
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
--- 1,4 ----
Karsten Hopp 80c26f
! /* vi:set ts=8 sts=4 sw=4 noet:
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
   * VIM - Vi IMproved	by Bram Moolenaar
Karsten Hopp 80c26f
   *
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 56,61 ****
Karsten Hopp 80c26f
--- 56,63 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  static void init_structs(void);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ #define PyBytes_FromString PyString_FromString
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /* No-op conversion functions, use with care! */
Karsten Hopp 80c26f
  #define PyString_AsBytes(obj) (obj)
Karsten Hopp 80c26f
  #define PyString_FreeBytes(obj)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 122,132 ****
Karsten Hopp 80c26f
--- 124,136 ----
Karsten Hopp 80c26f
  /* This makes if_python.c compile without warnings against Python 2.5
Karsten Hopp 80c26f
   * on Win32 and Win64. */
Karsten Hopp 80c26f
  # undef PyRun_SimpleString
Karsten Hopp 80c26f
+ # undef PyRun_String
Karsten Hopp 80c26f
  # undef PyArg_Parse
Karsten Hopp 80c26f
  # undef PyArg_ParseTuple
Karsten Hopp 80c26f
  # undef Py_BuildValue
Karsten Hopp 80c26f
  # undef Py_InitModule4
Karsten Hopp 80c26f
  # undef Py_InitModule4_64
Karsten Hopp 80c26f
+ # undef PyObject_CallMethod
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Wrapper defines
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 134,139 ****
Karsten Hopp 80c26f
--- 138,144 ----
Karsten Hopp 80c26f
  # define PyArg_Parse dll_PyArg_Parse
Karsten Hopp 80c26f
  # define PyArg_ParseTuple dll_PyArg_ParseTuple
Karsten Hopp 80c26f
  # define PyMem_Free dll_PyMem_Free
Karsten Hopp 80c26f
+ # define PyMem_Malloc dll_PyMem_Malloc
Karsten Hopp 80c26f
  # define PyDict_SetItemString dll_PyDict_SetItemString
Karsten Hopp 80c26f
  # define PyErr_BadArgument dll_PyErr_BadArgument
Karsten Hopp 80c26f
  # define PyErr_Clear dll_PyErr_Clear
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 150,172 ****
Karsten Hopp 80c26f
--- 155,202 ----
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
  # define PyInt_AsLong dll_PyInt_AsLong
Karsten Hopp 80c26f
  # define PyInt_FromLong dll_PyInt_FromLong
Karsten Hopp 80c26f
+ # define PyLong_AsLong dll_PyLong_AsLong
Karsten Hopp 80c26f
+ # define PyLong_FromLong dll_PyLong_FromLong
Karsten Hopp 80c26f
  # define PyInt_Type (*dll_PyInt_Type)
Karsten Hopp 80c26f
+ # define PyLong_Type (*dll_PyLong_Type)
Karsten Hopp 80c26f
  # define PyList_GetItem dll_PyList_GetItem
Karsten Hopp 80c26f
  # define PyList_Append dll_PyList_Append
Karsten Hopp 80c26f
  # define PyList_New dll_PyList_New
Karsten Hopp 80c26f
  # define PyList_SetItem dll_PyList_SetItem
Karsten Hopp 80c26f
  # define PyList_Size dll_PyList_Size
Karsten Hopp 80c26f
  # define PyList_Type (*dll_PyList_Type)
Karsten Hopp 80c26f
+ # define PySequence_Check dll_PySequence_Check
Karsten Hopp 80c26f
+ # define PySequence_Size dll_PySequence_Size
Karsten Hopp 80c26f
+ # define PySequence_GetItem dll_PySequence_GetItem
Karsten Hopp 80c26f
+ # define PyTuple_Size dll_PyTuple_Size
Karsten Hopp 80c26f
+ # define PyTuple_GetItem dll_PyTuple_GetItem
Karsten Hopp 80c26f
+ # define PyTuple_Type (*dll_PyTuple_Type)
Karsten Hopp 80c26f
  # define PyImport_ImportModule dll_PyImport_ImportModule
Karsten Hopp 80c26f
  # define PyDict_New dll_PyDict_New
Karsten Hopp 80c26f
  # define PyDict_GetItemString dll_PyDict_GetItemString
Karsten Hopp 80c26f
+ # define PyDict_Next dll_PyDict_Next
Karsten Hopp 80c26f
+ # ifdef PyMapping_Items
Karsten Hopp 80c26f
+ #  define PY_NO_MAPPING_ITEMS
Karsten Hopp 80c26f
+ # else
Karsten Hopp 80c26f
+ #  define PyMapping_Items dll_PyMapping_Items
Karsten Hopp 80c26f
+ # endif
Karsten Hopp 80c26f
+ # define PyObject_CallMethod dll_PyObject_CallMethod
Karsten Hopp 80c26f
+ # define PyMapping_Check dll_PyMapping_Check
Karsten Hopp 80c26f
+ # define PyIter_Next dll_PyIter_Next
Karsten Hopp 80c26f
  # define PyModule_GetDict dll_PyModule_GetDict
Karsten Hopp 80c26f
  # define PyRun_SimpleString dll_PyRun_SimpleString
Karsten Hopp 80c26f
+ # define PyRun_String dll_PyRun_String
Karsten Hopp 80c26f
  # define PyString_AsString dll_PyString_AsString
Karsten Hopp 80c26f
  # define PyString_FromString dll_PyString_FromString
Karsten Hopp 80c26f
  # define PyString_FromStringAndSize dll_PyString_FromStringAndSize
Karsten Hopp 80c26f
  # define PyString_Size dll_PyString_Size
Karsten Hopp 80c26f
  # define PyString_Type (*dll_PyString_Type)
Karsten Hopp 80c26f
+ # define PyUnicode_Type (*dll_PyUnicode_Type)
Karsten Hopp 80c26f
+ # define PyUnicodeUCS4_AsEncodedString (*dll_PyUnicodeUCS4_AsEncodedString)
Karsten Hopp 80c26f
+ # define PyFloat_AsDouble dll_PyFloat_AsDouble
Karsten Hopp 80c26f
+ # define PyFloat_FromDouble dll_PyFloat_FromDouble
Karsten Hopp 80c26f
+ # define PyFloat_Type (*dll_PyFloat_Type)
Karsten Hopp 80c26f
+ # define PyImport_AddModule (*dll_PyImport_AddModule)
Karsten Hopp 80c26f
  # define PySys_SetObject dll_PySys_SetObject
Karsten Hopp 80c26f
  # define PySys_SetArgv dll_PySys_SetArgv
Karsten Hopp 80c26f
  # define PyType_Type (*dll_PyType_Type)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 179,186 ****
Karsten Hopp 80c26f
--- 209,218 ----
Karsten Hopp 80c26f
  # define Py_Finalize dll_Py_Finalize
Karsten Hopp 80c26f
  # define Py_IsInitialized dll_Py_IsInitialized
Karsten Hopp 80c26f
  # define _PyObject_New dll__PyObject_New
Karsten Hopp 80c26f
+ # define _PyObject_NextNotImplemented (*dll__PyObject_NextNotImplemented)
Karsten Hopp 80c26f
  # define _Py_NoneStruct (*dll__Py_NoneStruct)
Karsten Hopp 80c26f
  # define PyObject_Init dll__PyObject_Init
Karsten Hopp 80c26f
+ # define PyObject_GetIter dll_PyObject_GetIter
Karsten Hopp 80c26f
  # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
Karsten Hopp 80c26f
  #  define PyType_IsSubtype dll_PyType_IsSubtype
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 188,193 ****
Karsten Hopp 80c26f
--- 220,227 ----
Karsten Hopp 80c26f
  #  define PyObject_Malloc dll_PyObject_Malloc
Karsten Hopp 80c26f
  #  define PyObject_Free dll_PyObject_Free
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
+ # define PyCapsule_New dll_PyCapsule_New
Karsten Hopp 80c26f
+ # define PyCapsule_GetPointer dll_PyCapsule_GetPointer
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Pointers for dynamic link
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 195,200 ****
Karsten Hopp 80c26f
--- 229,235 ----
Karsten Hopp 80c26f
  static int(*dll_PyArg_Parse)(PyObject *, char *, ...);
Karsten Hopp 80c26f
  static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...);
Karsten Hopp 80c26f
  static int(*dll_PyMem_Free)(void *);
Karsten Hopp 80c26f
+ static void* (*dll_PyMem_Malloc)(size_t);
Karsten Hopp 80c26f
  static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
Karsten Hopp 80c26f
  static int(*dll_PyErr_BadArgument)(void);
Karsten Hopp 80c26f
  static void(*dll_PyErr_Clear)(void);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 208,233 ****
Karsten Hopp 80c26f
  # ifdef PY_CAN_RECURSE
Karsten Hopp 80c26f
  static PyGILState_STATE	(*dll_PyGILState_Ensure)(void);
Karsten Hopp 80c26f
  static void (*dll_PyGILState_Release)(PyGILState_STATE);
Karsten Hopp 80c26f
! #endif
Karsten Hopp 80c26f
  static long(*dll_PyInt_AsLong)(PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyInt_FromLong)(long);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyInt_Type;
Karsten Hopp 80c26f
  static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyList_New)(PyInt size);
Karsten Hopp 80c26f
  static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *);
Karsten Hopp 80c26f
  static PyInt(*dll_PyList_Size)(PyObject *);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyList_Type;
Karsten Hopp 80c26f
  static PyObject*(*dll_PyImport_ImportModule)(const char *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyDict_New)(void);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyModule_GetDict)(PyObject *);
Karsten Hopp 80c26f
  static int(*dll_PyRun_SimpleString)(char *);
Karsten Hopp 80c26f
  static char*(*dll_PyString_AsString)(PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyString_FromString)(const char *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
Karsten Hopp 80c26f
  static PyInt(*dll_PyString_Size)(PyObject *);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyString_Type;
Karsten Hopp 80c26f
  static int(*dll_PySys_SetObject)(char *, PyObject *);
Karsten Hopp 80c26f
  static int(*dll_PySys_SetArgv)(int, char **);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyType_Type;
Karsten Hopp 80c26f
--- 243,290 ----
Karsten Hopp 80c26f
  # ifdef PY_CAN_RECURSE
Karsten Hopp 80c26f
  static PyGILState_STATE	(*dll_PyGILState_Ensure)(void);
Karsten Hopp 80c26f
  static void (*dll_PyGILState_Release)(PyGILState_STATE);
Karsten Hopp 80c26f
! # endif
Karsten Hopp 80c26f
  static long(*dll_PyInt_AsLong)(PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyInt_FromLong)(long);
Karsten Hopp 80c26f
+ static long(*dll_PyLong_AsLong)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject*(*dll_PyLong_FromLong)(long);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyInt_Type;
Karsten Hopp 80c26f
+ static PyTypeObject* dll_PyLong_Type;
Karsten Hopp 80c26f
  static PyObject*(*dll_PyList_GetItem)(PyObject *, PyInt);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyList_Append)(PyObject *, PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyList_New)(PyInt size);
Karsten Hopp 80c26f
  static int(*dll_PyList_SetItem)(PyObject *, PyInt, PyObject *);
Karsten Hopp 80c26f
  static PyInt(*dll_PyList_Size)(PyObject *);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyList_Type;
Karsten Hopp 80c26f
+ static int (*dll_PySequence_Check)(PyObject *);
Karsten Hopp 80c26f
+ static PyInt(*dll_PySequence_Size)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject*(*dll_PySequence_GetItem)(PyObject *, PyInt);
Karsten Hopp 80c26f
+ static PyInt(*dll_PyTuple_Size)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject*(*dll_PyTuple_GetItem)(PyObject *, PyInt);
Karsten Hopp 80c26f
+ static PyTypeObject* dll_PyTuple_Type;
Karsten Hopp 80c26f
  static PyObject*(*dll_PyImport_ImportModule)(const char *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyDict_New)(void);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyDict_GetItemString)(PyObject *, const char *);
Karsten Hopp 80c26f
+ static int (*dll_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **);
Karsten Hopp 80c26f
+ # ifndef PY_NO_MAPPING_ITEMS
Karsten Hopp 80c26f
+ static PyObject* (*dll_PyMapping_Items)(PyObject *);
Karsten Hopp 80c26f
+ # endif
Karsten Hopp 80c26f
+ static PyObject* (*dll_PyObject_CallMethod)(PyObject *, char *, PyObject *);
Karsten Hopp 80c26f
+ static int (*dll_PyMapping_Check)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject* (*dll_PyIter_Next)(PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyModule_GetDict)(PyObject *);
Karsten Hopp 80c26f
  static int(*dll_PyRun_SimpleString)(char *);
Karsten Hopp 80c26f
+ static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *);
Karsten Hopp 80c26f
  static char*(*dll_PyString_AsString)(PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyString_FromString)(const char *);
Karsten Hopp 80c26f
  static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
Karsten Hopp 80c26f
  static PyInt(*dll_PyString_Size)(PyObject *);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyString_Type;
Karsten Hopp 80c26f
+ static PyTypeObject* dll_PyUnicode_Type;
Karsten Hopp 80c26f
+ static PyObject *(*PyUnicodeUCS4_AsEncodedString)(PyObject *, char *, char *);
Karsten Hopp 80c26f
+ static double(*dll_PyFloat_AsDouble)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject*(*dll_PyFloat_FromDouble)(double);
Karsten Hopp 80c26f
+ static PyTypeObject* dll_PyFloat_Type;
Karsten Hopp 80c26f
  static int(*dll_PySys_SetObject)(char *, PyObject *);
Karsten Hopp 80c26f
  static int(*dll_PySys_SetArgv)(int, char **);
Karsten Hopp 80c26f
  static PyTypeObject* dll_PyType_Type;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 235,246 ****
Karsten Hopp 80c26f
--- 292,306 ----
Karsten Hopp 80c26f
  static PyObject*(*dll_Py_BuildValue)(char *, ...);
Karsten Hopp 80c26f
  static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *);
Karsten Hopp 80c26f
  static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int);
Karsten Hopp 80c26f
+ static PyObject*(*dll_PyImport_AddModule)(char *);
Karsten Hopp 80c26f
  static void(*dll_Py_SetPythonHome)(char *home);
Karsten Hopp 80c26f
  static void(*dll_Py_Initialize)(void);
Karsten Hopp 80c26f
  static void(*dll_Py_Finalize)(void);
Karsten Hopp 80c26f
  static int(*dll_Py_IsInitialized)(void);
Karsten Hopp 80c26f
  static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *);
Karsten Hopp 80c26f
  static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *);
Karsten Hopp 80c26f
+ static PyObject* (*dll_PyObject_GetIter)(PyObject *);
Karsten Hopp 80c26f
+ static iternextfunc dll__PyObject_NextNotImplemented;
Karsten Hopp 80c26f
  static PyObject* dll__Py_NoneStruct;
Karsten Hopp 80c26f
  # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
Karsten Hopp 80c26f
  static int (*dll_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 249,254 ****
Karsten Hopp 80c26f
--- 309,316 ----
Karsten Hopp 80c26f
  static void* (*dll_PyObject_Malloc)(size_t);
Karsten Hopp 80c26f
  static void (*dll_PyObject_Free)(void*);
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
+ static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
Karsten Hopp 80c26f
+ static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  static HINSTANCE hinstPython = 0; /* Instance of python.dll */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 278,283 ****
Karsten Hopp 80c26f
--- 340,346 ----
Karsten Hopp 80c26f
      {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse},
Karsten Hopp 80c26f
      {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple},
Karsten Hopp 80c26f
      {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free},
Karsten Hopp 80c26f
+     {"PyMem_Malloc", (PYTHON_PROC*)&dll_PyMem_Malloc},
Karsten Hopp 80c26f
      {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString},
Karsten Hopp 80c26f
      {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument},
Karsten Hopp 80c26f
      {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 294,316 ****
Karsten Hopp 80c26f
--- 357,402 ----
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
      {"PyInt_AsLong", (PYTHON_PROC*)&dll_PyInt_AsLong},
Karsten Hopp 80c26f
      {"PyInt_FromLong", (PYTHON_PROC*)&dll_PyInt_FromLong},
Karsten Hopp 80c26f
+     {"PyLong_AsLong", (PYTHON_PROC*)&dll_PyLong_AsLong},
Karsten Hopp 80c26f
+     {"PyLong_FromLong", (PYTHON_PROC*)&dll_PyLong_FromLong},
Karsten Hopp 80c26f
      {"PyInt_Type", (PYTHON_PROC*)&dll_PyInt_Type},
Karsten Hopp 80c26f
+     {"PyLong_Type", (PYTHON_PROC*)&dll_PyLong_Type},
Karsten Hopp 80c26f
      {"PyList_GetItem", (PYTHON_PROC*)&dll_PyList_GetItem},
Karsten Hopp 80c26f
      {"PyList_Append", (PYTHON_PROC*)&dll_PyList_Append},
Karsten Hopp 80c26f
      {"PyList_New", (PYTHON_PROC*)&dll_PyList_New},
Karsten Hopp 80c26f
      {"PyList_SetItem", (PYTHON_PROC*)&dll_PyList_SetItem},
Karsten Hopp 80c26f
      {"PyList_Size", (PYTHON_PROC*)&dll_PyList_Size},
Karsten Hopp 80c26f
      {"PyList_Type", (PYTHON_PROC*)&dll_PyList_Type},
Karsten Hopp 80c26f
+     {"PySequence_GetItem", (PYTHON_PROC*)&dll_PySequence_GetItem},
Karsten Hopp 80c26f
+     {"PySequence_Size", (PYTHON_PROC*)&dll_PySequence_Size},
Karsten Hopp 80c26f
+     {"PySequence_Check", (PYTHON_PROC*)&dll_PySequence_Check},
Karsten Hopp 80c26f
+     {"PyTuple_GetItem", (PYTHON_PROC*)&dll_PyTuple_GetItem},
Karsten Hopp 80c26f
+     {"PyTuple_Size", (PYTHON_PROC*)&dll_PyTuple_Size},
Karsten Hopp 80c26f
+     {"PyTuple_Type", (PYTHON_PROC*)&dll_PyTuple_Type},
Karsten Hopp 80c26f
      {"PyImport_ImportModule", (PYTHON_PROC*)&dll_PyImport_ImportModule},
Karsten Hopp 80c26f
      {"PyDict_GetItemString", (PYTHON_PROC*)&dll_PyDict_GetItemString},
Karsten Hopp 80c26f
+     {"PyDict_Next", (PYTHON_PROC*)&dll_PyDict_Next},
Karsten Hopp 80c26f
      {"PyDict_New", (PYTHON_PROC*)&dll_PyDict_New},
Karsten Hopp 80c26f
+ # ifndef PY_NO_MAPPING_ITEMS
Karsten Hopp 80c26f
+     {"PyMapping_Items", (PYTHON_PROC*)&dll_PyMapping_Items},
Karsten Hopp 80c26f
+ # endif
Karsten Hopp 80c26f
+     {"PyObject_CallMethod", (PYTHON_PROC*)&dll_PyObject_CallMethod},
Karsten Hopp 80c26f
+     {"PyMapping_Check", (PYTHON_PROC*)&dll_PyMapping_Check},
Karsten Hopp 80c26f
+     {"PyIter_Next", (PYTHON_PROC*)&dll_PyIter_Next},
Karsten Hopp 80c26f
      {"PyModule_GetDict", (PYTHON_PROC*)&dll_PyModule_GetDict},
Karsten Hopp 80c26f
      {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString},
Karsten Hopp 80c26f
+     {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String},
Karsten Hopp 80c26f
      {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString},
Karsten Hopp 80c26f
      {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString},
Karsten Hopp 80c26f
      {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize},
Karsten Hopp 80c26f
      {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size},
Karsten Hopp 80c26f
      {"PyString_Type", (PYTHON_PROC*)&dll_PyString_Type},
Karsten Hopp 80c26f
+     {"PyUnicode_Type", (PYTHON_PROC*)&dll_PyUnicode_Type},
Karsten Hopp 80c26f
+     {"PyUnicodeUCS4_AsEncodedString", (PYTHON_PROC*)&dll_PyUnicodeUCS4_AsEncodedString},
Karsten Hopp 80c26f
+     {"PyFloat_Type", (PYTHON_PROC*)&dll_PyFloat_Type},
Karsten Hopp 80c26f
+     {"PyFloat_AsDouble", (PYTHON_PROC*)&dll_PyFloat_AsDouble},
Karsten Hopp 80c26f
+     {"PyFloat_FromDouble", (PYTHON_PROC*)&dll_PyFloat_FromDouble},
Karsten Hopp 80c26f
+     {"PyImport_AddModule", (PYTHON_PROC*)&dll_PyImport_AddModule},
Karsten Hopp 80c26f
      {"PySys_SetObject", (PYTHON_PROC*)&dll_PySys_SetObject},
Karsten Hopp 80c26f
      {"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv},
Karsten Hopp 80c26f
      {"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 328,333 ****
Karsten Hopp 80c26f
--- 414,421 ----
Karsten Hopp 80c26f
      {"Py_IsInitialized", (PYTHON_PROC*)&dll_Py_IsInitialized},
Karsten Hopp 80c26f
      {"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New},
Karsten Hopp 80c26f
      {"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init},
Karsten Hopp 80c26f
+     {"PyObject_GetIter", (PYTHON_PROC*)&dll_PyObject_GetIter},
Karsten Hopp 80c26f
+     {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&dll__PyObject_NextNotImplemented},
Karsten Hopp 80c26f
      {"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct},
Karsten Hopp 80c26f
  # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02020000
Karsten Hopp 80c26f
      {"PyType_IsSubtype", (PYTHON_PROC*)&dll_PyType_IsSubtype},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 336,341 ****
Karsten Hopp 80c26f
--- 424,431 ----
Karsten Hopp 80c26f
      {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc},
Karsten Hopp 80c26f
      {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free},
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
+     {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New},
Karsten Hopp 80c26f
+     {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer},
Karsten Hopp 80c26f
      {"", NULL},
Karsten Hopp 80c26f
  };
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 434,443 ****
Karsten Hopp 80c26f
--- 524,548 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  static PyObject *BufferNew (buf_T *);
Karsten Hopp 80c26f
  static PyObject *WindowNew(win_T *);
Karsten Hopp 80c26f
+ static PyObject *DictionaryNew(dict_T *);
Karsten Hopp 80c26f
  static PyObject *LineToString(const char *);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  static PyTypeObject RangeType;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ static int initialised = 0;
Karsten Hopp 80c26f
+ #define PYINITIALISED initialised
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ /* Add conversion from PyInt? */
Karsten Hopp 80c26f
+ #define DICTKEY_GET(err) \
Karsten Hopp 80c26f
+     if (!PyString_Check(keyObject)) \
Karsten Hopp 80c26f
+     { \
Karsten Hopp 80c26f
+ 	PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
Karsten Hopp 80c26f
+ 	return err; \
Karsten Hopp 80c26f
+     } \
Karsten Hopp 80c26f
+     key = (char_u *) PyString_AsString(keyObject);
Karsten Hopp 80c26f
+ #define DICTKEY_UNREF
Karsten Hopp 80c26f
+ #define DICTKEY_DECL
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Include the code shared with if_python3.c
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 451,456 ****
Karsten Hopp 80c26f
--- 556,563 ----
Karsten Hopp 80c26f
  static PyInt RangeStart;
Karsten Hopp 80c26f
  static PyInt RangeEnd;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ static PyObject *globals;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  static void PythonIO_Flush(void);
Karsten Hopp 80c26f
  static int PythonIO_Init(void);
Karsten Hopp 80c26f
  static int PythonMod_Init(void);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 466,473 ****
Karsten Hopp 80c26f
   * 1. Python interpreter main program.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
- static int initialised = 0;
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
  #if PYTHON_API_VERSION < 1007 /* Python 1.4 */
Karsten Hopp 80c26f
  typedef PyObject PyThreadState;
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
--- 573,578 ----
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 581,586 ****
Karsten Hopp 80c26f
--- 686,693 ----
Karsten Hopp 80c26f
  	if (PythonMod_Init())
Karsten Hopp 80c26f
  	    goto fail;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ 	globals = PyModule_GetDict(PyImport_AddModule("__main__"));
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  	/* Remove the element from sys.path that was added because of our
Karsten Hopp 80c26f
  	 * argv[0] value in PythonMod_Init().  Previously we used an empty
Karsten Hopp 80c26f
  	 * string, but dependinding on the OS we then get an empty entry or
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 609,615 ****
Karsten Hopp 80c26f
   * External interface
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
! DoPythonCommand(exarg_T *eap, const char *cmd)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
  #ifndef PY_CAN_RECURSE
Karsten Hopp 80c26f
      static int		recursive = 0;
Karsten Hopp 80c26f
--- 716,722 ----
Karsten Hopp 80c26f
   * External interface
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
! DoPythonCommand(exarg_T *eap, const char *cmd, typval_T *rettv)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
  #ifndef PY_CAN_RECURSE
Karsten Hopp 80c26f
      static int		recursive = 0;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 639,646 ****
Karsten Hopp 80c26f
      if (Python_Init())
Karsten Hopp 80c26f
  	goto theend;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     RangeStart = eap->line1;
Karsten Hopp 80c26f
!     RangeEnd = eap->line2;
Karsten Hopp 80c26f
      Python_Release_Vim();	    /* leave vim */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
Karsten Hopp 80c26f
--- 746,761 ----
Karsten Hopp 80c26f
      if (Python_Init())
Karsten Hopp 80c26f
  	goto theend;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (rettv == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	RangeStart = eap->line1;
Karsten Hopp 80c26f
! 	RangeEnd = eap->line2;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	RangeStart = (PyInt) curwin->w_cursor.lnum;
Karsten Hopp 80c26f
! 	RangeEnd = RangeStart;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
      Python_Release_Vim();	    /* leave vim */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 658,664 ****
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      Python_RestoreThread();	    /* enter python */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     PyRun_SimpleString((char *)(cmd));
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      Python_SaveThread();	    /* leave python */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
--- 773,795 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      Python_RestoreThread();	    /* enter python */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (rettv == NULL)
Karsten Hopp 80c26f
! 	PyRun_SimpleString((char *)(cmd));
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyObject	*r;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	r = PyRun_String((char *)(cmd), Py_eval_input, globals, globals);
Karsten Hopp 80c26f
! 	if (r == NULL)
Karsten Hopp 80c26f
! 	    EMSG(_("E858: Eval did not return a valid python object"));
Karsten Hopp 80c26f
! 	else
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    if (ConvertFromPyObject(r, rettv) == -1)
Karsten Hopp 80c26f
! 		EMSG(_("E859: Failed to convert returned python object to vim value"));
Karsten Hopp 80c26f
! 	    Py_DECREF(r);
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	PyErr_Clear();
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      Python_SaveThread();	    /* leave python */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 680,686 ****
Karsten Hopp 80c26f
  #ifndef PY_CAN_RECURSE
Karsten Hopp 80c26f
      --recursive;
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
!     return;	    /* keeps lint happy */
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
--- 811,817 ----
Karsten Hopp 80c26f
  #ifndef PY_CAN_RECURSE
Karsten Hopp 80c26f
      --recursive;
Karsten Hopp 80c26f
  #endif
Karsten Hopp 80c26f
!     return;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 695,703 ****
Karsten Hopp 80c26f
      if (!eap->skip)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
  	if (script == NULL)
Karsten Hopp 80c26f
! 	    DoPythonCommand(eap, (char *)eap->arg);
Karsten Hopp 80c26f
  	else
Karsten Hopp 80c26f
! 	    DoPythonCommand(eap, (char *)script);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      vim_free(script);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
--- 826,834 ----
Karsten Hopp 80c26f
      if (!eap->skip)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
  	if (script == NULL)
Karsten Hopp 80c26f
! 	    DoPythonCommand(eap, (char *)eap->arg, NULL);
Karsten Hopp 80c26f
  	else
Karsten Hopp 80c26f
! 	    DoPythonCommand(eap, (char *)script, NULL);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      vim_free(script);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 743,749 ****
Karsten Hopp 80c26f
      *p++ = '\0';
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Execute the file */
Karsten Hopp 80c26f
!     DoPythonCommand(eap, buffer);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /******************************************************
Karsten Hopp 80c26f
--- 874,880 ----
Karsten Hopp 80c26f
      *p++ = '\0';
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Execute the file */
Karsten Hopp 80c26f
!     DoPythonCommand(eap, buffer, NULL);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /******************************************************
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 765,778 ****
Karsten Hopp 80c26f
      static int
Karsten Hopp 80c26f
  OutputSetattr(PyObject *self, char *name, PyObject *val)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (val == NULL) {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      if (strcmp(name, "softspace") == 0)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	if (!PyInt_Check(val)) {
Karsten Hopp 80c26f
  	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
--- 896,911 ----
Karsten Hopp 80c26f
      static int
Karsten Hopp 80c26f
  OutputSetattr(PyObject *self, char *name, PyObject *val)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (val == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      if (strcmp(name, "softspace") == 0)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	if (!PyInt_Check(val))
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 800,805 ****
Karsten Hopp 80c26f
--- 933,941 ----
Karsten Hopp 80c26f
   * 3. Implementation of the Vim module for Python
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ static PyObject *ConvertToPyObject(typval_T *);
Karsten Hopp 80c26f
+ static int ConvertFromPyObject(PyObject *, typval_T *);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /* Window type - Implementation functions
Karsten Hopp 80c26f
   * --------------------------------------
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1441,1446 ****
Karsten Hopp 80c26f
--- 1577,1748 ----
Karsten Hopp 80c26f
      return result;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ static void DictionaryDestructor(PyObject *);
Karsten Hopp 80c26f
+ static PyObject *DictionaryGetattr(PyObject *, char*);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyMappingMethods DictionaryAsMapping = {
Karsten Hopp 80c26f
+     (PyInquiry)		DictionaryLength,
Karsten Hopp 80c26f
+     (binaryfunc)	DictionaryItem,
Karsten Hopp 80c26f
+     (objobjargproc)	DictionaryAssItem,
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyTypeObject DictionaryType = {
Karsten Hopp 80c26f
+     PyObject_HEAD_INIT(0)
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+     "vimdictionary",
Karsten Hopp 80c26f
+     sizeof(DictionaryObject),
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     (destructor)  DictionaryDestructor,
Karsten Hopp 80c26f
+     (printfunc)   0,
Karsten Hopp 80c26f
+     (getattrfunc) DictionaryGetattr,
Karsten Hopp 80c26f
+     (setattrfunc) 0,
Karsten Hopp 80c26f
+     (cmpfunc)     0,
Karsten Hopp 80c26f
+     (reprfunc)    0,
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     0,			    /* as number */
Karsten Hopp 80c26f
+     0,			    /* as sequence */
Karsten Hopp 80c26f
+     &DictionaryAsMapping,   /* as mapping */
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     (hashfunc)    0,
Karsten Hopp 80c26f
+     (ternaryfunc) 0,
Karsten Hopp 80c26f
+     (reprfunc)    0,
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ DictionaryDestructor(PyObject *self)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     DictionaryObject	*this = ((DictionaryObject *) (self));
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     pyll_remove(&this->ref, &lastdict);
Karsten Hopp 80c26f
+     dict_unref(this->dict);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     Py_DECREF(self);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static PyObject *
Karsten Hopp 80c26f
+ DictionaryGetattr(PyObject *self, char *name)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     return Py_FindMethod(DictionaryMethods, self, name);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static void ListDestructor(PyObject *);
Karsten Hopp 80c26f
+ static PyObject *ListGetattr(PyObject *, char *);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PySequenceMethods ListAsSeq = {
Karsten Hopp 80c26f
+     (PyInquiry)			ListLength,
Karsten Hopp 80c26f
+     (binaryfunc)		0,
Karsten Hopp 80c26f
+     (PyIntArgFunc)		0,
Karsten Hopp 80c26f
+     (PyIntArgFunc)		ListItem,
Karsten Hopp 80c26f
+     (PyIntIntArgFunc)		ListSlice,
Karsten Hopp 80c26f
+     (PyIntObjArgProc)		ListAssItem,
Karsten Hopp 80c26f
+     (PyIntIntObjArgProc)	ListAssSlice,
Karsten Hopp 80c26f
+     (objobjproc)		0,
Karsten Hopp 80c26f
+ #if PY_MAJOR_VERSION >= 2
Karsten Hopp 80c26f
+     (binaryfunc)		ListConcatInPlace,
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+ #endif
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyTypeObject ListType = {
Karsten Hopp 80c26f
+     PyObject_HEAD_INIT(0)
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+     "vimlist",
Karsten Hopp 80c26f
+     sizeof(ListObject),
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     (destructor)  ListDestructor,
Karsten Hopp 80c26f
+     (printfunc)   0,
Karsten Hopp 80c26f
+     (getattrfunc) ListGetattr,
Karsten Hopp 80c26f
+     (setattrfunc) 0,
Karsten Hopp 80c26f
+     (cmpfunc)     0,
Karsten Hopp 80c26f
+     (reprfunc)    0,
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     0,			    /* as number */
Karsten Hopp 80c26f
+     &ListAsSeq,		    /* as sequence */
Karsten Hopp 80c26f
+     0,			    /* as mapping */
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     (hashfunc)    0,
Karsten Hopp 80c26f
+     (ternaryfunc) 0,
Karsten Hopp 80c26f
+     (reprfunc)    0,
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ ListDestructor(PyObject *self)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     ListObject	*this = ((ListObject *) (self));
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     pyll_remove(&this->ref, &lastlist);
Karsten Hopp 80c26f
+     list_unref(this->list);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     Py_DECREF(self);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static PyObject *
Karsten Hopp 80c26f
+ ListGetattr(PyObject *self, char *name)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     return Py_FindMethod(ListMethods, self, name);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static void FunctionDestructor(PyObject *);
Karsten Hopp 80c26f
+ static PyObject *FunctionGetattr(PyObject *, char *);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyTypeObject FunctionType = {
Karsten Hopp 80c26f
+     PyObject_HEAD_INIT(0)
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+     "vimfunction",
Karsten Hopp 80c26f
+     sizeof(FunctionObject),
Karsten Hopp 80c26f
+     0,
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     (destructor)  FunctionDestructor,
Karsten Hopp 80c26f
+     (printfunc)   0,
Karsten Hopp 80c26f
+     (getattrfunc) FunctionGetattr,
Karsten Hopp 80c26f
+     (setattrfunc) 0,
Karsten Hopp 80c26f
+     (cmpfunc)     0,
Karsten Hopp 80c26f
+     (reprfunc)    0,
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     0,			    /* as number */
Karsten Hopp 80c26f
+     0,			    /* as sequence */
Karsten Hopp 80c26f
+     0,			    /* as mapping */
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     (hashfunc)    0,
Karsten Hopp 80c26f
+     (ternaryfunc) FunctionCall,
Karsten Hopp 80c26f
+     (reprfunc)    0,
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ FunctionDestructor(PyObject *self)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     FunctionObject	*this = (FunctionObject *) (self);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     func_unref(this->name);
Karsten Hopp 80c26f
+     PyMem_Del(this->name);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     Py_DECREF(self);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static PyObject *
Karsten Hopp 80c26f
+ FunctionGetattr(PyObject *self, char *name)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     FunctionObject	*this = (FunctionObject *)(self);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     if (strcmp(name, "name") == 0)
Karsten Hopp 80c26f
+ 	return PyString_FromString((char *)(this->name));
Karsten Hopp 80c26f
+     else
Karsten Hopp 80c26f
+ 	return Py_FindMethod(FunctionMethods, self, name);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     void
Karsten Hopp 80c26f
+ do_pyeval (char_u *str, typval_T *rettv)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     DoPythonCommand(NULL, (char *) str, rettv);
Karsten Hopp 80c26f
+     switch(rettv->v_type)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
Karsten Hopp 80c26f
+ 	case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
Karsten Hopp 80c26f
+ 	case VAR_FUNC: func_ref(rettv->vval.v_string);    break;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /* Don't generate a prototype for the next function, it generates an error on
Karsten Hopp 80c26f
   * newer Python versions. */
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1453,1458 ****
Karsten Hopp 80c26f
--- 1755,1766 ----
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  #endif /* Python 1.4 */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+     void
Karsten Hopp 80c26f
+ set_ref_in_python (int copyID)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     set_ref_in_py(copyID);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
  init_structs(void)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/if_python3.c	2012-02-04 20:17:21.000000000 +0100
Karsten Hopp 80c26f
--- src/if_python3.c	2012-06-29 11:54:10.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 77,83 ****
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #define PyInt Py_ssize_t
Karsten Hopp 80c26f
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 80c26f
! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
Karsten Hopp 80c26f
  #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
Karsten Hopp 80c26f
  #define PyString_AsString(obj) PyBytes_AsString(obj)
Karsten Hopp 80c26f
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 80c26f
--- 77,83 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #define PyInt Py_ssize_t
Karsten Hopp 80c26f
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 80c26f
! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER)
Karsten Hopp 80c26f
  #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
Karsten Hopp 80c26f
  #define PyString_AsString(obj) PyBytes_AsString(obj)
Karsten Hopp 80c26f
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 109,114 ****
Karsten Hopp 80c26f
--- 109,115 ----
Karsten Hopp 80c26f
  # undef PyArg_ParseTuple
Karsten Hopp 80c26f
  # define PyArg_ParseTuple py3_PyArg_ParseTuple
Karsten Hopp 80c26f
  # define PyMem_Free py3_PyMem_Free
Karsten Hopp 80c26f
+ # define PyMem_Malloc py3_PyMem_Malloc
Karsten Hopp 80c26f
  # define PyDict_SetItemString py3_PyDict_SetItemString
Karsten Hopp 80c26f
  # define PyErr_BadArgument py3_PyErr_BadArgument
Karsten Hopp 80c26f
  # define PyErr_Clear py3_PyErr_Clear
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 128,141 ****
Karsten Hopp 80c26f
--- 129,155 ----
Karsten Hopp 80c26f
  # define PyList_New py3_PyList_New
Karsten Hopp 80c26f
  # define PyList_SetItem py3_PyList_SetItem
Karsten Hopp 80c26f
  # define PyList_Size py3_PyList_Size
Karsten Hopp 80c26f
+ # define PySequence_Check py3_PySequence_Check
Karsten Hopp 80c26f
+ # define PySequence_Size py3_PySequence_Size
Karsten Hopp 80c26f
+ # define PySequence_GetItem py3_PySequence_GetItem
Karsten Hopp 80c26f
+ # define PyTuple_Size py3_PyTuple_Size
Karsten Hopp 80c26f
+ # define PyTuple_GetItem py3_PyTuple_GetItem
Karsten Hopp 80c26f
  # define PySlice_GetIndicesEx py3_PySlice_GetIndicesEx
Karsten Hopp 80c26f
  # define PyImport_ImportModule py3_PyImport_ImportModule
Karsten Hopp 80c26f
+ # define PyImport_AddModule py3_PyImport_AddModule
Karsten Hopp 80c26f
  # define PyObject_Init py3__PyObject_Init
Karsten Hopp 80c26f
  # define PyDict_New py3_PyDict_New
Karsten Hopp 80c26f
  # define PyDict_GetItemString py3_PyDict_GetItemString
Karsten Hopp 80c26f
+ # define PyDict_Next py3_PyDict_Next
Karsten Hopp 80c26f
+ # define PyMapping_Check py3_PyMapping_Check
Karsten Hopp 80c26f
+ # define PyMapping_Items py3_PyMapping_Items
Karsten Hopp 80c26f
+ # define PyIter_Next py3_PyIter_Next
Karsten Hopp 80c26f
+ # define PyObject_GetIter py3_PyObject_GetIter
Karsten Hopp 80c26f
  # define PyModule_GetDict py3_PyModule_GetDict
Karsten Hopp 80c26f
  #undef PyRun_SimpleString
Karsten Hopp 80c26f
  # define PyRun_SimpleString py3_PyRun_SimpleString
Karsten Hopp 80c26f
+ #undef PyRun_String
Karsten Hopp 80c26f
+ # define PyRun_String py3_PyRun_String
Karsten Hopp 80c26f
  # define PySys_SetObject py3_PySys_SetObject
Karsten Hopp 80c26f
  # define PySys_SetArgv py3_PySys_SetArgv
Karsten Hopp 80c26f
  # define PyType_Type (*py3_PyType_Type)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 147,152 ****
Karsten Hopp 80c26f
--- 161,167 ----
Karsten Hopp 80c26f
  # define Py_Finalize py3_Py_Finalize
Karsten Hopp 80c26f
  # define Py_IsInitialized py3_Py_IsInitialized
Karsten Hopp 80c26f
  # define _Py_NoneStruct (*py3__Py_NoneStruct)
Karsten Hopp 80c26f
+ # define _PyObject_NextNotImplemented (*py3__PyObject_NextNotImplemented)
Karsten Hopp 80c26f
  # define PyModule_AddObject py3_PyModule_AddObject
Karsten Hopp 80c26f
  # define PyImport_AppendInittab py3_PyImport_AppendInittab
Karsten Hopp 80c26f
  # define _PyUnicode_AsString py3__PyUnicode_AsString
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 154,161 ****
Karsten Hopp 80c26f
--- 169,181 ----
Karsten Hopp 80c26f
  # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString
Karsten Hopp 80c26f
  # undef PyBytes_AsString
Karsten Hopp 80c26f
  # define PyBytes_AsString py3_PyBytes_AsString
Karsten Hopp 80c26f
+ # undef PyBytes_FromString
Karsten Hopp 80c26f
+ # define PyBytes_FromString py3_PyBytes_FromString
Karsten Hopp 80c26f
+ # define PyFloat_FromDouble py3_PyFloat_FromDouble
Karsten Hopp 80c26f
+ # define PyFloat_AsDouble py3_PyFloat_AsDouble
Karsten Hopp 80c26f
  # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr
Karsten Hopp 80c26f
  # define PySlice_Type (*py3_PySlice_Type)
Karsten Hopp 80c26f
+ # define PyFloat_Type (*py3_PyFloat_Type)
Karsten Hopp 80c26f
  # define PyErr_NewException py3_PyErr_NewException
Karsten Hopp 80c26f
  # ifdef Py_DEBUG
Karsten Hopp 80c26f
  #  define _Py_NegativeRefcount py3__Py_NegativeRefcount
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 174,179 ****
Karsten Hopp 80c26f
--- 194,202 ----
Karsten Hopp 80c26f
  # define PyUnicode_FromString py3_PyUnicode_FromString
Karsten Hopp 80c26f
  # undef PyUnicode_Decode
Karsten Hopp 80c26f
  # define PyUnicode_Decode py3_PyUnicode_Decode
Karsten Hopp 80c26f
+ # define PyType_IsSubtype py3_PyType_IsSubtype
Karsten Hopp 80c26f
+ # define PyCapsule_New py3_PyCapsule_New
Karsten Hopp 80c26f
+ # define PyCapsule_GetPointer py3_PyCapsule_GetPointer
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  # ifdef Py_DEBUG
Karsten Hopp 80c26f
  #  undef PyObject_NEW
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 194,215 ****
Karsten Hopp 80c26f
--- 217,250 ----
Karsten Hopp 80c26f
  static int (*py3_PySys_SetObject)(char *, PyObject *);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyList_Append)(PyObject *, PyObject *);
Karsten Hopp 80c26f
  static Py_ssize_t (*py3_PyList_Size)(PyObject *);
Karsten Hopp 80c26f
+ static int (*py3_PySequence_Check)(PyObject *);
Karsten Hopp 80c26f
+ static Py_ssize_t (*py3_PySequence_Size)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PySequence_GetItem)(PyObject *, Py_ssize_t);
Karsten Hopp 80c26f
+ static Py_ssize_t (*py3_PyTuple_Size)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyTuple_GetItem)(PyObject *, Py_ssize_t);
Karsten Hopp 80c26f
+ static int (*py3_PyMapping_Check)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyMapping_Items)(PyObject *);
Karsten Hopp 80c26f
  static int (*py3_PySlice_GetIndicesEx)(PyObject *r, Py_ssize_t length,
Karsten Hopp 80c26f
  		     Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyErr_NoMemory)(void);
Karsten Hopp 80c26f
  static void (*py3_Py_Finalize)(void);
Karsten Hopp 80c26f
  static void (*py3_PyErr_SetString)(PyObject *, const char *);
Karsten Hopp 80c26f
  static int (*py3_PyRun_SimpleString)(char *);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyRun_String)(char *, int, PyObject *, PyObject *);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyList_GetItem)(PyObject *, Py_ssize_t);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyImport_ImportModule)(const char *);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyImport_AddModule)(const char *);
Karsten Hopp 80c26f
  static int (*py3_PyErr_BadArgument)(void);
Karsten Hopp 80c26f
  static PyTypeObject* py3_PyType_Type;
Karsten Hopp 80c26f
  static PyObject* (*py3_PyErr_Occurred)(void);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyModule_GetDict)(PyObject *);
Karsten Hopp 80c26f
  static int (*py3_PyList_SetItem)(PyObject *, Py_ssize_t, PyObject *);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyDict_GetItemString)(PyObject *, const char *);
Karsten Hopp 80c26f
+ static int (*py3_PyDict_Next)(PyObject *, Py_ssize_t *, PyObject **, PyObject **);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyLong_FromLong)(long);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyDict_New)(void);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyIter_Next)(PyObject *);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyObject_GetIter)(PyObject *);
Karsten Hopp 80c26f
  static PyObject* (*py3_Py_BuildValue)(char *, ...);
Karsten Hopp 80c26f
  static int (*py3_PyType_Ready)(PyTypeObject *type);
Karsten Hopp 80c26f
  static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 224,244 ****
Karsten Hopp 80c26f
--- 259,287 ----
Karsten Hopp 80c26f
  static int (*py3_PyArg_Parse)(PyObject *, char *, ...);
Karsten Hopp 80c26f
  static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...);
Karsten Hopp 80c26f
  static int (*py3_PyMem_Free)(void *);
Karsten Hopp 80c26f
+ static void* (*py3_PyMem_Malloc)(size_t);
Karsten Hopp 80c26f
  static int (*py3_Py_IsInitialized)(void);
Karsten Hopp 80c26f
  static void (*py3_PyErr_Clear)(void);
Karsten Hopp 80c26f
  static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *);
Karsten Hopp 80c26f
+ static iternextfunc py3__PyObject_NextNotImplemented;
Karsten Hopp 80c26f
  static PyObject* py3__Py_NoneStruct;
Karsten Hopp 80c26f
  static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o);
Karsten Hopp 80c26f
  static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void));
Karsten Hopp 80c26f
  static char* (*py3__PyUnicode_AsString)(PyObject *unicode);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors);
Karsten Hopp 80c26f
  static char* (*py3_PyBytes_AsString)(PyObject *bytes);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyBytes_FromString)(char *str);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyFloat_FromDouble)(double num);
Karsten Hopp 80c26f
+ static double (*py3_PyFloat_AsDouble)(PyObject *);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyObject_GenericGetAttr)(PyObject *obj, PyObject *name);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems);
Karsten Hopp 80c26f
  static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds);
Karsten Hopp 80c26f
  static PyTypeObject* py3_PySlice_Type;
Karsten Hopp 80c26f
+ static PyTypeObject* py3_PyFloat_Type;
Karsten Hopp 80c26f
  static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict);
Karsten Hopp 80c26f
+ static PyObject* (*py3_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
Karsten Hopp 80c26f
+ static void* (*py3_PyCapsule_GetPointer)(PyObject *, char *);
Karsten Hopp 80c26f
  # ifdef Py_DEBUG
Karsten Hopp 80c26f
      static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op);
Karsten Hopp 80c26f
      static Py_ssize_t* py3__Py_RefTotal;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 249,254 ****
Karsten Hopp 80c26f
--- 292,298 ----
Karsten Hopp 80c26f
      static void (*py3_PyObject_Free)(void*);
Karsten Hopp 80c26f
      static void* (*py3_PyObject_Malloc)(size_t);
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
+ static int (*py3_PyType_IsSubtype)(PyTypeObject *, PyTypeObject *);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  static HINSTANCE hinstPy3 = 0; /* Instance of python.dll */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 280,304 ****
Karsten Hopp 80c26f
--- 324,361 ----
Karsten Hopp 80c26f
      {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize},
Karsten Hopp 80c26f
      {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
Karsten Hopp 80c26f
      {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free},
Karsten Hopp 80c26f
+     {"PyMem_Malloc", (PYTHON_PROC*)&py3_PyMem_Malloc},
Karsten Hopp 80c26f
      {"PyList_New", (PYTHON_PROC*)&py3_PyList_New},
Karsten Hopp 80c26f
      {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure},
Karsten Hopp 80c26f
      {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release},
Karsten Hopp 80c26f
      {"PySys_SetObject", (PYTHON_PROC*)&py3_PySys_SetObject},
Karsten Hopp 80c26f
      {"PyList_Append", (PYTHON_PROC*)&py3_PyList_Append},
Karsten Hopp 80c26f
      {"PyList_Size", (PYTHON_PROC*)&py3_PyList_Size},
Karsten Hopp 80c26f
+     {"PySequence_Check", (PYTHON_PROC*)&py3_PySequence_Check},
Karsten Hopp 80c26f
+     {"PySequence_Size", (PYTHON_PROC*)&py3_PySequence_Size},
Karsten Hopp 80c26f
+     {"PySequence_GetItem", (PYTHON_PROC*)&py3_PySequence_GetItem},
Karsten Hopp 80c26f
+     {"PyTuple_Size", (PYTHON_PROC*)&py3_PyTuple_Size},
Karsten Hopp 80c26f
+     {"PyTuple_GetItem", (PYTHON_PROC*)&py3_PyTuple_GetItem},
Karsten Hopp 80c26f
      {"PySlice_GetIndicesEx", (PYTHON_PROC*)&py3_PySlice_GetIndicesEx},
Karsten Hopp 80c26f
      {"PyErr_NoMemory", (PYTHON_PROC*)&py3_PyErr_NoMemory},
Karsten Hopp 80c26f
      {"Py_Finalize", (PYTHON_PROC*)&py3_Py_Finalize},
Karsten Hopp 80c26f
      {"PyErr_SetString", (PYTHON_PROC*)&py3_PyErr_SetString},
Karsten Hopp 80c26f
      {"PyRun_SimpleString", (PYTHON_PROC*)&py3_PyRun_SimpleString},
Karsten Hopp 80c26f
+     {"PyRun_String", (PYTHON_PROC*)&py3_PyRun_String},
Karsten Hopp 80c26f
      {"PyList_GetItem", (PYTHON_PROC*)&py3_PyList_GetItem},
Karsten Hopp 80c26f
      {"PyImport_ImportModule", (PYTHON_PROC*)&py3_PyImport_ImportModule},
Karsten Hopp 80c26f
+     {"PyImport_AddModule", (PYTHON_PROC*)&py3_PyImport_AddModule},
Karsten Hopp 80c26f
      {"PyErr_BadArgument", (PYTHON_PROC*)&py3_PyErr_BadArgument},
Karsten Hopp 80c26f
      {"PyType_Type", (PYTHON_PROC*)&py3_PyType_Type},
Karsten Hopp 80c26f
      {"PyErr_Occurred", (PYTHON_PROC*)&py3_PyErr_Occurred},
Karsten Hopp 80c26f
      {"PyModule_GetDict", (PYTHON_PROC*)&py3_PyModule_GetDict},
Karsten Hopp 80c26f
      {"PyList_SetItem", (PYTHON_PROC*)&py3_PyList_SetItem},
Karsten Hopp 80c26f
      {"PyDict_GetItemString", (PYTHON_PROC*)&py3_PyDict_GetItemString},
Karsten Hopp 80c26f
+     {"PyDict_Next", (PYTHON_PROC*)&py3_PyDict_Next},
Karsten Hopp 80c26f
+     {"PyMapping_Check", (PYTHON_PROC*)&py3_PyMapping_Check},
Karsten Hopp 80c26f
+     {"PyMapping_Items", (PYTHON_PROC*)&py3_PyMapping_Items},
Karsten Hopp 80c26f
+     {"PyIter_Next", (PYTHON_PROC*)&py3_PyIter_Next},
Karsten Hopp 80c26f
+     {"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter},
Karsten Hopp 80c26f
      {"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong},
Karsten Hopp 80c26f
      {"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New},
Karsten Hopp 80c26f
      {"Py_BuildValue", (PYTHON_PROC*)&py3_Py_BuildValue},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 311,316 ****
Karsten Hopp 80c26f
--- 368,374 ----
Karsten Hopp 80c26f
      {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread},
Karsten Hopp 80c26f
      {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse},
Karsten Hopp 80c26f
      {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized},
Karsten Hopp 80c26f
+     {"_PyObject_NextNotImplemented", (PYTHON_PROC*)&py3__PyObject_NextNotImplemented},
Karsten Hopp 80c26f
      {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct},
Karsten Hopp 80c26f
      {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear},
Karsten Hopp 80c26f
      {"PyObject_Init", (PYTHON_PROC*)&py3__PyObject_Init},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 318,328 ****
Karsten Hopp 80c26f
--- 376,390 ----
Karsten Hopp 80c26f
      {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab},
Karsten Hopp 80c26f
      {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
Karsten Hopp 80c26f
      {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
Karsten Hopp 80c26f
+     {"PyBytes_FromString", (PYTHON_PROC*)&py3_PyBytes_FromString},
Karsten Hopp 80c26f
+     {"PyFloat_FromDouble", (PYTHON_PROC*)&py3_PyFloat_FromDouble},
Karsten Hopp 80c26f
+     {"PyFloat_AsDouble", (PYTHON_PROC*)&py3_PyFloat_AsDouble},
Karsten Hopp 80c26f
      {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr},
Karsten Hopp 80c26f
      {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2},
Karsten Hopp 80c26f
      {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc},
Karsten Hopp 80c26f
      {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew},
Karsten Hopp 80c26f
      {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
Karsten Hopp 80c26f
+     {"PyFloat_Type", (PYTHON_PROC*)&py3_PyFloat_Type},
Karsten Hopp 80c26f
      {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException},
Karsten Hopp 80c26f
  # ifdef Py_DEBUG
Karsten Hopp 80c26f
      {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount},
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 334,339 ****
Karsten Hopp 80c26f
--- 396,404 ----
Karsten Hopp 80c26f
      {"PyObject_Malloc", (PYTHON_PROC*)&py3_PyObject_Malloc},
Karsten Hopp 80c26f
      {"PyObject_Free", (PYTHON_PROC*)&py3_PyObject_Free},
Karsten Hopp 80c26f
  # endif
Karsten Hopp 80c26f
+     {"PyType_IsSubtype", (PYTHON_PROC*)&py3_PyType_IsSubtype},
Karsten Hopp 80c26f
+     {"PyCapsule_New", (PYTHON_PROC*)&py3_PyCapsule_New},
Karsten Hopp 80c26f
+     {"PyCapsule_GetPointer", (PYTHON_PROC*)&py3_PyCapsule_GetPointer},
Karsten Hopp 80c26f
      {"", NULL},
Karsten Hopp 80c26f
  };
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 472,482 ****
Karsten Hopp 80c26f
--- 537,577 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  static PyTypeObject RangeType;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ static int py3initialised = 0;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ #define PYINITIALISED py3initialised
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ /* Add conversion from PyInt? */
Karsten Hopp 80c26f
+ #define DICTKEY_GET(err) \
Karsten Hopp 80c26f
+     if (PyBytes_Check(keyObject)) \
Karsten Hopp 80c26f
+ 	key = (char_u *) PyBytes_AsString(keyObject); \
Karsten Hopp 80c26f
+     else if (PyUnicode_Check(keyObject)) \
Karsten Hopp 80c26f
+     { \
Karsten Hopp 80c26f
+ 	bytes = PyString_AsBytes(keyObject); \
Karsten Hopp 80c26f
+ 	if (bytes == NULL) \
Karsten Hopp 80c26f
+ 	    return err; \
Karsten Hopp 80c26f
+ 	key = (char_u *) PyBytes_AsString(bytes); \
Karsten Hopp 80c26f
+ 	if (key == NULL) \
Karsten Hopp 80c26f
+ 	    return err; \
Karsten Hopp 80c26f
+     } \
Karsten Hopp 80c26f
+     else \
Karsten Hopp 80c26f
+     { \
Karsten Hopp 80c26f
+ 	PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
Karsten Hopp 80c26f
+ 	return err; \
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ #define DICTKEY_UNREF \
Karsten Hopp 80c26f
+     if (bytes != NULL) \
Karsten Hopp 80c26f
+ 	Py_XDECREF(bytes);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ #define DICTKEY_DECL PyObject *bytes = NULL;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /*
Karsten Hopp 80c26f
   * Include the code shared with if_python.c
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
  #include "if_py_both.h"
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
  call_PyObject_Free(void *p)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 506,511 ****
Karsten Hopp 80c26f
--- 601,608 ----
Karsten Hopp 80c26f
  static Py_ssize_t RangeStart;
Karsten Hopp 80c26f
  static Py_ssize_t RangeEnd;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ static PyObject *globals;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  static int PythonIO_Init(void);
Karsten Hopp 80c26f
  static void PythonIO_Fini(void);
Karsten Hopp 80c26f
  PyMODINIT_FUNC Py3Init_vim(void);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 514,521 ****
Karsten Hopp 80c26f
   * 1. Python interpreter main program.
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
- static int py3initialised = 0;
Karsten Hopp 80c26f
- 
Karsten Hopp 80c26f
  static PyGILState_STATE pygilstate = PyGILState_UNLOCKED;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      void
Karsten Hopp 80c26f
--- 611,616 ----
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 593,598 ****
Karsten Hopp 80c26f
--- 688,695 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	PyImport_AppendInittab("vim", Py3Init_vim);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ 	globals = PyModule_GetDict(PyImport_AddModule("__main__"));
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  	/* Remove the element from sys.path that was added because of our
Karsten Hopp 80c26f
  	 * argv[0] value in Py3Init_vim().  Previously we used an empty
Karsten Hopp 80c26f
  	 * string, but dependinding on the OS we then get an empty entry or
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 629,635 ****
Karsten Hopp 80c26f
   * External interface
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
! DoPy3Command(exarg_T *eap, const char *cmd)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
  #if defined(MACOS) && !defined(MACOS_X_UNIX)
Karsten Hopp 80c26f
      GrafPtr		oldPort;
Karsten Hopp 80c26f
--- 726,732 ----
Karsten Hopp 80c26f
   * External interface
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
! DoPy3Command(exarg_T *eap, const char *cmd, typval_T *rettv)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
  #if defined(MACOS) && !defined(MACOS_X_UNIX)
Karsten Hopp 80c26f
      GrafPtr		oldPort;
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 649,656 ****
Karsten Hopp 80c26f
      if (Python3_Init())
Karsten Hopp 80c26f
  	goto theend;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     RangeStart = eap->line1;
Karsten Hopp 80c26f
!     RangeEnd = eap->line2;
Karsten Hopp 80c26f
      Python_Release_Vim();	    /* leave vim */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
Karsten Hopp 80c26f
--- 746,761 ----
Karsten Hopp 80c26f
      if (Python3_Init())
Karsten Hopp 80c26f
  	goto theend;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (rettv == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	RangeStart = eap->line1;
Karsten Hopp 80c26f
! 	RangeEnd = eap->line2;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	RangeStart = (PyInt) curwin->w_cursor.lnum;
Karsten Hopp 80c26f
! 	RangeEnd = RangeStart;
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
      Python_Release_Vim();	    /* leave vim */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 674,680 ****
Karsten Hopp 80c26f
  					(char *)ENC_OPT, CODEC_ERROR_HANDLER);
Karsten Hopp 80c26f
      cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
Karsten Hopp 80c26f
      Py_XDECREF(cmdstr);
Karsten Hopp 80c26f
!     PyRun_SimpleString(PyBytes_AsString(cmdbytes));
Karsten Hopp 80c26f
      Py_XDECREF(cmdbytes);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      PyGILState_Release(pygilstate);
Karsten Hopp 80c26f
--- 779,802 ----
Karsten Hopp 80c26f
  					(char *)ENC_OPT, CODEC_ERROR_HANDLER);
Karsten Hopp 80c26f
      cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
Karsten Hopp 80c26f
      Py_XDECREF(cmdstr);
Karsten Hopp 80c26f
!     if (rettv == NULL)
Karsten Hopp 80c26f
! 	PyRun_SimpleString(PyBytes_AsString(cmdbytes));
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
! 	PyObject	*r;
Karsten Hopp 80c26f
! 
Karsten Hopp 80c26f
! 	r = PyRun_String(PyBytes_AsString(cmdbytes), Py_eval_input,
Karsten Hopp 80c26f
! 			 globals, globals);
Karsten Hopp 80c26f
! 	if (r == NULL)
Karsten Hopp 80c26f
! 	    EMSG(_("E860: Eval did not return a valid python 3 object"));
Karsten Hopp 80c26f
! 	else
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
! 	    if (ConvertFromPyObject(r, rettv) == -1)
Karsten Hopp 80c26f
! 		EMSG(_("E861: Failed to convert returned python 3 object to vim value"));
Karsten Hopp 80c26f
! 	    Py_DECREF(r);
Karsten Hopp 80c26f
! 	}
Karsten Hopp 80c26f
! 	PyErr_Clear();
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
      Py_XDECREF(cmdbytes);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      PyGILState_Release(pygilstate);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 709,717 ****
Karsten Hopp 80c26f
      if (!eap->skip)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
  	if (script == NULL)
Karsten Hopp 80c26f
! 	    DoPy3Command(eap, (char *)eap->arg);
Karsten Hopp 80c26f
  	else
Karsten Hopp 80c26f
! 	    DoPy3Command(eap, (char *)script);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      vim_free(script);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
--- 831,839 ----
Karsten Hopp 80c26f
      if (!eap->skip)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
  	if (script == NULL)
Karsten Hopp 80c26f
! 	    DoPy3Command(eap, (char *)eap->arg, NULL);
Karsten Hopp 80c26f
  	else
Karsten Hopp 80c26f
! 	    DoPy3Command(eap, (char *)script, NULL);
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
      vim_free(script);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 772,778 ****
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Execute the file */
Karsten Hopp 80c26f
!     DoPy3Command(eap, buffer);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /******************************************************
Karsten Hopp 80c26f
--- 894,900 ----
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Execute the file */
Karsten Hopp 80c26f
!     DoPy3Command(eap, buffer, NULL);
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  /******************************************************
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 802,815 ****
Karsten Hopp 80c26f
      if (PyUnicode_Check(nameobj))
Karsten Hopp 80c26f
  	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (val == NULL) {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      if (strcmp(name, "softspace") == 0)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	if (!PyLong_Check(val)) {
Karsten Hopp 80c26f
  	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
--- 924,939 ----
Karsten Hopp 80c26f
      if (PyUnicode_Check(nameobj))
Karsten Hopp 80c26f
  	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
!     if (val == NULL)
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      if (strcmp(name, "softspace") == 0)
Karsten Hopp 80c26f
      {
Karsten Hopp 80c26f
! 	if (!PyLong_Check(val))
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1030,1049 ****
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
  BufferSubscript(PyObject *self, PyObject* idx)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx)) {
Karsten Hopp 80c26f
  	long _idx = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return BufferItem(self,_idx);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx)) {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
Karsten Hopp 80c26f
  	      &start, &stop,
Karsten Hopp 80c26f
! 	      &step, &slicelen) < 0) {
Karsten Hopp 80c26f
  	    return NULL;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return BufferSlice(self, start, stop);
Karsten Hopp 80c26f
!     } else {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
--- 1154,1178 ----
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
  BufferSubscript(PyObject *self, PyObject* idx)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	long _idx = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return BufferItem(self,_idx);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
Karsten Hopp 80c26f
  	      &start, &stop,
Karsten Hopp 80c26f
! 	      &step, &slicelen) < 0)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    return NULL;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return BufferSlice(self, start, stop);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1052,1075 ****
Karsten Hopp 80c26f
      static Py_ssize_t
Karsten Hopp 80c26f
  BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx)) {
Karsten Hopp 80c26f
  	long n = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return RBAsItem((BufferObject *)(self), n, val, 1,
Karsten Hopp 80c26f
  		    (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 80c26f
  		    NULL);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx)) {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
Karsten Hopp 80c26f
  	      &start, &stop,
Karsten Hopp 80c26f
! 	      &step, &slicelen) < 0) {
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
Karsten Hopp 80c26f
  			  (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 80c26f
  			  NULL);
Karsten Hopp 80c26f
!     } else {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
--- 1181,1209 ----
Karsten Hopp 80c26f
      static Py_ssize_t
Karsten Hopp 80c26f
  BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	long n = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return RBAsItem((BufferObject *)(self), n, val, 1,
Karsten Hopp 80c26f
  		    (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 80c26f
  		    NULL);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
Karsten Hopp 80c26f
  	      &start, &stop,
Karsten Hopp 80c26f
! 	      &step, &slicelen) < 0)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
Karsten Hopp 80c26f
  			  (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 80c26f
  			  NULL);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1142,1161 ****
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
  RangeSubscript(PyObject *self, PyObject* idx)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx)) {
Karsten Hopp 80c26f
  	long _idx = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return RangeItem(self,_idx);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx)) {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  		((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
Karsten Hopp 80c26f
  		&start, &stop,
Karsten Hopp 80c26f
! 		&step, &slicelen) < 0) {
Karsten Hopp 80c26f
  	    return NULL;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return RangeSlice(self, start, stop);
Karsten Hopp 80c26f
!     } else {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
--- 1276,1300 ----
Karsten Hopp 80c26f
      static PyObject *
Karsten Hopp 80c26f
  RangeSubscript(PyObject *self, PyObject* idx)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	long _idx = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return RangeItem(self,_idx);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  		((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
Karsten Hopp 80c26f
  		&start, &stop,
Karsten Hopp 80c26f
! 		&step, &slicelen) < 0)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    return NULL;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return RangeSlice(self, start, stop);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return NULL;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1164,1183 ****
Karsten Hopp 80c26f
      static Py_ssize_t
Karsten Hopp 80c26f
  RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx)) {
Karsten Hopp 80c26f
  	long n = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return RangeAsItem(self, n, val);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx)) {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  		((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
Karsten Hopp 80c26f
  		&start, &stop,
Karsten Hopp 80c26f
! 		&step, &slicelen) < 0) {
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return RangeAsSlice(self, start, stop, val);
Karsten Hopp 80c26f
!     } else {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
--- 1303,1327 ----
Karsten Hopp 80c26f
      static Py_ssize_t
Karsten Hopp 80c26f
  RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
!     if (PyLong_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	long n = PyLong_AsLong(idx);
Karsten Hopp 80c26f
  	return RangeAsItem(self, n, val);
Karsten Hopp 80c26f
!     } else if (PySlice_Check(idx))
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  	if (PySlice_GetIndicesEx((PyObject *)idx,
Karsten Hopp 80c26f
  		((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
Karsten Hopp 80c26f
  		&start, &stop,
Karsten Hopp 80c26f
! 		&step, &slicelen) < 0)
Karsten Hopp 80c26f
! 	{
Karsten Hopp 80c26f
  	    return -1;
Karsten Hopp 80c26f
  	}
Karsten Hopp 80c26f
  	return RangeAsSlice(self, start, stop, val);
Karsten Hopp 80c26f
!     }
Karsten Hopp 80c26f
!     else
Karsten Hopp 80c26f
!     {
Karsten Hopp 80c26f
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
  	return -1;
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1390,1395 ****
Karsten Hopp 80c26f
--- 1534,1680 ----
Karsten Hopp 80c26f
      }
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+ /* Dictionary object - Definitions
Karsten Hopp 80c26f
+  */
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyInt DictionaryLength(PyObject *);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyMappingMethods DictionaryAsMapping = {
Karsten Hopp 80c26f
+     /* mp_length	*/ (lenfunc) DictionaryLength,
Karsten Hopp 80c26f
+     /* mp_subscript     */ (binaryfunc) DictionaryItem,
Karsten Hopp 80c26f
+     /* mp_ass_subscript */ (objobjargproc) DictionaryAssItem,
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyTypeObject DictionaryType;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ DictionaryDestructor(PyObject *self)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     DictionaryObject *this = (DictionaryObject *)(self);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     pyll_remove(&this->ref, &lastdict);
Karsten Hopp 80c26f
+     dict_unref(this->dict);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     Py_TYPE(self)->tp_free((PyObject*)self);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ /* List object - Definitions
Karsten Hopp 80c26f
+  */
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyInt ListLength(PyObject *);
Karsten Hopp 80c26f
+ static PyObject *ListItem(PyObject *, Py_ssize_t);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PySequenceMethods ListAsSeq = {
Karsten Hopp 80c26f
+     (lenfunc)		ListLength,	 /* sq_length,	  len(x)   */
Karsten Hopp 80c26f
+     (binaryfunc)	0,		 /* RangeConcat, sq_concat,  x+y   */
Karsten Hopp 80c26f
+     (ssizeargfunc)	0,		 /* RangeRepeat, sq_repeat,  x*n   */
Karsten Hopp 80c26f
+     (ssizeargfunc)	ListItem,	 /* sq_item,	  x[i]	   */
Karsten Hopp 80c26f
+     (void *)		0,		 /* was_sq_slice,     x[i:j]   */
Karsten Hopp 80c26f
+     (ssizeobjargproc)	ListAssItem,	 /* sq_as_item,  x[i]=v   */
Karsten Hopp 80c26f
+     (void *)		0,		 /* was_sq_ass_slice, x[i:j]=v */
Karsten Hopp 80c26f
+     0,					 /* sq_contains */
Karsten Hopp 80c26f
+     (binaryfunc)	ListConcatInPlace,/* sq_inplace_concat */
Karsten Hopp 80c26f
+     0,					 /* sq_inplace_repeat */
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyObject *ListSubscript(PyObject *, PyObject *);
Karsten Hopp 80c26f
+ static Py_ssize_t ListAsSubscript(PyObject *, PyObject *, PyObject *);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyMappingMethods ListAsMapping = {
Karsten Hopp 80c26f
+     /* mp_length	*/ (lenfunc) ListLength,
Karsten Hopp 80c26f
+     /* mp_subscript     */ (binaryfunc) ListSubscript,
Karsten Hopp 80c26f
+     /* mp_ass_subscript */ (objobjargproc) ListAsSubscript,
Karsten Hopp 80c26f
+ };
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ static PyTypeObject ListType;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static PyObject *
Karsten Hopp 80c26f
+ ListSubscript(PyObject *self, PyObject* idxObject)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     if (PyLong_Check(idxObject))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	long idx = PyLong_AsLong(idxObject);
Karsten Hopp 80c26f
+ 	return ListItem(self, idx);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (PySlice_Check(idxObject))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
Karsten Hopp 80c26f
+ 				 &step, &slicelen) < 0)
Karsten Hopp 80c26f
+ 	    return NULL;
Karsten Hopp 80c26f
+ 	return ListSlice(self, start, stop);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
+ 	return NULL;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static Py_ssize_t
Karsten Hopp 80c26f
+ ListAsSubscript(PyObject *self, PyObject *idxObject, PyObject *obj)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     if (PyLong_Check(idxObject))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	long idx = PyLong_AsLong(idxObject);
Karsten Hopp 80c26f
+ 	return ListAssItem(self, idx, obj);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else if (PySlice_Check(idxObject))
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ 	if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop,
Karsten Hopp 80c26f
+ 				 &step, &slicelen) < 0)
Karsten Hopp 80c26f
+ 	    return -1;
Karsten Hopp 80c26f
+ 	return ListAssSlice(self, start, stop, obj);
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+     else
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 80c26f
+ 	return -1;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ ListDestructor(PyObject *self)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     ListObject *this = (ListObject *)(self);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     pyll_remove(&this->ref, &lastlist);
Karsten Hopp 80c26f
+     list_unref(this->list);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     Py_TYPE(self)->tp_free((PyObject*)self);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ /* Function object - Definitions
Karsten Hopp 80c26f
+  */
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static void
Karsten Hopp 80c26f
+ FunctionDestructor(PyObject *self)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     FunctionObject	*this = (FunctionObject *) (self);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     func_unref(this->name);
Karsten Hopp 80c26f
+     PyMem_Del(this->name);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     Py_TYPE(self)->tp_free((PyObject*)self);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     static PyObject *
Karsten Hopp 80c26f
+ FunctionGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     FunctionObject	*this = (FunctionObject *)(self);
Karsten Hopp 80c26f
+     char	*name = "";
Karsten Hopp 80c26f
+     if (PyUnicode_Check(nameobj))
Karsten Hopp 80c26f
+ 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     if (strcmp(name, "name") == 0)
Karsten Hopp 80c26f
+ 	return PyUnicode_FromString((char *)(this->name));
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     return PyObject_GenericGetAttr(self, nameobj);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
  /* External interface
Karsten Hopp 80c26f
   */
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1449,1454 ****
Karsten Hopp 80c26f
--- 1734,1742 ----
Karsten Hopp 80c26f
      PyType_Ready(&BufListType);
Karsten Hopp 80c26f
      PyType_Ready(&WinListType);
Karsten Hopp 80c26f
      PyType_Ready(&CurrentType);
Karsten Hopp 80c26f
+     PyType_Ready(&DictionaryType);
Karsten Hopp 80c26f
+     PyType_Ready(&ListType);
Karsten Hopp 80c26f
+     PyType_Ready(&FunctionType);
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
      /* Set sys.argv[] to avoid a crash in warn(). */
Karsten Hopp 80c26f
      PySys_SetArgv(1, argv);
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1517,1522 ****
Karsten Hopp 80c26f
--- 1805,1828 ----
Karsten Hopp 80c26f
      return result;
Karsten Hopp 80c26f
  }
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+     void
Karsten Hopp 80c26f
+ do_py3eval (char_u *str, typval_T *rettv)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     DoPy3Command(NULL, (char *) str, rettv);
Karsten Hopp 80c26f
+     switch(rettv->v_type)
Karsten Hopp 80c26f
+     {
Karsten Hopp 80c26f
+ 	case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
Karsten Hopp 80c26f
+ 	case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
Karsten Hopp 80c26f
+ 	case VAR_FUNC: func_ref(rettv->vval.v_string);    break;
Karsten Hopp 80c26f
+     }
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     void
Karsten Hopp 80c26f
+ set_ref_in_python3 (int copyID)
Karsten Hopp 80c26f
+ {
Karsten Hopp 80c26f
+     set_ref_in_py(copyID);
Karsten Hopp 80c26f
+ }
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
      static void
Karsten Hopp 80c26f
  init_structs(void)
Karsten Hopp 80c26f
  {
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 1598,1603 ****
Karsten Hopp 80c26f
--- 1904,1938 ----
Karsten Hopp 80c26f
      CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
Karsten Hopp 80c26f
      CurrentType.tp_doc = "vim current object";
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
+     vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
Karsten Hopp 80c26f
+     DictionaryType.tp_name = "vim.dictionary";
Karsten Hopp 80c26f
+     DictionaryType.tp_basicsize = sizeof(DictionaryObject);
Karsten Hopp 80c26f
+     DictionaryType.tp_dealloc = DictionaryDestructor;
Karsten Hopp 80c26f
+     DictionaryType.tp_as_mapping = &DictionaryAsMapping;
Karsten Hopp 80c26f
+     DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
Karsten Hopp 80c26f
+     DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
Karsten Hopp 80c26f
+     DictionaryType.tp_methods = DictionaryMethods;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     vim_memset(&ListType, 0, sizeof(ListType));
Karsten Hopp 80c26f
+     ListType.tp_name = "vim.list";
Karsten Hopp 80c26f
+     ListType.tp_dealloc = ListDestructor;
Karsten Hopp 80c26f
+     ListType.tp_basicsize = sizeof(ListObject);
Karsten Hopp 80c26f
+     ListType.tp_as_sequence = &ListAsSeq;
Karsten Hopp 80c26f
+     ListType.tp_as_mapping = &ListAsMapping;
Karsten Hopp 80c26f
+     ListType.tp_flags = Py_TPFLAGS_DEFAULT;
Karsten Hopp 80c26f
+     ListType.tp_doc = "list pushing modifications to vim structure";
Karsten Hopp 80c26f
+     ListType.tp_methods = ListMethods;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+     vim_memset(&FunctionType, 0, sizeof(FunctionType));
Karsten Hopp 80c26f
+     FunctionType.tp_name = "vim.list";
Karsten Hopp 80c26f
+     FunctionType.tp_basicsize = sizeof(FunctionObject);
Karsten Hopp 80c26f
+     FunctionType.tp_getattro = FunctionGetattro;
Karsten Hopp 80c26f
+     FunctionType.tp_dealloc = FunctionDestructor;
Karsten Hopp 80c26f
+     FunctionType.tp_call = FunctionCall;
Karsten Hopp 80c26f
+     FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
Karsten Hopp 80c26f
+     FunctionType.tp_doc = "object that calls vim function";
Karsten Hopp 80c26f
+     FunctionType.tp_methods = FunctionMethods;
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
      vim_memset(&vimmodule, 0, sizeof(vimmodule));
Karsten Hopp 80c26f
      vimmodule.m_name = "vim";
Karsten Hopp 80c26f
      vimmodule.m_doc = vim_module_doc;
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/proto/eval.pro	2011-09-14 16:52:02.000000000 +0200
Karsten Hopp 80c26f
--- src/proto/eval.pro	2012-06-20 18:20:28.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 46,57 ****
Karsten Hopp 80c26f
--- 46,66 ----
Karsten Hopp 80c26f
  list_T *list_alloc __ARGS((void));
Karsten Hopp 80c26f
  void list_unref __ARGS((list_T *l));
Karsten Hopp 80c26f
  void list_free __ARGS((list_T *l, int recurse));
Karsten Hopp 80c26f
+ listitem_T *listitem_alloc __ARGS((void));
Karsten Hopp 80c26f
+ void listitem_remove __ARGS((list_T *l, listitem_T *item));
Karsten Hopp 80c26f
  dictitem_T *dict_lookup __ARGS((hashitem_T *hi));
Karsten Hopp 80c26f
+ listitem_T *list_find __ARGS((list_T *l, long n));
Karsten Hopp 80c26f
  char_u *list_find_str __ARGS((list_T *l, long idx));
Karsten Hopp 80c26f
+ void list_append __ARGS((list_T *l, listitem_T *item));
Karsten Hopp 80c26f
  int list_append_tv __ARGS((list_T *l, typval_T *tv));
Karsten Hopp 80c26f
  int list_append_dict __ARGS((list_T *list, dict_T *dict));
Karsten Hopp 80c26f
  int list_append_string __ARGS((list_T *l, char_u *str, int len));
Karsten Hopp 80c26f
+ int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
Karsten Hopp 80c26f
+ void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
Karsten Hopp 80c26f
  int garbage_collect __ARGS((void));
Karsten Hopp 80c26f
+ void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
Karsten Hopp 80c26f
+ void set_ref_in_list __ARGS((list_T *l, int copyID));
Karsten Hopp 80c26f
+ void set_ref_in_item __ARGS((typval_T *tv, int copyID));
Karsten Hopp 80c26f
  dict_T *dict_alloc __ARGS((void));
Karsten Hopp 80c26f
  void dict_unref __ARGS((dict_T *d));
Karsten Hopp 80c26f
  dictitem_T *dictitem_alloc __ARGS((char_u *key));
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 64,69 ****
Karsten Hopp 80c26f
--- 73,79 ----
Karsten Hopp 80c26f
  long get_dict_number __ARGS((dict_T *d, char_u *key));
Karsten Hopp 80c26f
  char_u *get_function_name __ARGS((expand_T *xp, int idx));
Karsten Hopp 80c26f
  char_u *get_expr_name __ARGS((expand_T *xp, int idx));
Karsten Hopp 80c26f
+ int func_call __ARGS((char_u *name, typval_T *args, dict_T *selfdict, typval_T *rettv));
Karsten Hopp 80c26f
  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));
Karsten Hopp 80c26f
  void set_vim_var_nr __ARGS((int idx, long val));
Karsten Hopp 80c26f
  long get_vim_var_nr __ARGS((int idx));
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 94,99 ****
Karsten Hopp 80c26f
--- 104,111 ----
Karsten Hopp 80c26f
  void func_dump_profile __ARGS((FILE *fd));
Karsten Hopp 80c26f
  char_u *get_user_func_name __ARGS((expand_T *xp, int idx));
Karsten Hopp 80c26f
  void ex_delfunction __ARGS((exarg_T *eap));
Karsten Hopp 80c26f
+ void func_unref __ARGS((char_u *name));
Karsten Hopp 80c26f
+ void func_ref __ARGS((char_u *name));
Karsten Hopp 80c26f
  void ex_return __ARGS((exarg_T *eap));
Karsten Hopp 80c26f
  int do_return __ARGS((exarg_T *eap, int reanimate, int is_cmd, void *rettv));
Karsten Hopp 80c26f
  void discard_pending_return __ARGS((void *rettv));
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/proto/if_python.pro	2010-08-15 21:57:28.000000000 +0200
Karsten Hopp 80c26f
--- src/proto/if_python.pro	2012-06-20 18:23:06.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6,9 ****
Karsten Hopp 80c26f
--- 6,11 ----
Karsten Hopp 80c26f
  void ex_pyfile __ARGS((exarg_T *eap));
Karsten Hopp 80c26f
  void python_buffer_free __ARGS((buf_T *buf));
Karsten Hopp 80c26f
  void python_window_free __ARGS((win_T *win));
Karsten Hopp 80c26f
+ void do_pyeval __ARGS((char_u *str, typval_T *rettv));
Karsten Hopp 80c26f
+ void set_ref_in_python __ARGS((int copyID));
Karsten Hopp 80c26f
  /* vim: set ft=c : */
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/proto/if_python3.pro	2010-08-15 21:57:28.000000000 +0200
Karsten Hopp 80c26f
--- src/proto/if_python3.pro	2012-06-20 18:34:26.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 6,9 ****
Karsten Hopp 80c26f
--- 6,11 ----
Karsten Hopp 80c26f
  void ex_py3file __ARGS((exarg_T *eap));
Karsten Hopp 80c26f
  void python3_buffer_free __ARGS((buf_T *buf));
Karsten Hopp 80c26f
  void python3_window_free __ARGS((win_T *win));
Karsten Hopp 80c26f
+ void do_py3eval __ARGS((char_u *str, typval_T *rettv));
Karsten Hopp 80c26f
+ void set_ref_in_python3 __ARGS((int copyID));
Karsten Hopp 80c26f
  /* vim: set ft=c : */
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/Make_amiga.mak	2012-04-05 16:56:38.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/Make_amiga.mak	2012-06-20 18:43:05.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 14,19 ****
Karsten Hopp 80c26f
--- 14,20 ----
Karsten Hopp 80c26f
  # test27	can't edit file with "*"
Karsten Hopp 80c26f
  # test52	only for Win32
Karsten Hopp 80c26f
  # test85	no Lua interface
Karsten Hopp 80c26f
+ # test86, 87	no Python interface
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
Karsten Hopp 80c26f
  		test7.out test8.out test9.out \
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/Make_dos.mak	2012-04-13 19:11:16.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/Make_dos.mak	2012-06-20 18:43:45.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 30,36 ****
Karsten Hopp 80c26f
  		test68.out test69.out test71.out test72.out test73.out \
Karsten Hopp 80c26f
  		test74.out test75.out test76.out test77.out test78.out \
Karsten Hopp 80c26f
  		test79.out test80.out test81.out test82.out test83.out \
Karsten Hopp 80c26f
! 		test84.out test85.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS32 =	test50.out test70.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
--- 30,36 ----
Karsten Hopp 80c26f
  		test68.out test69.out test71.out test72.out test73.out \
Karsten Hopp 80c26f
  		test74.out test75.out test76.out test77.out test78.out \
Karsten Hopp 80c26f
  		test79.out test80.out test81.out test82.out test83.out \
Karsten Hopp 80c26f
! 		test84.out test85.out test86.out test87.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS32 =	test50.out test70.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/Make_ming.mak	2012-04-13 19:11:16.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/Make_ming.mak	2012-06-20 18:44:12.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 50,56 ****
Karsten Hopp 80c26f
  		test68.out test69.out test71.out test72.out test73.out \
Karsten Hopp 80c26f
  		test74.out test75.out test76.out test77.out test78.out \
Karsten Hopp 80c26f
  		test79.out test80.out test81.out test82.out test83.out \
Karsten Hopp 80c26f
! 		test84.out test85.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS32 =	test50.out test70.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
--- 50,56 ----
Karsten Hopp 80c26f
  		test68.out test69.out test71.out test72.out test73.out \
Karsten Hopp 80c26f
  		test74.out test75.out test76.out test77.out test78.out \
Karsten Hopp 80c26f
  		test79.out test80.out test81.out test82.out test83.out \
Karsten Hopp 80c26f
! 		test84.out test85.out test86.out test87.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS32 =	test50.out test70.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/Make_os2.mak	2012-04-05 16:56:38.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/Make_os2.mak	2012-06-20 18:44:32.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 14,19 ****
Karsten Hopp 80c26f
--- 14,20 ----
Karsten Hopp 80c26f
  # test27	can't edit file with "*" in file name
Karsten Hopp 80c26f
  # test52	only for Win32
Karsten Hopp 80c26f
  # test85	no Lua interface
Karsten Hopp 80c26f
+ # test86, 87	no Python interface
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
Karsten Hopp 80c26f
  		test7.out test8.out test9.out \
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/Makefile	2012-04-05 16:56:38.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/Makefile	2012-06-29 11:56:00.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 27,33 ****
Karsten Hopp 80c26f
  		test69.out test70.out test71.out test72.out test73.out \
Karsten Hopp 80c26f
  		test74.out test75.out test76.out test77.out test78.out \
Karsten Hopp 80c26f
  		test79.out test80.out test81.out test82.out test83.out \
Karsten Hopp 80c26f
! 		test84.out test85.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS_GUI = test16.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
--- 27,33 ----
Karsten Hopp 80c26f
  		test69.out test70.out test71.out test72.out test73.out \
Karsten Hopp 80c26f
  		test74.out test75.out test76.out test77.out test78.out \
Karsten Hopp 80c26f
  		test79.out test80.out test81.out test82.out test83.out \
Karsten Hopp 80c26f
! 		test84.out test85.out test86.out test87.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
  SCRIPTS_GUI = test16.out
Karsten Hopp 80c26f
  
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/test86.in	2012-06-20 20:19:31.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/test86.in	2012-06-20 18:01:02.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 0 ****
Karsten Hopp 80c26f
--- 1,211 ----
Karsten Hopp 80c26f
+ Tests for various python features.     vim: set ft=vim :
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ STARTTEST
Karsten Hopp 80c26f
+ :so small.vim
Karsten Hopp 80c26f
+ :if !has('python') | e! test.ok | wq! test.out | endif
Karsten Hopp 80c26f
+ :py import vim
Karsten Hopp 80c26f
+ :fun Test()
Karsten Hopp 80c26f
+ :let l = []
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py f=vim.bindeval('function("strlen")')
Karsten Hopp 80c26f
+ :" Extending List directly with different types
Karsten Hopp 80c26f
+ :py l.extend([1, "as'd", [1, 2, f, {'a': 1}]])
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :$put =string(l[-1])
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :  $put =string(l[-4])
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :  $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :" List assignment
Karsten Hopp 80c26f
+ :py l[0]=0
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py l[-2]=f
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Extending Dictionary directly with different types
Karsten Hopp 80c26f
+ :let d = {}
Karsten Hopp 80c26f
+ :py d=vim.bindeval('d')
Karsten Hopp 80c26f
+ :py d['1']='asd'
Karsten Hopp 80c26f
+ :py d['b']=[1, 2, f]
Karsten Hopp 80c26f
+ :py d['-1']={'a': 1}
Karsten Hopp 80c26f
+ :let dkeys = []
Karsten Hopp 80c26f
+ :py dk=vim.bindeval('dkeys')
Karsten Hopp 80c26f
+ :py dkeys=d.keys()
Karsten Hopp 80c26f
+ :py dkeys.sort()
Karsten Hopp 80c26f
+ :py dk.extend(dkeys)
Karsten Hopp 80c26f
+ :$put =string(dkeys)
Karsten Hopp 80c26f
+ :for [key, val] in sort(items(d))
Karsten Hopp 80c26f
+ :  $put =string(key) . ' : ' . string(val)
Karsten Hopp 80c26f
+ :  unlet key val
Karsten Hopp 80c26f
+ :endfor
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" removing items with del
Karsten Hopp 80c26f
+ :py del l[2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = range(8)
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   py del l[:3]
Karsten Hopp 80c26f
+ :   py del l[1:]
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :py del d['-1']
Karsten Hopp 80c26f
+ :$put =string(d)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" removing items out of range: silently skip items that don't exist
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :" The following two ranges delete nothing as they match empty list:
Karsten Hopp 80c26f
+ :py del l[2:1]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py del l[2:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py del l[2:3]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py del l[2:4]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py del l[2:5]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py del l[2:6]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :" The following two ranges delete nothing as they match empty list:
Karsten Hopp 80c26f
+ :py del l[-1:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py del l[-2:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py del l[-3:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py del l[-4:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py del l[-5:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py del l[-6:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Slice assignment to a list
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[0:0]=['a']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[1:2]=['b']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[2:4]=['c']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[4:4]=['d']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[-1:2]=['e']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[-10:2]=['f']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[2:-10]=['g']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = []
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l[0:0]=['h']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Locked variables
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :lockvar! l
Karsten Hopp 80c26f
+ :py l[2]='i'
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :unlockvar! l
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Function calls
Karsten Hopp 80c26f
+ :function New(...)
Karsten Hopp 80c26f
+ :return ['NewStart']+a:000+['NewEnd']
Karsten Hopp 80c26f
+ :endfunction
Karsten Hopp 80c26f
+ :function DictNew(...) dict
Karsten Hopp 80c26f
+ :return ['DictNewStart']+a:000+['DictNewEnd', self]
Karsten Hopp 80c26f
+ :endfunction
Karsten Hopp 80c26f
+ :let l=[function('New'), function('DictNew')]
Karsten Hopp 80c26f
+ :py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py l.extend(list(l[0](1, 2, 3)))
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py l.extend([l[0].name])
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   py l[1](1, 2, 3)
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:16]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :delfunction New
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   py l[0](1, 2, 3)
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:16]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :if has('float')
Karsten Hopp 80c26f
+ :   let l=[0.0]
Karsten Hopp 80c26f
+ :   py l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :   py l.extend([0.0])
Karsten Hopp 80c26f
+ :   $put =string(l)
Karsten Hopp 80c26f
+ :else
Karsten Hopp 80c26f
+ :   $put ='[0.0, 0.0]'
Karsten Hopp 80c26f
+ :endif
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" pyeval()
Karsten Hopp 80c26f
+ :let l=pyeval('range(3)')
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let d=pyeval('{"a": "b", "c": 1, "d": ["e"]}')
Karsten Hopp 80c26f
+ :$put =sort(items(d))
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   let undef=pyeval('undefined_name')
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   let vim=pyeval('vim')
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :if has('float')
Karsten Hopp 80c26f
+ :   let f=pyeval('0.0')
Karsten Hopp 80c26f
+ :   $put =string(f)
Karsten Hopp 80c26f
+ :else
Karsten Hopp 80c26f
+ :   $put ='0.0'
Karsten Hopp 80c26f
+ :endif
Karsten Hopp 80c26f
+ :endfun
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :call Test()
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :delfunc Test
Karsten Hopp 80c26f
+ :call garbagecollect(1)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :/^start:/,$wq! test.out
Karsten Hopp 80c26f
+ ENDTEST
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ start:
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/test86.ok	2012-06-20 20:19:31.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/test86.ok	2012-06-20 18:01:02.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 0 ****
Karsten Hopp 80c26f
--- 1,47 ----
Karsten Hopp 80c26f
+ start:
Karsten Hopp 80c26f
+ [1, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
Karsten Hopp 80c26f
+ [1, 2, function('strlen'), {'a': 1}]
Karsten Hopp 80c26f
+ Vim(put):E684:
Karsten Hopp 80c26f
+ [0, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
Karsten Hopp 80c26f
+ [0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]]
Karsten Hopp 80c26f
+ ['-1', '1', 'b']
Karsten Hopp 80c26f
+ '-1' : {'a': 1}
Karsten Hopp 80c26f
+ '1' : 'asd'
Karsten Hopp 80c26f
+ 'b' : [1, 2, function('strlen')]
Karsten Hopp 80c26f
+ [0, function('strlen')]
Karsten Hopp 80c26f
+ [3]
Karsten Hopp 80c26f
+ {'1': 'asd', 'b': [1, 2, function('strlen')]}
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 3]
Karsten Hopp 80c26f
+ [0, 1]
Karsten Hopp 80c26f
+ [0, 1]
Karsten Hopp 80c26f
+ [0, 1]
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 2, 3]
Karsten Hopp 80c26f
+ [2, 3]
Karsten Hopp 80c26f
+ [2, 3]
Karsten Hopp 80c26f
+ [2, 3]
Karsten Hopp 80c26f
+ ['a', 0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 'b', 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 'c']
Karsten Hopp 80c26f
+ [0, 1, 2, 3, 'd']
Karsten Hopp 80c26f
+ [0, 1, 2, 'e', 3]
Karsten Hopp 80c26f
+ ['f', 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 'g', 2, 3]
Karsten Hopp 80c26f
+ ['h']
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd']
Karsten Hopp 80c26f
+ [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}]
Karsten Hopp 80c26f
+ [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New']
Karsten Hopp 80c26f
+ Vim(python):E725:
Karsten Hopp 80c26f
+ Vim(python):E117:
Karsten Hopp 80c26f
+ [0.0, 0.0]
Karsten Hopp 80c26f
+ [0, 1, 2]
Karsten Hopp 80c26f
+ ['a', 'b']
Karsten Hopp 80c26f
+ ['c', 1]
Karsten Hopp 80c26f
+ ['d', ['e']]
Karsten Hopp 80c26f
+ Vim(let):E858:
Karsten Hopp 80c26f
+ Vim(let):E859:
Karsten Hopp 80c26f
+ 0.0
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/test87.in	2012-06-20 20:19:31.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/test87.in	2012-06-20 18:01:02.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 0 ****
Karsten Hopp 80c26f
--- 1,211 ----
Karsten Hopp 80c26f
+ Tests for various python features.     vim: set ft=vim :
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ STARTTEST
Karsten Hopp 80c26f
+ :so small.vim
Karsten Hopp 80c26f
+ :if !has('python3') | e! test.ok | wq! test.out | endif
Karsten Hopp 80c26f
+ :py3 import vim
Karsten Hopp 80c26f
+ :fun Test()
Karsten Hopp 80c26f
+ :let l = []
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 f=vim.bindeval('function("strlen")')
Karsten Hopp 80c26f
+ :" Extending List directly with different types
Karsten Hopp 80c26f
+ :py3 l+=[1, "as'd", [1, 2, f, {'a': 1}]]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :$put =string(l[-1])
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :  $put =string(l[-4])
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :  $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :" List assignment
Karsten Hopp 80c26f
+ :py3 l[0]=0
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 l[-2]=f
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Extending Dictionary directly with different types
Karsten Hopp 80c26f
+ :let d = {}
Karsten Hopp 80c26f
+ :py3 d=vim.bindeval('d')
Karsten Hopp 80c26f
+ :py3 d['1']='asd'
Karsten Hopp 80c26f
+ :py3 d['b']=[1, 2, f]
Karsten Hopp 80c26f
+ :py3 d['-1']={'a': 1}
Karsten Hopp 80c26f
+ :let dkeys = []
Karsten Hopp 80c26f
+ :py3 dk=vim.bindeval('dkeys')
Karsten Hopp 80c26f
+ :py3 dkeys=d.keys()
Karsten Hopp 80c26f
+ :py3 dkeys.sort()
Karsten Hopp 80c26f
+ :py3 dk+=dkeys
Karsten Hopp 80c26f
+ :$put =string(dkeys)
Karsten Hopp 80c26f
+ :for [key, val] in sort(items(d))
Karsten Hopp 80c26f
+ :  $put =string(key) . ' : ' . string(val)
Karsten Hopp 80c26f
+ :  unlet key val
Karsten Hopp 80c26f
+ :endfor
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" removing items with del
Karsten Hopp 80c26f
+ :py3 del l[2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = range(8)
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   py3 del l[:3]
Karsten Hopp 80c26f
+ :   py3 del l[1:]
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :py3 del d['-1']
Karsten Hopp 80c26f
+ :$put =string(d)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" removing items out of range: silently skip items that don't exist
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :" The following two ranges delete nothing as they match empty list:
Karsten Hopp 80c26f
+ :py3 del l[2:1]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 del l[2:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 del l[2:3]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 del l[2:4]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 del l[2:5]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 del l[2:6]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :" The following two ranges delete nothing as they match empty list:
Karsten Hopp 80c26f
+ :py3 del l[-1:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 del l[-2:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 del l[-3:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 del l[-4:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 del l[-5:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 del l[-6:2]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Slice assignment to a list
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[0:0]=['a']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[1:2]=['b']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[2:4]=['c']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[4:4]=['d']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[-1:2]=['e']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[-10:2]=['f']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[2:-10]=['g']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let l = []
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l[0:0]=['h']
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Locked variables
Karsten Hopp 80c26f
+ :let l = [0, 1, 2, 3]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :lockvar! l
Karsten Hopp 80c26f
+ :py3 l[2]='i'
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :unlockvar! l
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" Function calls
Karsten Hopp 80c26f
+ :function New(...)
Karsten Hopp 80c26f
+ :return ['NewStart']+a:000+['NewEnd']
Karsten Hopp 80c26f
+ :endfunction
Karsten Hopp 80c26f
+ :function DictNew(...) dict
Karsten Hopp 80c26f
+ :return ['DictNewStart']+a:000+['DictNewEnd', self]
Karsten Hopp 80c26f
+ :endfunction
Karsten Hopp 80c26f
+ :let l=[function('New'), function('DictNew')]
Karsten Hopp 80c26f
+ :py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :py3 l.extend(list(l[0](1, 2, 3)))
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :py3 l+=[l[0].name]
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   py3 l[1](1, 2, 3)
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :delfunction New
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   py3 l[0](1, 2, 3)
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :if has('float')
Karsten Hopp 80c26f
+ :   let l=[0.0]
Karsten Hopp 80c26f
+ :   py3 l=vim.bindeval('l')
Karsten Hopp 80c26f
+ :   py3 l.extend([0.0])
Karsten Hopp 80c26f
+ :   $put =string(l)
Karsten Hopp 80c26f
+ :else
Karsten Hopp 80c26f
+ :   $put ='[0.0, 0.0]'
Karsten Hopp 80c26f
+ :endif
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :" py3eval()
Karsten Hopp 80c26f
+ :let l=py3eval('[0, 1, 2]')
Karsten Hopp 80c26f
+ :$put =string(l)
Karsten Hopp 80c26f
+ :let d=py3eval('{"a": "b", "c": 1, "d": ["e"]}')
Karsten Hopp 80c26f
+ :$put =sort(items(d))
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   let undef=py3eval('undefined_name')
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :try
Karsten Hopp 80c26f
+ :   let vim=py3eval('vim')
Karsten Hopp 80c26f
+ :catch
Karsten Hopp 80c26f
+ :   $put =v:exception[:13]
Karsten Hopp 80c26f
+ :endtry
Karsten Hopp 80c26f
+ :if has('float')
Karsten Hopp 80c26f
+ :   let f=py3eval('0.0')
Karsten Hopp 80c26f
+ :   $put =string(f)
Karsten Hopp 80c26f
+ :else
Karsten Hopp 80c26f
+ :   $put ='0.0'
Karsten Hopp 80c26f
+ :endif
Karsten Hopp 80c26f
+ :endfun
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :call Test()
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :delfunc Test
Karsten Hopp 80c26f
+ :call garbagecollect(1)
Karsten Hopp 80c26f
+ :"
Karsten Hopp 80c26f
+ :/^start:/,$wq! test.out
Karsten Hopp 80c26f
+ ENDTEST
Karsten Hopp 80c26f
+ 
Karsten Hopp 80c26f
+ start:
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/testdir/test87.ok	2012-06-20 20:19:31.000000000 +0200
Karsten Hopp 80c26f
--- src/testdir/test87.ok	2012-06-20 18:01:02.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 0 ****
Karsten Hopp 80c26f
--- 1,47 ----
Karsten Hopp 80c26f
+ start:
Karsten Hopp 80c26f
+ [1, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
Karsten Hopp 80c26f
+ [1, 2, function('strlen'), {'a': 1}]
Karsten Hopp 80c26f
+ Vim(put):E684:
Karsten Hopp 80c26f
+ [0, 'as''d', [1, 2, function('strlen'), {'a': 1}]]
Karsten Hopp 80c26f
+ [0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]]
Karsten Hopp 80c26f
+ ['-1', '1', 'b']
Karsten Hopp 80c26f
+ '-1' : {'a': 1}
Karsten Hopp 80c26f
+ '1' : 'asd'
Karsten Hopp 80c26f
+ 'b' : [1, 2, function('strlen')]
Karsten Hopp 80c26f
+ [0, function('strlen')]
Karsten Hopp 80c26f
+ [3]
Karsten Hopp 80c26f
+ {'1': 'asd', 'b': [1, 2, function('strlen')]}
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 3]
Karsten Hopp 80c26f
+ [0, 1]
Karsten Hopp 80c26f
+ [0, 1]
Karsten Hopp 80c26f
+ [0, 1]
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 2, 3]
Karsten Hopp 80c26f
+ [2, 3]
Karsten Hopp 80c26f
+ [2, 3]
Karsten Hopp 80c26f
+ [2, 3]
Karsten Hopp 80c26f
+ ['a', 0, 1, 2, 3]
Karsten Hopp 80c26f
+ [0, 'b', 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 'c']
Karsten Hopp 80c26f
+ [0, 1, 2, 3, 'd']
Karsten Hopp 80c26f
+ [0, 1, 2, 'e', 3]
Karsten Hopp 80c26f
+ ['f', 2, 3]
Karsten Hopp 80c26f
+ [0, 1, 'g', 2, 3]
Karsten Hopp 80c26f
+ ['h']
Karsten Hopp 80c26f
+ [0, 1, 2, 3]
Karsten Hopp 80c26f
+ [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd']
Karsten Hopp 80c26f
+ [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}]
Karsten Hopp 80c26f
+ [function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New']
Karsten Hopp 80c26f
+ Vim(py3):E725:
Karsten Hopp 80c26f
+ Vim(py3):E117:
Karsten Hopp 80c26f
+ [0.0, 0.0]
Karsten Hopp 80c26f
+ [0, 1, 2]
Karsten Hopp 80c26f
+ ['a', 'b']
Karsten Hopp 80c26f
+ ['c', 1]
Karsten Hopp 80c26f
+ ['d', ['e']]
Karsten Hopp 80c26f
+ Vim(let):E860:
Karsten Hopp 80c26f
+ Vim(let):E861:
Karsten Hopp 80c26f
+ 0.0
Karsten Hopp 80c26f
*** ../vim-7.3.568/src/version.c	2012-06-29 12:35:40.000000000 +0200
Karsten Hopp 80c26f
--- src/version.c	2012-06-29 12:47:03.000000000 +0200
Karsten Hopp 80c26f
***************
Karsten Hopp 80c26f
*** 716,717 ****
Karsten Hopp 80c26f
--- 716,719 ----
Karsten Hopp 80c26f
  {   /* Add new patch number below this line */
Karsten Hopp 80c26f
+ /**/
Karsten Hopp 80c26f
+     569,
Karsten Hopp 80c26f
  /**/
Karsten Hopp 80c26f
Karsten Hopp 80c26f
-- 
Karsten Hopp 80c26f
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 80c26f
69. Yahoo welcomes you with your own start page
Karsten Hopp 80c26f
Karsten Hopp 80c26f
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 80c26f
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 80c26f
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 80c26f
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///