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

@ -297,18 +297,28 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
_PyArg_BadArgument("blobopen", "argument 1", "str", args[0]);
goto exit;
}
table = PyUnicode_AsUTF8(args[0]);
Py_ssize_t table_length;
table = PyUnicode_AsUTF8AndSize(args[0], &table_length);
if (table == NULL) {
goto exit;
}
if (strlen(table) != (size_t)table_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!PyUnicode_Check(args[1])) {
_PyArg_BadArgument("blobopen", "argument 2", "str", args[1]);
goto exit;
}
col = PyUnicode_AsUTF8(args[1]);
Py_ssize_t col_length;
col = PyUnicode_AsUTF8AndSize(args[1], &col_length);
if (col == NULL) {
goto exit;
}
if (strlen(col) != (size_t)col_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!sqlite3_int64_converter(args[2], &row)) {
goto exit;
}
@ -328,10 +338,15 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
_PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]);
goto exit;
}
name = PyUnicode_AsUTF8(args[4]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[4], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
skip_optional_kwonly:
return_value = blobopen_impl(self, table, col, row, readonly, name);
@ -484,10 +499,15 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
_PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
goto exit;
}
name = PyUnicode_AsUTF8(args[0]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
narg = PyLong_AsInt(args[1]);
if (narg == -1 && PyErr_Occurred()) {
goto exit;
@ -562,10 +582,15 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c
_PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]);
goto exit;
}
name = PyUnicode_AsUTF8(args[0]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
num_params = PyLong_AsInt(args[1]);
if (num_params == -1 && PyErr_Occurred()) {
goto exit;
@ -663,10 +688,15 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl
_PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
goto exit;
}
name = PyUnicode_AsUTF8(args[0]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
n_arg = PyLong_AsInt(args[1]);
if (n_arg == -1 && PyErr_Occurred()) {
goto exit;
@ -1033,10 +1063,15 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
_PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
goto exit;
}
extension_name = PyUnicode_AsUTF8(args[0]);
Py_ssize_t extension_name_length;
extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
if (extension_name == NULL) {
goto exit;
}
if (strlen(extension_name) != (size_t)extension_name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!noptargs) {
goto skip_optional_kwonly;
}
@ -1044,10 +1079,15 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
entrypoint = NULL;
}
else if (PyUnicode_Check(args[1])) {
entrypoint = PyUnicode_AsUTF8(args[1]);
Py_ssize_t entrypoint_length;
entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length);
if (entrypoint == NULL) {
goto exit;
}
if (strlen(entrypoint) != (size_t)entrypoint_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
}
else {
_PyArg_BadArgument("load_extension", "argument 'entrypoint'", "str or None", args[1]);
@ -1266,10 +1306,15 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_
_PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
goto exit;
}
name = PyUnicode_AsUTF8(args[3]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!--noptargs) {
goto skip_optional_kwonly;
}
@ -1335,10 +1380,15 @@ pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cl
_PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
goto exit;
}
name = PyUnicode_AsUTF8(args[0]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
callable = args[1];
return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable);
@ -1412,10 +1462,15 @@ serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, Py
_PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
goto exit;
}
name = PyUnicode_AsUTF8(args[0]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
skip_optional_kwonly:
return_value = serialize_impl(self, name);
@ -1510,10 +1565,15 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
_PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
goto exit;
}
name = PyUnicode_AsUTF8(args[1]);
Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
if (name == NULL) {
goto exit;
}
if (strlen(name) != (size_t)name_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
skip_optional_kwonly:
return_value = deserialize_impl(self, &data, name);
@ -1758,4 +1818,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
/*[clinic end generated code: output=7d2a4d9272f7cb9e input=a9049054013a1b77]*/
/*[clinic end generated code: output=90b5b9c14261b8d7 input=a9049054013a1b77]*/

View file

@ -135,10 +135,15 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
_PyArg_BadArgument("executescript", "argument", "str", arg);
goto exit;
}
sql_script = PyUnicode_AsUTF8(arg);
Py_ssize_t sql_script_length;
sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length);
if (sql_script == NULL) {
goto exit;
}
if (strlen(sql_script) != (size_t)sql_script_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
return_value = pysqlite_cursor_executescript_impl(self, sql_script);
exit:
@ -308,4 +313,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_cursor_close_impl(self);
}
/*[clinic end generated code: output=c772882c7df587ea input=a9049054013a1b77]*/
/*[clinic end generated code: output=a8ce095c3c80cf65 input=a9049054013a1b77]*/

View file

@ -60,10 +60,15 @@ pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t
_PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]);
goto exit;
}
statement = PyUnicode_AsUTF8(args[0]);
Py_ssize_t statement_length;
statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length);
if (statement == NULL) {
goto exit;
}
if (strlen(statement) != (size_t)statement_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
return_value = pysqlite_complete_statement_impl(module, statement);
exit:
@ -203,4 +208,4 @@ skip_optional:
exit:
return return_value;
}
/*[clinic end generated code: output=19016e67830c19eb input=a9049054013a1b77]*/
/*[clinic end generated code: output=457ab0fdbb9e1880 input=a9049054013a1b77]*/

View file

@ -76,10 +76,15 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
*result = NULL;
}
else if (PyUnicode_Check(str_or_none)) {
const char *str = PyUnicode_AsUTF8(str_or_none);
Py_ssize_t sz;
const char *str = PyUnicode_AsUTF8AndSize(str_or_none, &sz);
if (str == NULL) {
return 0;
}
if (strlen(str) != (size_t)sz) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
return 0;
}
const char *level = get_isolation_level(str);
if (level == NULL) {