Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-105927: _abc and _thread use PyWeakref_GetRef()#105961

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:getref
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletionsModules/_abc.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@
#include"pycore_object.h"// _PyType_GetSubclasses()
#include"pycore_runtime.h"// _Py_ID()
#include"pycore_typeobject.h"// _PyType_GetMRO()
#include"pycore_weakref.h"// _PyWeakref_GET_REF()
#include"clinic/_abc.c.h"

/*[clinic input]
Expand DownExpand Up@@ -150,12 +151,10 @@ _in_weak_set(PyObject *set, PyObject *obj)
staticPyObject*
_destroy(PyObject*setweakref,PyObject*objweakref)
{
PyObject*set;
set=PyWeakref_GET_OBJECT(setweakref);
if (set==Py_None) {
PyObject*set=_PyWeakref_GET_REF(setweakref);
if (set==NULL) {
Py_RETURN_NONE;
}
Py_INCREF(set);
if (PySet_Discard(set,objweakref)<0) {
Py_DECREF(set);
returnNULL;
Expand DownExpand Up@@ -843,16 +842,16 @@ subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
assert(i==registry_size);

for (i=0;i<registry_size;i++) {
PyObject*rkey=PyWeakref_GetObject(copy[i]);
if (rkey==NULL) {
PyObject*rkey;
if (PyWeakref_GetRef(copy[i],&rkey)<0) {
// Someone inject non-weakref type in the registry.
ret=-1;
break;
}
if (rkey==Py_None) {

if (rkey==NULL) {
continue;
}
Py_INCREF(rkey);
intr=PyObject_IsSubclass(subclass,rkey);
Py_DECREF(rkey);
if (r<0) {
Expand Down
26 changes: 13 additions & 13 deletionsModules/_threadmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pylifecycle.h"
#include "pycore_pystate.h" // _PyThreadState_SetCurrent()
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
#include <stddef.h> // offsetof()
#include "structmember.h" // PyMemberDef

Expand DownExpand Up@@ -1024,25 +1025,23 @@ local_getattro(localobject *self, PyObject *name)
static PyObject *
_localdummy_destroyed(PyObject *localweakref, PyObject *dummyweakref)
{
assert(PyWeakref_CheckRef(localweakref));
PyObject *obj = PyWeakref_GET_OBJECT(localweakref);
if (obj == Py_None) {
localobject *self = (localobject *)_PyWeakref_GET_REF(localweakref);
if (self == NULL) {
Py_RETURN_NONE;
}

/* If the thread-local object is still alive and not being cleared,
remove the corresponding local dict */
localobject *self = (localobject *)Py_NewRef(obj);
if (self->dummies != NULL) {
PyObject *ldict;
ldict = PyDict_GetItemWithError(self->dummies, dummyweakref);
if (ldict != NULL) {
PyDict_DelItem(self->dummies, dummyweakref);
}
if (PyErr_Occurred())
PyErr_WriteUnraisable(obj);
PyErr_WriteUnraisable((PyObject*)self);
}
Py_DECREF(obj);
Py_DECREF(self);
Py_RETURN_NONE;
}

Expand DownExpand Up@@ -1314,24 +1313,25 @@ This function is meant for internal and specialized purposes only.\n\
In most applications `threading.enumerate()` should be used instead.");

static void
release_sentinel(void *wr_raw)
release_sentinel(void *weakref_raw)
{
PyObject *wr = _PyObject_CAST(wr_raw);
PyObject *weakref = _PyObject_CAST(weakref_raw);

/* Tricky: this function is called when the current thread state
is being deleted. Therefore, only simple C code can safely
execute here. */
PyObject *obj = PyWeakref_GET_OBJECT(wr);
lockobject *lock;
if (obj != Py_None) {
lock = (lockobject *) obj;
lockobject *lock = (lockobject *)_PyWeakref_GET_REF(weakref);
if (lock != NULL) {
if (lock->locked) {
PyThread_release_lock(lock->lock_lock);
lock->locked = 0;
}
Py_DECREF(lock);
}

/* Deallocating a weakref with a NULL callback only calls
PyObject_GC_Del(), which can't call any Python code. */
Py_DECREF(wr);
Py_DECREF(weakref);
}

static PyObject *
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp