summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-07-21 17:22:18 +0000
committerMartin v. Löwis <martin@v.loewis.de>2007-07-21 17:22:18 +0000
commit9f2e346911988cda95fec7c901e8d10d34fa9563 (patch)
tree1632c78fb8e18b2f789102451bedd15996bff6c5 /Include
parentb972a78e17beeb997d809d87f2e422e6622efd52 (diff)
downloadcpython-git-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.gz
Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines Merged revisions 56466-56476 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines PEP 3123: Provide forward compatibility with Python 3.0, while keeping backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT. ........ ................ r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines PEP 3123: Use proper C inheritance for PyObject. ................ r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines Add longintrepr.h to Python.h, so that the compiler can see that PyFalse is really some kind of PyObject*. ................ r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines Qualify SHIFT, MASK, BASE. ................ r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines Correctly refer to _ob_next. ................
Diffstat (limited to 'Include')
-rw-r--r--Include/Python.h3
-rw-r--r--Include/abstract.h2
-rw-r--r--Include/boolobject.h2
-rw-r--r--Include/bufferobject.h2
-rw-r--r--Include/bytesobject.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/floatobject.h2
-rw-r--r--Include/frameobject.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/longintrepr.h8
-rw-r--r--Include/longobject.h4
-rw-r--r--Include/methodobject.h2
-rw-r--r--Include/moduleobject.h2
-rw-r--r--Include/object.h50
-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.h4
-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
35 files changed, 95 insertions, 90 deletions
diff --git a/Include/Python.h b/Include/Python.h
index 397ceb99ff..43f16f76c3 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -67,8 +67,9 @@
#include "bytesobject.h"
#include "unicodeobject.h"
#include "intobject.h"
-#include "boolobject.h"
#include "longobject.h"
+#include "longintrepr.h"
+#include "boolobject.h"
#include "floatobject.h"
#ifndef WITHOUT_COMPLEX
#include "complexobject.h"
diff --git a/Include/abstract.h b/Include/abstract.h
index 23bff6d673..22b5d0118e 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -986,7 +986,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 f5d7eec7c7..33f8112268 100644
--- a/Include/boolobject.h
+++ b/Include/boolobject.h
@@ -9,7 +9,7 @@ extern "C" {
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 75ba4963f5..639b08d865 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/bytesobject.h b/Include/bytesobject.h
index 9c1f4ba1b1..a649d39c02 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -30,7 +30,7 @@ PyAPI_DATA(PyTypeObject) PyBytes_Type;
/* Type check macros */
#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
-#define PyBytes_CheckExact(self) ((self)->ob_type == &PyBytes_Type)
+#define PyBytes_CheckExact(self) (Py_Type(self) == &PyBytes_Type)
/* Direct API functions */
PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
diff --git a/Include/cStringIO.h b/Include/cStringIO.h
index 25fc9dd0d8..50f8cbef85 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 fd186e28c2..1036420313 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 ad23ac8d6a..0e0ed1b2cb 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 e2eb59d244..2bd6c5b03f 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -59,7 +59,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 e59bf2ca95..3e1cda5870 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 db0f3aa5ad..43e3093206 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 a74af6009b..a45a80132c 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 ec2e0c8214..fec62958fe 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/floatobject.h b/Include/floatobject.h
index b535e34f34..56598146ae 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. */
PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*);
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 392db46d7f..0dc4d06591 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -51,7 +51,7 @@ typedef struct _frame {
PyAPI_DATA(PyTypeObject) PyFrame_Type;
-#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
+#define PyFrame_Check(op) (Py_Type(op) == &PyFrame_Type)
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
PyObject *, PyObject *);
diff --git a/Include/funcobject.h b/Include/funcobject.h
index 5739dd65be..2f64e52439 100644
--- a/Include/funcobject.h
+++ b/Include/funcobject.h
@@ -41,7 +41,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 ca8443203c..f9d9b16466 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 69deb45de3..12853b4146 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 *);
diff --git a/Include/listobject.h b/Include/listobject.h
index db3124ed56..e8b192adff 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/longintrepr.h b/Include/longintrepr.h
index b1574ba507..691cc368cf 100644
--- a/Include/longintrepr.h
+++ b/Include/longintrepr.h
@@ -24,11 +24,11 @@ typedef unsigned int wdigit; /* digit widened to parameter size */
typedef unsigned BASE_TWODIGITS_TYPE twodigits;
typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
-#define SHIFT 15
-#define BASE ((digit)1 << SHIFT)
-#define MASK ((int)(BASE - 1))
+#define PyLong_SHIFT 15
+#define PyLong_BASE ((digit)1 << PyLong_SHIFT)
+#define PyLong_MASK ((int)(PyLong_BASE - 1))
-#if SHIFT % 5 != 0
+#if PyLong_SHIFT % 5 != 0
#error "longobject.c requires that SHIFT be divisible by 5"
#endif
diff --git a/Include/longobject.h b/Include/longobject.h
index e8981eb182..6bf3409611 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 67a24732fd..7b23fe9941 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 3d278af873..c43cb93b5a 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 46f4ce6221..9470ed79e5 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))
diff --git a/Include/objimpl.h b/Include/objimpl.h
index c6cb2fa0d1..6e30ded7bb 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) \
@@ -326,7 +326,7 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
#define PyType_SUPPORTS_WEAKREFS(t) ((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 aaff4bd836..62d00d82c2 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 847da80b89..2403807081 100644
--- a/Include/rangeobject.h
+++ b/Include/rangeobject.h
@@ -17,7 +17,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 750a2a8a21..891474959e 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 dbc34b2aea..21bc0257c6 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 0a932f043a..1d932ff54b 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -52,8 +52,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 *);
diff --git a/Include/symtable.h b/Include/symtable.h
index da11603b98..12efd7f16e 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -53,7 +53,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 6501600c0c..4c7b8cc3e5 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 738cea1e97..423103a277 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 1f6b729b40..6e2d2aa28f 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -405,8 +405,8 @@ PyAPI_DATA(PyTypeObject) PyUnicode_Type;
#define SSTATE_INTERNED_IMMORTAL 2
#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 0a659b027c..e58c352983 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