10000 Address review: let connection_close() return a value and the caller … · python/cpython@7b3d032 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b3d032

Browse files
Address review: let connection_close() return a value and the caller decide what to do
1 parent 367f192 commit 7b3d032

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Modules/_sqlite/connection.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
149149
static void free_callback_context(callback_context *ctx);
150150
static void set_callback_context(callback_context **ctx_pp,
151151
callback_context *ctx);
152-
static void connection_close(pysqlite_Connection *self);
152+
static int connection_close(pysqlite_Connection *self);
153153
PyObject *_pysqlite_query_execute(pysqlite_Cursor *, int, PyObject *, PyObject *);
154154

155155
static PyObject *
@@ -249,7 +249,9 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
249249
if (self->initialized) {
250250
PyTypeObject *tp = Py_TYPE(self);
251251
tp->tp_clear((PyObject *)self);
252-
connection_close(self);
252+
if (connection_close(self) < 0) {
253+
return -1;
254+
}
253255
self->initialized = 0;
254256
}
255257

@@ -439,7 +441,7 @@ remove_callbacks(sqlite3 *db)
439441
(void)sqlite3_set_authorizer(db, NULL, NULL);
440442
}
441443

442-
static void
444+
static int
443445
connection_close(pysqlite_Connection *self)
444446
{
445447
if (self->db) {
@@ -452,7 +454,7 @@ connection_close(pysqlite_Connection *self)
452454
remove_callbacks(self->db);
453455
}
454456
if (connection_exec_stmt(self, "ROLLBACK") < 0) {
455-
PyErr_WriteUnraisable((PyObject *)self);
457+
return -1;
456458
}
457459
}
458460

@@ -466,17 +468,21 @@ connection_close(pysqlite_Connection *self)
466468
assert(rc == SQLITE_OK), (void)rc;
467469
Py_END_ALLOW_THREADS
468470
}
471+
return 0;
469472
}
470473

471474
static void
472-
connection_dealloc(pysqlite_Connection *self)
475+
connection_dealloc(PyObject *self)
473476
{
477+
pysqlite_Connection *con = (pysqlite_Connection *)self;
474478
PyTypeObject *tp = Py_TYPE(self);
475479
PyObject_GC_UnTrack(self);
476-
tp->tp_clear((PyObject *)self);
480+
tp->tp_clear(self);
477481

478482
/* Clean up if user has not called .close() explicitly. */
479-
connection_close(self);
483+
if (connection_close(con) < 0) {
484+
PyErr_WriteUnraisable((PyObject *)self);
485+
}
480486

481487
tp->tp_free(self);
482488
Py_DECREF(tp);
@@ -625,7 +631,9 @@ pysqlite_connection_close_impl(pysqlite_Connection *self)
625631

626632
pysqlite_close_all_blobs(self);
627633
Py_CLEAR(self->statement_cache);
628-
connection_close(self);
634+
if (connection_close(self) < 0) {
635+
return NULL;
636+
}
629637

630638
Py_RETURN_NONE;
631639
}

0 commit comments

Comments
 (0)
0