Skip to content

Commit df5212d

Browse files
authored
gh-112529: Simplify PyObject_GC_IsTracked and PyObject_GC_IsFinalized (#114732)
1 parent c43b26d commit df5212d

File tree

3 files changed

+51
-28
lines changed

3 files changed

+51
-28
lines changed

Modules/clinic/gcmodule.c.h

+39-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/gcmodule.c

+10-19
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ gc_get_stats_impl(PyObject *module)
383383

384384

385385
/*[clinic input]
386-
gc.is_tracked
386+
gc.is_tracked -> bool
387387
388388
obj: object
389389
/
@@ -393,36 +393,27 @@ Returns true if the object is tracked by the garbage collector.
393393
Simple atomic objects will return false.
394394
[clinic start generated code]*/
395395

396-
static PyObject *
397-
gc_is_tracked(PyObject *module, PyObject *obj)
398-
/*[clinic end generated code: output=14f0103423b28e31 input=d83057f170ea2723]*/
396+
static int
397+
gc_is_tracked_impl(PyObject *module, PyObject *obj)
398+
/*[clinic end generated code: output=91c8d086b7f47a33 input=423b98ec680c3126]*/
399399
{
400-
PyObject *result;
401-
402-
if (_PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj))
403-
result = Py_True;
404-
else
405-
result = Py_False;
406-
return Py_NewRef(result);
400+
return PyObject_GC_IsTracked(obj);
407401
}
408402

409403
/*[clinic input]
410-
gc.is_finalized
404+
gc.is_finalized -> bool
411405
412406
obj: object
413407
/
414408
415409
Returns true if the object has been already finalized by the GC.
416410
[clinic start generated code]*/
417411

418-
static PyObject *
419-
gc_is_finalized(PyObject *module, PyObject *obj)
420-
/*[clinic end generated code: output=e1516ac119a918ed input=201d0c58f69ae390]*/
412+
static int
413+
gc_is_finalized_impl(PyObject *module, PyObject *obj)
414+
/*[clinic end generated code: output=401ff5d6fc660429 input=ca4d111c8f8c4e3a]*/
421415
{
422-
if (_PyObject_IS_GC(obj) && _PyGC_FINALIZED(obj)) {
423-
Py_RETURN_TRUE;
424-
}
425-
Py_RETURN_FALSE;
416+
return PyObject_GC_IsFinalized(obj);
426417
}
427418

428419
/*[clinic input]

Python/gc_free_threading.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -1693,19 +1693,13 @@ PyObject_GC_Del(void *op)
16931693
int
16941694
PyObject_GC_IsTracked(PyObject* obj)
16951695
{
1696-
if (_PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj)) {
1697-
return 1;
1698-
}
1699-
return 0;
1696+
return _PyObject_GC_IS_TRACKED(obj);
17001697
}
17011698

17021699
int
17031700
PyObject_GC_IsFinalized(PyObject *obj)
17041701
{
1705-
if (_PyObject_IS_GC(obj) && _PyGC_FINALIZED(obj)) {
1706-
return 1;
1707-
}
1708-
return 0;
1702+
return _PyGC_FINALIZED(obj);
17091703
}
17101704

17111705
struct custom_visitor_args {

0 commit comments

Comments
 (0)