Skip to content

gh-103015: Add entrypoint parameter to sqlite3.Connection.load_extension #103073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1041,19 +1041,37 @@ Connection objects
(2, 'broccoli pie', 'broccoli cheese onions flour')
(3, 'pumpkin pie', 'pumpkin sugar flour butter')

.. method:: load_extension(path, /)
.. method:: load_extension(path, /, *, entrypoint=None)

Load an SQLite extension from a shared library located at *path*.
Load an SQLite extension from a shared library.
Enable extension loading with :meth:`enable_load_extension` before
calling this method.

:param str path:

The path to the SQLite extension.

:param entrypoint:

Entry point name.
If ``None`` (the default),
SQLite will come up with an entry point name of its own;
see the SQLite docs `Loading an Extension`_ for details.

:type entrypoint: str | None

.. audit-event:: sqlite3.load_extension connection,path sqlite3.Connection.load_extension

.. versionadded:: 3.2

.. versionchanged:: 3.10
Added the ``sqlite3.load_extension`` auditing event.

.. versionadded:: 3.12
The *entrypoint* parameter.

.. _Loading an Extension: https://www.sqlite.org/loadext.html#loading_an_extension_

.. method:: iterdump

Return an :term:`iterator` to dump the database as SQL source code.
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ sqlite3
:ref:`transaction handling <sqlite3-transaction-control-autocommit>`.
(Contributed by Erlend E. Aasland in :gh:`83638`.)

* Add *entrypoint* keyword-only parameter to
:meth:`~sqlite3.Connection.load_extension`,
for overriding the SQLite extension entry point.
(Contributed by Erlend E. Aasland in :gh:`103015`.)

threading
---------

Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(end_lineno)
STRUCT_FOR_ID(end_offset)
STRUCT_FOR_ID(endpos)
STRUCT_FOR_ID(entrypoint)
STRUCT_FOR_ID(env)
STRUCT_FOR_ID(errors)
STRUCT_FOR_ID(event)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add *entrypoint* keyword-only parameter to
:meth:`sqlite3.Connection.load_extension`, for overriding the SQLite
extension entry point. Patch by Erlend E. Aasland.
73 changes: 64 additions & 9 deletions Modules/_sqlite/clinic/connection.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,14 +1601,17 @@ _sqlite3.Connection.load_extension as pysqlite_connection_load_extension

name as extension_name: str
/
*
entrypoint: str(accept={str, NoneType}) = None

Load SQLite extension module.
[clinic start generated code]*/

static PyObject *
pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
const char *extension_name)
/*[clinic end generated code: output=47eb1d7312bc97a7 input=edd507389d89d621]*/
const char *extension_name,
const char *entrypoint)
/*[clinic end generated code: output=7e61a7add9de0286 input=c36b14ea702e04f5]*/
{
int rc;
char* errmsg;
Expand All @@ -1621,7 +1624,7 @@ pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
return NULL;
}

rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg);
rc = sqlite3_load_extension(self->db, extension_name, entrypoint, &errmsg);
if (rc != 0) {
PyErr_SetString(self->OperationalError, errmsg);
return NULL;
Expand Down