diff options
Diffstat (limited to 'Include/object.h')
-rw-r--r-- | Include/object.h | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/Include/object.h b/Include/object.h index 46f4ce6..9470ed7 100644 --- a/Include/object.h +++ b/Include/object.h @@ -75,14 +75,14 @@ whose size is determined when the object is allocated. #endif /* PyObject_HEAD defines the initial segment of every PyObject. */ -#define PyObject_HEAD \ - _PyObject_HEAD_EXTRA \ - Py_ssize_t ob_refcnt; \ - struct _typeobject *ob_type; +#define PyObject_HEAD PyObject ob_base; #define PyObject_HEAD_INIT(type) \ - _PyObject_EXTRA_INIT \ - 1, type, + { _PyObject_EXTRA_INIT \ + 1, type }, + +#define PyVarObject_HEAD_INIT(type, size) \ + { PyObject_HEAD_INIT(type) size }, /* PyObject_VAR_HEAD defines the initial segment of all variable-size * container objects. These end with a declaration of an array with 1 @@ -90,9 +90,7 @@ whose size is determined when the object is allocated. * has room for ob_size elements. Note that ob_size is an element count, * not necessarily a byte count. */ -#define PyObject_VAR_HEAD \ - PyObject_HEAD \ - Py_ssize_t ob_size; /* Number of items in variable part */ +#define PyObject_VAR_HEAD PyVarObject ob_base; #define Py_INVALID_SIZE (Py_ssize_t)-1 /* Nothing is actually declared to be a PyObject, but every pointer to @@ -101,13 +99,19 @@ whose size is determined when the object is allocated. * in addition, be cast to PyVarObject*. */ typedef struct _object { - PyObject_HEAD + _PyObject_HEAD_EXTRA + Py_ssize_t ob_refcnt; + struct _typeobject *ob_type; } PyObject; typedef struct { - PyObject_VAR_HEAD + PyObject ob_base; + Py_ssize_t ob_size; /* Number of items in variable part */ } PyVarObject; +#define Py_Refcnt(ob) (((PyObject*)(ob))->ob_refcnt) +#define Py_Type(ob) (((PyObject*)(ob))->ob_type) +#define Py_Size(ob) (((PyVarObject*)(ob))->ob_size) /* Type objects contain a string containing the type name (to help somewhat @@ -346,21 +350,21 @@ typedef struct _heaptypeobject { /* access macro to the members which are floating "behind" the object */ #define PyHeapType_GET_MEMBERS(etype) \ - ((PyMemberDef *)(((char *)etype) + (etype)->ht_type.ob_type->tp_basicsize)) + ((PyMemberDef *)(((char *)etype) + Py_Type(etype)->tp_basicsize)) /* Generic type check */ PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *); #define PyObject_TypeCheck(ob, tp) \ - ((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp))) + (Py_Type(ob) == (tp) || PyType_IsSubtype(Py_Type(ob), (tp))) PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */ PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ #define PyType_Check(op) \ - PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TYPE_SUBCLASS) -#define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type) + PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TYPE_SUBCLASS) +#define PyType_CheckExact(op) (Py_Type(op) == &PyType_Type) PyAPI_FUNC(int) PyType_Ready(PyTypeObject *); PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); @@ -543,7 +547,7 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); #define _Py_DEC_REFTOTAL _Py_RefTotal-- #define _Py_REF_DEBUG_COMMA , #define _Py_CHECK_REFCNT(OP) \ -{ if ((OP)->ob_refcnt < 0) \ +{ if (((PyObject*)OP)->ob_refcnt < 0) \ _Py_NegativeRefcount(__FILE__, __LINE__, \ (PyObject *)(OP)); \ } @@ -557,9 +561,9 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); #ifdef COUNT_ALLOCS PyAPI_FUNC(void) inc_count(PyTypeObject *); PyAPI_FUNC(void) dec_count(PyTypeObject *); -#define _Py_INC_TPALLOCS(OP) inc_count((OP)->ob_type) -#define _Py_INC_TPFREES(OP) dec_count((OP)->ob_type) -#define _Py_DEC_TPFREES(OP) (OP)->ob_type->tp_frees-- +#define _Py_INC_TPALLOCS(OP) inc_count(Py_Type(OP)) +#define _Py_INC_TPFREES(OP) dec_count(Py_Type(OP)) +#define _Py_DEC_TPFREES(OP) Py_Type(OP)->tp_frees-- #define _Py_COUNT_ALLOCS_COMMA , #else #define _Py_INC_TPALLOCS(OP) @@ -584,22 +588,22 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force); #define _Py_NewReference(op) ( \ _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ - (op)->ob_refcnt = 1) + Py_Refcnt(op) = 1) #define _Py_ForgetReference(op) _Py_INC_TPFREES(op) #define _Py_Dealloc(op) ( \ _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \ - (*(op)->ob_type->tp_dealloc)((PyObject *)(op))) + (*Py_Type(op)->tp_dealloc)((PyObject *)(op))) #endif /* !Py_TRACE_REFS */ #define Py_INCREF(op) ( \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ - (op)->ob_refcnt++) + ((PyObject*)(op))->ob_refcnt++) #define Py_DECREF(op) \ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ - --(op)->ob_refcnt != 0) \ + --((PyObject*)(op))->ob_refcnt != 0) \ _Py_CHECK_REFCNT(op) \ else \ _Py_Dealloc((PyObject *)(op)) |