summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/clinic
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2023-04-26 19:22:03 (GMT)
committerGitHub <noreply@github.com>2023-04-26 19:22:03 (GMT)
commit222c63fc6b91f42e7cc53574615f4e9b7a33c28f (patch)
tree92bc902ce83e10b4fcad67cccfa292e3851a98c0 /Modules/_sqlite/clinic
parent28a05f4cc2b150b3ff02ec255daf1b6ec886ca6f (diff)
downloadcpython-222c63fc6b91f42e7cc53574615f4e9b7a33c28f.zip
cpython-222c63fc6b91f42e7cc53574615f4e9b7a33c28f.tar.gz
cpython-222c63fc6b91f42e7cc53574615f4e9b7a33c28f.tar.bz2
gh-103015: Add entrypoint keyword param to sqlite3.Connection.load_extension (#103073)
Diffstat (limited to 'Modules/_sqlite/clinic')
-rw-r--r--Modules/_sqlite/clinic/connection.c.h73
1 files changed, 64 insertions, 9 deletions
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
index 4c3fd1b..090f5d8 100644
--- a/Modules/_sqlite/clinic/connection.c.h
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -846,30 +846,63 @@ exit:
#if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
-"load_extension($self, name, /)\n"
+"load_extension($self, name, /, *, entrypoint=None)\n"
"--\n"
"\n"
"Load SQLite extension module.");
#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF \
- {"load_extension", (PyCFunction)pysqlite_connection_load_extension, METH_O, pysqlite_connection_load_extension__doc__},
+ {"load_extension", _PyCFunction_CAST(pysqlite_connection_load_extension), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_load_extension__doc__},
static PyObject *
pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
- const char *extension_name);
+ const char *extension_name,
+ const char *entrypoint);
static PyObject *
-pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *arg)
+pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 1
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(entrypoint), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"", "entrypoint", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "load_extension",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
const char *extension_name;
+ const char *entrypoint = NULL;
- if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("load_extension", "argument", "str", arg);
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
goto exit;
}
Py_ssize_t extension_name_length;
- extension_name = PyUnicode_AsUTF8AndSize(arg, &extension_name_length);
+ extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
if (extension_name == NULL) {
goto exit;
}
@@ -877,7 +910,29 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *arg)
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- return_value = pysqlite_connection_load_extension_impl(self, extension_name);
+ if (!noptargs) {
+ goto skip_optional_kwonly;
+ }
+ if (args[1] == Py_None) {
+ entrypoint = NULL;
+ }
+ else if (PyUnicode_Check(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]);
+ goto exit;
+ }
+skip_optional_kwonly:
+ return_value = pysqlite_connection_load_extension_impl(self, extension_name, entrypoint);
exit:
return return_value;
@@ -1532,4 +1587,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=f10306e10427488b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=833f0e27cd3a4560 input=a9049054013a1b77]*/