Karsten Hopp a30b22
To: vim_dev@googlegroups.com
Karsten Hopp a30b22
Subject: Patch 7.3.1099
Karsten Hopp a30b22
Fcc: outbox
Karsten Hopp a30b22
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp a30b22
Mime-Version: 1.0
Karsten Hopp a30b22
Content-Type: text/plain; charset=UTF-8
Karsten Hopp a30b22
Content-Transfer-Encoding: 8bit
Karsten Hopp a30b22
------------
Karsten Hopp a30b22
Karsten Hopp a30b22
Patch 7.3.1099
Karsten Hopp a30b22
Problem:    Python: Changing directory with os.chdir() causes problems for
Karsten Hopp a30b22
	    Vim's notion of directories.
Karsten Hopp a30b22
Solution:   Add vim.chdir() and vim.fchdir(). (ZyX)
Karsten Hopp a30b22
Files:	    runtime/doc/if_pyth.txt, src/ex_docmd.c, src/if_py_both.h,
Karsten Hopp a30b22
	    src/if_python3.c, src/if_python.c, src/proto/ex_docmd.pro,
Karsten Hopp a30b22
	    src/testdir/test86.in, src/testdir/test86.ok,
Karsten Hopp a30b22
	    src/testdir/test87.in, src/testdir/test87.ok
Karsten Hopp a30b22
Karsten Hopp a30b22
Karsten Hopp a30b22
*** ../vim-7.3.1098/runtime/doc/if_pyth.txt	2013-06-02 17:46:37.000000000 +0200
Karsten Hopp a30b22
--- runtime/doc/if_pyth.txt	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 180,185 ****
Karsten Hopp a30b22
--- 180,192 ----
Karsten Hopp a30b22
  	Like |strwidth()|: returns number of display cells str occupies, tab 
Karsten Hopp a30b22
  	is counted as one cell.
Karsten Hopp a30b22
  
Karsten Hopp a30b22
+ vim.chdir(*args, **kwargs)				*python-chdir*
Karsten Hopp a30b22
+ vim.fchdir(*args, **kwargs)				*python-fchdir*
Karsten Hopp a30b22
+ 	Run os.chdir or os.fchdir, then all appropriate vim stuff.
Karsten Hopp a30b22
+ 	Note: you should not use these functions directly, use os.chdir and 
Karsten Hopp a30b22
+ 	      os.fchdir instead. Behavior of vim.fchdir is undefined in case 
Karsten Hopp a30b22
+ 	      os.fchdir does not exist.
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
  Error object of the "vim" module
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  vim.error						*python-error*
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/ex_docmd.c	2013-05-17 16:39:59.000000000 +0200
Karsten Hopp a30b22
--- src/ex_docmd.c	2013-06-02 18:20:05.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 8182,8187 ****
Karsten Hopp a30b22
--- 8182,8218 ----
Karsten Hopp a30b22
  }
Karsten Hopp a30b22
  #endif
Karsten Hopp a30b22
  
