Skip to content

Commit

Permalink
Revert "pythongh-111089: Use PyUnicode_AsUTF8() in getargs.c (python#…
Browse files Browse the repository at this point in the history
…111620)"

This reverts commit cde1071.
  • Loading branch information
vstinner committed Nov 7, 2023
1 parent cba249d commit 938652f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,15 +932,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
} else {
/* "s" or "z" */
const char **p = va_arg(*p_va, const char **);
Py_ssize_t len;
sarg = NULL;

if (c == 'z' && arg == Py_None)
*p = NULL;
else if (PyUnicode_Check(arg)) {
sarg = PyUnicode_AsUTF8(arg);
if (sarg == NULL) {
sarg = PyUnicode_AsUTF8AndSize(arg, &len);
if (sarg == NULL)
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
if (strlen(sarg) != (size_t)len) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
RETURN_ERR_OCCURRED;
}
*p = sarg;
}
Expand Down

0 comments on commit 938652f

Please sign in to comment.