diff options
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r-- | Modules/_sqlite/cursor.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 861704f..84f4817 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -35,6 +35,28 @@ class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/ +/* + * Registers a cursor with the connection. + * + * 0 => error; 1 => ok + */ +static int +register_cursor(pysqlite_Connection *connection, PyObject *cursor) +{ + PyObject *weakref = PyWeakref_NewRef((PyObject *)cursor, NULL); + if (weakref == NULL) { + return 0; + } + + if (PyList_Append(connection->cursors, weakref) < 0) { + Py_CLEAR(weakref); + return 0; + } + + Py_DECREF(weakref); + return 1; +} + /*[clinic input] _sqlite3.Cursor.__init__ as pysqlite_cursor_init @@ -70,7 +92,7 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self, return -1; } - if (!pysqlite_connection_register_cursor(connection, (PyObject*)self)) { + if (!register_cursor(connection, (PyObject *)self)) { return -1; } |