Karsten Hopp 7ef2e6
To: vim_dev@googlegroups.com
Karsten Hopp 7ef2e6
Subject: Patch 7.3.250
Karsten Hopp 7ef2e6
Fcc: outbox
Karsten Hopp 7ef2e6
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 7ef2e6
Mime-Version: 1.0
Karsten Hopp 7ef2e6
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 7ef2e6
Content-Transfer-Encoding: 8bit
Karsten Hopp 7ef2e6
------------
Karsten Hopp 7ef2e6
Karsten Hopp 7ef2e6
Patch 7.3.250
Karsten Hopp 7ef2e6
Problem:    Python: Errors in Unicode characters not handled nicely.
Karsten Hopp 7ef2e6
Solution:   Add the surrogateescape error handler. (lilydjwg)
Karsten Hopp 7ef2e6
Files:	    src/if_python3.c
Karsten Hopp 7ef2e6
Karsten Hopp 7ef2e6
Karsten Hopp 7ef2e6
*** ../vim-7.3.249/src/if_python3.c	2011-06-26 19:13:33.000000000 +0200
Karsten Hopp 7ef2e6
--- src/if_python3.c	2011-07-15 15:50:01.000000000 +0200
Karsten Hopp 7ef2e6
***************
Karsten Hopp 7ef2e6
*** 68,76 ****
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
  static void init_structs(void);
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
  #define PyInt Py_ssize_t
Karsten Hopp 7ef2e6
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 7ef2e6
! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
Karsten Hopp 7ef2e6
  #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
Karsten Hopp 7ef2e6
  #define PyString_AsString(obj) PyBytes_AsString(obj)
Karsten Hopp 7ef2e6
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 7ef2e6
--- 68,83 ----
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
  static void init_structs(void);
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
+ /* The "surrogateescape" error handler is new in Python 3.1 */
Karsten Hopp 7ef2e6
+ #if PY_VERSION_HEX >= 0x030100f0
Karsten Hopp 7ef2e6
+ # define CODEC_ERROR_HANDLER "surrogateescape"
Karsten Hopp 7ef2e6
+ #else
Karsten Hopp 7ef2e6
+ # define CODEC_ERROR_HANDLER NULL
Karsten Hopp 7ef2e6
+ #endif
Karsten Hopp 7ef2e6
+ 
Karsten Hopp 7ef2e6
  #define PyInt Py_ssize_t
Karsten Hopp 7ef2e6
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 7ef2e6
! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
Karsten Hopp 7ef2e6
  #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
Karsten Hopp 7ef2e6
  #define PyString_AsString(obj) PyBytes_AsString(obj)
Karsten Hopp 7ef2e6
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 7ef2e6
***************
Karsten Hopp 7ef2e6
*** 661,668 ****
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
      /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
Karsten Hopp 7ef2e6
       * SyntaxError (unicode error). */
Karsten Hopp 7ef2e6
!     cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, NULL);
Karsten Hopp 7ef2e6
!     cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL);
Karsten Hopp 7ef2e6
      Py_XDECREF(cmdstr);
Karsten Hopp 7ef2e6
      PyRun_SimpleString(PyBytes_AsString(cmdbytes));
Karsten Hopp 7ef2e6
      Py_XDECREF(cmdbytes);
Karsten Hopp 7ef2e6
--- 668,676 ----
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
      /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
Karsten Hopp 7ef2e6
       * SyntaxError (unicode error). */
Karsten Hopp 7ef2e6
!     cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
Karsten Hopp 7ef2e6
! 					(char *)ENC_OPT, CODEC_ERROR_HANDLER);
Karsten Hopp 7ef2e6
!     cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
Karsten Hopp 7ef2e6
      Py_XDECREF(cmdstr);
Karsten Hopp 7ef2e6
      PyRun_SimpleString(PyBytes_AsString(cmdbytes));
Karsten Hopp 7ef2e6
      Py_XDECREF(cmdbytes);
Karsten Hopp 7ef2e6
***************
Karsten Hopp 7ef2e6
*** 1463,1469 ****
Karsten Hopp 7ef2e6
      }
Karsten Hopp 7ef2e6
      *p = '\0';
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
!     result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, NULL);
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
      vim_free(tmp);
Karsten Hopp 7ef2e6
      return result;
Karsten Hopp 7ef2e6
--- 1471,1477 ----
Karsten Hopp 7ef2e6
      }
Karsten Hopp 7ef2e6
      *p = '\0';
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
!     result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
Karsten Hopp 7ef2e6
  
Karsten Hopp 7ef2e6
      vim_free(tmp);
Karsten Hopp 7ef2e6
      return result;
Karsten Hopp 7ef2e6
*** ../vim-7.3.249/src/version.c	2011-07-15 14:12:25.000000000 +0200
Karsten Hopp 7ef2e6
--- src/version.c	2011-07-15 15:46:19.000000000 +0200
Karsten Hopp 7ef2e6
***************
Karsten Hopp 7ef2e6
*** 711,712 ****
Karsten Hopp 7ef2e6
--- 711,714 ----
Karsten Hopp 7ef2e6
  {   /* Add new patch number below this line */
Karsten Hopp 7ef2e6
+ /**/
Karsten Hopp 7ef2e6
+     250,
Karsten Hopp 7ef2e6
  /**/
Karsten Hopp 7ef2e6
Karsten Hopp 7ef2e6
-- 
Karsten Hopp 7ef2e6
DINGO:   You must spank her well and after you have spanked her you
Karsten Hopp 7ef2e6
         may deal with her as you like and then ... spank me.
Karsten Hopp 7ef2e6
AMAZING: And spank me!
Karsten Hopp 7ef2e6
STUNNER: And me.
Karsten Hopp 7ef2e6
LOVELY:  And me.
Karsten Hopp 7ef2e6
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 7ef2e6
Karsten Hopp 7ef2e6
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 7ef2e6
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 7ef2e6
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 7ef2e6
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///