gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)

* Revert "gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)"

This reverts commit d9b606b3d0.

* Revert "gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)"

This reverts commit cde1071b2a.

* Revert "gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)"

This reverts commit d731579bfb.

* Revert "gh-111089: Add PyUnicode_AsUTF8() to the limited C API (#111121)"

This reverts commit d8f32be5b6.

* Revert "gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)"

This reverts commit 37e4e20eaa.
This commit is contained in:
Victor Stinner 2023-11-07 23:36:13 +01:00 committed by GitHub
parent ea970fb116
commit 11e83488c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 951 additions and 243 deletions

View file

@ -203,10 +203,15 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
_PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]);
goto exit;
}
encoding = PyUnicode_AsUTF8(args[0]);
Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
if (encoding == NULL) {
goto exit;
}
if (strlen(encoding) != (size_t)encoding_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!--noptargs) {
goto skip_optional_pos;
}
@ -215,10 +220,15 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
_PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]);
goto exit;
}
errors = PyUnicode_AsUTF8(args[1]);
Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
if (errors == NULL) {
goto exit;
}
if (strlen(errors) != (size_t)errors_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
skip_optional_pos:
return_value = unicode_encode_impl(self, encoding, errors);
@ -1463,10 +1473,15 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]);
goto exit;
}
encoding = PyUnicode_AsUTF8(fastargs[1]);
Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
if (encoding == NULL) {
goto exit;
}
if (strlen(encoding) != (size_t)encoding_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!--noptargs) {
goto skip_optional_pos;
}
@ -1475,14 +1490,19 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]);
goto exit;
}
errors = PyUnicode_AsUTF8(fastargs[2]);
Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
if (errors == NULL) {
goto exit;
}
if (strlen(errors) != (size_t)errors_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
skip_optional_pos:
return_value = unicode_new_impl(type, x, encoding, errors);
exit:
return return_value;
}
/*[clinic end generated code: output=20313d6339272ddc input=a9049054013a1b77]*/
/*[clinic end generated code: output=873d8b3d09af3095 input=a9049054013a1b77]*/