mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)
* Revert "gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)" This reverts commitd9b606b3d0
. * Revert "gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)" This reverts commitcde1071b2a
. * Revert "gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)" This reverts commitd731579bfb
. * Revert "gh-111089: Add PyUnicode_AsUTF8() to the limited C API (#111121)" This reverts commitd8f32be5b6
. * Revert "gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)" This reverts commit37e4e20eaa
.
This commit is contained in:
parent
ea970fb116
commit
11e83488c5
50 changed files with 951 additions and 243 deletions
86
Modules/_sqlite/clinic/connection.c.h
generated
86
Modules/_sqlite/clinic/connection.c.h
generated
|
@ -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]*/
|
||||
|
|
9
Modules/_sqlite/clinic/cursor.c.h
generated
9
Modules/_sqlite/clinic/cursor.c.h
generated
|
@ -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]*/
|
||||
|
|
9
Modules/_sqlite/clinic/module.c.h
generated
9
Modules/_sqlite/clinic/module.c.h
generated
|
@ -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]*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue