-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-139327: consolidate sqlite3_finalize and sqlite3_reset usages
#139329
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 4 commits
b50713c
a1b9eaa
5653512
6a3a708
44f72e9
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 |
|---|---|---|
|
|
@@ -135,21 +135,22 @@ set_error_from_code(pysqlite_state *state, int code) | |
| /** | ||
| * Checks the SQLite error code and sets the appropriate DB-API exception. | ||
| */ | ||
| void | ||
| int | ||
|
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. In 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. Oh I missed the blob stuff. I think we should also assert this indeed. 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. Also, I think there was an API misuse here. We pass |
||
| set_error_from_db(pysqlite_state *state, sqlite3 *db) | ||
| { | ||
| int errorcode = sqlite3_errcode(db); | ||
| PyObject *exc_class = get_exception_class(state, errorcode); | ||
| if (exc_class == NULL) { | ||
| // No new exception need be raised. | ||
| return; | ||
| return SQLITE_OK; | ||
| } | ||
|
|
||
| /* Create and set the exception. */ | ||
| int extended_errcode = sqlite3_extended_errcode(db); | ||
| // sqlite3_errmsg() always returns an UTF-8 encoded message | ||
| const char *errmsg = sqlite3_errmsg(db); | ||
| raise_exception(exc_class, extended_errcode, errmsg); | ||
| return errorcode; | ||
| } | ||
|
|
||
| #ifdef WORDS_BIGENDIAN | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm a bit unsure whether we should call
Py_CLEAR(self->statement)after a reset failure. If we cannot reset the statement, that means we were not able to free the memory (or maybe it's something else). However, the exact return codes being returned are not documented on sqlite3's side so I can't have a finer check.In other places,
Py_CLEARis always called even in the case of a reset failure, however here we're in the "close" method and thus I don't know if I should callPy_CLEAR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, actually I could have a double-free:
stmt_clearfails but internally manages to free the memory.