Karsten Hopp a30b22
+ /*
Karsten Hopp a30b22
+  * Deal with the side effects of changing the current directory.
Karsten Hopp a30b22
+  * When "local" is TRUE then this was after an ":lcd" command.
Karsten Hopp a30b22
+  */
Karsten Hopp a30b22
+     void
Karsten Hopp a30b22
+ post_chdir(local)
Karsten Hopp a30b22
+     int		local;
Karsten Hopp a30b22
+ {
Karsten Hopp a30b22
+     vim_free(curwin->w_localdir);
Karsten Hopp a30b22
+     if (local)
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	/* If still in global directory, need to remember current
Karsten Hopp a30b22
+ 	 * directory as global directory. */
Karsten Hopp a30b22
+ 	if (globaldir == NULL && prev_dir != NULL)
Karsten Hopp a30b22
+ 	    globaldir = vim_strsave(prev_dir);
Karsten Hopp a30b22
+ 	/* Remember this local directory for the window. */
Karsten Hopp a30b22
+ 	if (mch_dirname(NameBuff, MAXPATHL) == OK)
Karsten Hopp a30b22
+ 	    curwin->w_localdir = vim_strsave(NameBuff);
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+     else
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	/* We are now in the global directory, no need to remember its
Karsten Hopp a30b22
+ 	 * name. */
Karsten Hopp a30b22
+ 	vim_free(globaldir);
Karsten Hopp a30b22
+ 	globaldir = NULL;
Karsten Hopp a30b22
+ 	curwin->w_localdir = NULL;
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     shorten_fnames(TRUE);
Karsten Hopp a30b22
+ }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  /*
Karsten Hopp a30b22
   * ":cd", ":lcd", ":chdir" and ":lchdir".
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 8253,8279 ****
Karsten Hopp a30b22
  	    EMSG(_(e_failed));
Karsten Hopp a30b22
  	else
Karsten Hopp a30b22
  	{
Karsten Hopp a30b22
! 	    vim_free(curwin->w_localdir);
Karsten Hopp a30b22
! 	    if (eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir)
Karsten Hopp a30b22
! 	    {
Karsten Hopp a30b22
! 		/* If still in global directory, need to remember current
Karsten Hopp a30b22
! 		 * directory as global directory. */
Karsten Hopp a30b22
! 		if (globaldir == NULL && prev_dir != NULL)
Karsten Hopp a30b22
! 		    globaldir = vim_strsave(prev_dir);
Karsten Hopp a30b22
! 		/* Remember this local directory for the window. */
Karsten Hopp a30b22
! 		if (mch_dirname(NameBuff, MAXPATHL) == OK)
Karsten Hopp a30b22
! 		    curwin->w_localdir = vim_strsave(NameBuff);
Karsten Hopp a30b22
! 	    }
Karsten Hopp a30b22
! 	    else
Karsten Hopp a30b22
! 	    {
Karsten Hopp a30b22
! 		/* We are now in the global directory, no need to remember its
Karsten Hopp a30b22
! 		 * name. */
Karsten Hopp a30b22
! 		vim_free(globaldir);
Karsten Hopp a30b22
! 		globaldir = NULL;
Karsten Hopp a30b22
! 		curwin->w_localdir = NULL;
Karsten Hopp a30b22
! 	    }
Karsten Hopp a30b22
! 
Karsten Hopp a30b22
! 	    shorten_fnames(TRUE);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  	    /* Echo the new current directory if the command was typed. */
Karsten Hopp a30b22
  	    if (KeyTyped || p_verbose >= 5)
Karsten Hopp a30b22
--- 8284,8290 ----
Karsten Hopp a30b22
  	    EMSG(_(e_failed));
Karsten Hopp a30b22
  	else
