1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Python: Errors in Unicode characters not handled nicely.
12 Solution: Add the surrogateescape error handler. (lilydjwg)
13 Files: src/if_python3.c
16 *** ../vim-7.3.249/src/if_python3.c 2011-06-26 19:13:33.000000000 +0200
17 --- src/if_python3.c 2011-07-15 15:50:01.000000000 +0200
21 static void init_structs(void);
23 #define PyInt Py_ssize_t
24 #define PyString_Check(obj) PyUnicode_Check(obj)
25 ! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
26 #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
27 #define PyString_AsString(obj) PyBytes_AsString(obj)
28 #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
31 static void init_structs(void);
33 + /* The "surrogateescape" error handler is new in Python 3.1 */
34 + #if PY_VERSION_HEX >= 0x030100f0
35 + # define CODEC_ERROR_HANDLER "surrogateescape"
37 + # define CODEC_ERROR_HANDLER NULL
40 #define PyInt Py_ssize_t
41 #define PyString_Check(obj) PyUnicode_Check(obj)
42 ! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
43 #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
44 #define PyString_AsString(obj) PyBytes_AsString(obj)
45 #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
49 /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
50 * SyntaxError (unicode error). */
51 ! cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, NULL);
52 ! cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL);
54 PyRun_SimpleString(PyBytes_AsString(cmdbytes));
58 /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
59 * SyntaxError (unicode error). */
60 ! cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
61 ! (char *)ENC_OPT, CODEC_ERROR_HANDLER);
62 ! cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
64 PyRun_SimpleString(PyBytes_AsString(cmdbytes));
71 ! result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, NULL);
79 ! result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
83 *** ../vim-7.3.249/src/version.c 2011-07-15 14:12:25.000000000 +0200
84 --- src/version.c 2011-07-15 15:46:19.000000000 +0200
88 { /* Add new patch number below this line */
94 DINGO: You must spank her well and after you have spanked her you
95 may deal with her as you like and then ... spank me.
96 AMAZING: And spank me!
99 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
101 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
102 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
103 \\\ an exciting new programming language -- http://www.Zimbu.org ///
104 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///