summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-06-03 16:38:19 (GMT)
committerGitHub <noreply@github.com>2021-06-03 16:38:19 (GMT)
commitd88b47b5a396aa8d66f9a0e6b13a0825d59d0eff (patch)
treed932a399ff6b69078f5a0bf5874b4e7e438a6b69 /Modules/_sqlite
parent2c1e2583fdc4db6b43d163239ea42b0e8394171f (diff)
downloadcpython-d88b47b5a396aa8d66f9a0e6b13a0825d59d0eff.zip
cpython-d88b47b5a396aa8d66f9a0e6b13a0825d59d0eff.tar.gz
cpython-d88b47b5a396aa8d66f9a0e6b13a0825d59d0eff.tar.bz2
bpo-42213: Remove redundant cyclic GC hack in sqlite3 (GH-26517)
The sqlite3 module now fully implements the GC protocol, so there's no need for this workaround anymore. - Add and use managed resource helper for connections using TESTFN - Sort test imports - Split open-tests into their own test case Automerge-Triggered-By: GH:vstinner
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/cache.c11
-rw-r--r--Modules/_sqlite/cache.h4
-rw-r--r--Modules/_sqlite/connection.c8
3 files changed, 2 insertions, 21 deletions
diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c
index fd4e619..8196e3c 100644
--- a/Modules/_sqlite/cache.c
+++ b/Modules/_sqlite/cache.c
@@ -97,9 +97,6 @@ pysqlite_cache_init(pysqlite_Cache *self, PyObject *args, PyObject *kwargs)
}
self->factory = Py_NewRef(factory);
-
- self->decref_factory = 1;
-
return 0;
}
@@ -108,9 +105,7 @@ cache_traverse(pysqlite_Cache *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->mapping);
- if (self->decref_factory) {
- Py_VISIT(self->factory);
- }
+ Py_VISIT(self->factory);
pysqlite_Node *node = self->first;
while (node) {
@@ -124,9 +119,7 @@ static int
cache_clear(pysqlite_Cache *self)
{
Py_CLEAR(self->mapping);
- if (self->decref_factory) {
- Py_CLEAR(self->factory);
- }
+ Py_CLEAR(self->factory);
/* iterate over all nodes and deallocate them */
pysqlite_Node *node = self->first;
diff --git a/Modules/_sqlite/cache.h b/Modules/_sqlite/cache.h
index 083356f..209c80d 100644
--- a/Modules/_sqlite/cache.h
+++ b/Modules/_sqlite/cache.h
@@ -52,10 +52,6 @@ typedef struct
pysqlite_Node* first;
pysqlite_Node* last;
-
- /* if set, decrement the factory function when the Cache is deallocated.
- * this is almost always desirable, but not in the pysqlite context */
- int decref_factory;
} pysqlite_Cache;
extern PyTypeObject *pysqlite_NodeType;
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 62c4dc3..c1a5677 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -149,14 +149,6 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
return -1;
}
- /* By default, the Cache class INCREFs the factory in its initializer, and
- * decrefs it in its deallocator method. Since this would create a circular
- * reference here, we're breaking it by decrementing self, and telling the
- * cache class to not decref the factory (self) in its deallocator.
- */
- self->statement_cache->decref_factory = 0;
- Py_DECREF(self);
-
self->detect_types = detect_types;
self->timeout = timeout;
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));