GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources
@@ -68,11 +68,9 @@ module gc
6868// most gc_list_* functions for it.
6969#defineNEXT_MASK_UNREACHABLE (1)
707071-/* Get an object's GC head */
72-#defineAS_GC(o) ((PyGC_Head *)(((char *)(o))-sizeof(PyGC_Head)))
71+#defineAS_GC(op) _Py_AS_GC(op)
72+#defineFROM_GC(gc) _Py_FROM_GC(gc)
737374-/* Get the object given the GC head */
75-#defineFROM_GC(g) ((PyObject *)(((char *)(g))+sizeof(PyGC_Head)))
76747775staticinlineint
7876gc_is_collecting(PyGC_Head*g)
@@ -861,7 +859,7 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
861859 * to imagine how calling it later could create a problem for us. wr
862860 * is moved to wrcb_to_call in this case.
863861 */
864-if (gc_is_collecting(AS_GC(wr))) {
862+if (gc_is_collecting(AS_GC((PyObject*)wr))) {
865863/* it should already have been cleared above */
866864assert(wr->wr_object==Py_None);
867865continue;
@@ -873,7 +871,7 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
873871Py_INCREF(wr);
874872875873/* Move wr to wrcb_to_call, for the next pass. */
876-wrasgc=AS_GC(wr);
874+wrasgc=AS_GC((PyObject*)wr);
877875assert(wrasgc!=next); /* wrasgc is reachable, but
878876 next isn't, so they can't
879877 be the same */
@@ -1909,7 +1907,7 @@ static PyObject *
19091907gc_is_finalized(PyObject*module, PyObject*obj)
19101908/*[clinic end generated code: output=e1516ac119a918ed input=201d0c58f69ae390]*/
19111909{
1912-if (_PyObject_IS_GC(obj) &&_PyGCHead_FINALIZED(AS_GC(obj))) {
1910+if (_PyObject_IS_GC(obj) &&_PyGC_FINALIZED(obj)) {
19131911Py_RETURN_TRUE;
19141912 }
19151913Py_RETURN_FALSE;
@@ -2409,7 +2407,7 @@ PyObject_GC_IsTracked(PyObject* obj)
24092407int
24102408PyObject_GC_IsFinalized(PyObject*obj)
24112409{
2412-if (_PyObject_IS_GC(obj) &&_PyGCHead_FINALIZED(AS_GC(obj))) {
2410+if (_PyObject_IS_GC(obj) &&_PyGC_FINALIZED(obj)) {
24132411return1;
24142412 }
24152413return0;