|
68 | 68 |
|
69 | 69 | static void init_structs(void); |
70 | 70 |
|
| 71 | +/* The "surrogateescape" error handler is new in Python 3.1 */ |
| 72 | +#if PY_VERSION_HEX >= 0x030100f0 |
| 73 | +# define CODEC_ERROR_HANDLER "surrogateescape" |
| 74 | +#else |
| 75 | +# define CODEC_ERROR_HANDLER NULL |
| 76 | +#endif |
| 77 | + |
71 | 78 | #define PyInt Py_ssize_t |
72 | 79 | #define PyString_Check(obj) PyUnicode_Check(obj) |
73 | | -#define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL); |
| 80 | +#define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER); |
74 | 81 | #define PyString_FreeBytes(obj) Py_XDECREF(bytes) |
75 | 82 | #define PyString_AsString(obj) PyBytes_AsString(obj) |
76 | 83 | #define PyString_Size(obj) PyBytes_GET_SIZE(bytes) |
@@ -661,8 +668,9 @@ DoPy3Command(exarg_T *eap, const char *cmd) |
661 | 668 |
|
662 | 669 | /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause |
663 | 670 | * SyntaxError (unicode error). */ |
664 | | - cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, NULL); |
665 | | - cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL); |
| 671 | + cmdstr = PyUnicode_Decode(cmd, strlen(cmd), |
| 672 | + (char *)ENC_OPT, CODEC_ERROR_HANDLER); |
| 673 | + cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER); |
666 | 674 | Py_XDECREF(cmdstr); |
667 | 675 | PyRun_SimpleString(PyBytes_AsString(cmdbytes)); |
668 | 676 | Py_XDECREF(cmdbytes); |
@@ -1463,7 +1471,7 @@ LineToString(const char *str) |
1463 | 1471 | } |
1464 | 1472 | *p = '\0'; |
1465 | 1473 |
|
1466 | | - result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, NULL); |
| 1474 | + result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER); |
1467 | 1475 |
|
1468 | 1476 | vim_free(tmp); |
1469 | 1477 | return result; |
|
0 commit comments