Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
23263:fa5052e3f93a | 23264:f9526a3c9bbf |
---|---|
128 } | 128 } |
129 else if (PyUnicode_Check(obj)) | 129 else if (PyUnicode_Check(obj)) |
130 { | 130 { |
131 PyObject *bytes; | 131 PyObject *bytes; |
132 | 132 |
133 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) | 133 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, |
134 ERRORS_ENCODE_ARG))) | |
134 return NULL; | 135 return NULL; |
135 | 136 |
136 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1 | 137 if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1 |
137 || str == NULL) | 138 || str == NULL) |
138 { | 139 { |
139 Py_DECREF(bytes); | 140 Py_DECREF(bytes); |
140 return NULL; | 141 return NULL; |
141 } | 142 } |
4241 || str == NULL) | 4242 || str == NULL) |
4242 return NULL; | 4243 return NULL; |
4243 } | 4244 } |
4244 else if (PyUnicode_Check(obj)) | 4245 else if (PyUnicode_Check(obj)) |
4245 { | 4246 { |
4246 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) | 4247 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, |
4248 ERRORS_ENCODE_ARG))) | |
4247 return NULL; | 4249 return NULL; |
4248 | 4250 |
4249 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1 | 4251 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1 |
4250 || str == NULL) | 4252 || str == NULL) |
4251 { | 4253 { |
6288 else if (PyUnicode_Check(obj)) | 6290 else if (PyUnicode_Check(obj)) |
6289 { | 6291 { |
6290 PyObject *bytes; | 6292 PyObject *bytes; |
6291 char_u *str; | 6293 char_u *str; |
6292 | 6294 |
6293 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL); | 6295 bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, ERRORS_ENCODE_ARG); |
6294 if (bytes == NULL) | 6296 if (bytes == NULL) |
6295 return -1; | 6297 return -1; |
6296 | 6298 |
6297 if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1) | 6299 if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1) |
6298 return -1; | 6300 return -1; |
6299 if (str == NULL) | 6301 if (str == NULL) |
6300 return -1; | 6302 return -1; |
6301 | 6303 |
6302 if (set_string_copy(str, tv)) | 6304 if (set_string_copy(str, tv)) |