Karsten Hopp a30b22
  	{
Karsten Hopp a30b22
! 	    post_chdir(eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  	    /* Echo the new current directory if the command was typed. */
Karsten Hopp a30b22
  	    if (KeyTyped || p_verbose >= 5)
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/if_py_both.h	2013-06-02 18:07:33.000000000 +0200
Karsten Hopp a30b22
--- src/if_py_both.h	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 52,57 ****
Karsten Hopp a30b22
--- 52,61 ----
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  static PyObject *globals;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
+ static PyObject *py_chdir;
Karsten Hopp a30b22
+ static PyObject *py_fchdir;
Karsten Hopp a30b22
+ static PyObject *py_getcwd;
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
  /*
Karsten Hopp a30b22
   * obtain a lock on the Vim data structures
Karsten Hopp a30b22
   */
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 706,722 ****
Karsten Hopp a30b22
  	    );
Karsten Hopp a30b22
  }
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  /*
Karsten Hopp a30b22
   * Vim module - Definitions
Karsten Hopp a30b22
   */
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  static struct PyMethodDef VimMethods[] = {
Karsten Hopp a30b22
!     /* name,	     function,		calling,	documentation */
Karsten Hopp a30b22
!     {"command",	     VimCommand,	METH_VARARGS,	"Execute a Vim ex-mode command" },
Karsten Hopp a30b22
!     {"eval",	     VimEval,		METH_VARARGS,	"Evaluate an expression using Vim evaluator" },
Karsten Hopp a30b22
!     {"bindeval",     VimEvalPy,		METH_VARARGS,	"Like eval(), but returns objects attached to vim ones"},
Karsten Hopp a30b22
!     {"strwidth",     VimStrwidth,	METH_VARARGS,	"Screen string width, counts <Tab> as having width 1"},
Karsten Hopp a30b22
!     { NULL,	     NULL,		0,		NULL }
Karsten Hopp a30b22
  };
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  /*
Karsten Hopp a30b22
--- 710,793 ----
Karsten Hopp a30b22
  	    );
Karsten Hopp a30b22
  }
Karsten Hopp a30b22
  
Karsten Hopp a30b22
+     static PyObject *
Karsten Hopp a30b22
+ _VimChdir(PyObject *_chdir, PyObject *args, PyObject *kwargs)
Karsten Hopp a30b22
+ {
Karsten Hopp a30b22
+     PyObject	*r;
Karsten Hopp a30b22
+     PyObject	*newwd;
Karsten Hopp a30b22
+     PyObject	*todecref;
Karsten Hopp a30b22
+     char_u	*new_dir;
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (!(r = PyObject_Call(_chdir, args, kwargs)))
Karsten Hopp a30b22
+ 	return NULL;
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (!(newwd = PyObject_CallFunctionObjArgs(py_getcwd, NULL)))
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	Py_DECREF(r);
Karsten Hopp a30b22
+ 	return NULL;
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (!(new_dir = StringToChars(newwd, &todecref)))
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	Py_DECREF(r);
Karsten Hopp a30b22
+ 	Py_DECREF(newwd);
Karsten Hopp a30b22
+ 	return NULL;
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     VimTryStart();
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (vim_chdir(new_dir))
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	Py_DECREF(r);
Karsten Hopp a30b22
+ 	Py_DECREF(newwd);
Karsten Hopp a30b22
+ 	Py_XDECREF(todecref);
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+ 	if (VimTryEnd())
Karsten Hopp a30b22
+ 	    return NULL;
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+ 	PyErr_SetVim(_("failed to change directory"));
Karsten Hopp a30b22
+ 	return NULL;
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     Py_DECREF(newwd);
Karsten Hopp a30b22
+     Py_XDECREF(todecref);
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     post_chdir(FALSE);
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (VimTryEnd())
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	Py_DECREF(r);
Karsten Hopp a30b22
+ 	return NULL;
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     return r;
Karsten Hopp a30b22
+ }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     static PyObject *
Karsten Hopp a30b22
+ VimChdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
Karsten Hopp a30b22
+ {
Karsten Hopp a30b22
+     return _VimChdir(py_chdir, args, kwargs);
Karsten Hopp a30b22
+ }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     static PyObject *
Karsten Hopp a30b22
+ VimFchdir(PyObject *self UNUSED, PyObject *args, PyObject *kwargs)
Karsten Hopp a30b22
+ {
Karsten Hopp a30b22
+     return _VimChdir(py_fchdir, args, kwargs);
Karsten Hopp a30b22
+ }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
  /*
Karsten Hopp a30b22
   * Vim module - Definitions
Karsten Hopp a30b22
   */
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  static struct PyMethodDef VimMethods[] = {
Karsten Hopp a30b22
!     /* name,	     function,			calling,			documentation */
Karsten Hopp a30b22
!     {"command",	     VimCommand,		METH_VARARGS,			"Execute a Vim ex-mode command" },
Karsten Hopp a30b22
!     {"eval",	     VimEval,			METH_VARARGS,			"Evaluate an expression using Vim evaluator" },
Karsten Hopp a30b22
!     {"bindeval",     VimEvalPy,			METH_VARARGS,			"Like eval(), but returns objects attached to vim ones"},
Karsten Hopp a30b22
!     {"strwidth",     VimStrwidth,		METH_VARARGS,			"Screen string width, counts <Tab> as having width 1"},
Karsten Hopp a30b22
!     {"chdir",	     (PyCFunction)VimChdir,	METH_VARARGS|METH_KEYWORDS,	"Change directory"},
Karsten Hopp a30b22
!     {"fchdir",	     (PyCFunction)VimFchdir,	METH_VARARGS|METH_KEYWORDS,	"Change directory"},
Karsten Hopp a30b22
!     { NULL,	     NULL,			0,				NULL }
Karsten Hopp a30b22
  };
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  /*
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 5274,5279 ****
Karsten Hopp a30b22
--- 5345,5351 ----
Karsten Hopp a30b22
  };
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  typedef int (*object_adder)(PyObject *, const char *, PyObject *);
Karsten Hopp a30b22
+ typedef PyObject *(*attr_getter)(PyObject *, const char *);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  #define ADD_OBJECT(m, name, obj) \
Karsten Hopp a30b22
      if (add_object(m, name, obj)) \
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 5288,5296 ****
Karsten Hopp a30b22
      }
Karsten Hopp a30b22
  
Karsten Hopp a30b22
      static int
Karsten Hopp a30b22
! populate_module(PyObject *m, object_adder add_object)
Karsten Hopp a30b22
  {
Karsten Hopp a30b22
      int i;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
      for (i = 0; i < (int)(sizeof(numeric_constants)
Karsten Hopp a30b22
  					   / sizeof(struct numeric_constant));
Karsten Hopp a30b22
--- 5360,5369 ----
Karsten Hopp a30b22
      }
Karsten Hopp a30b22
  
Karsten Hopp a30b22
      static int
Karsten Hopp a30b22
! populate_module(PyObject *m, object_adder add_object, attr_getter get_attr)
Karsten Hopp a30b22
  {
Karsten Hopp a30b22
      int i;
Karsten Hopp a30b22
+     PyObject	*os;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
      for (i = 0; i < (int)(sizeof(numeric_constants)
Karsten Hopp a30b22
  					   / sizeof(struct numeric_constant));
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 5317,5321 ****
Karsten Hopp a30b22
--- 5390,5416 ----
Karsten Hopp a30b22
      ADD_CHECKED_OBJECT(m, "vvars", NEW_DICTIONARY(&vimvardict));
Karsten Hopp a30b22
      ADD_CHECKED_OBJECT(m, "options",
Karsten Hopp a30b22
  	    OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (!(os = PyImport_ImportModule("os")))
Karsten Hopp a30b22
+ 	return -1;
Karsten Hopp a30b22
+     ADD_OBJECT(m, "os", os);
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (!(py_getcwd = PyObject_GetAttrString(os, "getcwd")))
Karsten Hopp a30b22
+ 	return -1;
Karsten Hopp a30b22
+     ADD_OBJECT(m, "_getcwd", py_getcwd)
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if (!(py_chdir = PyObject_GetAttrString(os, "chdir")))
Karsten Hopp a30b22
+ 	return -1;
Karsten Hopp a30b22
+     ADD_OBJECT(m, "_chdir", py_chdir);
Karsten Hopp a30b22
+     if (PyObject_SetAttrString(os, "chdir", get_attr(m, "chdir")))
Karsten Hopp a30b22
+ 	return -1;
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
+     if ((py_fchdir = PyObject_GetAttrString(os, "fchdir")))
Karsten Hopp a30b22
+     {
Karsten Hopp a30b22
+ 	ADD_OBJECT(m, "_fchdir", py_fchdir);
Karsten Hopp a30b22
+ 	if (PyObject_SetAttrString(os, "fchdir", get_attr(m, "fchdir")))
Karsten Hopp a30b22
+ 	    return -1;
Karsten Hopp a30b22
+     }
Karsten Hopp a30b22
+ 
Karsten Hopp a30b22
      return 0;
Karsten Hopp a30b22
  }
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/if_python3.c	2013-05-30 13:22:07.000000000 +0200
Karsten Hopp a30b22
--- src/if_python3.c	2013-06-02 18:14:51.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 174,179 ****
Karsten Hopp a30b22
--- 174,180 ----
Karsten Hopp a30b22
  # define PyObject_HasAttrString py3_PyObject_HasAttrString
Karsten Hopp a30b22
  # define PyObject_SetAttrString py3_PyObject_SetAttrString
Karsten Hopp a30b22
  # define PyObject_CallFunctionObjArgs py3_PyObject_CallFunctionObjArgs
Karsten Hopp a30b22
+ # define PyObject_Call py3_PyObject_Call
Karsten Hopp a30b22
  # define PyEval_GetLocals py3_PyEval_GetLocals
Karsten Hopp a30b22
  # define PyEval_GetGlobals py3_PyEval_GetGlobals
Karsten Hopp a30b22
  # define PySys_SetObject py3_PySys_SetObject
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 290,295 ****
Karsten Hopp a30b22
--- 291,297 ----
Karsten Hopp a30b22
  static int (*py3_PyObject_HasAttrString)(PyObject *, const char *);
Karsten Hopp a30b22
  static PyObject* (*py3_PyObject_SetAttrString)(PyObject *, const char *, PyObject *);
Karsten Hopp a30b22
  static PyObject* (*py3_PyObject_CallFunctionObjArgs)(PyObject *, ...);
Karsten Hopp a30b22
+ static PyObject* (*py3_PyObject_Call)(PyObject *, PyObject *, PyObject *);
Karsten Hopp a30b22
  static PyObject* (*py3_PyEval_GetGlobals)();
Karsten Hopp a30b22
  static PyObject* (*py3_PyEval_GetLocals)();
Karsten Hopp a30b22
  static PyObject* (*py3_PyList_GetItem)(PyObject *, Py_ssize_t);
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 446,451 ****
Karsten Hopp a30b22
--- 448,454 ----
Karsten Hopp a30b22
      {"PyObject_HasAttrString", (PYTHON_PROC*)&py3_PyObject_HasAttrString},
Karsten Hopp a30b22
      {"PyObject_SetAttrString", (PYTHON_PROC*)&py3_PyObject_SetAttrString},
Karsten Hopp a30b22
      {"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&py3_PyObject_CallFunctionObjArgs},
Karsten Hopp a30b22
+     {"PyObject_Call", (PYTHON_PROC*)&py3_PyObject_Call},
Karsten Hopp a30b22
      {"PyEval_GetGlobals", (PYTHON_PROC*)&py3_PyEval_GetGlobals},
Karsten Hopp a30b22
      {"PyEval_GetLocals", (PYTHON_PROC*)&py3_PyEval_GetLocals},
Karsten Hopp a30b22
      {"PyList_GetItem", (PYTHON_PROC*)&py3_PyList_GetItem},
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 1600,1606 ****
Karsten Hopp a30b22
      if (mod == NULL)
Karsten Hopp a30b22
  	return NULL;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
!     if (populate_module(mod, PyModule_AddObject))
Karsten Hopp a30b22
  	return NULL;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
      return mod;
Karsten Hopp a30b22
--- 1603,1609 ----
Karsten Hopp a30b22
      if (mod == NULL)
Karsten Hopp a30b22
  	return NULL;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
!     if (populate_module(mod, PyModule_AddObject, PyObject_GetAttrString))
Karsten Hopp a30b22
  	return NULL;
Karsten Hopp a30b22
  
Karsten Hopp a30b22
      return mod;
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/if_python.c	2013-05-30 15:38:20.000000000 +0200
Karsten Hopp a30b22
--- src/if_python.c	2013-06-02 18:14:46.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 213,218 ****
Karsten Hopp a30b22
--- 213,219 ----
Karsten Hopp a30b22
  # define PyObject_HasAttrString dll_PyObject_HasAttrString
Karsten Hopp a30b22
  # define PyObject_SetAttrString dll_PyObject_SetAttrString
Karsten Hopp a30b22
  # define PyObject_CallFunctionObjArgs dll_PyObject_CallFunctionObjArgs
Karsten Hopp a30b22
+ # define PyObject_Call dll_PyObject_Call
Karsten Hopp a30b22
  # define PyString_AsString dll_PyString_AsString
Karsten Hopp a30b22
  # define PyString_AsStringAndSize dll_PyString_AsStringAndSize
Karsten Hopp a30b22
  # define PyString_FromString dll_PyString_FromString
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 346,351 ****
Karsten Hopp a30b22
--- 347,353 ----
Karsten Hopp a30b22
  static int (*dll_PyObject_HasAttrString)(PyObject *, const char *);
Karsten Hopp a30b22
  static PyObject* (*dll_PyObject_SetAttrString)(PyObject *, const char *, PyObject *);
Karsten Hopp a30b22
  static PyObject* (*dll_PyObject_CallFunctionObjArgs)(PyObject *, ...);
Karsten Hopp a30b22
+ static PyObject* (*dll_PyObject_Call)(PyObject *, PyObject *, PyObject *);
Karsten Hopp a30b22
  static char*(*dll_PyString_AsString)(PyObject *);
Karsten Hopp a30b22
  static int(*dll_PyString_AsStringAndSize)(PyObject *, char **, int *);
Karsten Hopp a30b22
  static PyObject*(*dll_PyString_FromString)(const char *);
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 510,515 ****
Karsten Hopp a30b22
--- 512,518 ----
Karsten Hopp a30b22
      {"PyObject_HasAttrString", (PYTHON_PROC*)&dll_PyObject_HasAttrString},
Karsten Hopp a30b22
      {"PyObject_SetAttrString", (PYTHON_PROC*)&dll_PyObject_SetAttrString},
Karsten Hopp a30b22
      {"PyObject_CallFunctionObjArgs", (PYTHON_PROC*)&dll_PyObject_CallFunctionObjArgs},
Karsten Hopp a30b22
+     {"PyObject_Call", (PYTHON_PROC*)&dll_PyObject_Call},
Karsten Hopp a30b22
      {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString},
Karsten Hopp a30b22
      {"PyString_AsStringAndSize", (PYTHON_PROC*)&dll_PyString_AsStringAndSize},
Karsten Hopp a30b22
      {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString},
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 1374,1383 ****
Karsten Hopp a30b22
      /* Set sys.argv[] to avoid a crash in warn(). */
