summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-07-21 06:55:02 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-07-21 06:55:02 (GMT)
commit6819210b9e4e5719a6f7f9c1725f8fa70a8936f6 (patch)
tree456e2e6b3d9d71e966f3b0e419ecfe44ce3c1fdd /Include
parentb1994b4a5d0139a010eb0af1d6615a3df92fe786 (diff)
downloadcpython-6819210b9e4e5719a6f7f9c1725f8fa70a8936f6.zip
cpython-6819210b9e4e5719a6f7f9c1725f8fa70a8936f6.tar.gz
cpython-6819210b9e4e5719a6f7f9c1725f8fa70a8936f6.tar.bz2
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT.
Diffstat (limited to 'Include')
-rw-r--r--Include/abstract.h2
-rw-r--r--Include/boolobject.h2
-rw-r--r--Include/bufferobject.h2
-rw-r--r--Include/cStringIO.h4
-rw-r--r--Include/cellobject.h2
-rw-r--r--Include/cobject.h2
-rw-r--r--Include/code.h4
-rw-r--r--Include/complexobject.h2
-rw-r--r--Include/datetime.h20
-rw-r--r--Include/descrobject.h2
-rw-r--r--Include/dictobject.h4
-rw-r--r--Include/fileobject.h2
-rw-r--r--Include/floatobject.h2
-rw-r--r--Include/funcobject.h2
-rw-r--r--Include/genobject.h2
-rw-r--r--Include/iterobject.h4
-rw-r--r--Include/listobject.h6
-rw-r--r--Include/longobject.h4
-rw-r--r--Include/methodobject.h2
-rw-r--r--Include/moduleobject.h2
-rw-r--r--Include/object.h30
-rw-r--r--Include/objimpl.h10
-rw-r--r--Include/py_curses.h2
-rw-r--r--Include/rangeobject.h2
-rw-r--r--Include/setobject.h10
-rw-r--r--Include/sliceobject.h2
-rw-r--r--Include/stringobject.h6
-rw-r--r--Include/symtable.h2
-rw-r--r--Include/traceback.h2
-rw-r--r--Include/tupleobject.h6
-rw-r--r--Include/unicodeobject.h4
-rw-r--r--Include/weakrefobject.h6
32 files changed, 80 insertions, 74 deletions
diff --git a/Include/abstract.h b/Include/abstract.h
index 14510c6..29f091e 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -1064,7 +1064,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/
#define PySequence_ITEM(o, i)\
- ( o->ob_type->tp_as_sequence->sq_item(o, i) )
+ ( Py_Type(o)->tp_as_sequence->sq_item(o, i) )
/* Assume tp_as_sequence and sq_item exist and that i does not
need to be corrected for a negative index
*/
diff --git a/Include/boolobject.h b/Include/boolobject.h
index 7f9ad01..6499345 100644
--- a/Include/boolobject.h
+++ b/Include/boolobject.h
@@ -11,7 +11,7 @@ typedef PyIntObject PyBoolObject;
PyAPI_DATA(PyTypeObject) PyBool_Type;
-#define PyBool_Check(x) ((x)->ob_type == &PyBool_Type)
+#define PyBool_Check(x) (Py_Type(x) == &PyBool_Type)
/* Py_False and Py_True are the only two bools in existence.
Don't forget to apply Py_INCREF() when returning either!!! */
diff --git a/Include/bufferobject.h b/Include/bufferobject.h
index 75ba496..639b08d 100644
--- a/Include/bufferobject.h
+++ b/Include/bufferobject.h
@@ -12,7 +12,7 @@ extern "C" {
PyAPI_DATA(PyTypeObject) PyBuffer_Type;
-#define PyBuffer_Check(op) ((op)->ob_type == &PyBuffer_Type)
+#define PyBuffer_Check(op) (Py_Type(op) == &PyBuffer_Type)
#define Py_END_OF_BUFFER (-1)
diff --git a/Include/cStringIO.h b/Include/cStringIO.h
index 25fc9dd..50f8cbe 100644
--- a/Include/cStringIO.h
+++ b/Include/cStringIO.h
@@ -60,9 +60,9 @@ static struct PycStringIO_CAPI {
/* These can be used to test if you have one */
#define PycStringIO_InputCheck(O) \
- ((O)->ob_type==PycStringIO->InputType)
+ (Py_Type(O)==PycStringIO->InputType)
#define PycStringIO_OutputCheck(O) \
- ((O)->ob_type==PycStringIO->OutputType)
+ (Py_Type(O)==PycStringIO->OutputType)
#ifdef __cplusplus
}
diff --git a/Include/cellobject.h b/Include/cellobject.h
index fd186e2..1036420 100644
--- a/Include/cellobject.h
+++ b/Include/cellobject.h
@@ -13,7 +13,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyCell_Type;
-#define PyCell_Check(op) ((op)->ob_type == &PyCell_Type)
+#define PyCell_Check(op) (Py_Type(op) == &PyCell_Type)
PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
diff --git a/Include/cobject.h b/Include/cobject.h
index ad23ac8..0e0ed1b 100644
--- a/Include/cobject.h
+++ b/Include/cobject.h
@@ -16,7 +16,7 @@ extern "C" {
PyAPI_DATA(PyTypeObject) PyCObject_Type;
-#define PyCObject_Check(op) ((op)->ob_type == &PyCObject_Type)
+#define PyCObject_Check(op) (Py_Type(op) == &PyCObject_Type)
/* Create a PyCObject from a pointer to a C object and an optional
destructor function. If the second argument is non-null, then it
diff --git a/Include/code.h b/Include/code.h
index 744c1a6..2ec756b 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -60,7 +60,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyCode_Type;
-#define PyCode_Check(op) ((op)->ob_type == &PyCode_Type)
+#define PyCode_Check(op) (Py_Type(op) == &PyCode_Type)
#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
/* Public interface */
@@ -72,7 +72,7 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
/* for internal use only */
#define _PyCode_GETCODEPTR(co, pp) \
- ((*(co)->co_code->ob_type->tp_as_buffer->bf_getreadbuffer) \
+ ((*Py_Type((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \
((co)->co_code, 0, (void **)(pp)))
typedef struct _addr_pair {
diff --git a/Include/complexobject.h b/Include/complexobject.h
index e59bf2c..3e1cda5 100644
--- a/Include/complexobject.h
+++ b/Include/complexobject.h
@@ -43,7 +43,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyComplex_Type;
#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
-#define PyComplex_CheckExact(op) ((op)->ob_type == &PyComplex_Type)
+#define PyComplex_CheckExact(op) (Py_Type(op) == &PyComplex_Type)
PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
diff --git a/Include/datetime.h b/Include/datetime.h
index db0f3aa..43e3093 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -166,19 +166,19 @@ typedef struct {
/* Macros for type checking when building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
-#define PyDate_CheckExact(op) ((op)->ob_type == &PyDateTime_DateType)
+#define PyDate_CheckExact(op) (Py_Type(op) == &PyDateTime_DateType)
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
-#define PyDateTime_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeType)
+#define PyDateTime_CheckExact(op) (Py_Type(op) == &PyDateTime_DateTimeType)
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
-#define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType)
+#define PyTime_CheckExact(op) (Py_Type(op) == &PyDateTime_TimeType)
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
-#define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType)
+#define PyDelta_CheckExact(op) (Py_Type(op) == &PyDateTime_DeltaType)
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
-#define PyTZInfo_CheckExact(op) ((op)->ob_type == &PyDateTime_TZInfoType)
+#define PyTZInfo_CheckExact(op) (Py_Type(op) == &PyDateTime_TZInfoType)
#else
@@ -198,19 +198,19 @@ static PyDateTime_CAPI *PyDateTimeAPI;
/* Macros for type checking when not building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
-#define PyDate_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DateType)
+#define PyDate_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->DateType)
#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
-#define PyDateTime_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DateTimeType)
+#define PyDateTime_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->DateTimeType)
#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
-#define PyTime_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->TimeType)
+#define PyTime_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->TimeType)
#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
-#define PyDelta_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DeltaType)
+#define PyDelta_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->DeltaType)
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
-#define PyTZInfo_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->TZInfoType)
+#define PyTZInfo_CheckExact(op) (Py_Type(op) == PyDateTimeAPI->TZInfoType)
/* Macros for accessing constructors in a simplified fashion. */
#define PyDate_FromDate(year, month, day) \
diff --git a/Include/descrobject.h b/Include/descrobject.h
index a74af60..a45a801 100644
--- a/Include/descrobject.h
+++ b/Include/descrobject.h
@@ -77,7 +77,7 @@ PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
struct PyGetSetDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
struct wrapperbase *, void *);
-#define PyDescr_IsData(d) ((d)->ob_type->tp_descr_set != NULL)
+#define PyDescr_IsData(d) (Py_Type(d)->tp_descr_set != NULL)
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
diff --git a/Include/dictobject.h b/Include/dictobject.h
index ec2e0c8..fec6295 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -91,8 +91,8 @@ struct _dictobject {
PyAPI_DATA(PyTypeObject) PyDict_Type;
#define PyDict_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_DICT_SUBCLASS)
-#define PyDict_CheckExact(op) ((op)->ob_type == &PyDict_Type)
+ PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_DICT_SUBCLASS)
+#define PyDict_CheckExact(op) (Py_Type(op) == &PyDict_Type)
PyAPI_FUNC(PyObject *) PyDict_New(void);
PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
diff --git a/Include/fileobject.h b/Include/fileobject.h
index 9fd0646..dde5b8f 100644
--- a/Include/fileobject.h
+++ b/Include/fileobject.h
@@ -30,7 +30,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyFile_Type;
#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
-#define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type)
+#define PyFile_CheckExact(op) (Py_Type(op) == &PyFile_Type)
PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
diff --git a/Include/floatobject.h b/Include/floatobject.h
index f695de8..bfbc580 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -19,7 +19,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyFloat_Type;
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
-#define PyFloat_CheckExact(op) ((op)->ob_type == &PyFloat_Type)
+#define PyFloat_CheckExact(op) (Py_Type(op) == &PyFloat_Type)
/* Return Python float from string PyObject. Second argument ignored on
input, and, if non-NULL, NULL is stored into *junk (this tried to serve a
diff --git a/Include/funcobject.h b/Include/funcobject.h
index 59c19bb..3e37e11 100644
--- a/Include/funcobject.h
+++ b/Include/funcobject.h
@@ -39,7 +39,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyFunction_Type;
-#define PyFunction_Check(op) ((op)->ob_type == &PyFunction_Type)
+#define PyFunction_Check(op) (Py_Type(op) == &PyFunction_Type)
PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *);
diff --git a/Include/genobject.h b/Include/genobject.h
index ca84432..f9d9b16 100644
--- a/Include/genobject.h
+++ b/Include/genobject.h
@@ -26,7 +26,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyGen_Type;
#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
-#define PyGen_CheckExact(op) ((op)->ob_type == &PyGen_Type)
+#define PyGen_CheckExact(op) (Py_Type(op) == &PyGen_Type)
PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
diff --git a/Include/iterobject.h b/Include/iterobject.h
index c078ebb..8e17d35 100644
--- a/Include/iterobject.h
+++ b/Include/iterobject.h
@@ -7,13 +7,13 @@ extern "C" {
PyAPI_DATA(PyTypeObject) PySeqIter_Type;
-#define PySeqIter_Check(op) ((op)->ob_type == &PySeqIter_Type)
+#define PySeqIter_Check(op) (Py_Type(op) == &PySeqIter_Type)
PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
PyAPI_DATA(PyTypeObject) PyCallIter_Type;
-#define PyCallIter_Check(op) ((op)->ob_type == &PyCallIter_Type)
+#define PyCallIter_Check(op) (Py_Type(op) == &PyCallIter_Type)
PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
#ifdef __cplusplus
diff --git a/Include/listobject.h b/Include/listobject.h
index db3124e..e8b192a 100644
--- a/Include/listobject.h
+++ b/Include/listobject.h
@@ -41,8 +41,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyList_Type;
#define PyList_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LIST_SUBCLASS)
-#define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
+ PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LIST_SUBCLASS)
+#define PyList_CheckExact(op) (Py_Type(op) == &PyList_Type)
PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
@@ -60,7 +60,7 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
/* Macro, trading safety for speed */
#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
-#define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size)
+#define PyList_GET_SIZE(op) Py_Size(op)
#ifdef __cplusplus
}
diff --git a/Include/longobject.h b/Include/longobject.h
index 3893ad6..657cd0b 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -12,8 +12,8 @@ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
PyAPI_DATA(PyTypeObject) PyLong_Type;
#define PyLong_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LONG_SUBCLASS)
-#define PyLong_CheckExact(op) ((op)->ob_type == &PyLong_Type)
+ PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_LONG_SUBCLASS)
+#define PyLong_CheckExact(op) (Py_Type(op) == &PyLong_Type)
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
diff --git a/Include/methodobject.h b/Include/methodobject.h
index c887d94..511a747 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -13,7 +13,7 @@ extern "C" {
PyAPI_DATA(PyTypeObject) PyCFunction_Type;
-#define PyCFunction_Check(op) ((op)->ob_type == &PyCFunction_Type)
+#define PyCFunction_Check(op) (Py_Type(op) == &PyCFunction_Type)
typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index 3d278af..c43cb93 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -10,7 +10,7 @@ extern "C" {
PyAPI_DATA(PyTypeObject) PyModule_Type;
#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
-#define PyModule_CheckExact(op) ((op)->ob_type == &PyModule_Type)
+#define PyModule_CheckExact(op) (Py_Type(op) == &PyModule_Type)
PyAPI_FUNC(PyObject *) PyModule_New(const char *);
PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
diff --git a/Include/object.h b/Include/object.h
index 0f6ff77..daba4b6 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -84,6 +84,9 @@ whose size is determined when the object is allocated.
_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
* element, but enough space is malloc'ed so that the array actually
@@ -108,6 +111,9 @@ typedef struct {
PyObject_VAR_HEAD
} 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
@@ -364,21 +370,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);
@@ -599,7 +605,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)); \
}
@@ -613,9 +619,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)
@@ -640,22 +646,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))
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 03b6a8d..9f8523f 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -154,9 +154,9 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
/* Macros trading binary compatibility for speed. See also pymem.h.
Note that these macros expect non-NULL object pointers.*/
#define PyObject_INIT(op, typeobj) \
- ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
+ ( Py_Type(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
#define PyObject_INIT_VAR(op, typeobj, size) \
- ( (op)->ob_size = (size), PyObject_INIT((op), (typeobj)) )
+ ( Py_Size(op) = (size), PyObject_INIT((op), (typeobj)) )
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
@@ -231,8 +231,8 @@ PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
/* Test if an object has a GC head */
-#define PyObject_IS_GC(o) (PyType_IS_GC((o)->ob_type) && \
- ((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o)))
+#define PyObject_IS_GC(o) (PyType_IS_GC(Py_Type(o)) && \
+ (Py_Type(o)->tp_is_gc == NULL || Py_Type(o)->tp_is_gc(o)))
PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
#define PyObject_GC_Resize(type, op, n) \
@@ -328,7 +328,7 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
&& ((t)->tp_weaklistoffset > 0))
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
- ((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset))
+ ((PyObject **) (((char *) (o)) + Py_Type(o)->tp_weaklistoffset))
#ifdef __cplusplus
}
diff --git a/Include/py_curses.h b/Include/py_curses.h
index aaff4bd..62d00d8 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -73,7 +73,7 @@ typedef struct {
WINDOW *win;
} PyCursesWindowObject;
-#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
+#define PyCursesWindow_Check(v) (Py_Type(v) == &PyCursesWindow_Type)
#ifdef CURSES_MODULE
/* This section is used when compiling _cursesmodule.c */
diff --git a/Include/rangeobject.h b/Include/rangeobject.h
index 359bcb6..407fd16 100644
--- a/Include/rangeobject.h
+++ b/Include/rangeobject.h
@@ -20,7 +20,7 @@ they are represented by a start, stop, and step datamembers.
PyAPI_DATA(PyTypeObject) PyRange_Type;
-#define PyRange_Check(op) ((op)->ob_type == &PyRange_Type)
+#define PyRange_Check(op) (Py_Type(op) == &PyRange_Type)
#ifdef __cplusplus
}
diff --git a/Include/setobject.h b/Include/setobject.h
index 750a2a8..8914749 100644
--- a/Include/setobject.h
+++ b/Include/setobject.h
@@ -66,13 +66,13 @@ PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
* hash is -1
*/
-#define PyFrozenSet_CheckExact(ob) ((ob)->ob_type == &PyFrozenSet_Type)
+#define PyFrozenSet_CheckExact(ob) (Py_Type(ob) == &PyFrozenSet_Type)
#define PyAnySet_CheckExact(ob) \
- ((ob)->ob_type == &PySet_Type || (ob)->ob_type == &PyFrozenSet_Type)
+ (Py_Type(ob) == &PySet_Type || Py_Type(ob) == &PyFrozenSet_Type)
#define PyAnySet_Check(ob) \
- ((ob)->ob_type == &PySet_Type || (ob)->ob_type == &PyFrozenSet_Type || \
- PyType_IsSubtype((ob)->ob_type, &PySet_Type) || \
- PyType_IsSubtype((ob)->ob_type, &PyFrozenSet_Type))
+ (Py_Type(ob) == &PySet_Type || Py_Type(ob) == &PyFrozenSet_Type || \
+ PyType_IsSubtype(Py_Type(ob), &PySet_Type) || \
+ PyType_IsSubtype(Py_Type(ob), &PyFrozenSet_Type))
PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
diff --git a/Include/sliceobject.h b/Include/sliceobject.h
index dbc34b2..21bc025 100644
--- a/Include/sliceobject.h
+++ b/Include/sliceobject.h
@@ -26,7 +26,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PySlice_Type;
-#define PySlice_Check(op) ((op)->ob_type == &PySlice_Type)
+#define PySlice_Check(op) (Py_Type(op) == &PySlice_Type)
PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
PyObject* step);
diff --git a/Include/stringobject.h b/Include/stringobject.h
index 03c3777..cc79462 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -56,8 +56,8 @@ PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyString_Type;
#define PyString_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_STRING_SUBCLASS)
-#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
+ PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_STRING_SUBCLASS)
+#define PyString_CheckExact(op) (Py_Type(op) == &PyString_Type)
PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
@@ -89,7 +89,7 @@ PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
/* Macro, trading safety for speed */
#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
-#define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
+#define PyString_GET_SIZE(op) Py_Size(op)
/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
x must be an iterable object. */
diff --git a/Include/symtable.h b/Include/symtable.h
index 1e5996d..28fd978 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -49,7 +49,7 @@ typedef struct _symtable_entry {
PyAPI_DATA(PyTypeObject) PySTEntry_Type;
-#define PySTEntry_Check(op) ((op)->ob_type == &PySTEntry_Type)
+#define PySTEntry_Check(op) (Py_Type(op) == &PySTEntry_Type)
PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
diff --git a/Include/traceback.h b/Include/traceback.h
index 6501600..4c7b8cc 100644
--- a/Include/traceback.h
+++ b/Include/traceback.h
@@ -22,7 +22,7 @@ PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
/* Reveal traceback type so we can typecheck traceback objects */
PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
-#define PyTraceBack_Check(v) ((v)->ob_type == &PyTraceBack_Type)
+#define PyTraceBack_Check(v) (Py_Type(v) == &PyTraceBack_Type)
#ifdef __cplusplus
}
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index 738cea1..423103a 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -34,8 +34,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyTuple_Type;
#define PyTuple_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TUPLE_SUBCLASS)
-#define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
+ PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_TUPLE_SUBCLASS)
+#define PyTuple_CheckExact(op) (Py_Type(op) == &PyTuple_Type)
PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
@@ -47,7 +47,7 @@ PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
/* Macro, trading safety for speed */
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
-#define PyTuple_GET_SIZE(op) (((PyTupleObject *)(op))->ob_size)
+#define PyTuple_GET_SIZE(op) Py_Size(op)
/* Macro, *only* to be used to fill in brand new tuples */
#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 0bad8c3..5d9263b 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -393,8 +393,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
#define PyUnicode_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_UNICODE_SUBCLASS)
-#define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type)
+ PyType_FastSubclass(Py_Type(op), Py_TPFLAGS_UNICODE_SUBCLASS)
+#define PyUnicode_CheckExact(op) (Py_Type(op) == &PyUnicode_Type)
/* Fast access macros */
#define PyUnicode_GET_SIZE(op) \
diff --git a/Include/weakrefobject.h b/Include/weakrefobject.h
index 0a659b0..e58c352 100644
--- a/Include/weakrefobject.h
+++ b/Include/weakrefobject.h
@@ -44,10 +44,10 @@ PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;
#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)
#define PyWeakref_CheckRefExact(op) \
- ((op)->ob_type == &_PyWeakref_RefType)
+ (Py_Type(op) == &_PyWeakref_RefType)
#define PyWeakref_CheckProxy(op) \
- (((op)->ob_type == &_PyWeakref_ProxyType) || \
- ((op)->ob_type == &_PyWeakref_CallableProxyType))
+ ((Py_Type(op) == &_PyWeakref_ProxyType) || \
+ (Py_Type(op) == &_PyWeakref_CallableProxyType))
/* This macro calls PyWeakref_CheckRef() last since that can involve a
function call; this makes it more likely that the function call