Skip to content

Commit

Permalink
pythongh-106104: Use public weakref APIs in sqlite3
Browse files Browse the repository at this point in the history
The sqlite3 extension module should be built using the public API, so
we're removing the Py_BUILD_CORE_MODULE define that was introduced as
part of the pythongh-105927 changes.
  • Loading branch information
erlend-aasland committed Jun 26, 2023
1 parent c075a19 commit 43cbf83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
19 changes: 10 additions & 9 deletions Modules/_sqlite/blob.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif

#include "blob.h"
#include "util.h"
#include "pycore_weakref.h" // _PyWeakref_GET_REF()

#define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
#include "clinic/blob.c.h"
Expand Down Expand Up @@ -102,12 +97,18 @@ pysqlite_close_all_blobs(pysqlite_Connection *self)
{
for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
PyObject *weakref = PyList_GET_ITEM(self->blobs, i);
PyObject *blob = _PyWeakref_GET_REF(weakref);
if (blob == NULL) {
PyObject *blob;
if (!PyWeakref_Check(weakref)) {
continue;
}
close_blob((pysqlite_Blob *)blob);
Py_DECREF(blob);
if (PyWeakref_GetRef(weakref, &blob) < 0) {
PyErr_WriteUnraisable((PyObject *)self);
continue;
}
if (blob) {
close_blob((pysqlite_Blob *)blob);
Py_DECREF(blob);
}
}
}

Expand Down
24 changes: 14 additions & 10 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
* 3. This notice may not be removed or altered from any source distribution.
*/

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif

#include "module.h"
#include "structmember.h" // PyMemberDef
#include "connection.h"
Expand All @@ -33,7 +29,6 @@
#include "blob.h"
#include "prepare_protocol.h"
#include "util.h"
#include "pycore_weakref.h" // _PyWeakref_IS_DEAD()

#include <stdbool.h>

Expand Down Expand Up @@ -987,13 +982,22 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
}

for (Py_ssize_t i = 0; i < PyList_Size(self->cursors); i++) {
PyObject* weakref = PyList_GetItem(self->cursors, i);
if (_PyWeakref_IS_DEAD(weakref)) {
PyObject *weakref = PyList_GetItem(self->cursors, i);
PyObject *item;
if (!PyWeakref_Check(weakref)) {
continue;
}
if (PyList_Append(new_list, weakref) != 0) {
Py_DECREF(new_list);
return;
if (PyWeakref_GetRef(weakref, &item) < 0) {
PyErr_WriteUnraisable((PyObject *)self);
continue;
}
if (item) {
int rc = PyList_Append(new_list, item);
Py_DECREF(item);
if (rc < 0) {
Py_DECREF(new_list);
return;
}
}
}

Expand Down

0 comments on commit 43cbf83

Please sign in to comment.