Karsten Hopp a30b22
      PySys_SetArgv(1, argv);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
!     mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL, PYTHON_API_VERSION);
Karsten Hopp a30b22
      dict = PyModule_GetDict(mod);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
!     return populate_module(dict, add_object);
Karsten Hopp a30b22
  }
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  /*************************************************************************
Karsten Hopp a30b22
--- 1377,1387 ----
Karsten Hopp a30b22
      /* Set sys.argv[] to avoid a crash in warn(). */
Karsten Hopp a30b22
      PySys_SetArgv(1, argv);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
!     mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL,
Karsten Hopp a30b22
! 			    PYTHON_API_VERSION);
Karsten Hopp a30b22
      dict = PyModule_GetDict(mod);
Karsten Hopp a30b22
  
Karsten Hopp a30b22
!     return populate_module(dict, add_object, PyDict_GetItemString);
Karsten Hopp a30b22
  }
Karsten Hopp a30b22
  
Karsten Hopp a30b22
  /*************************************************************************
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/proto/ex_docmd.pro	2012-02-04 21:57:44.000000000 +0100
Karsten Hopp a30b22
--- src/proto/ex_docmd.pro	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 53,56 ****
Karsten Hopp a30b22
--- 53,57 ----
Karsten Hopp a30b22
  int put_line __ARGS((FILE *fd, char *s));
Karsten Hopp a30b22
  void dialog_msg __ARGS((char_u *buff, char *format, char_u *fname));
Karsten Hopp a30b22
  char_u *get_behave_arg __ARGS((expand_T *xp, int idx));
Karsten Hopp a30b22
+ void post_chdir __ARGS((int local));
Karsten Hopp a30b22
  /* vim: set ft=c : */
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/testdir/test86.in	2013-06-02 17:41:50.000000000 +0200
Karsten Hopp a30b22
--- src/testdir/test86.in	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 788,793 ****
Karsten Hopp a30b22
--- 788,807 ----
Karsten Hopp a30b22
  :$put =string(pyeval('dl2'))
