-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-42213: Remove redundant cyclic GC hack in sqlite3 #26462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
70511f3
6cb435b
1e3f589
5ff1a80
866e226
063878c
b53aacb
e0ffe76
4ebb593
7d8014a
1b23df1
d31403e
aba8dd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,14 +149,6 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args, | |
return -1; | ||
} | ||
|
||
/* By default, the Cache class INCREFs the factory in its initializer, and | ||
* decrefs it in its deallocator method. Since this would create a circular | ||
* reference here, we're breaking it by decrementing self, and telling the | ||
* cache class to not decref the factory (self) in its deallocator. | ||
*/ | ||
self->statement_cache->decref_factory = 0; | ||
Py_DECREF(self); | ||
|
||
self->detect_types = detect_types; | ||
self->timeout = timeout; | ||
(void)sqlite3_busy_timeout(self->db, (int)(timeout*1000)); | ||
|
@@ -258,6 +250,16 @@ connection_clear(pysqlite_Connection *self) | |
return 0; | ||
} | ||
|
||
static void | ||
connection_close(pysqlite_Connection *self) | ||
{ | ||
if (self->db) { | ||
int rc = sqlite3_close_v2(self->db); | ||
assert(rc == SQLITE_OK); | ||
self->db = NULL; | ||
} | ||
} | ||
|
||
static void | ||
connection_dealloc(pysqlite_Connection *self) | ||
{ | ||
|
@@ -266,9 +268,7 @@ connection_dealloc(pysqlite_Connection *self) | |
tp->tp_clear((PyObject *)self); | ||
|
||
/* Clean up if user has not called .close() explicitly. */ | ||
if (self->db) { | ||
sqlite3_close_v2(self->db); | ||
} | ||
connection_close(self); | ||
|
||
tp->tp_free(self); | ||
Py_DECREF(tp); | ||
|
@@ -353,23 +353,18 @@ static PyObject * | |
pysqlite_connection_close_impl(pysqlite_Connection *self) | ||
/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/ | ||
{ | ||
int rc; | ||
|
||
if (!pysqlite_check_thread(self)) { | ||
return NULL; | ||
} | ||
|
||
pysqlite_do_all_statements(self, ACTION_FINALIZE, 1); | ||
|
||
if (self->db) { | ||
rc = sqlite3_close_v2(self->db); | ||
/* Free pending statements before closing. This implies also cleaning | ||
* up cursors, as they may have strong refs to statements. */ | ||
Py_CLEAR(self->statement_cache); | ||
Py_CLEAR(self->statements); | ||
Py_CLEAR(self->cursors); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if you use the connection after you call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll get a After close, if you try to use a cursor, fetch from a pending statement, or manipulate the connection, you'll get a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some more tests wrt. this: 1b23df1 Let me know if you want me to add more tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a strange observation: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc. @vstinner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CI seems to be fine with this: erlend-aasland#9 |
||
|
||
if (rc != SQLITE_OK) { | ||
_pysqlite_seterror(self->db); | ||
return NULL; | ||
} else { | ||
self->db = NULL; | ||
} | ||
connection_close(self); | ||
} | ||
|
||
Py_RETURN_NONE; | ||
|
Uh oh!
There was an error while loading. Please reload this page.