Skip to content

Commit 3b23da2

Browse files
committed
Simplify _PyGC_SET_FINALIZED
1 parent cedc2e5 commit 3b23da2

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Include/objimpl.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ extern PyGC_Head *_PyGC_generation0;
261261

262262
#define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)
263263

264+
/* Bit flags for gc_prev */
264265
/* Bit 0 is set when tp_finalize is called */
265266
#define _PyGC_PREV_MASK_FINALIZED (1 << 0)
266267
/* Bit 1 and 2 is used in gcmodule.c */
@@ -276,13 +277,10 @@ extern PyGC_Head *_PyGC_generation0;
276277
} while (0)
277278

278279
#define _PyGCHead_FINALIZED(g) (((g)->gc.gc_prev & _PyGC_PREV_MASK_FINALIZED) != 0)
279-
#define _PyGCHead_SET_FINALIZED(g, v) do { \
280-
(g)->gc.gc_prev = ((g)->gc.gc_prev & ~_PyGC_PREV_MASK_FINALIZED) \
281-
| (v != 0); \
282-
} while (0)
280+
#define _PyGCHead_SET_FINALIZED(g) ((g)->gc.gc_prev |= _PyGC_PREV_MASK_FINALIZED)
283281

284282
#define _PyGC_FINALIZED(o) _PyGCHead_FINALIZED(_Py_AS_GC(o))
285-
#define _PyGC_SET_FINALIZED(o, v) _PyGCHead_SET_FINALIZED(_Py_AS_GC(o), v)
283+
#define _PyGC_SET_FINALIZED(o) _PyGCHead_SET_FINALIZED(_Py_AS_GC(o))
286284

287285
/* Tell the GC to track this object. NB: While the object is tracked the
288286
* collector it must be safe to call the ob_traverse method. */

Modules/gcmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ finalize_garbage(PyGC_Head *collectable)
772772
if (!_PyGCHead_FINALIZED(gc) &&
773773
PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_HAVE_FINALIZE) &&
774774
(finalize = Py_TYPE(op)->tp_finalize) != NULL) {
775-
_PyGCHead_SET_FINALIZED(gc, 1);
775+
_PyGCHead_SET_FINALIZED(gc);
776776
Py_INCREF(op);
777777
finalize(op);
778778
Py_DECREF(op);

Objects/object.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ PyObject_CallFinalizer(PyObject *self)
284284
return;
285285

286286
tp->tp_finalize(self);
287-
if (PyType_IS_GC(tp))
288-
_PyGC_SET_FINALIZED(self, 1);
287+
if (PyType_IS_GC(tp)) {
288+
_PyGC_SET_FINALIZED(self);
289+
}
289290
}
290291

291292
int

0 commit comments

Comments
 (0)