mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-105927: Avoid calling PyWeakref_GET_OBJECT() (#105997)
* Replace PyWeakref_GET_OBJECT() with _PyWeakref_GET_REF(). * _sqlite/blob.c now holds a strong reference to the blob object while calling close_blob(). * _xidregistry_find_type() now holds a strong reference to registered while using it.
This commit is contained in:
parent
c38da1e3e1
commit
46a3190fcf
3 changed files with 21 additions and 7 deletions
|
@ -1,5 +1,10 @@
|
|||
#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"
|
||||
|
@ -97,10 +102,12 @@ 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_GetObject(weakref);
|
||||
if (!Py_IsNone(blob)) {
|
||||
close_blob((pysqlite_Blob *)blob);
|
||||
PyObject *blob = _PyWeakref_GET_REF(weakref);
|
||||
if (blob == NULL) {
|
||||
continue;
|
||||
}
|
||||
close_blob((pysqlite_Blob *)blob);
|
||||
Py_DECREF(blob);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue