diff src/if_py_both.h @ 23264:f9526a3c9bbf v8.2.2178

patch 8.2.2178: Python 3: non-utf8 character cannot be handled Commit: https://github.com/vim/vim/commit/2e2f52a4a0fd560d37a11a7383a4d52b63ca6cfc Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 21 16:03:02 2020 +0100 patch 8.2.2178: Python 3: non-utf8 character cannot be handled Problem: Python 3: non-utf8 character cannot be handled. Solution: Change the string decode. (Bj?rn Linse, closes https://github.com/vim/vim/issues/1053)
author Bram Moolenaar <Bram@vim.org>
date Mon, 21 Dec 2020 16:15:05 +0100
parents 3ceb24835183
children faca24acb37f
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -130,10 +130,11 @@ StringToChars(PyObject *obj, PyObject **
     {
 	PyObject	*bytes;
 
-	if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
+	if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT,
+							   ERRORS_ENCODE_ARG)))
 	    return NULL;
 
-	if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
+	if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
 		|| str == NULL)
 	{
 	    Py_DECREF(bytes);
@@ -4243,7 +4244,8 @@ StringToLine(PyObject *obj)
     }
     else if (PyUnicode_Check(obj))
     {
-	if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
+	if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT,
+							   ERRORS_ENCODE_ARG)))
 	    return NULL;
 
 	if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
@@ -6290,11 +6292,11 @@ ConvertFromPyObject(PyObject *obj, typva
 	PyObject	*bytes;
 	char_u	*str;
 
-	bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL);
+	bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, ERRORS_ENCODE_ARG);
 	if (bytes == NULL)
 	    return -1;
 
-	if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1)
+	if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1)
 	    return -1;
 	if (str == NULL)
 	    return -1;