summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-11-01 15:34:42 (GMT)
committerGitHub <noreply@github.com>2023-11-01 15:34:42 (GMT)
commitd9b606b3d04fc56fb0bcc479d7d6c14562edb5e2 (patch)
tree14d10605507380e411d5f62e5bab28f74091129d /Modules/_sqlite
parent97b3cd38d105fd891ba46dd27d08f03d1c6dd348 (diff)
downloadcpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.zip
cpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.tar.gz
cpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.tar.bz2
gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)
Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove the explicit check for embedded null characters. The change avoids to have to include explicitly <string.h> to get the strlen() function when using a recent version of the limited C API.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/clinic/connection.c.h86
-rw-r--r--Modules/_sqlite/clinic/cursor.c.h9
-rw-r--r--Modules/_sqlite/clinic/module.c.h9
3 files changed, 17 insertions, 87 deletions
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
index db5eb77..8e1a574 100644
--- a/Modules/_sqlite/clinic/connection.c.h
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -297,28 +297,18 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
_PyArg_BadArgument("blobopen", "argument 1", "str", args[0]);
goto exit;
}
- Py_ssize_t table_length;
- table = PyUnicode_AsUTF8AndSize(args[0], &table_length);
+ table = PyUnicode_AsUTF8(args[0]);
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;
}
- Py_ssize_t col_length;
- col = PyUnicode_AsUTF8AndSize(args[1], &col_length);
+ col = PyUnicode_AsUTF8(args[1]);
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;
}
@@ -338,15 +328,10 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
_PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[4], &name_length);
+ name = PyUnicode_AsUTF8(args[4]);
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);
@@ -499,15 +484,10 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
_PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ name = PyUnicode_AsUTF8(args[0]);
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;
@@ -582,15 +562,10 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c
_PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ name = PyUnicode_AsUTF8(args[0]);
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;
@@ -688,15 +663,10 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl
_PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ name = PyUnicode_AsUTF8(args[0]);
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;
@@ -1063,15 +1033,10 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
_PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
goto exit;
}
- Py_ssize_t extension_name_length;
- extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
+ extension_name = PyUnicode_AsUTF8(args[0]);
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;
}
@@ -1079,15 +1044,10 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a
entrypoint = NULL;
}
else if (PyUnicode_Check(args[1])) {
- Py_ssize_t entrypoint_length;
- entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length);
+ entrypoint = PyUnicode_AsUTF8(args[1]);
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]);
@@ -1306,15 +1266,10 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_
_PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
+ name = PyUnicode_AsUTF8(args[3]);
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;
}
@@ -1380,15 +1335,10 @@ pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cl
_PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ name = PyUnicode_AsUTF8(args[0]);
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);
@@ -1462,15 +1412,10 @@ serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, Py
_PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ name = PyUnicode_AsUTF8(args[0]);
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);
@@ -1565,15 +1510,10 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
_PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
goto exit;
}
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
+ name = PyUnicode_AsUTF8(args[1]);
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);
@@ -1818,4 +1758,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=90b5b9c14261b8d7 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7d2a4d9272f7cb9e input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h
index a13e0d0..7a58503 100644
--- a/Modules/_sqlite/clinic/cursor.c.h
+++ b/Modules/_sqlite/clinic/cursor.c.h
@@ -135,15 +135,10 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
_PyArg_BadArgument("executescript", "argument", "str", arg);
goto exit;
}
- Py_ssize_t sql_script_length;
- sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length);
+ sql_script = PyUnicode_AsUTF8(arg);
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:
@@ -313,4 +308,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_cursor_close_impl(self);
}
-/*[clinic end generated code: output=a8ce095c3c80cf65 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c772882c7df587ea input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/module.c.h b/Modules/_sqlite/clinic/module.c.h
index 529dc4e..d3c7ad8 100644
--- a/Modules/_sqlite/clinic/module.c.h
+++ b/Modules/_sqlite/clinic/module.c.h
@@ -60,15 +60,10 @@ pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t
_PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]);
goto exit;
}
- Py_ssize_t statement_length;
- statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length);
+ statement = PyUnicode_AsUTF8(args[0]);
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:
@@ -208,4 +203,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=457ab0fdbb9e1880 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=19016e67830c19eb input=a9049054013a1b77]*/