summaryrefslogtreecommitdiff
path: root/src/if_python3.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-21 16:03:02 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-21 16:03:02 +0100
commit2e2f52a4a0fd560d37a11a7383a4d52b63ca6cfc (patch)
treec4bde05ee74541b38cfb98052cb4dd64ea91c999 /src/if_python3.c
parentef2dff52de52c17fe1bd7c06cbb32d8955901f5a (diff)
downloadvim-git-2e2f52a4a0fd560d37a11a7383a4d52b63ca6cfc.tar.gz
patch 8.2.2178: Python 3: non-utf8 character cannot be handledv8.2.2178
Problem: Python 3: non-utf8 character cannot be handled. Solution: Change the string decode. (Björn Linse, closes #1053)
Diffstat (limited to 'src/if_python3.c')
-rw-r--r--src/if_python3.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/if_python3.c b/src/if_python3.c
index a51be2949..ea4fd7dd8 100644
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -81,12 +81,15 @@
// Python 3 does not support CObjects, always use Capsules
#define PY_USE_CAPSULE
+#define ERRORS_DECODE_ARG CODEC_ERROR_HANDLER
+#define ERRORS_ENCODE_ARG ERRORS_DECODE_ARG
+
#define PyInt Py_ssize_t
#ifndef PyString_Check
# define PyString_Check(obj) PyUnicode_Check(obj)
#endif
#define PyString_FromString(repr) \
- PyUnicode_Decode(repr, STRLEN(repr), ENC_OPT, NULL)
+ PyUnicode_Decode(repr, STRLEN(repr), ENC_OPT, ERRORS_DECODE_ARG)
#define PyString_FromFormat PyUnicode_FromFormat
#ifndef PyInt_Check
# define PyInt_Check(obj) PyLong_Check(obj)
@@ -1088,8 +1091,8 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
// PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
// SyntaxError (unicode error).
cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
- (char *)ENC_OPT, CODEC_ERROR_HANDLER);
- cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
+ (char *)ENC_OPT, ERRORS_DECODE_ARG);
+ cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", ERRORS_ENCODE_ARG);
Py_XDECREF(cmdstr);
run(PyBytes_AsString(cmdbytes), arg, &pygilstate);
@@ -1745,7 +1748,7 @@ LineToString(const char *str)
}
*p = '\0';
- result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
+ result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, ERRORS_DECODE_ARG);
vim_free(tmp);
return result;