aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_sqlite/module.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-06-03 21:59:26 +0200
committerGitHub <noreply@github.com>2021-06-03 20:59:26 +0100
commitf461a7fc3f8740b9e79e8874175115a3474e5930 (patch)
treec3338f262e91aa6468ce5be059d473bf830a0274 /Modules/_sqlite/module.c
parentf3fa63ec75fdbb4a08a10957a5c631bf0c4a5970 (diff)
downloadcpython-f461a7fc3f8740b9e79e8874175115a3474e5930.tar.gz
cpython-f461a7fc3f8740b9e79e8874175115a3474e5930.zip
bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module (GH-24203)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r--Modules/_sqlite/module.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index a5e5525481f..c60007e2059 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -24,7 +24,6 @@
#include "connection.h"
#include "statement.h"
#include "cursor.h"
-#include "cache.h"
#include "prepare_protocol.h"
#include "microprotocols.h"
#include "row.h"
@@ -56,6 +55,14 @@ PyObject* _pysqlite_converters = NULL;
int _pysqlite_enable_callback_tracebacks = 0;
int pysqlite_BaseTypeAdapted = 0;
+pysqlite_state pysqlite_global_state;
+
+pysqlite_state *
+pysqlite_get_state(PyObject *Py_UNUSED(module))
+{
+ return &pysqlite_global_state;
+}
+
static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
kwargs)
{
@@ -261,6 +268,23 @@ static int converters_init(PyObject* module)
return res;
}
+static int
+load_functools_lru_cache(PyObject *module)
+{
+ PyObject *functools = PyImport_ImportModule("functools");
+ if (functools == NULL) {
+ return -1;
+ }
+
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->lru_cache = PyObject_GetAttrString(functools, "lru_cache");
+ Py_DECREF(functools);
+ if (state->lru_cache == NULL) {
+ return -1;
+ }
+ return 0;
+}
+
static PyMethodDef module_methods[] = {
{"connect", (PyCFunction)(void(*)(void))module_connect,
METH_VARARGS | METH_KEYWORDS, module_connect_doc},
@@ -373,7 +397,6 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
(pysqlite_row_setup_types(module) < 0) ||
(pysqlite_cursor_setup_types(module) < 0) ||
(pysqlite_connection_setup_types(module) < 0) ||
- (pysqlite_cache_setup_types(module) < 0) ||
(pysqlite_statement_setup_types(module) < 0) ||
(pysqlite_prepare_protocol_setup_types(module) < 0)
) {
@@ -424,6 +447,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
goto error;
}
+ if (load_functools_lru_cache(module) < 0) {
+ goto error;
+ }
+
return module;
error: