aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-06-22 22:31:31 +0200
committerGitHub <noreply@github.com>2023-06-22 22:31:31 +0200
commit46a3190fcf8580f322047395408cd60feba67041 (patch)
treef7a27fae83831b5ce9109f81506e7c5e5c9757e5 /Python/pystate.c
parentc38da1e3e19a7bf1053c6d52e730e970efeceff6 (diff)
downloadcpython-46a3190fcf8580f322047395408cd60feba67041.tar.gz
cpython-46a3190fcf8580f322047395408cd60feba67041.zip
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.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 2c39ac9eb8d..20b02ef2210 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -13,7 +13,8 @@
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
#include "pycore_pystate.h"
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
-#include "pycore_sysmodule.h"
+#include "pycore_sysmodule.h" // _PySys_Audit()
+#include "pycore_weakref.h" // _PyWeakref_GET_REF()
/* --------------------------------------------------------------------------
CAUTION
@@ -2589,16 +2590,18 @@ _xidregistry_find_type(struct _xidregistry *xidregistry, PyTypeObject *cls)
{
struct _xidregitem *cur = xidregistry->head;
while (cur != NULL) {
- PyObject *registered = PyWeakref_GetObject(cur->cls);
- if (registered == Py_None) {
+ PyObject *registered = _PyWeakref_GET_REF(cur->cls);
+ if (registered == NULL) {
// The weakly ref'ed object was freed.
cur = _xidregistry_remove_entry(xidregistry, cur);
}
else {
assert(PyType_Check(registered));
if (registered == (PyObject *)cls) {
+ Py_DECREF(registered);
return cur;
}
+ Py_DECREF(registered);
cur = cur->next;
}
}