Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 355625a

Browse files
committedAug 5, 2022
gh-95348: Update new functions in weakrefobject.c
1 parent 8a24c4f commit 355625a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎Objects/weakrefobject.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,41 @@ new_weakref(PyObject *ob, PyObject *callback)
4747

4848

4949
/* This function is responsible for clearing the callback slot. When using this
50-
* It must be called before calling remove_weakref, otherwise a segmentation fault will
51-
* occur at build time.
50+
* function it must be called before calling remove_weakref_from_referent,
51+
* otherwise a segmentation fault will occur at build time.
5252
*/
5353
static void
5454
clear_weakref(PyWeakReference *self)
5555
{
5656
PyObject *callback = self->wr_callback;
57+
5758
if (callback != NULL) {
5859
Py_DECREF(callback);
5960
self->wr_callback = NULL;
6061
}
6162
}
6263

63-
/* This function removes the pass in reference from the list of weak references
64-
* for the referent. This should be called from remove_weakref_fromt_referent
65-
* as it will pass the required list argument.
64+
/* This function removes the pass in reference from the list of weak
65+
* references for the referent. This should be called from
66+
* remove_weakref_fromt_referent as it will pass the required list
67+
* argument.
6668
*/
6769
static void
6870
remove_weakref(PyWeakReference *self, PyWeakReference **list)
6971
{
70-
if (*list == self)
72+
if (*list == self) {
7173
/* If 'self' is the end of the list (and thus self->wr_next == NULL)
7274
then the weakref list itself (and thus the value of *list) will
7375
end up being set to NULL. */
7476
*list = self->wr_next;
77+
}
7578
self->wr_object = Py_None;
76-
if (self->wr_prev != NULL)
79+
if (self->wr_prev != NULL) {
7780
self->wr_prev->wr_next = self->wr_next;
78-
if (self->wr_next != NULL)
81+
}
82+
if (self->wr_next != NULL) {
7983
self->wr_next->wr_prev = self->wr_prev;
84+
}
8085
self->wr_prev = NULL;
8186
self->wr_next = NULL;
8287
}

0 commit comments

Comments
 (0)
Please sign in to comment.