Skip to content

gh-112529: Simplify PyObject_GC_IsTracked and PyObject_GC_IsFinalized #114732

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all 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
40 changes: 39 additions & 1 deletion Modules/clinic/gcmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 10 additions & 19 deletions Modules/gcmodule.c
Original file line number Diff line number Diff line change
@@ -358,7 +358,7 @@ gc_get_stats_impl(PyObject *module)


/*[clinic input]
gc.is_tracked
gc.is_tracked -> bool
obj: object
/
@@ -368,36 +368,27 @@ Returns true if the object is tracked by the garbage collector.
Simple atomic objects will return false.
[clinic start generated code]*/

static PyObject *
gc_is_tracked(PyObject *module, PyObject *obj)
/*[clinic end generated code: output=14f0103423b28e31 input=d83057f170ea2723]*/
static int
gc_is_tracked_impl(PyObject *module, PyObject *obj)
/*[clinic end generated code: output=91c8d086b7f47a33 input=423b98ec680c3126]*/
{
PyObject *result;

if (_PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj))
result = Py_True;
else
result = Py_False;
return Py_NewRef(result);
return PyObject_GC_IsTracked(obj);
}

/*[clinic input]
gc.is_finalized
gc.is_finalized -> bool
obj: object
/
Returns true if the object has been already finalized by the GC.
[clinic start generated code]*/

static PyObject *
gc_is_finalized(PyObject *module, PyObject *obj)
/*[clinic end generated code: output=e1516ac119a918ed input=201d0c58f69ae390]*/
static int
gc_is_finalized_impl(PyObject *module, PyObject *obj)
/*[clinic end generated code: output=401ff5d6fc660429 input=ca4d111c8f8c4e3a]*/
{
if (_PyObject_IS_GC(obj) && _PyGC_FINALIZED(obj)) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyObject_GC_IsFinalized(obj);
}

/*[clinic input]
10 changes: 2 additions & 8 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
@@ -1647,19 +1647,13 @@ PyObject_GC_Del(void *op)
int
PyObject_GC_IsTracked(PyObject* obj)
{
if (_PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj)) {
return 1;
}
return 0;
return _PyObject_GC_IS_TRACKED(obj);
}

int
PyObject_GC_IsFinalized(PyObject *obj)
{
if (_PyObject_IS_GC(obj) && _PyGC_FINALIZED(obj)) {
return 1;
}
return 0;
return _PyGC_FINALIZED(obj);
}

struct custom_visitor_args {