Karsten Hopp a30b22
  :$put =string(pyeval('df(2)'))
Karsten Hopp a30b22
  :"
Karsten Hopp a30b22
+ :" Test chdir
Karsten Hopp a30b22
+ py << EOF
Karsten Hopp a30b22
+ import os
Karsten Hopp a30b22
+ fnamemodify = vim.Function('fnamemodify')
Karsten Hopp a30b22
+ cb.append(fnamemodify('.', ':p:h:t'))
Karsten Hopp a30b22
+ cb.append(vim.eval('@%'))
Karsten Hopp a30b22
+ os.chdir('..')
Karsten Hopp a30b22
+ cb.append(fnamemodify('.', ':p:h:t'))
Karsten Hopp a30b22
+ cb.append(vim.eval('@%').replace(os.path.sep, '/'))
Karsten Hopp a30b22
+ os.chdir('testdir')
Karsten Hopp a30b22
+ cb.append(fnamemodify('.', ':p:h:t'))
Karsten Hopp a30b22
+ cb.append(vim.eval('@%'))
Karsten Hopp a30b22
+ EOF
Karsten Hopp a30b22
+ :"
Karsten Hopp a30b22
  :" Test errors
Karsten Hopp a30b22
  :fun F() dict
Karsten Hopp a30b22
  :endfun
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/testdir/test86.ok	2013-06-02 17:41:50.000000000 +0200
Karsten Hopp a30b22
--- src/testdir/test86.ok	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 429,434 ****
Karsten Hopp a30b22
--- 429,440 ----
Karsten Hopp a30b22
  ['a', 'b', 'c']
