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