Py_DECREF(tp);
}
-/*
- * Registers a cursor with the connection.
- *
- * 0 => error; 1 => ok
- */
-int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor)
-{
- PyObject* weakref;
-
- weakref = PyWeakref_NewRef((PyObject*)cursor, NULL);
- if (!weakref) {
- goto error;
- }
-
- if (PyList_Append(connection->cursors, weakref) != 0) {
- Py_CLEAR(weakref);
- goto error;
- }
-
- Py_DECREF(weakref);
-
- return 1;
-error:
- return 0;
-}
-
/*[clinic input]
_sqlite3.Connection.cursor as pysqlite_connection_cursor
PyObject* NotSupportedError;
} pysqlite_Connection;
-int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor);
int pysqlite_check_thread(pysqlite_Connection* self);
int pysqlite_check_connection(pysqlite_Connection* con);
[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
return -1;
}
- if (!pysqlite_connection_register_cursor(connection, (PyObject*)self)) {
+ if (!register_cursor(connection, (PyObject *)self)) {
return -1;
}