Karsten Hopp a30b22
  [2, 2]
Karsten Hopp a30b22
  [2, 2]
Karsten Hopp a30b22
+ testdir
Karsten Hopp a30b22
+ test86.in
Karsten Hopp a30b22
+ src
Karsten Hopp a30b22
+ testdir/test86.in
Karsten Hopp a30b22
+ testdir
Karsten Hopp a30b22
+ test86.in
Karsten Hopp a30b22
  > Output
Karsten Hopp a30b22
  >> OutputSetattr
Karsten Hopp a30b22
  del sys.stdout.softspace:(<type 'exceptions.AttributeError'>, AttributeError("can't delete OutputObject attributes",))
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/testdir/test87.in	2013-06-02 17:41:50.000000000 +0200
Karsten Hopp a30b22
--- src/testdir/test87.in	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 748,753 ****
Karsten Hopp a30b22
--- 748,767 ----
Karsten Hopp a30b22
  :$put =string(py3eval('dl2'))
Karsten Hopp a30b22
  :$put =string(py3eval('df(2)'))
Karsten Hopp a30b22
  :"
Karsten Hopp a30b22
+ :" Test chdir
Karsten Hopp a30b22
+ py3 << EOF
Karsten Hopp a30b22
+ import os
Karsten Hopp a30b22
+ fnamemodify = vim.Function('fnamemodify')
Karsten Hopp a30b22
+ cb.append(str(fnamemodify('.', ':p:h:t')))
Karsten Hopp a30b22
+ cb.append(vim.eval('@%'))
Karsten Hopp a30b22
+ os.chdir('..')
Karsten Hopp a30b22
+ cb.append(str(fnamemodify('.', ':p:h:t')))
Karsten Hopp a30b22
+ cb.append(vim.eval('@%').replace(os.path.sep, '/'))
Karsten Hopp a30b22
+ os.chdir('testdir')
Karsten Hopp a30b22
+ cb.append(str(fnamemodify('.', ':p:h:t')))
Karsten Hopp a30b22
+ cb.append(vim.eval('@%'))
Karsten Hopp a30b22
+ EOF
Karsten Hopp a30b22
+ :"
Karsten Hopp a30b22
  :" Test errors
