|
7 | 7 | #include "pycore_moduleobject.h" // _PyModule_GetState()
|
8 | 8 | #include "pycore_pylifecycle.h"
|
9 | 9 | #include "pycore_pystate.h" // _PyThreadState_SetCurrent()
|
| 10 | +#include "pycore_weakref.h" // _PyWeakref_GET_REF() |
10 | 11 | #include <stddef.h> // offsetof()
|
11 | 12 | #include "structmember.h" // PyMemberDef
|
12 | 13 |
|
@@ -1024,25 +1025,23 @@ local_getattro(localobject *self, PyObject *name)
|
1024 | 1025 | static PyObject *
|
1025 | 1026 | _localdummy_destroyed(PyObject *localweakref, PyObject *dummyweakref)
|
1026 | 1027 | {
|
1027 |
| - assert(PyWeakref_CheckRef(localweakref)); |
1028 |
| - PyObject *obj = PyWeakref_GET_OBJECT(localweakref); |
1029 |
| - if (obj == Py_None) { |
| 1028 | + localobject *self = (localobject *)_PyWeakref_GET_REF(localweakref); |
| 1029 | + if (self == NULL) { |
1030 | 1030 | Py_RETURN_NONE;
|
1031 | 1031 | }
|
1032 | 1032 |
|
1033 | 1033 | /* If the thread-local object is still alive and not being cleared,
|
1034 | 1034 | remove the corresponding local dict */
|
1035 |
| - localobject *self = (localobject *)Py_NewRef(obj); |
1036 | 1035 | if (self->dummies != NULL) {
|
1037 | 1036 | PyObject *ldict;
|
1038 | 1037 | ldict = PyDict_GetItemWithError(self->dummies, dummyweakref);
|
1039 | 1038 | if (ldict != NULL) {
|
1040 | 1039 | PyDict_DelItem(self->dummies, dummyweakref);
|
1041 | 1040 | }
|
1042 | 1041 | if (PyErr_Occurred())
|
1043 |
| - PyErr_WriteUnraisable(obj); |
| 1042 | + PyErr_WriteUnraisable((PyObject*)self); |
1044 | 1043 | }
|
1045 |
| - Py_DECREF(obj); |
| 1044 | + Py_DECREF(self); |
1046 | 1045 | Py_RETURN_NONE;
|
1047 | 1046 | }
|
1048 | 1047 |
|
@@ -1314,24 +1313,25 @@ This function is meant for internal and specialized purposes only.\n\
|
1314 | 1313 | In most applications `threading.enumerate()` should be used instead.");
|
1315 | 1314 |
|
1316 | 1315 | static void
|
1317 |
| -release_sentinel(void *wr_raw) |
| 1316 | +release_sentinel(void *weakref_raw) |
1318 | 1317 | {
|
1319 |
| - PyObject *wr = _PyObject_CAST(wr_raw); |
| 1318 | + PyObject *weakref = _PyObject_CAST(weakref_raw); |
| 1319 | + |
1320 | 1320 | /* Tricky: this function is called when the current thread state
|
1321 | 1321 | is being deleted. Therefore, only simple C code can safely
|
1322 | 1322 | execute here. */
|
1323 |
| - PyObject *obj = PyWeakref_GET_OBJECT(wr); |
1324 |
| - lockobject *lock; |
1325 |
| - if (obj != Py_None) { |
1326 |
| - lock = (lockobject *) obj; |
| 1323 | + lockobject *lock = (lockobject *)_PyWeakref_GET_REF(weakref); |
| 1324 | + if (lock != NULL) { |
1327 | 1325 | if (lock->locked) {
|
1328 | 1326 | PyThread_release_lock(lock->lock_lock);
|
1329 | 1327 | lock->locked = 0;
|
1330 | 1328 | }
|
| 1329 | + Py_DECREF(lock); |
1331 | 1330 | }
|
| 1331 | + |
1332 | 1332 | /* Deallocating a weakref with a NULL callback only calls
|
1333 | 1333 | PyObject_GC_Del(), which can't call any Python code. */
|
1334 |
| - Py_DECREF(wr); |
| 1334 | + Py_DECREF(weakref); |
1335 | 1335 | }
|
1336 | 1336 |
|
1337 | 1337 | static PyObject *
|
|
0 commit comments