8000 sqlite.Connection type now implements GC protocol · python/cpython@6ece632 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ece632

Browse files
author
Erlend E. Aasland
committed
sqlite.Connection type now implements GC protocol
1 parent 504ffda commit 6ece632

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

Modules/_sqlite/connection.c

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,28 +225,51 @@ pysqlite_do_all_statements(pysqlite_Connection *self, int action,
225225
}
226226
}
227227

228+
static int
229+
connection_traverse(pysqlite_Connection *self, visitproc visit, void *arg)
230+
{
231+
Py_VISIT(self->statement_cache);
232+
Py_VISIT(self->function_pinboard_trace_callback);
233+
Py_VISIT(self->function_pinboard_progress_handler);
234+
Py_VISIT(self->function_pinboard_authorizer_cb);
235+
Py_VISIT(self->row_factory);
236+
Py_VISIT(self->text_factory);
237+
Py_VISIT(self->collations);
238+
Py_VISIT(self->statements);
239+
Py_VISIT(self->cursors);
240+
Py_VISIT(Py_TYPE(self));
241+
return 0;
242+
}
243+
244+
static int
245+
connection_clear(pysqlite_Connection *self)
246+
{
247+
Py_CLEAR(self->statement_cache);
248+
Py_CLEAR(self->isolation_level);
249+
Py_CLEAR(self->function_pinboard_trace_callback);
250+
Py_CLEAR(self->function_pinboard_progress_handler);
251+
Py_CLEAR(self->function_pinboard_authorizer_cb);
252+
Py_CLEAR(self->row_factory);
253+
Py_CLEAR(self->text_factory);
254+
Py_CLEAR(self->collations);
255+
Py_CLEAR(self->statements);
256+
Py_CLEAR(self->cursors);
257+
return 0;
258+
}
259+
228260
static void
229261
pysqlite_connection_dealloc(pysqlite_Connection *self)
230262
{
231263
PyTypeObject *tp = Py_TYPE(self);
232-
233-
Py_XDECREF(self->statement_cache);
264+
PyObject_GC_UnTrack(self);
265+
tp->tp_clear((PyObject *)self);
234266

235267
/* Clean up if user has not called .close() explicitly. */
236268
if (self->db) {
237269
sqlite3_close_v2(self->db);
270+
self->db = NULL;
238271
}
239272

240-
Py_XDECREF(self->isolation_level);
241-
Py_XDECREF(self->function_pinboard_trace_callback);
242-
Py_XDECREF(self->function_pinboard_progress_handler);
243-
Py_XDECREF(self->function_pinboard_authorizer_cb);
244-
Py_XDECREF(self->row_factory);
245-
Py_XDECREF(self->text_factory);
246-
Py_XDECREF(self->collations);
247-
Py_XDECREF(self->statements);
248-
Py_XDECREF(self->cursors);
249-
250273
tp->tp_free(self);
251274
Py_DECREF(tp);
252275
}
@@ -1914,16 +1937,17 @@ static PyType_Slot connection_slots[] = {
19141937
{Py_tp_methods, connection_methods},
19151938
{Py_tp_members, connection_members},
19161939
{Py_tp_getset, connection_getset},
1917-
{Py_tp_new, PyType_GenericNew},
19181940
{Py_tp_init, pysqlite_connection_init},
19191941
{Py_tp_call, pysqlite_connection_call},
1942+
{Py_tp_traverse, connection_traverse},
1943+
{Py_tp_clear, connection_clear},
19201944
{0, NULL},
19211945
};
19221946

19231947
static PyType_Spec connection_spec = {
19241948
.name = MODULE_NAME ".Connection",
19251949
.basicsize = sizeof(pysqlite_Connection),
1926-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1950+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
19271951
.slots = connection_slots,
19281952
};
19291953

0 commit comments

Comments
 (0)
0