Karsten Hopp a30b22
  :fun F() dict
Karsten Hopp a30b22
  :endfun
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/testdir/test87.ok	2013-06-02 17:41:50.000000000 +0200
Karsten Hopp a30b22
--- src/testdir/test87.ok	2013-06-02 18:11:13.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 418,423 ****
Karsten Hopp a30b22
--- 418,429 ----
Karsten Hopp a30b22
  ['a', 'b', 'c']
Karsten Hopp a30b22
  [2, 2]
Karsten Hopp a30b22
  [2, 2]
Karsten Hopp a30b22
+ b'testdir'
Karsten Hopp a30b22
+ test87.in
Karsten Hopp a30b22
+ b'src'
Karsten Hopp a30b22
+ testdir/test87.in
Karsten Hopp a30b22
+ b'testdir'
Karsten Hopp a30b22
+ test87.in
Karsten Hopp a30b22
  > Output
Karsten Hopp a30b22
  >> OutputSetattr
Karsten Hopp a30b22
  del sys.stdout.softspace:(<class 'AttributeError'>, AttributeError("can't delete OutputObject attributes",))
Karsten Hopp a30b22
*** ../vim-7.3.1098/src/version.c	2013-06-02 18:07:33.000000000 +0200
Karsten Hopp a30b22
--- src/version.c	2013-06-02 18:12:58.000000000 +0200
Karsten Hopp a30b22
***************
Karsten Hopp a30b22
*** 730,731 ****
Karsten Hopp a30b22
--- 730,733 ----
Karsten Hopp a30b22
  {   /* Add new patch number below this line */
Karsten Hopp a30b22
+ /**/
Karsten Hopp a30b22
+     1099,
Karsten Hopp a30b22
  /**/