diff options
author | Bram Moolenaar <Bram@vim.org> | 2011-07-15 15:54:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2011-07-15 15:54:44 +0200 |
commit | 3d64a3176c9ffe249ad4b5403a18f8364e707813 (patch) | |
tree | cb1e9daef3a741e84aa700ddb70ef2b51597bd9f | |
parent | 50f42cadb1a5970d3a6b83d961e66fa486df8fcb (diff) | |
download | vim-git-3d64a3176c9ffe249ad4b5403a18f8364e707813.tar.gz |
updated for version 7.3.250v7.3.250
Problem: Python: Errors in Unicode characters not handled nicely.
Solution: Add the surrogateescape error handler. (lilydjwg)
-rw-r--r-- | src/if_python3.c | 16 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/if_python3.c b/src/if_python3.c index b16dfc68a..023a773e2 100644 --- a/src/if_python3.c +++ b/src/if_python3.c @@ -68,9 +68,16 @@ static void init_structs(void); +/* The "surrogateescape" error handler is new in Python 3.1 */ +#if PY_VERSION_HEX >= 0x030100f0 +# define CODEC_ERROR_HANDLER "surrogateescape" +#else +# define CODEC_ERROR_HANDLER NULL +#endif + #define PyInt Py_ssize_t #define PyString_Check(obj) PyUnicode_Check(obj) -#define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL); +#define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER); #define PyString_FreeBytes(obj) Py_XDECREF(bytes) #define PyString_AsString(obj) PyBytes_AsString(obj) #define PyString_Size(obj) PyBytes_GET_SIZE(bytes) @@ -661,8 +668,9 @@ DoPy3Command(exarg_T *eap, const char *cmd) /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause * SyntaxError (unicode error). */ - cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, NULL); - cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL); + cmdstr = PyUnicode_Decode(cmd, strlen(cmd), + (char *)ENC_OPT, CODEC_ERROR_HANDLER); + cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER); Py_XDECREF(cmdstr); PyRun_SimpleString(PyBytes_AsString(cmdbytes)); Py_XDECREF(cmdbytes); @@ -1463,7 +1471,7 @@ LineToString(const char *str) } *p = '\0'; - result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, NULL); + result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER); vim_free(tmp); return result; diff --git a/src/version.c b/src/version.c index a13868106..ffed791cf 100644 --- a/src/version.c +++ b/src/version.c @@ -710,6 +710,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 250, +/**/ 249, /**/ 248, |