File tree Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,21 @@ typedef struct {
19
19
uintptr_t _gc_prev ;
20
20
} PyGC_Head ;
21
21
22
+ #define _PyGC_Head_UNUSED PyGC_Head
23
+
24
+
25
+ /* Get an object's GC head */
22
26
static inline PyGC_Head * _Py_AS_GC (PyObject * op ) {
23
- return (_Py_CAST (PyGC_Head * , op ) - 1 );
27
+ char * gc = ((char * )op ) - sizeof (PyGC_Head );
28
+ return (PyGC_Head * )gc ;
24
29
}
25
- #define _PyGC_Head_UNUSED PyGC_Head
30
+
31
+ /* Get the object given the GC head */
32
+ static inline PyObject * _Py_FROM_GC (PyGC_Head * gc ) {
33
+ char * op = ((char * )gc ) + sizeof (PyGC_Head );
34
+ return (PyObject * )op ;
35
+ }
36
+
26
37
27
38
/* True if the object is currently tracked by the GC. */
28
39
static inline int _PyObject_GC_IS_TRACKED (PyObject * op ) {
Original file line number Diff line number Diff line change @@ -326,9 +326,9 @@ _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET(PyObject *op)
326
326
static inline int
327
327
_PyObject_IS_GC (PyObject * obj )
328
328
{
329
- return ( PyType_IS_GC ( Py_TYPE (obj ))
330
- && ( Py_TYPE ( obj ) -> tp_is_gc == NULL
331
- || Py_TYPE ( obj ) -> tp_is_gc (obj )));
329
+ PyTypeObject * type = Py_TYPE (obj );
330
+ return ( PyType_IS_GC ( type )
331
+ && ( type -> tp_is_gc == NULL || type -> tp_is_gc (obj )));
332
332
}
333
333
334
334
// Fast inlined version of PyType_IS_GC()
Original file line number Diff line number Diff line change @@ -68,11 +68,9 @@ module gc
68
68
// most gc_list_* functions for it.
69
69
#define NEXT_MASK_UNREACHABLE (1)
70
70
71
- /* Get an object's GC head */
72
- #define AS_GC ( o ) ((PyGC_Head *)(((char *)(o))-sizeof(PyGC_Head)) )
71
+ #define AS_GC ( op ) _Py_AS_GC(op)
72
+ #define FROM_GC ( gc ) _Py_FROM_GC(op )
73
73
74
- /* Get the object given the GC head */
75
- #define FROM_GC (g ) ((PyObject *)(((char *)(g))+sizeof(PyGC_Head)))
76
74
77
75
static inline int
78
76
gc_is_collecting (PyGC_Head * g )
@@ -1909,7 +1907,7 @@ static PyObject *
1909
1907
gc_is_finalized (PyObject * module , PyObject * obj )
1910
1908
/*[clinic end generated code: output=e1516ac119a918ed input=201d0c58f69ae390]*/
1911
1909
{
1912
- if (_PyObject_IS_GC (obj ) && _PyGCHead_FINALIZED ( AS_GC ( obj ) )) {
1910
+ if (_PyObject_IS_GC (obj ) && _PyGC_FINALIZED ( obj )) {
1913
1911
Py_RETURN_TRUE ;
1914
1912
}
1915
1913
Py_RETURN_FALSE ;
@@ -2409,7 +2407,7 @@ PyObject_GC_IsTracked(PyObject* obj)
2409
2407
int
2410
2408
PyObject_GC_IsFinalized (PyObject * obj )
2411
2409
{
2412
- if (_PyObject_IS_GC (obj ) && _PyGCHead_FINALIZED ( AS_GC ( obj ) )) {
2410
+ if (_PyObject_IS_GC (obj ) && _PyGC_FINALIZED ( obj )) {
2413
2411
return 1 ;
2414
2412
}
2415
2413
return 0 ;
You can’t perform that action at this time.
0 commit comments