Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70511f3

Browse files
author
Erlend E. Aasland
committed
bpo-42213: Remove redundant cyclic GC hack in sqlite3
The sqlite3 module now fully implements the GC protocol, so there's no need for this workaround anymore.
1 parent fffa0f9 commit 70511f3

File tree

3 files changed

+2
-21
lines changed

3 files changed

+2
-21
lines changed

Modules/_sqlite/cache.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ pysqlite_cache_init(pysqlite_Cache *self, PyObject *args, PyObject *kwargs)
9797
}
9898

9999
self->factory = Py_NewRef(factory);
100-
101-
self->decref_factory = 1;
102-
103100
return 0;
104101
}
105102

@@ -108,9 +105,7 @@ cache_traverse(pysqlite_Cache *self, visitproc visit, void *arg)
108105
{
109106
Py_VISIT(Py_TYPE(self));
110107
Py_VISIT(self->mapping);
111-
if (self->decref_factory) {
112-
Py_VISIT(self->factory);
113-
}
108+
Py_VISIT(self->factory);
114109

115110
pysqlite_Node *node = self->first;
116111
while (node) {
@@ -124,9 +119,7 @@ static int
124119
cache_clear(pysqlite_Cache *self)
125120
{
126121
Py_CLEAR(self->mapping);
127-
if (self->decref_factory) {
128-
Py_CLEAR(self->factory);
129-
}
122+
Py_CLEAR(self->factory);
130123

131124
/* iterate over all nodes and deallocate them */
132125
pysqlite_Node *node = self->first;

Modules/_sqlite/cache.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ typedef struct
5252

5353
pysqlite_Node* first;
5454
pysqlite_Node* last;
55-
56-
/* if set, decrement the factory function when the Cache is deallocated.
57-
* this is almost always desirable, but not in the pysqlite context */
58-
int decref_factory;
5955
} pysqlite_Cache;
6056

6157
extern PyTypeObject *pysqlite_NodeType;

Modules/_sqlite/connection.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
149149
return -1;
150150
}
151151

152-
/* By default, the Cache class INCREFs the factory in its initializer, and
153-
* decrefs it in its deallocator method. Since this would create a circular
154-
* reference here, we're breaking it by decrementing self, and telling the
155-
* cache class to not decref the factory (self) in its deallocator.
156-
*/
157-
self->statement_cache->decref_factory = 0;
158-
Py_DECREF(self);
159-
160152
self->detect_types = detect_types;
161153
self->timeout = timeout;
162154
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));

0 commit comments

Comments
 (0)