summaryrefslogtreecommitdiffstats
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
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.
-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
-rw-r--r--Misc/NEWS4
-rw-r--r--Modules/_bsddb.c28
-rw-r--r--Modules/_collectionsmodule.c24
-rw-r--r--Modules/_csv.c13
-rw-r--r--Modules/_ctypes/_ctypes.c89
-rw-r--r--Modules/_ctypes/callproc.c7
-rw-r--r--Modules/_ctypes/cfield.c3
-rw-r--r--Modules/_ctypes/stgdict.c9
-rw-r--r--Modules/_curses_panel.c7
-rw-r--r--Modules/_cursesmodule.c5
-rw-r--r--Modules/_elementtree.c12
-rw-r--r--Modules/_functoolsmodule.c5
-rw-r--r--Modules/_hashopenssl.c5
-rw-r--r--Modules/_hotshot.c10
-rw-r--r--Modules/_lsprof.c6
-rw-r--r--Modules/_randommodule.c7
-rw-r--r--Modules/_sqlite/cache.c10
-rw-r--r--Modules/_sqlite/connection.c5
-rw-r--r--Modules/_sqlite/cursor.c5
-rw-r--r--Modules/_sqlite/prepare_protocol.c7
-rw-r--r--Modules/_sqlite/row.c5
-rw-r--r--Modules/_sqlite/statement.c5
-rw-r--r--Modules/_sre.c2
-rw-r--r--Modules/_ssl.c9
-rw-r--r--Modules/_struct.c11
-rw-r--r--Modules/_testcapimodule.c5
-rw-r--r--Modules/_tkinter.c16
-rw-r--r--Modules/_typesmodule.c3
-rw-r--r--Modules/_weakref.c4
-rw-r--r--Modules/arraymodule.c238
-rw-r--r--Modules/bz2module.c23
-rw-r--r--Modules/cPickle.c30
-rw-r--r--Modules/cStringIO.c10
-rw-r--r--Modules/cjkcodecs/multibytecodec.c23
-rw-r--r--Modules/datetimemodule.c50
-rw-r--r--Modules/dbmmodule.c5
-rw-r--r--Modules/dlmodule.c7
-rw-r--r--Modules/gcmodule.c22
-rw-r--r--Modules/gdbmmodule.c5
-rw-r--r--Modules/itertoolsmodule.c103
-rw-r--r--Modules/linuxaudiodev.c3
-rw-r--r--Modules/md5module.c5
-rw-r--r--Modules/mmapmodule.c5
-rw-r--r--Modules/operator.c6
-rw-r--r--Modules/ossaudiodev.c6
-rw-r--r--Modules/parsermodule.c9
-rw-r--r--Modules/posixmodule.c2
-rw-r--r--Modules/pyexpat.c7
-rw-r--r--Modules/selectmodule.c5
-rw-r--r--Modules/sha256module.c12
-rw-r--r--Modules/sha512module.c10
-rw-r--r--Modules/shamodule.c5
-rw-r--r--Modules/socketmodule.c19
-rw-r--r--Modules/sunaudiodev.c10
-rw-r--r--Modules/threadmodule.c14
-rw-r--r--Modules/unicodedata.c5
-rw-r--r--Modules/xxmodule.c11
-rw-r--r--Modules/xxsubtype.c6
-rw-r--r--Modules/zipimport.c5
-rw-r--r--Modules/zlibmodule.c10
-rw-r--r--Objects/boolobject.c3
-rw-r--r--Objects/bufferobject.c3
-rw-r--r--Objects/cellobject.c3
-rw-r--r--Objects/cobject.c3
-rw-r--r--Objects/codeobject.c3
-rw-r--r--Objects/complexobject.c3
-rw-r--r--Objects/descrobject.c24
-rw-r--r--Objects/dictobject.c20
-rw-r--r--Objects/enumobject.c12
-rw-r--r--Objects/exceptions.c24
-rw-r--r--Objects/fileobject.c5
-rw-r--r--Objects/floatobject.c27
-rw-r--r--Objects/frameobject.c5
-rw-r--r--Objects/funcobject.c17
-rw-r--r--Objects/genobject.c5
-rw-r--r--Objects/intobject.c27
-rw-r--r--Objects/iterobject.c6
-rw-r--r--Objects/listobject.c179
-rw-r--r--Objects/longobject.c178
-rw-r--r--Objects/methodobject.c3
-rw-r--r--Objects/moduleobject.c5
-rw-r--r--Objects/object.c80
-rw-r--r--Objects/obmalloc.c2
-rw-r--r--Objects/setobject.c43
-rw-r--r--Objects/sliceobject.c11
-rw-r--r--Objects/stringobject.c134
-rw-r--r--Objects/structseq.c15
-rw-r--r--Objects/tupleobject.c78
-rw-r--r--Objects/typeobject.c189
-rw-r--r--Objects/unicodeobject.c28
-rw-r--r--Objects/weakrefobject.c33
-rw-r--r--PC/_msi.c12
-rw-r--r--PC/_winreg.c3
-rw-r--r--Python/ceval.c2
-rw-r--r--Python/import.c3
-rw-r--r--Python/symtable.c3
-rw-r--r--Python/traceback.c3
129 files changed, 1090 insertions, 1250 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
diff --git a/Misc/NEWS b/Misc/NEWS
index c4f0eee..1f8c44a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.6 alpha 1?
Core and builtins
-----------------
+- PEP 3123: Provide forward compatibility with Python 3.0, while keeping
+ backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
+ PyVarObject_HEAD_INIT.
+
- Patch #1673759: add a missing overflow check when formatting floats
with %G.
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index e71169c..0347907 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -300,13 +300,13 @@ staticforward PyTypeObject DBSequence_Type;
staticforward PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, DBLock_Type;
-#define DBObject_Check(v) ((v)->ob_type == &DB_Type)
-#define DBCursorObject_Check(v) ((v)->ob_type == &DBCursor_Type)
-#define DBEnvObject_Check(v) ((v)->ob_type == &DBEnv_Type)
-#define DBTxnObject_Check(v) ((v)->ob_type == &DBTxn_Type)
-#define DBLockObject_Check(v) ((v)->ob_type == &DBLock_Type)
+#define DBObject_Check(v) (Py_Type(v) == &DB_Type)
+#define DBCursorObject_Check(v) (Py_Type(v) == &DBCursor_Type)
+#define DBEnvObject_Check(v) (Py_Type(v) == &DBEnv_Type)
+#define DBTxnObject_Check(v) (Py_Type(v) == &DBTxn_Type)
+#define DBLockObject_Check(v) (Py_Type(v) == &DBLock_Type)
#if (DBVER >= 43)
-#define DBSequenceObject_Check(v) ((v)->ob_type == &DBSequence_Type)
+#define DBSequenceObject_Check(v) (Py_Type(v) == &DBSequence_Type)
#endif
@@ -461,7 +461,7 @@ make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags)
else {
PyErr_Format(PyExc_TypeError,
"String or Integer object expected for key, %s found",
- keyobj->ob_type->tp_name);
+ Py_Type(keyobj)->tp_name);
return 0;
}
@@ -616,7 +616,7 @@ static int makeDBError(int err)
static void makeTypeError(char* expected, PyObject* found)
{
PyErr_Format(PyExc_TypeError, "Expected %s argument, %s found.",
- expected, found->ob_type->tp_name);
+ expected, Py_Type(found)->tp_name);
}
@@ -5666,13 +5666,13 @@ DL_EXPORT(void) init_bsddb(void)
/* Initialize the type of the new type objects here; doing it here
is required for portability to Windows without requiring C++. */
- DB_Type.ob_type = &PyType_Type;
- DBCursor_Type.ob_type = &PyType_Type;
- DBEnv_Type.ob_type = &PyType_Type;
- DBTxn_Type.ob_type = &PyType_Type;
- DBLock_Type.ob_type = &PyType_Type;
+ Py_Type(&DB_Type) = &PyType_Type;
+ Py_Type(&DBCursor_Type) = &PyType_Type;
+ Py_Type(&DBEnv_Type) = &PyType_Type;
+ Py_Type(&DBTxn_Type) = &PyType_Type;
+ Py_Type(&DBLock_Type) = &PyType_Type;
#if (DBVER >= 43)
- DBSequence_Type.ob_type = &PyType_Type;
+ Py_Type(&DBSequence_Type) = &PyType_Type;
#endif
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index c70019c..7f5e2ae 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -544,7 +544,7 @@ deque_dealloc(dequeobject *deque)
}
deque->leftblock = NULL;
deque->rightblock = NULL;
- deque->ob_type->tp_free(deque);
+ Py_Type(deque)->tp_free(deque);
}
static int
@@ -579,7 +579,7 @@ deque_nohash(PyObject *self)
static PyObject *
deque_copy(PyObject *deque)
{
- return PyObject_CallFunctionObjArgs((PyObject *)(deque->ob_type),
+ return PyObject_CallFunctionObjArgs((PyObject *)(Py_Type(deque)),
deque, NULL);
}
@@ -601,7 +601,7 @@ deque_reduce(dequeobject *deque)
Py_DECREF(dict);
return NULL;
}
- result = Py_BuildValue("O()ON", deque->ob_type, dict, it);
+ result = Py_BuildValue("O()ON", Py_Type(deque), dict, it);
Py_DECREF(dict);
return result;
}
@@ -825,8 +825,7 @@ PyDoc_STRVAR(deque_doc,
Build an ordered collection accessible from endpoints only.");
static PyTypeObject deque_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"collections.deque", /* tp_name */
sizeof(dequeobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -903,7 +902,7 @@ static void
dequeiter_dealloc(dequeiterobject *dio)
{
Py_XDECREF(dio->deque);
- dio->ob_type->tp_free(dio);
+ Py_Type(dio)->tp_free(dio);
}
static PyObject *
@@ -948,8 +947,7 @@ static PyMethodDef dequeiter_methods[] = {
};
PyTypeObject dequeiter_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"deque_iterator", /* tp_name */
sizeof(dequeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1031,8 +1029,7 @@ dequereviter_next(dequeiterobject *it)
}
PyTypeObject dequereviter_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"deque_reverse_iterator", /* tp_name */
sizeof(dequeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1113,7 +1110,7 @@ defdict_copy(defdictobject *dd)
whose class constructor has the same signature. Subclasses that
define a different constructor signature must override copy().
*/
- return PyObject_CallFunctionObjArgs((PyObject *)dd->dict.ob_type,
+ return PyObject_CallFunctionObjArgs(Py_Type(dd),
dd->default_factory, dd, NULL);
}
@@ -1156,7 +1153,7 @@ defdict_reduce(defdictobject *dd)
Py_DECREF(args);
return NULL;
}
- result = PyTuple_Pack(5, dd->dict.ob_type, args,
+ result = PyTuple_Pack(5, Py_Type(dd), args,
Py_None, Py_None, items);
Py_DECREF(items);
Py_DECREF(args);
@@ -1288,8 +1285,7 @@ A defaultdict compares equal to a dict with the same items.\n\
#define DEFERRED_ADDRESS(ADDR) 0
static PyTypeObject defdict_type = {
- PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"collections.defaultdict", /* tp_name */
sizeof(defdictobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 5e03635..1bb8332 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -125,7 +125,7 @@ typedef struct {
staticforward PyTypeObject Reader_Type;
-#define ReaderObject_Check(v) ((v)->ob_type == &Reader_Type)
+#define ReaderObject_Check(v) (Py_Type(v) == &Reader_Type)
typedef struct {
PyObject_HEAD
@@ -310,7 +310,7 @@ static void
Dialect_dealloc(DialectObj *self)
{
Py_XDECREF(self->lineterminator);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static char *dialect_kws[] = {
@@ -460,8 +460,7 @@ PyDoc_STRVAR(Dialect_Type_doc,
"The Dialect type records CSV parsing and generation options.\n");
static PyTypeObject Dialect_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_csv.Dialect", /* tp_name */
sizeof(DialectObj), /* tp_basicsize */
0, /* tp_itemsize */
@@ -869,8 +868,7 @@ static struct PyMemberDef Reader_memberlist[] = {
static PyTypeObject Reader_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_csv.reader", /*tp_name*/
sizeof(ReaderObj), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -1280,8 +1278,7 @@ PyDoc_STRVAR(Writer_Type_doc,
);
static PyTypeObject Writer_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_csv.writer", /*tp_name*/
sizeof(WriterObj), /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 8eeb865..020f473 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -333,7 +333,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
Py_INCREF(value);
return value;
}
- ob_name = (ob) ? ob->ob_type->tp_name : "???";
+ ob_name = (ob) ? Py_Type(ob)->tp_name : "???";
PyErr_Format(PyExc_TypeError,
"expected %s instance instead of pointer to %s",
((PyTypeObject *)type)->tp_name, ob_name);
@@ -349,7 +349,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
PyErr_Format(PyExc_TypeError,
"expected %s instance instead of %s",
((PyTypeObject *)type)->tp_name,
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return NULL;
}
@@ -435,8 +435,7 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
PyTypeObject StructType_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.StructType", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -478,8 +477,7 @@ PyTypeObject StructType_Type = {
};
static PyTypeObject UnionType_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.UnionType", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -693,8 +691,7 @@ static PyMethodDef PointerType_methods[] = {
};
PyTypeObject PointerType_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.PointerType", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -751,7 +748,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
char *ptr;
Py_ssize_t size;
if (PyBuffer_Check(value)) {
- size = value->ob_type->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
+ size = Py_Type(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
if (size < 0)
return -1;
} else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) {
@@ -800,7 +797,7 @@ CharArray_set_value(CDataObject *self, PyObject *value)
} else if (!PyString_Check(value)) {
PyErr_Format(PyExc_TypeError,
"string expected instead of %s instance",
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return -1;
} else
Py_INCREF(value);
@@ -855,7 +852,7 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
} else if (!PyUnicode_Check(value)) {
PyErr_Format(PyExc_TypeError,
"unicode string expected instead of %s instance",
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return -1;
} else
Py_INCREF(value);
@@ -1051,8 +1048,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
PyTypeObject ArrayType_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.ArrayType", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -1684,8 +1680,7 @@ static PyMethodDef SimpleType_methods[] = {
};
PyTypeObject SimpleType_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.SimpleType", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -1899,8 +1894,7 @@ CFuncPtrType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
PyTypeObject CFuncPtrType_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CFuncPtrType", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -2076,7 +2070,7 @@ static void
CData_dealloc(PyObject *self)
{
CData_clear((CDataObject *)self);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static PyMemberDef CData_members[] = {
@@ -2143,8 +2137,7 @@ static PyMethodDef CData_methods[] = {
};
PyTypeObject CData_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes._CData",
sizeof(CDataObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2350,7 +2343,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
PyErr_Format(PyExc_TypeError,
"expected %s instance, got %s",
((PyTypeObject *)type)->tp_name,
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return NULL;
}
}
@@ -2381,7 +2374,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
if (p1->proto != p2->proto) {
PyErr_Format(PyExc_TypeError,
"incompatible types, %s instance instead of %s instance",
- value->ob_type->tp_name,
+ Py_Type(value)->tp_name,
((PyTypeObject *)type)->tp_name);
return NULL;
}
@@ -2400,7 +2393,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
}
PyErr_Format(PyExc_TypeError,
"incompatible types, %s instance instead of %s instance",
- value->ob_type->tp_name,
+ Py_Type(value)->tp_name,
((PyTypeObject *)type)->tp_name);
return NULL;
}
@@ -2661,7 +2654,7 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
Py_SAFE_DOWNCAST(index, Py_ssize_t, int),
PyType_Check(arg) ?
((PyTypeObject *)arg)->tp_name :
- arg->ob_type->tp_name);
+ Py_Type(arg)->tp_name);
return 0;
}
@@ -3447,7 +3440,7 @@ static void
CFuncPtr_dealloc(CFuncPtrObject *self)
{
CFuncPtr_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static PyObject *
@@ -3457,17 +3450,16 @@ CFuncPtr_repr(CFuncPtrObject *self)
if (self->index)
return PyString_FromFormat("<COM method offset %d: %s at %p>",
self->index - 0x1000,
- self->ob_type->tp_name,
+ Py_Type(self)->tp_name,
self);
#endif
return PyString_FromFormat("<%s object at %p>",
- self->ob_type->tp_name,
+ Py_Type(self)->tp_name,
self);
}
PyTypeObject CFuncPtr_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CFuncPtr",
sizeof(CFuncPtrObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3595,8 +3587,7 @@ Struct_init(PyObject *self, PyObject *args, PyObject *kwds)
}
static PyTypeObject Struct_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.Structure",
sizeof(CDataObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3638,8 +3629,7 @@ static PyTypeObject Struct_Type = {
};
static PyTypeObject Union_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.Union",
sizeof(CDataObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3871,8 +3861,7 @@ static PySequenceMethods Array_as_sequence = {
};
PyTypeObject Array_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.Array",
sizeof(CDataObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -4025,7 +4014,7 @@ static PyGetSetDef Simple_getsets[] = {
static PyObject *
Simple_from_outparm(PyObject *self, PyObject *args)
{
- if (IsSimpleSubType((PyObject *)self->ob_type)) {
+ if (IsSimpleSubType((PyObject *)Py_Type(self))) {
Py_INCREF(self);
return self;
}
@@ -4090,9 +4079,9 @@ Simple_repr(CDataObject *self)
PyObject *val, *name, *args, *result;
static PyObject *format;
- if (self->ob_type->tp_base != &Simple_Type) {
+ if (Py_Type(self)->tp_base != &Simple_Type) {
return PyString_FromFormat("<%s object at %p>",
- self->ob_type->tp_name, self);
+ Py_Type(self)->tp_name, self);
}
if (format == NULL) {
@@ -4105,7 +4094,7 @@ Simple_repr(CDataObject *self)
if (val == NULL)
return NULL;
- name = PyString_FromString(self->ob_type->tp_name);
+ name = PyString_FromString(Py_Type(self)->tp_name);
if (name == NULL) {
Py_DECREF(val);
return NULL;
@@ -4123,8 +4112,7 @@ Simple_repr(CDataObject *self)
}
static PyTypeObject Simple_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes._SimpleCData",
sizeof(CDataObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -4277,7 +4265,7 @@ Pointer_set_contents(CDataObject *self, PyObject *value, void *closure)
PyErr_Format(PyExc_TypeError,
"expected %s instead of %s",
((PyTypeObject *)(stgdict->proto))->tp_name,
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return -1;
}
@@ -4406,8 +4394,7 @@ static PyNumberMethods Pointer_as_number = {
};
PyTypeObject Pointer_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes._Pointer",
sizeof(CDataObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -4585,7 +4572,7 @@ cast_check_pointertype(PyObject *arg)
"cast() argument 2 must be a pointer type, not %s",
PyType_Check(arg)
? ((PyTypeObject *)arg)->tp_name
- : arg->ob_type->tp_name);
+ : Py_Type(arg)->tp_name);
return 0;
}
@@ -4712,37 +4699,37 @@ init_ctypes(void)
if (PyType_Ready(&CData_Type) < 0)
return;
- Struct_Type.ob_type = &StructType_Type;
+ Py_Type(&Struct_Type) = &StructType_Type;
Struct_Type.tp_base = &CData_Type;
if (PyType_Ready(&Struct_Type) < 0)
return;
PyModule_AddObject(m, "Structure", (PyObject *)&Struct_Type);
- Union_Type.ob_type = &UnionType_Type;
+ Py_Type(&Union_Type) = &UnionType_Type;
Union_Type.tp_base = &CData_Type;
if (PyType_Ready(&Union_Type) < 0)
return;
PyModule_AddObject(m, "Union", (PyObject *)&Union_Type);
- Pointer_Type.ob_type = &PointerType_Type;
+ Py_Type(&Pointer_Type) = &PointerType_Type;
Pointer_Type.tp_base = &CData_Type;
if (PyType_Ready(&Pointer_Type) < 0)
return;
PyModule_AddObject(m, "_Pointer", (PyObject *)&Pointer_Type);
- Array_Type.ob_type = &ArrayType_Type;
+ Py_Type(&Array_Type) = &ArrayType_Type;
Array_Type.tp_base = &CData_Type;
if (PyType_Ready(&Array_Type) < 0)
return;
PyModule_AddObject(m, "Array", (PyObject *)&Array_Type);
- Simple_Type.ob_type = &SimpleType_Type;
+ Py_Type(&Simple_Type) = &SimpleType_Type;
Simple_Type.tp_base = &CData_Type;
if (PyType_Ready(&Simple_Type) < 0)
return;
PyModule_AddObject(m, "_SimpleCData", (PyObject *)&Simple_Type);
- CFuncPtr_Type.ob_type = &CFuncPtrType_Type;
+ Py_Type(&CFuncPtr_Type) = &CFuncPtrType_Type;
CFuncPtr_Type.tp_base = &CData_Type;
if (PyType_Ready(&CFuncPtr_Type) < 0)
return;
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 7f95b9e..80d6dff 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -381,8 +381,7 @@ static PyMemberDef PyCArgType_members[] = {
};
PyTypeObject PyCArg_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"CArgObject",
sizeof(PyCArgObject),
0,
@@ -1180,7 +1179,7 @@ call_commethod(PyObject *self, PyObject *args)
if (!CDataObject_Check(pcom) || (pcom->b_size != sizeof(void *))) {
PyErr_Format(PyExc_TypeError,
"COM Pointer expected instead of %s instance",
- pcom->ob_type->tp_name);
+ Py_Type(pcom)->tp_name);
return NULL;
}
@@ -1420,7 +1419,7 @@ byref(PyObject *self, PyObject *obj)
if (!CDataObject_Check(obj)) {
PyErr_Format(PyExc_TypeError,
"byref() argument must be a ctypes instance, not '%s'",
- obj->ob_type->tp_name);
+ Py_Type(obj)->tp_name);
return NULL;
}
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index ccdab0a..0e4c19e 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -286,8 +286,7 @@ CField_repr(CFieldObject *self)
}
PyTypeObject CField_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_ctypes.CField", /* tp_name */
sizeof(CFieldObject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index cfa72ef..a126eb7 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -83,8 +83,7 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src)
}
PyTypeObject StgDict_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"StgDict",
sizeof(StgDictObject),
0,
@@ -192,7 +191,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
Py_DECREF(fieldlist);
return -1;
}
- if (fdescr->ob_type != &CField_Type) {
+ if (Py_Type(fdescr) != &CField_Type) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
Py_DECREF(fdescr);
Py_DECREF(fieldlist);
@@ -215,7 +214,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
Py_DECREF(fieldlist);
return -1;
}
- assert(new_descr->ob_type == &CField_Type);
+ assert(Py_Type(new_descr) == &CField_Type);
new_descr->size = fdescr->size;
new_descr->offset = fdescr->offset + offset;
new_descr->index = fdescr->index + index;
@@ -263,7 +262,7 @@ MakeAnonFields(PyObject *type)
Py_DECREF(anon_names);
return -1;
}
- assert(descr->ob_type == &CField_Type);
+ assert(Py_Type(descr) == &CField_Type);
descr->anonymous = 1;
/* descr is in the field descriptor. */
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index 0acf3fd..5eb4cf8 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -56,7 +56,7 @@ typedef struct {
PyTypeObject PyCursesPanel_Type;
-#define PyCursesPanel_Check(v) ((v)->ob_type == &PyCursesPanel_Type)
+#define PyCursesPanel_Check(v) (Py_Type(v) == &PyCursesPanel_Type)
/* Some helper functions. The problem is that there's always a window
associated with a panel. To ensure that Python's GC doesn't pull
@@ -338,8 +338,7 @@ PyCursesPanel_GetAttr(PyCursesPanelObject *self, char *name)
/* -------------------------------------------------------*/
PyTypeObject PyCursesPanel_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_curses_panel.curses panel", /*tp_name*/
sizeof(PyCursesPanelObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -458,7 +457,7 @@ init_curses_panel(void)
PyObject *m, *d, *v;
/* Initialize object type */
- PyCursesPanel_Type.ob_type = &PyType_Type;
+ Py_Type(&PyCursesPanel_Type) = &PyType_Type;
import_curses();
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 1ee407e..fa6548a 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -1566,8 +1566,7 @@ PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
/* -------------------------------------------------------*/
PyTypeObject PyCursesWindow_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_curses.curses window", /*tp_name*/
sizeof(PyCursesWindowObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -2657,7 +2656,7 @@ init_curses(void)
static void *PyCurses_API[PyCurses_API_pointers];
/* Initialize object type */
- PyCursesWindow_Type.ob_type = &PyType_Type;
+ Py_Type(&PyCursesWindow_Type) = &PyType_Type;
/* Initialize the C API pointer array */
PyCurses_API[0] = (void *)&PyCursesWindow_Type;
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index f21cf56..d8a28b4 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -269,7 +269,7 @@ typedef struct {
staticforward PyTypeObject Element_Type;
-#define Element_CheckExact(op) ((op)->ob_type == &Element_Type)
+#define Element_CheckExact(op) (Py_Type(op) == &Element_Type)
/* -------------------------------------------------------------------- */
/* element constructor and destructor */
@@ -1207,7 +1207,7 @@ element_setslice(PyObject* self_, Py_ssize_t start, Py_ssize_t end, PyObject* it
/* FIXME: support arbitrary sequences? */
PyErr_Format(
PyExc_TypeError,
- "expected list, not \"%.200s\"", item->ob_type->tp_name
+ "expected list, not \"%.200s\"", Py_Type(item)->tp_name
);
return -1;
}
@@ -1440,7 +1440,7 @@ typedef struct {
staticforward PyTypeObject TreeBuilder_Type;
-#define TreeBuilder_CheckExact(op) ((op)->ob_type == &TreeBuilder_Type)
+#define TreeBuilder_CheckExact(op) (Py_Type(op) == &TreeBuilder_Type)
/* -------------------------------------------------------------------- */
/* constructor and destructor */
@@ -1607,7 +1607,7 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
Py_INCREF(data); self->data = data;
} else {
/* more than one item; use a list to collect items */
- if (PyString_CheckExact(self->data) && self->data->ob_refcnt == 1 &&
+ if (PyString_CheckExact(self->data) && Py_Refcnt(self->data) == 1 &&
PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) {
/* expat often generates single character data sections; handle
the most common case by resizing the existing string... */
@@ -2623,9 +2623,9 @@ init_elementtree(void)
#endif
/* Patch object type */
- Element_Type.ob_type = TreeBuilder_Type.ob_type = &PyType_Type;
+ Py_Type(&Element_Type) = Py_Type(&TreeBuilder_Type) = &PyType_Type;
#if defined(USE_EXPAT)
- XMLParser_Type.ob_type = &PyType_Type;
+ Py_Type(&XMLParser_Type) = &PyType_Type;
#endif
m = Py_InitModule("_elementtree", _functions);
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 54abb89..96bdc20 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -81,7 +81,7 @@ partial_dealloc(partialobject *pto)
Py_XDECREF(pto->args);
Py_XDECREF(pto->kw);
Py_XDECREF(pto->dict);
- pto->ob_type->tp_free(pto);
+ Py_Type(pto)->tp_free(pto);
}
static PyObject *
@@ -197,8 +197,7 @@ static PyGetSetDef partial_getsetlist[] = {
};
static PyTypeObject partial_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"functools.partial", /* tp_name */
sizeof(partialobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 859644f..fa8dafc 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -281,8 +281,7 @@ name -- the hash algorithm being used by this object\n\
digest_size -- number of bytes in this hashes output\n");
static PyTypeObject EVPtype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_hashlib.HASH", /*tp_name*/
sizeof(EVPobject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -464,7 +463,7 @@ init_hashlib(void)
* but having some be unsupported. Only init appropriate
* constants. */
- EVPtype.ob_type = &PyType_Type;
+ Py_Type(&EVPtype) = &PyType_Type;
if (PyType_Ready(&EVPtype) < 0)
return;
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 21bd383..4bbb3b5 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -1220,8 +1220,7 @@ PyDoc_STRVAR(profiler_object__doc__,
"linetimings: True if line events collect timing information.");
static PyTypeObject ProfilerType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_hotshot.ProfilerType", /* tp_name */
(int) sizeof(ProfilerObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1305,8 +1304,7 @@ static PyGetSetDef logreader_getsets[] = {
};
static PyTypeObject LogReaderType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_hotshot.LogReaderType", /* tp_name */
(int) sizeof(LogReaderObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1613,8 +1611,8 @@ init_hotshot(void)
{
PyObject *module;
- LogReaderType.ob_type = &PyType_Type;
- ProfilerType.ob_type = &PyType_Type;
+ Py_Type(&LogReaderType) = &PyType_Type;
+ Py_Type(&ProfilerType) = &PyType_Type;
module = Py_InitModule("_hotshot", functions);
if (module != NULL) {
char *s = get_version_string();
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index d35c894..5b03b56 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -120,7 +120,7 @@ typedef struct {
staticforward PyTypeObject PyProfiler_Type;
#define PyProfiler_Check(op) PyObject_TypeCheck(op, &PyProfiler_Type)
-#define PyProfiler_CheckExact(op) ((op)->ob_type == &PyProfiler_Type)
+#define PyProfiler_CheckExact(op) (Py_Type(op) == &PyProfiler_Type)
/*** External Timers ***/
@@ -207,7 +207,7 @@ normalizeUserObj(PyObject *obj)
PyObject *self = fn->m_self;
PyObject *name = PyString_FromString(fn->m_ml->ml_name);
if (name != NULL) {
- PyObject *mo = _PyType_Lookup(self->ob_type, name);
+ PyObject *mo = _PyType_Lookup(Py_Type(self), name);
Py_XINCREF(mo);
Py_DECREF(name);
if (mo != NULL) {
@@ -744,7 +744,7 @@ profiler_dealloc(ProfilerObject *op)
flush_unmatched(op);
clearEntries(op);
Py_XDECREF(op->externalTimer);
- op->ob_type->tp_free(op);
+ Py_Type(op)->tp_free(op);
}
static int
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 591947e..25adc2e 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -84,7 +84,7 @@ typedef struct {
static PyTypeObject Random_Type;
-#define RandomObject_Check(v) ((v)->ob_type == &Random_Type)
+#define RandomObject_Check(v) (Py_Type(v) == &Random_Type)
/* Random methods */
@@ -404,7 +404,7 @@ random_jumpahead(RandomObject *self, PyObject *n)
if (!PyInt_Check(n) && !PyLong_Check(n)) {
PyErr_Format(PyExc_TypeError, "jumpahead requires an "
"integer, not '%s'",
- n->ob_type->tp_name);
+ Py_Type(n)->tp_name);
return NULL;
}
@@ -518,8 +518,7 @@ PyDoc_STRVAR(random_doc,
"Random() -> create a random number generator with its own internal state.");
static PyTypeObject Random_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_random.Random", /*tp_name*/
sizeof(RandomObject), /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c
index 6094eb3..829c175 100644
--- a/Modules/_sqlite/cache.c
+++ b/Modules/_sqlite/cache.c
@@ -51,7 +51,7 @@ void pysqlite_node_dealloc(pysqlite_Node* self)
Py_DECREF(self->key);
Py_DECREF(self->data);
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs)
@@ -109,7 +109,7 @@ void pysqlite_cache_dealloc(pysqlite_Cache* self)
}
Py_DECREF(self->mapping);
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args)
@@ -274,8 +274,7 @@ static PyMethodDef cache_methods[] = {
};
PyTypeObject pysqlite_NodeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME "Node", /* tp_name */
sizeof(pysqlite_Node), /* tp_basicsize */
0, /* tp_itemsize */
@@ -317,8 +316,7 @@ PyTypeObject pysqlite_NodeType = {
};
PyTypeObject pysqlite_CacheType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".Cache", /* tp_name */
sizeof(pysqlite_Cache), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 924d582..add2e6f 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -205,7 +205,7 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
Py_XDECREF(self->collations);
Py_XDECREF(self->statements);
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
@@ -1206,8 +1206,7 @@ static struct PyMemberDef connection_members[] =
};
PyTypeObject pysqlite_ConnectionType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".Connection", /* tp_name */
sizeof(pysqlite_Connection), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 4ca1063..2032a25 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -134,7 +134,7 @@ void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
Py_XDECREF(self->row_factory);
Py_XDECREF(self->next_row);
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
PyObject* _pysqlite_get_converter(PyObject* key)
@@ -1020,8 +1020,7 @@ static char cursor_doc[] =
PyDoc_STR("SQLite database cursor class.");
PyTypeObject pysqlite_CursorType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".Cursor", /* tp_name */
sizeof(pysqlite_Cursor), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_sqlite/prepare_protocol.c b/Modules/_sqlite/prepare_protocol.c
index a8ca518..c979610 100644
--- a/Modules/_sqlite/prepare_protocol.c
+++ b/Modules/_sqlite/prepare_protocol.c
@@ -30,12 +30,11 @@ int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* arg
void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self)
{
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
PyTypeObject pysqlite_PrepareProtocolType= {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".PrepareProtocol", /* tp_name */
sizeof(pysqlite_PrepareProtocol), /* tp_basicsize */
0, /* tp_itemsize */
@@ -79,6 +78,6 @@ PyTypeObject pysqlite_PrepareProtocolType= {
extern int pysqlite_prepare_protocol_setup_types(void)
{
pysqlite_PrepareProtocolType.tp_new = PyType_GenericNew;
- pysqlite_PrepareProtocolType.ob_type= &PyType_Type;
+ Py_Type(&pysqlite_PrepareProtocolType)= &PyType_Type;
return PyType_Ready(&pysqlite_PrepareProtocolType);
}
diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c
index 7cfcfc3..9ada8a9 100644
--- a/Modules/_sqlite/row.c
+++ b/Modules/_sqlite/row.c
@@ -30,7 +30,7 @@ void pysqlite_row_dealloc(pysqlite_Row* self)
Py_XDECREF(self->data);
Py_XDECREF(self->description);
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
int pysqlite_row_init(pysqlite_Row* self, PyObject* args, PyObject* kwargs)
@@ -183,8 +183,7 @@ static PyMethodDef pysqlite_row_methods[] = {
PyTypeObject pysqlite_RowType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".Row", /* tp_name */
sizeof(pysqlite_Row), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 86d2178..20c1aac 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -309,7 +309,7 @@ void pysqlite_statement_dealloc(pysqlite_Statement* self)
PyObject_ClearWeakRefs((PyObject*)self);
}
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
/*
@@ -383,8 +383,7 @@ static int pysqlite_check_remaining_sql(const char* tail)
}
PyTypeObject pysqlite_StatementType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".Statement", /* tp_name */
sizeof(pysqlite_Statement), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_sre.c b/Modules/_sre.c
index c1eb71c..7dafaeb 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1689,7 +1689,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
#endif
/* get pointer to string buffer */
- buffer = string->ob_type->tp_as_buffer;
+ buffer = Py_Type(string)->tp_as_buffer;
if (!buffer || !buffer->bf_getreadbuffer || !buffer->bf_getsegcount ||
buffer->bf_getsegcount(string, NULL) != 1) {
PyErr_SetString(PyExc_TypeError, "expected string or buffer");
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index f1e1092..d0f7115 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -72,7 +72,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args);
static int check_socket_and_wait_for_timeout(PySocketSockObject *s,
int writing);
-#define PySSLObject_Check(v) ((v)->ob_type == &PySSL_Type)
+#define PySSLObject_Check(v) (Py_Type(v) == &PySSL_Type)
typedef enum {
SOCKET_IS_NONBLOCKING,
@@ -570,8 +570,7 @@ static PyObject *PySSL_getattr(PySSLObject *self, char *name)
}
static PyTypeObject PySSL_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"socket.SSL", /*tp_name*/
sizeof(PySSLObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -632,7 +631,7 @@ PySSL_RAND_egd(PyObject *self, PyObject *arg)
if (!PyString_Check(arg))
return PyErr_Format(PyExc_TypeError,
"RAND_egd() expected string, found %s",
- arg->ob_type->tp_name);
+ Py_Type(arg)->tp_name);
bytes = RAND_egd(PyString_AS_STRING(arg));
if (bytes == -1) {
PyErr_SetString(PySSLErrorObject,
@@ -678,7 +677,7 @@ init_ssl(void)
{
PyObject *m, *d;
- PySSL_Type.ob_type = &PyType_Type;
+ Py_Type(&PySSL_Type) = &PyType_Type;
m = Py_InitModule3("_ssl", PySSL_methods, module_doc);
if (m == NULL)
diff --git a/Modules/_struct.c b/Modules/_struct.c
index ee938d6..36e64be 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -72,7 +72,7 @@ typedef struct {
#define PyStruct_Check(op) PyObject_TypeCheck(op, &PyStructType)
-#define PyStruct_CheckExact(op) ((op)->ob_type == &PyStructType)
+#define PyStruct_CheckExact(op) (Py_Type(op) == &PyStructType)
/* Exception */
@@ -133,7 +133,7 @@ get_pylong(PyObject *v)
Py_INCREF(v);
return v;
}
- m = v->ob_type->tp_as_number;
+ m = Py_Type(v)->tp_as_number;
if (m != NULL && m->nb_long != NULL) {
v = m->nb_long(v);
if (v == NULL)
@@ -1487,7 +1487,7 @@ s_dealloc(PyStructObject *s)
PyMem_FREE(s->s_codes);
}
Py_XDECREF(s->s_format);
- s->ob_type->tp_free((PyObject *)s);
+ Py_Type(s)->tp_free((PyObject *)s);
}
static PyObject *
@@ -1806,8 +1806,7 @@ static PyGetSetDef s_getsetlist[] = {
static
PyTypeObject PyStructType = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"Struct",
sizeof(PyStructObject),
0,
@@ -1857,7 +1856,7 @@ init_struct(void)
if (m == NULL)
return;
- PyStructType.ob_type = &PyType_Type;
+ Py_Type(&PyStructType) = &PyType_Type;
if (PyType_Ready(&PyStructType) < 0)
return;
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 84dc1e1..c5a0bc5 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -839,8 +839,7 @@ static void test_structmembers_free(PyObject *ob){
}
static PyTypeObject test_structmembersType = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"test_structmembersType",
sizeof(test_structmembers), /* tp_basicsize */
0, /* tp_itemsize */
@@ -890,7 +889,7 @@ init_testcapi(void)
if (m == NULL)
return;
- test_structmembersType.ob_type=&PyType_Type;
+ Py_Type(&test_structmembersType)=&PyType_Type;
Py_INCREF(&test_structmembersType);
PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType);
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 22d930b..07570f3 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -262,12 +262,12 @@ typedef struct {
Tcl_ObjType *StringType;
} TkappObject;
-#define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type)
+#define Tkapp_Check(v) (Py_Type(v) == &Tkapp_Type)
#define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
#define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v))
#define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \
-(void *) v, ((PyObject *) v)->ob_refcnt))
+(void *) v, Py_Refcnt(v)))
@@ -2420,8 +2420,7 @@ Tktt_GetAttr(PyObject *self, char *name)
static PyTypeObject Tktt_Type =
{
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"tktimertoken", /*tp_name */
sizeof(TkttObject), /*tp_basicsize */
0, /*tp_itemsize */
@@ -2765,8 +2764,7 @@ Tkapp_GetAttr(PyObject *self, char *name)
static PyTypeObject Tkapp_Type =
{
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"tkapp", /*tp_name */
sizeof(TkappObject), /*tp_basicsize */
0, /*tp_itemsize */
@@ -3105,7 +3103,7 @@ init_tkinter(void)
{
PyObject *m, *d;
- Tkapp_Type.ob_type = &PyType_Type;
+ Py_Type(&Tkapp_Type) = &PyType_Type;
#ifdef WITH_THREAD
tcl_lock = PyThread_allocate_lock();
@@ -3133,10 +3131,10 @@ init_tkinter(void)
PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type);
- Tktt_Type.ob_type = &PyType_Type;
+ Py_Type(&Tktt_Type) = &PyType_Type;
PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
- PyTclObject_Type.ob_type = &PyType_Type;
+ Py_Type(&PyTclObject_Type) = &PyType_Type;
PyDict_SetItemString(d, "Tcl_Obj", (PyObject *)&PyTclObject_Type);
#ifdef TK_AQUA
diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c
index 5a6f2b9..e925664 100644
--- a/Modules/_typesmodule.c
+++ b/Modules/_typesmodule.c
@@ -33,8 +33,7 @@ static PyGetSetDef helper_getset[] = {
};
static PyTypeObject HelperType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_types.Helper", /* tp_name */
sizeof(Helper), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_weakref.c b/Modules/_weakref.c
index 1712f12..cb7977b 100644
--- a/Modules/_weakref.c
+++ b/Modules/_weakref.c
@@ -14,7 +14,7 @@ weakref_getweakrefcount(PyObject *self, PyObject *object)
{
PyObject *result = NULL;
- if (PyType_SUPPORTS_WEAKREFS(object->ob_type)) {
+ if (PyType_SUPPORTS_WEAKREFS(Py_Type(object))) {
PyWeakReference **list = GET_WEAKREFS_LISTPTR(object);
result = PyInt_FromSsize_t(_PyWeakref_GetWeakrefCount(*list));
@@ -35,7 +35,7 @@ weakref_getweakrefs(PyObject *self, PyObject *object)
{
PyObject *result = NULL;
- if (PyType_SUPPORTS_WEAKREFS(object->ob_type)) {
+ if (PyType_SUPPORTS_WEAKREFS(Py_Type(object))) {
PyWeakReference **list = GET_WEAKREFS_LISTPTR(object);
Py_ssize_t count = _PyWeakref_GetWeakrefCount(*list);
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 3ba5cf8..21a5e5b 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -39,7 +39,7 @@ typedef struct arrayobject {
static PyTypeObject Arraytype;
#define array_Check(op) PyObject_TypeCheck(op, &Arraytype)
-#define array_CheckExact(op) ((op)->ob_type == &Arraytype)
+#define array_CheckExact(op) (Py_Type(op) == &Arraytype)
static int
array_resize(arrayobject *self, Py_ssize_t newsize)
@@ -53,9 +53,9 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
*/
if (self->allocated >= newsize &&
- self->ob_size < newsize + 16 &&
+ Py_Size(self) < newsize + 16 &&
self->ob_item != NULL) {
- self->ob_size = newsize;
+ Py_Size(self) = newsize;
return 0;
}
@@ -71,7 +71,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
* memory critical.
*/
- _new_size = (newsize >> 4) + (self->ob_size < 8 ? 3 : 7) + newsize;
+ _new_size = (newsize >> 4) + (Py_Size(self) < 8 ? 3 : 7) + newsize;
items = self->ob_item;
/* XXX The following multiplication and division does not optimize away
like it does for lists since the size is not known at compile time */
@@ -84,7 +84,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
return -1;
}
self->ob_item = items;
- self->ob_size = newsize;
+ Py_Size(self) = newsize;
self->allocated = _new_size;
return 0;
}
@@ -432,7 +432,7 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr)
if (op == NULL) {
return NULL;
}
- op->ob_size = size;
+ Py_Size(op) = size;
if (size <= 0) {
op->ob_item = NULL;
}
@@ -455,7 +455,7 @@ getarrayitem(PyObject *op, Py_ssize_t i)
register arrayobject *ap;
assert(array_Check(op));
ap = (arrayobject *)op;
- assert(i>=0 && i<ap->ob_size);
+ assert(i>=0 && i<Py_Size(ap));
return (*ap->ob_descr->getitem)(ap, i);
}
@@ -463,7 +463,7 @@ static int
ins1(arrayobject *self, Py_ssize_t where, PyObject *v)
{
char *items;
- Py_ssize_t n = self->ob_size;
+ Py_ssize_t n = Py_Size(self);
if (v == NULL) {
PyErr_BadInternalCall();
return -1;
@@ -498,7 +498,7 @@ array_dealloc(arrayobject *op)
PyObject_ClearWeakRefs((PyObject *) op);
if (op->ob_item != NULL)
PyMem_DEL(op->ob_item);
- op->ob_type->tp_free((PyObject *)op);
+ Py_Type(op)->tp_free((PyObject *)op);
}
static PyObject *
@@ -518,7 +518,7 @@ array_richcompare(PyObject *v, PyObject *w, int op)
va = (arrayobject *)v;
wa = (arrayobject *)w;
- if (va->ob_size != wa->ob_size && (op == Py_EQ || op == Py_NE)) {
+ if (Py_Size(va) != Py_Size(wa) && (op == Py_EQ || op == Py_NE)) {
/* Shortcut: if the lengths differ, the arrays differ */
if (op == Py_EQ)
res = Py_False;
@@ -530,7 +530,7 @@ array_richcompare(PyObject *v, PyObject *w, int op)
/* Search for the first index where items are different */
k = 1;
- for (i = 0; i < va->ob_size && i < wa->ob_size; i++) {
+ for (i = 0; i < Py_Size(va) && i < Py_Size(wa); i++) {
vi = getarrayitem(v, i);
wi = getarrayitem(w, i);
if (vi == NULL || wi == NULL) {
@@ -549,8 +549,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
if (k) {
/* No more items to compare -- compare sizes */
- Py_ssize_t vs = va->ob_size;
- Py_ssize_t ws = wa->ob_size;
+ Py_ssize_t vs = Py_Size(va);
+ Py_ssize_t ws = Py_Size(wa);
int cmp;
switch (op) {
case Py_LT: cmp = vs < ws; break;
@@ -590,13 +590,13 @@ array_richcompare(PyObject *v, PyObject *w, int op)
static Py_ssize_t
array_length(arrayobject *a)
{
- return a->ob_size;
+ return Py_Size(a);
}
static PyObject *
array_item(arrayobject *a, Py_ssize_t i)
{
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError, "array index out of range");
return NULL;
}
@@ -609,14 +609,14 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
arrayobject *np;
if (ilow < 0)
ilow = 0;
- else if (ilow > a->ob_size)
- ilow = a->ob_size;
+ else if (ilow > Py_Size(a))
+ ilow = Py_Size(a);
if (ihigh < 0)
ihigh = 0;
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ else if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr);
if (np == NULL)
return NULL;
@@ -628,7 +628,7 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
static PyObject *
array_copy(arrayobject *a, PyObject *unused)
{
- return array_slice(a, 0, a->ob_size);
+ return array_slice(a, 0, Py_Size(a));
}
PyDoc_STRVAR(copy_doc,
@@ -644,7 +644,7 @@ array_concat(arrayobject *a, PyObject *bb)
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
"can only append array (not \"%.200s\") to array",
- bb->ob_type->tp_name);
+ Py_Type(bb)->tp_name);
return NULL;
}
#define b ((arrayobject *)bb)
@@ -652,14 +652,14 @@ array_concat(arrayobject *a, PyObject *bb)
PyErr_BadArgument();
return NULL;
}
- size = a->ob_size + b->ob_size;
+ size = Py_Size(a) + Py_Size(b);
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL) {
return NULL;
}
- memcpy(np->ob_item, a->ob_item, a->ob_size*a->ob_descr->itemsize);
- memcpy(np->ob_item + a->ob_size*a->ob_descr->itemsize,
- b->ob_item, b->ob_size*b->ob_descr->itemsize);
+ memcpy(np->ob_item, a->ob_item, Py_Size(a)*a->ob_descr->itemsize);
+ memcpy(np->ob_item + Py_Size(a)*a->ob_descr->itemsize,
+ b->ob_item, Py_Size(b)*b->ob_descr->itemsize);
return (PyObject *)np;
#undef b
}
@@ -674,12 +674,12 @@ array_repeat(arrayobject *a, Py_ssize_t n)
Py_ssize_t nbytes;
if (n < 0)
n = 0;
- size = a->ob_size * n;
+ size = Py_Size(a) * n;
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL)
return NULL;
p = np->ob_item;
- nbytes = a->ob_size * a->ob_descr->itemsize;
+ nbytes = Py_Size(a) * a->ob_descr->itemsize;
for (i = 0; i < n; i++) {
memcpy(p, a->ob_item, nbytes);
p += nbytes;
@@ -697,7 +697,7 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
if (v == NULL)
n = 0;
else if (array_Check(v)) {
- n = b->ob_size;
+ n = Py_Size(b);
if (a == b) {
/* Special case "a[i:j] = a" -- copy b first */
int ret;
@@ -716,44 +716,44 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
else {
PyErr_Format(PyExc_TypeError,
"can only assign array (not \"%.200s\") to array slice",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
return -1;
}
if (ilow < 0)
ilow = 0;
- else if (ilow > a->ob_size)
- ilow = a->ob_size;
+ else if (ilow > Py_Size(a))
+ ilow = Py_Size(a);
if (ihigh < 0)
ihigh = 0;
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ else if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
item = a->ob_item;
d = n - (ihigh-ilow);
if (d < 0) { /* Delete -d items */
memmove(item + (ihigh+d)*a->ob_descr->itemsize,
item + ihigh*a->ob_descr->itemsize,
- (a->ob_size-ihigh)*a->ob_descr->itemsize);
- a->ob_size += d;
- PyMem_RESIZE(item, char, a->ob_size*a->ob_descr->itemsize);
+ (Py_Size(a)-ihigh)*a->ob_descr->itemsize);
+ Py_Size(a) += d;
+ PyMem_RESIZE(item, char, Py_Size(a)*a->ob_descr->itemsize);
/* Can't fail */
a->ob_item = item;
- a->allocated = a->ob_size;
+ a->allocated = Py_Size(a);
}
else if (d > 0) { /* Insert d items */
PyMem_RESIZE(item, char,
- (a->ob_size + d)*a->ob_descr->itemsize);
+ (Py_Size(a) + d)*a->ob_descr->itemsize);
if (item == NULL) {
PyErr_NoMemory();
return -1;
}
memmove(item + (ihigh+d)*a->ob_descr->itemsize,
item + ihigh*a->ob_descr->itemsize,
- (a->ob_size-ihigh)*a->ob_descr->itemsize);
+ (Py_Size(a)-ihigh)*a->ob_descr->itemsize);
a->ob_item = item;
- a->ob_size += d;
- a->allocated = a->ob_size;
+ Py_Size(a) += d;
+ a->allocated = Py_Size(a);
}
if (n > 0)
memcpy(item + ilow*a->ob_descr->itemsize, b->ob_item,
@@ -765,7 +765,7 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
static int
array_ass_item(arrayobject *a, Py_ssize_t i, PyObject *v)
{
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError,
"array assignment index out of range");
return -1;
@@ -792,7 +792,7 @@ array_iter_extend(arrayobject *self, PyObject *bb)
return -1;
while ((v = PyIter_Next(it)) != NULL) {
- if (ins1(self, (int) self->ob_size, v) != 0) {
+ if (ins1(self, (int) Py_Size(self), v) != 0) {
Py_DECREF(v);
Py_DECREF(it);
return -1;
@@ -818,16 +818,16 @@ array_do_extend(arrayobject *self, PyObject *bb)
"can only extend with array of same kind");
return -1;
}
- size = self->ob_size + b->ob_size;
+ size = Py_Size(self) + Py_Size(b);
PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize);
if (self->ob_item == NULL) {
PyObject_Del(self);
PyErr_NoMemory();
return -1;
}
- memcpy(self->ob_item + self->ob_size*self->ob_descr->itemsize,
- b->ob_item, b->ob_size*b->ob_descr->itemsize);
- self->ob_size = size;
+ memcpy(self->ob_item + Py_Size(self)*self->ob_descr->itemsize,
+ b->ob_item, Py_Size(b)*b->ob_descr->itemsize);
+ Py_Size(self) = size;
self->allocated = size;
return 0;
@@ -840,7 +840,7 @@ array_inplace_concat(arrayobject *self, PyObject *bb)
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
"can only extend array with array (not \"%.200s\")",
- bb->ob_type->tp_name);
+ Py_Type(bb)->tp_name);
return NULL;
}
if (array_do_extend(self, bb) == -1)
@@ -855,15 +855,15 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
char *items, *p;
Py_ssize_t size, i;
- if (self->ob_size > 0) {
+ if (Py_Size(self) > 0) {
if (n < 0)
n = 0;
items = self->ob_item;
- size = self->ob_size * self->ob_descr->itemsize;
+ size = Py_Size(self) * self->ob_descr->itemsize;
if (n == 0) {
PyMem_FREE(items);
self->ob_item = NULL;
- self->ob_size = 0;
+ Py_Size(self) = 0;
self->allocated = 0;
}
else {
@@ -876,8 +876,8 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
memcpy(p, items, size);
}
self->ob_item = items;
- self->ob_size *= n;
- self->allocated = self->ob_size;
+ Py_Size(self) *= n;
+ self->allocated = Py_Size(self);
}
}
Py_INCREF(self);
@@ -900,7 +900,7 @@ array_count(arrayobject *self, PyObject *v)
Py_ssize_t count = 0;
Py_ssize_t i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -922,7 +922,7 @@ array_index(arrayobject *self, PyObject *v)
{
Py_ssize_t i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -947,7 +947,7 @@ array_contains(arrayobject *self, PyObject *v)
Py_ssize_t i;
int cmp;
- for (i = 0, cmp = 0 ; cmp == 0 && i < self->ob_size; i++) {
+ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -960,7 +960,7 @@ array_remove(arrayobject *self, PyObject *v)
{
int i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self,i);
int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -990,14 +990,14 @@ array_pop(arrayobject *self, PyObject *args)
PyObject *v;
if (!PyArg_ParseTuple(args, "|n:pop", &i))
return NULL;
- if (self->ob_size == 0) {
+ if (Py_Size(self) == 0) {
/* Special-case most common failure cause */
PyErr_SetString(PyExc_IndexError, "pop from empty array");
return NULL;
}
if (i < 0)
- i += self->ob_size;
- if (i < 0 || i >= self->ob_size) {
+ i += Py_Size(self);
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "pop index out of range");
return NULL;
}
@@ -1053,7 +1053,7 @@ array_buffer_info(arrayobject *self, PyObject *unused)
return NULL;
PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
- PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(self->ob_size)));
+ PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(Py_Size(self))));
return retval;
}
@@ -1070,7 +1070,7 @@ the buffer length in bytes.");
static PyObject *
array_append(arrayobject *self, PyObject *v)
{
- return ins(self, (int) self->ob_size, v);
+ return ins(self, (int) Py_Size(self), v);
}
PyDoc_STRVAR(append_doc,
@@ -1089,14 +1089,14 @@ array_byteswap(arrayobject *self, PyObject *unused)
case 1:
break;
case 2:
- for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 2) {
+ for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 2) {
char p0 = p[0];
p[0] = p[1];
p[1] = p0;
}
break;
case 4:
- for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 4) {
+ for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 4) {
char p0 = p[0];
char p1 = p[1];
p[0] = p[3];
@@ -1106,7 +1106,7 @@ array_byteswap(arrayobject *self, PyObject *unused)
}
break;
case 8:
- for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 8) {
+ for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 8) {
char p0 = p[0];
char p1 = p[1];
char p2 = p[2];
@@ -1147,16 +1147,16 @@ array_reduce(arrayobject *array)
dict = Py_None;
Py_INCREF(dict);
}
- if (array->ob_size > 0) {
+ if (Py_Size(array) > 0) {
result = Py_BuildValue("O(cs#)O",
- array->ob_type,
+ Py_Type(array),
array->ob_descr->typecode,
array->ob_item,
- array->ob_size * array->ob_descr->itemsize,
+ Py_Size(array) * array->ob_descr->itemsize,
dict);
} else {
result = Py_BuildValue("O(c)O",
- array->ob_type,
+ Py_Type(array),
array->ob_descr->typecode,
dict);
}
@@ -1175,9 +1175,9 @@ array_reverse(arrayobject *self, PyObject *unused)
char tmp[256]; /* 8 is probably enough -- but why skimp */
assert((size_t)itemsize <= sizeof(tmp));
- if (self->ob_size > 1) {
+ if (Py_Size(self) > 1) {
for (p = self->ob_item,
- q = self->ob_item + (self->ob_size - 1)*itemsize;
+ q = self->ob_item + (Py_Size(self) - 1)*itemsize;
p < q;
p += itemsize, q -= itemsize) {
/* memory areas guaranteed disjoint, so memcpy
@@ -1218,7 +1218,7 @@ array_fromfile(arrayobject *self, PyObject *args)
Py_ssize_t newlength;
size_t newbytes;
/* Be careful here about overflow */
- if ((newlength = self->ob_size + n) <= 0 ||
+ if ((newlength = Py_Size(self) + n) <= 0 ||
(newbytes = newlength * itemsize) / itemsize !=
(size_t)newlength)
goto nomem;
@@ -1229,15 +1229,15 @@ array_fromfile(arrayobject *self, PyObject *args)
return NULL;
}
self->ob_item = item;
- self->ob_size += n;
- self->allocated = self->ob_size;
- nread = fread(item + (self->ob_size - n) * itemsize,
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
+ nread = fread(item + (Py_Size(self) - n) * itemsize,
itemsize, n, fp);
if (nread < (size_t)n) {
- self->ob_size -= (n - nread);
- PyMem_RESIZE(item, char, self->ob_size*itemsize);
+ Py_Size(self) -= (n - nread);
+ PyMem_RESIZE(item, char, Py_Size(self)*itemsize);
self->ob_item = item;
- self->allocated = self->ob_size;
+ self->allocated = Py_Size(self);
PyErr_SetString(PyExc_EOFError,
"not enough items in file");
return NULL;
@@ -1297,23 +1297,23 @@ array_fromlist(arrayobject *self, PyObject *list)
if (n > 0) {
char *item = self->ob_item;
Py_ssize_t i;
- PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize);
+ PyMem_RESIZE(item, char, (Py_Size(self) + n) * itemsize);
if (item == NULL) {
PyErr_NoMemory();
return NULL;
}
self->ob_item = item;
- self->ob_size += n;
- self->allocated = self->ob_size;
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
for (i = 0; i < n; i++) {
PyObject *v = PyList_GetItem(list, i);
if ((*self->ob_descr->setitem)(self,
- self->ob_size - n + i, v) != 0) {
- self->ob_size -= n;
+ Py_Size(self) - n + i, v) != 0) {
+ Py_Size(self) -= n;
PyMem_RESIZE(item, char,
- self->ob_size * itemsize);
+ Py_Size(self) * itemsize);
self->ob_item = item;
- self->allocated = self->ob_size;
+ self->allocated = Py_Size(self);
return NULL;
}
}
@@ -1331,12 +1331,12 @@ Append items to array from list.");
static PyObject *
array_tolist(arrayobject *self, PyObject *unused)
{
- PyObject *list = PyList_New(self->ob_size);
+ PyObject *list = PyList_New(Py_Size(self));
Py_ssize_t i;
if (list == NULL)
return NULL;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *v = getarrayitem((PyObject *)self, i);
if (v == NULL) {
Py_DECREF(list);
@@ -1369,15 +1369,15 @@ array_fromstring(arrayobject *self, PyObject *args)
n = n / itemsize;
if (n > 0) {
char *item = self->ob_item;
- PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize);
+ PyMem_RESIZE(item, char, (Py_Size(self) + n) * itemsize);
if (item == NULL) {
PyErr_NoMemory();
return NULL;
}
self->ob_item = item;
- self->ob_size += n;
- self->allocated = self->ob_size;
- memcpy(item + (self->ob_size - n) * itemsize,
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
+ memcpy(item + (Py_Size(self) - n) * itemsize,
str, itemsize*n);
}
Py_INCREF(Py_None);
@@ -1395,7 +1395,7 @@ static PyObject *
array_tostring(arrayobject *self, PyObject *unused)
{
return PyString_FromStringAndSize(self->ob_item,
- self->ob_size * self->ob_descr->itemsize);
+ Py_Size(self) * self->ob_descr->itemsize);
}
PyDoc_STRVAR(tostring_doc,
@@ -1423,15 +1423,15 @@ array_fromunicode(arrayobject *self, PyObject *args)
}
if (n > 0) {
Py_UNICODE *item = (Py_UNICODE *) self->ob_item;
- PyMem_RESIZE(item, Py_UNICODE, self->ob_size + n);
+ PyMem_RESIZE(item, Py_UNICODE, Py_Size(self) + n);
if (item == NULL) {
PyErr_NoMemory();
return NULL;
}
self->ob_item = (char *) item;
- self->ob_size += n;
- self->allocated = self->ob_size;
- memcpy(item + self->ob_size - n,
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
+ memcpy(item + Py_Size(self) - n,
ustr, n * sizeof(Py_UNICODE));
}
@@ -1456,7 +1456,7 @@ array_tounicode(arrayobject *self, PyObject *unused)
"tounicode() may only be called on type 'u' arrays");
return NULL;
}
- return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, self->ob_size);
+ return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_Size(self));
}
PyDoc_STRVAR(tounicode_doc,
@@ -1554,7 +1554,7 @@ array_repr(arrayobject *a)
PyObject *s, *t, *v = NULL;
Py_ssize_t len;
- len = a->ob_size;
+ len = Py_Size(a);
typecode = a->ob_descr->typecode;
if (len == 0) {
PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode);
@@ -1588,7 +1588,7 @@ array_subscr(arrayobject* self, PyObject* item)
return NULL;
}
if (i < 0)
- i += self->ob_size;
+ i += Py_Size(self);
return array_item(self, i);
}
else if (PySlice_Check(item)) {
@@ -1597,7 +1597,7 @@ array_subscr(arrayobject* self, PyObject* item)
arrayobject* ar;
int itemsize = self->ob_descr->itemsize;
- if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
&start, &stop, &step, &slicelength) < 0) {
return NULL;
}
@@ -1636,14 +1636,14 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (i==-1 && PyErr_Occurred())
return -1;
if (i < 0)
- i += self->ob_size;
+ i += Py_Size(self);
return array_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
int itemsize = self->ob_descr->itemsize;
- if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
&start, &stop, &step, &slicelength) < 0) {
return -1;
}
@@ -1671,17 +1671,17 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
self->ob_item + (cur + 1)*itemsize,
(step - 1) * itemsize);
}
- extra = self->ob_size - (cur + 1);
+ extra = Py_Size(self) - (cur + 1);
if (extra > 0) {
memmove(self->ob_item + (cur - i)*itemsize,
self->ob_item + (cur + 1)*itemsize,
extra*itemsize);
}
- self->ob_size -= slicelength;
+ Py_Size(self) -= slicelength;
self->ob_item = (char *)PyMem_REALLOC(self->ob_item,
- itemsize*self->ob_size);
- self->allocated = self->ob_size;
+ itemsize*Py_Size(self));
+ self->allocated = Py_Size(self);
return 0;
}
@@ -1693,16 +1693,16 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (!array_Check(value)) {
PyErr_Format(PyExc_TypeError,
"must assign array (not \"%.200s\") to slice",
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return -1;
}
av = (arrayobject*)value;
- if (av->ob_size != slicelength) {
+ if (Py_Size(av) != slicelength) {
PyErr_Format(PyExc_ValueError,
"attempt to assign array of size %ld to extended slice of size %ld",
- /*XXX*/(long)av->ob_size, /*XXX*/(long)slicelength);
+ /*XXX*/(long)Py_Size(av), /*XXX*/(long)slicelength);
return -1;
}
@@ -1711,7 +1711,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
/* protect against a[::-1] = a */
if (self == av) {
- value = array_slice(av, 0, av->ob_size);
+ value = array_slice(av, 0, Py_Size(av));
av = (arrayobject*)value;
if (!av)
return -1;
@@ -1758,7 +1758,7 @@ array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr)
*ptr = (void *)self->ob_item;
if (*ptr == NULL)
*ptr = emptybuf;
- return self->ob_size*self->ob_descr->itemsize;
+ return Py_Size(self)*self->ob_descr->itemsize;
}
static Py_ssize_t
@@ -1772,14 +1772,14 @@ array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr)
*ptr = (void *)self->ob_item;
if (*ptr == NULL)
*ptr = emptybuf;
- return self->ob_size*self->ob_descr->itemsize;
+ return Py_Size(self)*self->ob_descr->itemsize;
}
static Py_ssize_t
array_buffer_getsegcount(arrayobject *self, Py_ssize_t *lenp)
{
if ( lenp )
- *lenp = self->ob_size*self->ob_descr->itemsize;
+ *lenp = Py_Size(self)*self->ob_descr->itemsize;
return 1;
}
@@ -1888,9 +1888,9 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
self->ob_item = item;
- self->ob_size = n / sizeof(Py_UNICODE);
+ Py_Size(self) = n / sizeof(Py_UNICODE);
memcpy(item, PyUnicode_AS_DATA(initial), n);
- self->allocated = self->ob_size;
+ self->allocated = Py_Size(self);
}
#endif
}
@@ -1978,8 +1978,7 @@ itemsize -- the length in bytes of one array item\n\
static PyObject *array_iter(arrayobject *ao);
static PyTypeObject Arraytype = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"array.array",
sizeof(arrayobject),
0,
@@ -2060,7 +2059,7 @@ static PyObject *
arrayiter_next(arrayiterobject *it)
{
assert(PyArrayIter_Check(it));
- if (it->index < it->ao->ob_size)
+ if (it->index < Py_Size(it->ao))
return (*it->getitem)(it->ao, it->index++);
return NULL;
}
@@ -2081,8 +2080,7 @@ arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
}
static PyTypeObject PyArrayIter_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"arrayiterator", /* tp_name */
sizeof(arrayiterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 9d92cf6..053461f 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -41,7 +41,7 @@ typedef fpos_t Py_off_t;
#define MODE_READ_EOF 2
#define MODE_WRITE 3
-#define BZ2FileObject_Check(v) ((v)->ob_type == &BZ2File_Type)
+#define BZ2FileObject_Check(v) (Py_Type(v) == &BZ2File_Type)
#ifdef BZ_CONFIG_ERROR
@@ -1418,7 +1418,7 @@ BZ2File_dealloc(BZ2FileObject *self)
}
Util_DropReadAhead(self);
Py_XDECREF(self->file);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
/* This is a hacked version of Python's fileobject.c:file_getiter(). */
@@ -1480,8 +1480,7 @@ newlines are available only when reading.\n\
;
static PyTypeObject BZ2File_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"bz2.BZ2File", /*tp_name*/
sizeof(BZ2FileObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -1735,7 +1734,7 @@ BZ2Comp_dealloc(BZ2CompObject *self)
PyThread_free_lock(self->lock);
#endif
BZ2_bzCompressEnd(&self->bzs);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
@@ -1752,8 +1751,7 @@ must be a number between 1 and 9.\n\
");
static PyTypeObject BZ2Comp_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"bz2.BZ2Compressor", /*tp_name*/
sizeof(BZ2CompObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -1958,7 +1956,7 @@ BZ2Decomp_dealloc(BZ2DecompObject *self)
#endif
Py_XDECREF(self->unused_data);
BZ2_bzDecompressEnd(&self->bzs);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
@@ -1974,8 +1972,7 @@ decompress() function instead.\n\
");
static PyTypeObject BZ2Decomp_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"bz2.BZ2Decompressor", /*tp_name*/
sizeof(BZ2DecompObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -2209,9 +2206,9 @@ initbz2(void)
{
PyObject *m;
- BZ2File_Type.ob_type = &PyType_Type;
- BZ2Comp_Type.ob_type = &PyType_Type;
- BZ2Decomp_Type.ob_type = &PyType_Type;
+ Py_Type(&BZ2File_Type) = &PyType_Type;
+ Py_Type(&BZ2Comp_Type) = &PyType_Type;
+ Py_Type(&BZ2Decomp_Type) = &PyType_Type;
m = Py_InitModule3("bz2", bz2_methods, bz2__doc__);
if (m == NULL)
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index dd9887b..fbf6a12 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -151,12 +151,12 @@ Pdata_dealloc(Pdata *self)
}
static PyTypeObject PdataType = {
- PyObject_HEAD_INIT(NULL) 0, "cPickle.Pdata", sizeof(Pdata), 0,
+ PyVarObject_HEAD_INIT(NULL, 0) "cPickle.Pdata", sizeof(Pdata), 0,
(destructor)Pdata_dealloc,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0L,0L,0L,0L, ""
};
-#define Pdata_Check(O) ((O)->ob_type == &PdataType)
+#define Pdata_Check(O) (Py_Type(O) == &PdataType)
static PyObject *
Pdata_New(void)
@@ -316,7 +316,7 @@ Pdata_popList(Pdata *self, int start)
}
#define FREE_ARG_TUP(self) { \
- if (self->arg->ob_refcnt > 1) { \
+ if (Py_Refcnt(self->arg) > 1) { \
Py_DECREF(self->arg); \
self->arg=NULL; \
} \
@@ -752,7 +752,7 @@ get(Picklerobject *self, PyObject *id)
static int
put(Picklerobject *self, PyObject *ob)
{
- if (ob->ob_refcnt < 2 || self->fast)
+ if (Py_Refcnt(ob) < 2 || self->fast)
return 0;
return put2(self, ob);
@@ -916,7 +916,7 @@ fast_save_enter(Picklerobject *self, PyObject *obj)
PyErr_Format(PyExc_ValueError,
"fast mode: can't pickle cyclic objects "
"including object type %s at %p",
- obj->ob_type->tp_name, obj);
+ Py_Type(obj)->tp_name, obj);
self->fast_container = -1;
return 0;
}
@@ -2320,7 +2320,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
goto finally;
}
- type = args->ob_type;
+ type = Py_Type(args);
switch (type->tp_name[0]) {
case 'b':
@@ -2372,7 +2372,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
#endif
}
- if (args->ob_refcnt > 1) {
+ if (Py_Refcnt(args) > 1) {
if (!( py_ob_id = PyLong_FromVoidPtr(args)))
goto finally;
@@ -2913,7 +2913,7 @@ Pickler_dealloc(Picklerobject *self)
Py_XDECREF(self->inst_pers_func);
Py_XDECREF(self->dispatch_table);
PyMem_Free(self->write_buf);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -3037,8 +3037,7 @@ PyDoc_STRVAR(Picklertype__doc__,
"Objects that know how to pickle objects\n");
static PyTypeObject Picklertype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"cPickle.Pickler", /*tp_name*/
sizeof(Picklerobject), /*tp_basicsize*/
0,
@@ -5254,7 +5253,7 @@ Unpickler_dealloc(Unpicklerobject *self)
free(self->buf);
}
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -5483,8 +5482,7 @@ PyDoc_STRVAR(Unpicklertype__doc__,
"Objects that know how to unpickle");
static PyTypeObject Unpicklertype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"cPickle.Unpickler", /*tp_name*/
sizeof(Unpicklerobject), /*tp_basicsize*/
0,
@@ -5708,9 +5706,9 @@ initcPickle(void)
PyObject *format_version;
PyObject *compatible_formats;
- Picklertype.ob_type = &PyType_Type;
- Unpicklertype.ob_type = &PyType_Type;
- PdataType.ob_type = &PyType_Type;
+ Py_Type(&Picklertype) = &PyType_Type;
+ Py_Type(&Unpicklertype) = &PyType_Type;
+ Py_Type(&PdataType) = &PyType_Type;
/* Initialize some pieces. We need to do this before module creation,
* so we're forced to use a temporary dictionary. :(
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 2085696..5834e20 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -514,8 +514,7 @@ O_dealloc(Oobject *self) {
PyDoc_STRVAR(Otype__doc__, "Simple type for output to strings.");
static PyTypeObject Otype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"cStringIO.StringO", /*tp_name*/
sizeof(Oobject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -635,8 +634,7 @@ PyDoc_STRVAR(Itype__doc__,
"Simple type for treating strings as input file streams");
static PyTypeObject Itype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"cStringIO.StringI", /*tp_name*/
sizeof(Iobject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -746,8 +744,8 @@ initcStringIO(void) {
d = PyModule_GetDict(m);
/* Export C API */
- Itype.ob_type=&PyType_Type;
- Otype.ob_type=&PyType_Type;
+ Py_Type(&Itype)=&PyType_Type;
+ Py_Type(&Otype)=&PyType_Type;
if (PyType_Ready(&Otype) < 0) return;
if (PyType_Ready(&Itype) < 0) return;
PyDict_SetItemString(d,"cStringIO_CAPI",
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 9fb9570..cde8822 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -670,8 +670,7 @@ multibytecodec_dealloc(MultibyteCodecObject *self)
}
static PyTypeObject MultibyteCodec_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"MultibyteCodec", /* tp_name */
sizeof(MultibyteCodecObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -946,12 +945,11 @@ mbiencoder_dealloc(MultibyteIncrementalEncoderObject *self)
{
PyObject_GC_UnTrack(self);
ERROR_DECREF(self->errors);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static PyTypeObject MultibyteIncrementalEncoder_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"MultibyteIncrementalEncoder", /* tp_name */
sizeof(MultibyteIncrementalEncoderObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1147,12 +1145,11 @@ mbidecoder_dealloc(MultibyteIncrementalDecoderObject *self)
{
PyObject_GC_UnTrack(self);
ERROR_DECREF(self->errors);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static PyTypeObject MultibyteIncrementalDecoder_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"MultibyteIncrementalDecoder", /* tp_name */
sizeof(MultibyteIncrementalDecoderObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1464,12 +1461,11 @@ mbstreamreader_dealloc(MultibyteStreamReaderObject *self)
PyObject_GC_UnTrack(self);
ERROR_DECREF(self->errors);
Py_DECREF(self->stream);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static PyTypeObject MultibyteStreamReader_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"MultibyteStreamReader", /* tp_name */
sizeof(MultibyteStreamReaderObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1667,7 +1663,7 @@ mbstreamwriter_dealloc(MultibyteStreamWriterObject *self)
PyObject_GC_UnTrack(self);
ERROR_DECREF(self->errors);
Py_DECREF(self->stream);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static struct PyMethodDef mbstreamwriter_methods[] = {
@@ -1688,8 +1684,7 @@ static PyMemberDef mbstreamwriter_members[] = {
};
static PyTypeObject MultibyteStreamWriter_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"MultibyteStreamWriter", /* tp_name */
sizeof(MultibyteStreamWriterObject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 026319a..4113e84 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -764,7 +764,7 @@ check_tzinfo_subclass(PyObject *p)
PyErr_Format(PyExc_TypeError,
"tzinfo argument must be None or of a tzinfo subclass, "
"not type '%s'",
- p->ob_type->tp_name);
+ Py_Type(p)->tp_name);
return -1;
}
@@ -855,7 +855,7 @@ call_utc_tzinfo_method(PyObject *tzinfo, char *name, PyObject *tzinfoarg,
PyErr_Format(PyExc_TypeError,
"tzinfo.%s() must return None or "
"timedelta, not '%s'",
- name, u->ob_type->tp_name);
+ name, Py_Type(u)->tp_name);
}
Py_DECREF(u);
@@ -948,7 +948,7 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
if (result != NULL && result != Py_None && ! PyString_Check(result)) {
PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
"return None or a string, not '%s'",
- result->ob_type->tp_name);
+ Py_Type(result)->tp_name);
Py_DECREF(result);
result = NULL;
}
@@ -1421,7 +1421,7 @@ cmperror(PyObject *a, PyObject *b)
{
PyErr_Format(PyExc_TypeError,
"can't compare %s to %s",
- a->ob_type->tp_name, b->ob_type->tp_name);
+ Py_Type(a)->tp_name, Py_Type(b)->tp_name);
return NULL;
}
@@ -1876,7 +1876,7 @@ accum(const char* tag, PyObject *sofar, PyObject *num, PyObject *factor,
PyErr_Format(PyExc_TypeError,
"unsupported type for timedelta %s component: %s",
- tag, num->ob_type->tp_name);
+ tag, Py_Type(num)->tp_name);
return NULL;
}
@@ -1980,18 +1980,18 @@ delta_repr(PyDateTime_Delta *self)
{
if (GET_TD_MICROSECONDS(self) != 0)
return PyString_FromFormat("%s(%d, %d, %d)",
- self->ob_type->tp_name,
+ Py_Type(self)->tp_name,
GET_TD_DAYS(self),
GET_TD_SECONDS(self),
GET_TD_MICROSECONDS(self));
if (GET_TD_SECONDS(self) != 0)
return PyString_FromFormat("%s(%d, %d)",
- self->ob_type->tp_name,
+ Py_Type(self)->tp_name,
GET_TD_DAYS(self),
GET_TD_SECONDS(self));
return PyString_FromFormat("%s(%d)",
- self->ob_type->tp_name,
+ Py_Type(self)->tp_name,
GET_TD_DAYS(self));
}
@@ -2055,7 +2055,7 @@ delta_getstate(PyDateTime_Delta *self)
static PyObject *
delta_reduce(PyDateTime_Delta* self)
{
- return Py_BuildValue("ON", self->ob_type, delta_getstate(self));
+ return Py_BuildValue("ON", Py_Type(self), delta_getstate(self));
}
#define OFFSET(field) offsetof(PyDateTime_Delta, field)
@@ -2125,8 +2125,7 @@ static PyNumberMethods delta_as_number = {
};
static PyTypeObject PyDateTime_DeltaType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.timedelta", /* tp_name */
sizeof(PyDateTime_Delta), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2415,7 +2414,7 @@ date_repr(PyDateTime_Date *self)
char buffer[1028];
const char *type_name;
- type_name = self->ob_type->tp_name;
+ type_name = Py_Type(self)->tp_name;
PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d)",
type_name,
GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
@@ -2555,7 +2554,7 @@ date_replace(PyDateTime_Date *self, PyObject *args, PyObject *kw)
tuple = Py_BuildValue("iii", year, month, day);
if (tuple == NULL)
return NULL;
- clone = date_new(self->ob_type, tuple, NULL);
+ clone = date_new(Py_Type(self), tuple, NULL);
Py_DECREF(tuple);
return clone;
}
@@ -2605,7 +2604,7 @@ date_getstate(PyDateTime_Date *self)
static PyObject *
date_reduce(PyDateTime_Date *self, PyObject *arg)
{
- return Py_BuildValue("(ON)", self->ob_type, date_getstate(self));
+ return Py_BuildValue("(ON)", Py_Type(self), date_getstate(self));
}
static PyMethodDef date_methods[] = {
@@ -2683,8 +2682,7 @@ static PyNumberMethods date_as_number = {
};
static PyTypeObject PyDateTime_DateType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.date", /* tp_name */
sizeof(PyDateTime_Date), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2908,10 +2906,10 @@ tzinfo_reduce(PyObject *self)
if (state == Py_None) {
Py_DECREF(state);
- return Py_BuildValue("(ON)", self->ob_type, args);
+ return Py_BuildValue("(ON)", Py_Type(self), args);
}
else
- return Py_BuildValue("(ONN)", self->ob_type, args, state);
+ return Py_BuildValue("(ONN)", Py_Type(self), args, state);
}
static PyMethodDef tzinfo_methods[] = {
@@ -3106,7 +3104,7 @@ time_dealloc(PyDateTime_Time *self)
if (HASTZINFO(self)) {
Py_XDECREF(self->tzinfo);
}
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
/*
@@ -3140,7 +3138,7 @@ static PyObject *
time_repr(PyDateTime_Time *self)
{
char buffer[100];
- const char *type_name = self->ob_type->tp_name;
+ const char *type_name = Py_Type(self)->tp_name;
int h = TIME_GET_HOUR(self);
int m = TIME_GET_MINUTE(self);
int s = TIME_GET_SECOND(self);
@@ -3354,7 +3352,7 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
tuple = Py_BuildValue("iiiiO", hh, mm, ss, us, tzinfo);
if (tuple == NULL)
return NULL;
- clone = time_new(self->ob_type, tuple, NULL);
+ clone = time_new(Py_Type(self), tuple, NULL);
Py_DECREF(tuple);
return clone;
}
@@ -3408,7 +3406,7 @@ time_getstate(PyDateTime_Time *self)
static PyObject *
time_reduce(PyDateTime_Time *self, PyObject *arg)
{
- return Py_BuildValue("(ON)", self->ob_type, time_getstate(self));
+ return Py_BuildValue("(ON)", Py_Type(self), time_getstate(self));
}
static PyMethodDef time_methods[] = {
@@ -3902,7 +3900,7 @@ datetime_dealloc(PyDateTime_DateTime *self)
if (HASTZINFO(self)) {
Py_XDECREF(self->tzinfo);
}
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
/*
@@ -4051,7 +4049,7 @@ static PyObject *
datetime_repr(PyDateTime_DateTime *self)
{
char buffer[1000];
- const char *type_name = self->ob_type->tp_name;
+ const char *type_name = Py_Type(self)->tp_name;
PyObject *baserepr;
if (DATE_GET_MICROSECOND(self)) {
@@ -4272,7 +4270,7 @@ datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
tuple = Py_BuildValue("iiiiiiiO", y, m, d, hh, mm, ss, us, tzinfo);
if (tuple == NULL)
return NULL;
- clone = datetime_new(self->ob_type, tuple, NULL);
+ clone = datetime_new(Py_Type(self), tuple, NULL);
Py_DECREF(tuple);
return clone;
}
@@ -4460,7 +4458,7 @@ datetime_getstate(PyDateTime_DateTime *self)
static PyObject *
datetime_reduce(PyDateTime_DateTime *self, PyObject *arg)
{
- return Py_BuildValue("(ON)", self->ob_type, datetime_getstate(self));
+ return Py_BuildValue("(ON)", Py_Type(self), datetime_getstate(self));
}
static PyMethodDef datetime_methods[] = {
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c
index fa1fde2..ae5eae6 100644
--- a/Modules/dbmmodule.c
+++ b/Modules/dbmmodule.c
@@ -36,7 +36,7 @@ typedef struct {
static PyTypeObject Dbmtype;
-#define is_dbmobject(v) ((v)->ob_type == &Dbmtype)
+#define is_dbmobject(v) (Py_Type(v) == &Dbmtype)
#define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \
{ PyErr_SetString(DbmError, "DBM object has already been closed"); \
return NULL; }
@@ -302,8 +302,7 @@ dbm_getattr(dbmobject *dp, char *name)
}
static PyTypeObject Dbmtype = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"dbm.dbm",
sizeof(dbmobject),
0,
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
index 5622ed9..63e25c7 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -62,7 +62,7 @@ dl_sym(dlobject *xp, PyObject *args)
name = PyString_AS_STRING(args);
} else {
PyErr_Format(PyExc_TypeError, "expected string, found %.200s",
- args->ob_type->tp_name);
+ Py_Type(args)->tp_name);
return NULL;
}
func = dlsym(xp->dl_handle, name);
@@ -141,8 +141,7 @@ dl_getattr(dlobject *xp, char *name)
static PyTypeObject Dltype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"dl.dl", /*tp_name*/
sizeof(dlobject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -237,7 +236,7 @@ initdl(void)
PyObject *m, *d, *x;
/* Initialize object type */
- Dltype.ob_type = &PyType_Type;
+ Py_Type(&Dltype) = &PyType_Type;
/* Create the module and add the functions */
m = Py_InitModule("dl", dl_methods);
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 6c5011c..b6a871b 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -239,7 +239,7 @@ update_refs(PyGC_Head *containers)
PyGC_Head *gc = containers->gc.gc_next;
for (; gc != containers; gc = gc->gc.gc_next) {
assert(gc->gc.gc_refs == GC_REACHABLE);
- gc->gc.gc_refs = FROM_GC(gc)->ob_refcnt;
+ gc->gc.gc_refs = Py_Refcnt(FROM_GC(gc));
/* Python's cyclic gc should never see an incoming refcount
* of 0: if something decref'ed to 0, it should have been
* deallocated immediately at that time.
@@ -291,7 +291,7 @@ subtract_refs(PyGC_Head *containers)
traverseproc traverse;
PyGC_Head *gc = containers->gc.gc_next;
for (; gc != containers; gc=gc->gc.gc_next) {
- traverse = FROM_GC(gc)->ob_type->tp_traverse;
+ traverse = Py_Type(FROM_GC(gc))->tp_traverse;
(void) traverse(FROM_GC(gc),
(visitproc)visit_decref,
NULL);
@@ -376,7 +376,7 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
* the next object to visit.
*/
PyObject *op = FROM_GC(gc);
- traverseproc traverse = op->ob_type->tp_traverse;
+ traverseproc traverse = Py_Type(op)->tp_traverse;
assert(gc->gc.gc_refs > 0);
gc->gc.gc_refs = GC_REACHABLE;
(void) traverse(op,
@@ -472,7 +472,7 @@ move_finalizer_reachable(PyGC_Head *finalizers)
PyGC_Head *gc = finalizers->gc.gc_next;
for (; gc != finalizers; gc = gc->gc.gc_next) {
/* Note that the finalizers list may grow during this. */
- traverse = FROM_GC(gc)->ob_type->tp_traverse;
+ traverse = Py_Type(FROM_GC(gc))->tp_traverse;
(void) traverse(FROM_GC(gc),
(visitproc)visit_move,
(void *)finalizers);
@@ -517,7 +517,7 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
assert(IS_TENTATIVELY_UNREACHABLE(op));
next = gc->gc.gc_next;
- if (! PyType_SUPPORTS_WEAKREFS(op->ob_type))
+ if (! PyType_SUPPORTS_WEAKREFS(Py_Type(op)))
continue;
/* It supports weakrefs. Does it have any? */
@@ -654,7 +654,7 @@ debug_cycle(char *msg, PyObject *op)
}
else if (debug & DEBUG_OBJECTS) {
PySys_WriteStderr("gc: %.100s <%.100s %p>\n",
- msg, op->ob_type->tp_name, op);
+ msg, Py_Type(op)->tp_name, op);
}
}
@@ -708,7 +708,7 @@ delete_garbage(PyGC_Head *collectable, PyGC_Head *old)
PyList_Append(garbage, op);
}
else {
- if ((clear = op->ob_type->tp_clear) != NULL) {
+ if ((clear = Py_Type(op)->tp_clear) != NULL) {
Py_INCREF(op);
clear(op);
Py_DECREF(op);
@@ -1079,7 +1079,7 @@ gc_referrers_for(PyObject *objs, PyGC_Head *list, PyObject *resultlist)
traverseproc traverse;
for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
obj = FROM_GC(gc);
- traverse = obj->ob_type->tp_traverse;
+ traverse = Py_Type(obj)->tp_traverse;
if (obj == objs || obj == resultlist)
continue;
if (traverse(obj, (visitproc)referrersvisit, objs)) {
@@ -1136,7 +1136,7 @@ gc_get_referents(PyObject *self, PyObject *args)
if (! PyObject_IS_GC(obj))
continue;
- traverse = obj->ob_type->tp_traverse;
+ traverse = Py_Type(obj)->tp_traverse;
if (! traverse)
continue;
if (traverse(obj, (visitproc)referentsvisit, result)) {
@@ -1359,13 +1359,13 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
PyVarObject *
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
{
- const size_t basicsize = _PyObject_VAR_SIZE(op->ob_type, nitems);
+ const size_t basicsize = _PyObject_VAR_SIZE(Py_Type(op), nitems);
PyGC_Head *g = AS_GC(op);
g = (PyGC_Head *)PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
if (g == NULL)
return (PyVarObject *)PyErr_NoMemory();
op = (PyVarObject *) FROM_GC(g);
- op->ob_size = nitems;
+ Py_Size(op) = nitems;
return op;
}
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index cfc6abc..a522059 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -36,7 +36,7 @@ typedef struct {
static PyTypeObject Dbmtype;
-#define is_dbmobject(v) ((v)->ob_type == &Dbmtype)
+#define is_dbmobject(v) (Py_Type(v) == &Dbmtype)
#define check_dbmobject_open(v) if ((v)->di_dbm == NULL) \
{ PyErr_SetString(DbmError, "GDBM object has already been closed"); \
return NULL; }
@@ -370,8 +370,7 @@ dbm_getattr(dbmobject *dp, char *name)
}
static PyTypeObject Dbmtype = {
- PyObject_HEAD_INIT(0)
- 0,
+ PyVarObject_HEAD_INIT(0, 0)
"gdbm.gdbm",
sizeof(dbmobject),
0,
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 33172b6..35b77e7 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -59,7 +59,7 @@ groupby_dealloc(groupbyobject *gbo)
Py_XDECREF(gbo->tgtkey);
Py_XDECREF(gbo->currkey);
Py_XDECREF(gbo->currvalue);
- gbo->ob_type->tp_free(gbo);
+ Py_Type(gbo)->tp_free(gbo);
}
static int
@@ -139,8 +139,7 @@ PyDoc_STRVAR(groupby_doc,
(key, sub-iterator) grouped by each value of key(value).\n");
static PyTypeObject groupby_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.groupby", /* tp_name */
sizeof(groupbyobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -261,8 +260,7 @@ _grouper_next(_grouperobject *igo)
}
static PyTypeObject _grouper_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools._grouper", /* tp_name */
sizeof(_grouperobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -415,8 +413,7 @@ teedataobject_dealloc(teedataobject *tdo)
PyDoc_STRVAR(teedataobject_doc, "Data container common to multiple tee objects.");
static PyTypeObject teedataobject_type = {
- PyObject_HEAD_INIT(0) /* Must fill in type value later */
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(0, 0) /* Must fill in type value later */
"itertools.tee_dataobject", /* tp_name */
sizeof(teedataobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -572,8 +569,7 @@ static PyMethodDef tee_methods[] = {
};
static PyTypeObject tee_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.tee", /* tp_name */
sizeof(teeobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -718,7 +714,7 @@ cycle_dealloc(cycleobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->saved);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -768,8 +764,7 @@ Return elements from the iterable until it is exhausted.\n\
Then repeat the sequence indefinitely.");
static PyTypeObject cycle_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.cycle", /* tp_name */
sizeof(cycleobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -862,7 +857,7 @@ dropwhile_dealloc(dropwhileobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -882,7 +877,7 @@ dropwhile_next(dropwhileobject *lz)
PyObject *(*iternext)(PyObject *);
assert(PyIter_Check(it));
- iternext = *it->ob_type->tp_iternext;
+ iternext = *Py_Type(it)->tp_iternext;
for (;;) {
item = iternext(it);
if (item == NULL)
@@ -912,8 +907,7 @@ Drop items from the iterable while predicate(item) is true.\n\
Afterwards, return every element until the iterable is exhausted.");
static PyTypeObject dropwhile_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.dropwhile", /* tp_name */
sizeof(dropwhileobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1006,7 +1000,7 @@ takewhile_dealloc(takewhileobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1028,7 +1022,7 @@ takewhile_next(takewhileobject *lz)
return NULL;
assert(PyIter_Check(it));
- item = (*it->ob_type->tp_iternext)(it);
+ item = (*Py_Type(it)->tp_iternext)(it);
if (item == NULL)
return NULL;
@@ -1053,8 +1047,7 @@ Return successive entries from an iterable as long as the \n\
predicate evaluates to true for each entry.");
static PyTypeObject takewhile_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.takewhile", /* tp_name */
sizeof(takewhileobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1197,7 +1190,7 @@ islice_dealloc(isliceobject *lz)
{
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1216,7 +1209,7 @@ islice_next(isliceobject *lz)
PyObject *(*iternext)(PyObject *);
assert(PyIter_Check(it));
- iternext = *it->ob_type->tp_iternext;
+ iternext = *Py_Type(it)->tp_iternext;
while (lz->cnt < lz->next) {
item = iternext(it);
if (item == NULL)
@@ -1249,8 +1242,7 @@ skipped between successive calls. Works like a slice() on a list\n\
but returns an iterator.");
static PyTypeObject islice_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.islice", /* tp_name */
sizeof(isliceobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1341,7 +1333,7 @@ starmap_dealloc(starmapobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1360,7 +1352,7 @@ starmap_next(starmapobject *lz)
PyObject *it = lz->it;
assert(PyIter_Check(it));
- args = (*it->ob_type->tp_iternext)(it);
+ args = (*Py_Type(it)->tp_iternext)(it);
if (args == NULL)
return NULL;
if (!PyTuple_CheckExact(args)) {
@@ -1381,8 +1373,7 @@ Return an iterator whose values are returned from the function evaluated\n\
with a argument tuple taken from the given sequence.");
static PyTypeObject starmap_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.starmap", /* tp_name */
sizeof(starmapobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1487,7 +1478,7 @@ imap_dealloc(imapobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->iters);
Py_XDECREF(lz->func);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1561,8 +1552,7 @@ iterable is exhausted instead of filling in None for shorter\n\
iterables.");
static PyTypeObject imap_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.imap", /* tp_name */
sizeof(imapobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1666,7 +1656,7 @@ chain_dealloc(chainobject *lz)
{
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->ittuple);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1706,8 +1696,7 @@ first iterable until it is exhausted, then elements from the next\n\
iterable, until all of the iterables are exhausted.");
static PyTypeObject chain_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.chain", /* tp_name */
sizeof(chainobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1798,7 +1787,7 @@ ifilter_dealloc(ifilterobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1818,7 +1807,7 @@ ifilter_next(ifilterobject *lz)
PyObject *(*iternext)(PyObject *);
assert(PyIter_Check(it));
- iternext = *it->ob_type->tp_iternext;
+ iternext = *Py_Type(it)->tp_iternext;
for (;;) {
item = iternext(it);
if (item == NULL)
@@ -1850,8 +1839,7 @@ Return those items of sequence for which function(item) is true.\n\
If function is None, return the items that are true.");
static PyTypeObject ifilter_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.ifilter", /* tp_name */
sizeof(ifilterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1943,7 +1931,7 @@ ifilterfalse_dealloc(ifilterfalseobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -1963,7 +1951,7 @@ ifilterfalse_next(ifilterfalseobject *lz)
PyObject *(*iternext)(PyObject *);
assert(PyIter_Check(it));
- iternext = *it->ob_type->tp_iternext;
+ iternext = *Py_Type(it)->tp_iternext;
for (;;) {
item = iternext(it);
if (item == NULL)
@@ -1995,8 +1983,7 @@ Return those items of sequence for which function(item) is false.\n\
If function is None, return the items that are false.");
static PyTypeObject ifilterfalse_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.ifilterfalse", /* tp_name */
sizeof(ifilterfalseobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2094,8 +2081,7 @@ Return a count object whose .next() method returns consecutive\n\
integers starting from zero or, if specified, from firstval.");
static PyTypeObject count_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.count", /* tp_name */
sizeof(countobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2214,7 +2200,7 @@ izip_dealloc(izipobject *lz)
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->ittuple);
Py_XDECREF(lz->result);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -2237,12 +2223,12 @@ izip_next(izipobject *lz)
if (tuplesize == 0)
return NULL;
- if (result->ob_refcnt == 1) {
+ if (Py_Refcnt(result) == 1) {
Py_INCREF(result);
for (i=0 ; i < tuplesize ; i++) {
it = PyTuple_GET_ITEM(lz->ittuple, i);
assert(PyIter_Check(it));
- item = (*it->ob_type->tp_iternext)(it);
+ item = (*Py_Type(it)->tp_iternext)(it);
if (item == NULL) {
Py_DECREF(result);
return NULL;
@@ -2258,7 +2244,7 @@ izip_next(izipobject *lz)
for (i=0 ; i < tuplesize ; i++) {
it = PyTuple_GET_ITEM(lz->ittuple, i);
assert(PyIter_Check(it));
- item = (*it->ob_type->tp_iternext)(it);
+ item = (*Py_Type(it)->tp_iternext)(it);
if (item == NULL) {
Py_DECREF(result);
return NULL;
@@ -2280,8 +2266,7 @@ function but consumes less memory by returning an iterator instead of\n\
a list.");
static PyTypeObject izip_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.izip", /* tp_name */
sizeof(izipobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2365,7 +2350,7 @@ repeat_dealloc(repeatobject *ro)
{
PyObject_GC_UnTrack(ro);
Py_XDECREF(ro->element);
- ro->ob_type->tp_free(ro);
+ Py_Type(ro)->tp_free(ro);
}
static int
@@ -2428,8 +2413,7 @@ for the specified number of times. If not specified, returns the element\n\
endlessly.");
static PyTypeObject repeat_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.repeat", /* tp_name */
sizeof(repeatobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2561,7 +2545,7 @@ izip_longest_dealloc(iziplongestobject *lz)
Py_XDECREF(lz->ittuple);
Py_XDECREF(lz->result);
Py_XDECREF(lz->fillvalue);
- lz->ob_type->tp_free(lz);
+ Py_Type(lz)->tp_free(lz);
}
static int
@@ -2587,7 +2571,7 @@ izip_longest_next(iziplongestobject *lz)
return NULL;
if (lz->numactive == 0)
return NULL;
- if (result->ob_refcnt == 1) {
+ if (Py_Refcnt(result) == 1) {
Py_INCREF(result);
for (i=0 ; i < tuplesize ; i++) {
it = PyTuple_GET_ITEM(lz->ittuple, i);
@@ -2596,7 +2580,7 @@ izip_longest_next(iziplongestobject *lz)
item = lz->fillvalue;
} else {
assert(PyIter_Check(it));
- item = (*it->ob_type->tp_iternext)(it);
+ item = (*Py_Type(it)->tp_iternext)(it);
if (item == NULL) {
lz->numactive -= 1;
if (lz->numactive == 0) {
@@ -2625,7 +2609,7 @@ izip_longest_next(iziplongestobject *lz)
item = lz->fillvalue;
} else {
assert(PyIter_Check(it));
- item = (*it->ob_type->tp_iternext)(it);
+ item = (*Py_Type(it)->tp_iternext)(it);
if (item == NULL) {
lz->numactive -= 1;
if (lz->numactive == 0) {
@@ -2657,8 +2641,7 @@ defaults to None or can be specified by a keyword argument.\n\
");
static PyTypeObject iziplongest_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"itertools.izip_longest", /* tp_name */
sizeof(iziplongestobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2757,7 +2740,7 @@ inititertools(void)
NULL
};
- teedataobject_type.ob_type = &PyType_Type;
+ Py_Type(&teedataobject_type) = &PyType_Type;
m = Py_InitModule3("itertools", module_methods, module_doc);
if (m == NULL)
return;
diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c
index b435d76..730ec0c 100644
--- a/Modules/linuxaudiodev.c
+++ b/Modules/linuxaudiodev.c
@@ -441,8 +441,7 @@ lad_getattr(lad_t *xp, char *name)
}
static PyTypeObject Ladtype = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"linuxaudiodev.linux_audio_device", /*tp_name*/
sizeof(lad_t), /*tp_size*/
0, /*tp_itemsize*/
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 5e4f116..f6e4299 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -221,8 +221,7 @@ hexdigest() -- return the current digest as a string of hexadecimal digits\n\
copy() -- return a copy of the current md5 object");
static PyTypeObject MD5type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_md5.md5", /*tp_name*/
sizeof(md5object), /*tp_size*/
0, /*tp_itemsize*/
@@ -299,7 +298,7 @@ init_md5(void)
{
PyObject *m, *d;
- MD5type.ob_type = &PyType_Type;
+ Py_Type(&MD5type) = &PyType_Type;
if (PyType_Ready(&MD5type) < 0)
return;
m = Py_InitModule3("_md5", md5_functions, module_doc);
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 091ecd6..a92954b 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -782,8 +782,7 @@ static PyBufferProcs mmap_as_buffer = {
};
static PyTypeObject mmap_object_type = {
- PyObject_HEAD_INIT(0) /* patched in module init */
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(0, 0) /* patched in module init */
"mmap.mmap", /* tp_name */
sizeof(mmap_object), /* tp_size */
0, /* tp_itemsize */
@@ -1141,7 +1140,7 @@ PyMODINIT_FUNC
PyObject *dict, *module;
/* Patch the object type */
- mmap_object_type.ob_type = &PyType_Type;
+ Py_Type(&mmap_object_type) = &PyType_Type;
module = Py_InitModule("mmap", mmap_functions);
if (module == NULL)
diff --git a/Modules/operator.c b/Modules/operator.c
index 0a7222a..b6c3d00 100644
--- a/Modules/operator.c
+++ b/Modules/operator.c
@@ -397,8 +397,7 @@ After, f=itemgetter(2), the call f(r) returns r[2].\n\
After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])");
static PyTypeObject itemgetter_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"operator.itemgetter", /* tp_name */
sizeof(itemgetterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -535,8 +534,7 @@ After, f=attrgetter('name'), the call f(r) returns r.name.\n\
After, g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).");
static PyTypeObject attrgetter_type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"operator.attrgetter", /* tp_name */
sizeof(attrgetterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index eb59c4d..ebf101a 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -841,8 +841,7 @@ oss_mixer_getattr(oss_mixer_t *self, char *name)
}
static PyTypeObject OSSAudioType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"ossaudiodev.oss_audio_device", /*tp_name*/
sizeof(oss_audio_t), /*tp_size*/
0, /*tp_itemsize*/
@@ -856,8 +855,7 @@ static PyTypeObject OSSAudioType = {
};
static PyTypeObject OSSMixerType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"ossaudiodev.oss_mixer_device", /*tp_name*/
sizeof(oss_mixer_t), /*tp_size*/
0, /*tp_itemsize*/
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 23364fe..f502bb5 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -166,8 +166,7 @@ static PyObject *parser_getattr(PyObject *self, char *name);
static
PyTypeObject PyST_Type = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"parser.st", /* tp_name */
(int) sizeof(PyST_Object), /* tp_basicsize */
0, /* tp_itemsize */
@@ -694,7 +693,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
PyErr_Format(parser_error,
"second item in terminal node must be a string,"
" found %s",
- temp->ob_type->tp_name);
+ Py_Type(temp)->tp_name);
Py_DECREF(temp);
return 0;
}
@@ -707,7 +706,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
PyErr_Format(parser_error,
"third item in terminal node must be an"
" integer, found %s",
- temp->ob_type->tp_name);
+ Py_Type(temp)->tp_name);
Py_DECREF(o);
Py_DECREF(temp);
return 0;
@@ -3233,7 +3232,7 @@ initparser(void)
{
PyObject *module, *copyreg;
- PyST_Type.ob_type = &PyType_Type;
+ Py_Type(&PyST_Type) = &PyType_Type;
module = Py_InitModule("parser", parser_functions);
if (module == NULL)
return;
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 2b62983..8a78d8c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2593,7 +2593,7 @@ extract_time(PyObject *t, long* sec, long* usec)
long intval;
if (PyFloat_Check(t)) {
double tval = PyFloat_AsDouble(t);
- PyObject *intobj = t->ob_type->tp_as_number->nb_int(t);
+ PyObject *intobj = Py_Type(t)->tp_as_number->nb_int(t);
if (!intobj)
return -1;
intval = PyInt_AsLong(intobj);
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 67f7007..301fbf5 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -974,7 +974,7 @@ readinst(char *buf, int buf_size, PyObject *meth)
if (!PyString_Check(str)) {
PyErr_Format(PyExc_TypeError,
"read() did not return a string object (type=%.400s)",
- str->ob_type->tp_name);
+ Py_Type(str)->tp_name);
goto finally;
}
len = PyString_GET_SIZE(str);
@@ -1687,8 +1687,7 @@ xmlparse_clear(xmlparseobject *op)
PyDoc_STRVAR(Xmlparsetype__doc__, "XML parser");
static PyTypeObject Xmlparsetype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"pyexpat.xmlparser", /*tp_name*/
sizeof(xmlparseobject) + PyGC_HEAD_SIZE,/*tp_basicsize*/
0, /*tp_itemsize*/
@@ -1860,7 +1859,7 @@ MODULE_INITFUNC(void)
if (modelmod_name == NULL)
return;
- Xmlparsetype.ob_type = &PyType_Type;
+ Py_Type(&Xmlparsetype) = &PyType_Type;
/* Create the module and add the functions */
m = Py_InitModule3(MODULE_NAME, pyexpat_methods,
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 9eaae84..995f8e7 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -587,8 +587,7 @@ poll_getattr(pollObject *self, char *name)
static PyTypeObject poll_Type = {
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"select.poll", /*tp_name*/
sizeof(pollObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -706,7 +705,7 @@ initselect(void)
#else
{
#endif
- poll_Type.ob_type = &PyType_Type;
+ Py_Type(&poll_Type) = &PyType_Type;
PyModule_AddIntConstant(m, "POLLIN", POLLIN);
PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);
PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 0effb07..24fd47a 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -409,7 +409,7 @@ SHA256_copy(SHAobject *self, PyObject *unused)
{
SHAobject *newobj;
- if (((PyObject*)self)->ob_type == &SHA256type) {
+ if (Py_Type(self) == &SHA256type) {
if ( (newobj = newSHA256object())==NULL)
return NULL;
} else {
@@ -536,8 +536,7 @@ static PyMemberDef SHA_members[] = {
};
static PyTypeObject SHA224type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_sha256.sha224", /*tp_name*/
sizeof(SHAobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -571,8 +570,7 @@ static PyTypeObject SHA224type = {
};
static PyTypeObject SHA256type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_sha256.sha256", /*tp_name*/
sizeof(SHAobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -689,10 +687,10 @@ init_sha256(void)
{
PyObject *m;
- SHA224type.ob_type = &PyType_Type;
+ Py_Type(&SHA224type) = &PyType_Type;
if (PyType_Ready(&SHA224type) < 0)
return;
- SHA256type.ob_type = &PyType_Type;
+ Py_Type(&SHA256type) = &PyType_Type;
if (PyType_Ready(&SHA256type) < 0)
return;
m = Py_InitModule("_sha256", SHA_functions);
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
index 9f47b61..b62cfd9 100644
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -602,8 +602,7 @@ static PyMemberDef SHA_members[] = {
};
static PyTypeObject SHA384type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_sha512.sha384", /*tp_name*/
sizeof(SHAobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -637,8 +636,7 @@ static PyTypeObject SHA384type = {
};
static PyTypeObject SHA512type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_sha512.sha512", /*tp_name*/
sizeof(SHAobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -755,10 +753,10 @@ init_sha512(void)
{
PyObject *m;
- SHA384type.ob_type = &PyType_Type;
+ Py_Type(&SHA384type) = &PyType_Type;
if (PyType_Ready(&SHA384type) < 0)
return;
- SHA512type.ob_type = &PyType_Type;
+ Py_Type(&SHA512type) = &PyType_Type;
if (PyType_Ready(&SHA512type) < 0)
return;
m = Py_InitModule("_sha512", SHA_functions);
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index 8d68d16..e268352 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -489,8 +489,7 @@ static PyGetSetDef SHA_getseters[] = {
};
static PyTypeObject SHAtype = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_sha.sha", /*tp_name*/
sizeof(SHAobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -577,7 +576,7 @@ init_sha(void)
{
PyObject *m;
- SHAtype.ob_type = &PyType_Type;
+ Py_Type(&SHAtype) = &PyType_Type;
if (PyType_Ready(&SHAtype) < 0)
return;
m = Py_InitModule("_sha", SHA_functions);
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 97ca816..d319ca3 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1245,7 +1245,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
PyExc_TypeError,
"getsockaddrarg: "
"AF_NETLINK address must be tuple, not %.500s",
- args->ob_type->tp_name);
+ Py_Type(args)->tp_name);
return 0;
}
if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups))
@@ -1268,7 +1268,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
PyExc_TypeError,
"getsockaddrarg: "
"AF_INET address must be tuple, not %.500s",
- args->ob_type->tp_name);
+ Py_Type(args)->tp_name);
return 0;
}
if (!PyArg_ParseTuple(args, "eti:getsockaddrarg",
@@ -1298,7 +1298,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
PyExc_TypeError,
"getsockaddrarg: "
"AF_INET6 address must be tuple, not %.500s",
- args->ob_type->tp_name);
+ Py_Type(args)->tp_name);
return 0;
}
if (!PyArg_ParseTuple(args, "eti|ii",
@@ -1420,7 +1420,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
PyExc_TypeError,
"getsockaddrarg: "
"AF_PACKET address must be tuple, not %.500s",
- args->ob_type->tp_name);
+ Py_Type(args)->tp_name);
return 0;
}
if (!PyArg_ParseTuple(args, "si|iis#", &interfaceName,
@@ -2843,7 +2843,7 @@ sock_dealloc(PySocketSockObject *s)
{
if (s->sock_fd != -1)
(void) SOCKETCLOSE(s->sock_fd);
- s->ob_type->tp_free((PyObject *)s);
+ Py_Type(s)->tp_free((PyObject *)s);
}
@@ -2928,8 +2928,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
/* Type object for socket objects. */
static PyTypeObject sock_type = {
- PyObject_HEAD_INIT(0) /* Must fill in type value later */
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(0, 0) /* Must fill in type value later */
"_socket.socket", /* tp_name */
sizeof(PySocketSockObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3555,7 +3554,7 @@ socket_ntohl(PyObject *self, PyObject *arg)
else
return PyErr_Format(PyExc_TypeError,
"expected int/long, %s found",
- arg->ob_type->tp_name);
+ Py_Type(arg)->tp_name);
if (x == (unsigned long) -1 && PyErr_Occurred())
return NULL;
return PyLong_FromUnsignedLong(ntohl(x));
@@ -3624,7 +3623,7 @@ socket_htonl(PyObject *self, PyObject *arg)
else
return PyErr_Format(PyExc_TypeError,
"expected int/long, %s found",
- arg->ob_type->tp_name);
+ Py_Type(arg)->tp_name);
return PyLong_FromUnsignedLong(htonl((unsigned long)x));
}
@@ -4274,7 +4273,7 @@ init_socket(void)
if (!os_init())
return;
- sock_type.ob_type = &PyType_Type;
+ Py_Type(&sock_type) = &PyType_Type;
m = Py_InitModule3(PySocket_MODULE_NAME,
socket_methods,
socket_doc);
diff --git a/Modules/sunaudiodev.c b/Modules/sunaudiodev.c
index 802184d..4288403 100644
--- a/Modules/sunaudiodev.c
+++ b/Modules/sunaudiodev.c
@@ -42,8 +42,8 @@ static sadstatusobject *sads_alloc(void); /* Forward */
static PyObject *SunAudioError;
-#define is_sadobject(v) ((v)->ob_type == &Sadtype)
-#define is_sadstatusobject(v) ((v)->ob_type == &Sadstatustype)
+#define is_sadobject(v) (Py_Type(v) == &Sadtype)
+#define is_sadstatusobject(v) (Py_Type(v) == &Sadstatustype)
static sadobject *
@@ -409,8 +409,7 @@ sads_setattr(sadstatusobject *xp, char *name, PyObject *v)
static PyTypeObject Sadtype = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"sunaudiodev.sun_audio_device", /*tp_name*/
sizeof(sadobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -424,8 +423,7 @@ static PyTypeObject Sadtype = {
};
static PyTypeObject Sadstatustype = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"sunaudiodev.sun_audio_device_status", /*tp_name*/
sizeof(sadstatusobject), /*tp_size*/
0, /*tp_itemsize*/
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 036619a..9e40771 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -126,8 +126,7 @@ lock_getattr(lockobject *self, char *name)
}
static PyTypeObject Locktype = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"thread.lock", /*tp_name*/
sizeof(lockobject), /*tp_size*/
0, /*tp_itemsize*/
@@ -251,7 +250,7 @@ local_dealloc(localobject *self)
}
local_clear(self);
- self->ob_type->tp_free((PyObject*)self);
+ Py_Type(self)->tp_free((PyObject*)self);
}
static PyObject *
@@ -283,8 +282,8 @@ _ldict(localobject *self)
Py_INCREF(ldict);
self->dict = ldict; /* still borrowed */
- if (self->ob_type->tp_init != PyBaseObject_Type.tp_init &&
- self->ob_type->tp_init((PyObject*)self,
+ if (Py_Type(self)->tp_init != PyBaseObject_Type.tp_init &&
+ Py_Type(self)->tp_init((PyObject*)self,
self->args, self->kw) < 0) {
/* we need to get rid of ldict from thread so
we create a new one the next time we do an attr
@@ -336,8 +335,7 @@ static PyGetSetDef local_getset[] = {
static PyObject *local_getattro(localobject *, PyObject *);
static PyTypeObject localtype = {
- PyObject_HEAD_INIT(NULL)
- /* ob_size */ 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
/* tp_name */ "thread._local",
/* tp_basicsize */ sizeof(localobject),
/* tp_itemsize */ 0,
@@ -388,7 +386,7 @@ local_getattro(localobject *self, PyObject *name)
if (ldict == NULL)
return NULL;
- if (self->ob_type != &localtype)
+ if (Py_Type(self) != &localtype)
/* use generic lookup for subtypes */
return PyObject_GenericGetAttr((PyObject *)self, name);
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index a30d30c..fac9adc 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -1134,8 +1134,7 @@ static PyMethodDef unicodedata_functions[] = {
static PyTypeObject UCD_Type = {
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"unicodedata.UCD", /*tp_name*/
sizeof(PreviousDBVersion), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -1193,7 +1192,7 @@ initunicodedata(void)
{
PyObject *m, *v;
- UCD_Type.ob_type = &PyType_Type;
+ Py_Type(&UCD_Type) = &PyType_Type;
m = Py_InitModule3(
"unicodedata", unicodedata_functions, unicodedata_docstring);
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index ea66eef..0923f81 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -25,7 +25,7 @@ typedef struct {
static PyTypeObject Xxo_Type;
-#define XxoObject_Check(v) ((v)->ob_type == &Xxo_Type)
+#define XxoObject_Check(v) (Py_Type(v) == &Xxo_Type)
static XxoObject *
newXxoObject(PyObject *arg)
@@ -97,8 +97,7 @@ Xxo_setattr(XxoObject *self, char *name, PyObject *v)
static PyTypeObject Xxo_Type = {
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"xxmodule.Xxo", /*tp_name*/
sizeof(XxoObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -216,8 +215,7 @@ xx_roj(PyObject *self, PyObject *args)
static PyTypeObject Str_Type = {
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"xxmodule.Str", /*tp_name*/
0, /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -272,8 +270,7 @@ null_richcompare(PyObject *self, PyObject *other, int op)
static PyTypeObject Null_Type = {
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"xxmodule.Null", /*tp_name*/
0, /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/Modules/xxsubtype.c b/Modules/xxsubtype.c
index 88ce6c5..0cf0b81 100644
--- a/Modules/xxsubtype.c
+++ b/Modules/xxsubtype.c
@@ -101,8 +101,7 @@ static PyGetSetDef spamlist_getsets[] = {
};
static PyTypeObject spamlist_type = {
- PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
- 0,
+ PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"xxsubtype.spamlist",
sizeof(spamlistobject),
0,
@@ -193,8 +192,7 @@ static PyMemberDef spamdict_members[] = {
};
static PyTypeObject spamdict_type = {
- PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
- 0,
+ PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"xxsubtype.spamdict",
sizeof(spamdictobject),
0,
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 69b2881..ae6af46 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -181,7 +181,7 @@ zipimporter_dealloc(ZipImporter *self)
Py_XDECREF(self->archive);
Py_XDECREF(self->prefix);
Py_XDECREF(self->files);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static PyObject *
@@ -561,8 +561,7 @@ a valid Zip archive.");
#define DEFERRED_ADDRESS(ADDR) 0
static PyTypeObject ZipImporter_Type = {
- PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
- 0,
+ PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"zipimport.zipimporter",
sizeof(ZipImporter),
0, /* tp_itemsize */
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index da31e8b..43f435a 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -935,8 +935,7 @@ static PyMethodDef zlib_methods[] =
};
static PyTypeObject Comptype = {
- PyObject_HEAD_INIT(0)
- 0,
+ PyVarObject_HEAD_INIT(0, 0)
"zlib.Compress",
sizeof(compobject),
0,
@@ -952,8 +951,7 @@ static PyTypeObject Comptype = {
};
static PyTypeObject Decomptype = {
- PyObject_HEAD_INIT(0)
- 0,
+ PyVarObject_HEAD_INIT(0, 0)
"zlib.Decompress",
sizeof(compobject),
0,
@@ -987,8 +985,8 @@ PyMODINIT_FUNC
PyInit_zlib(void)
{
PyObject *m, *ver;
- Comptype.ob_type = &PyType_Type;
- Decomptype.ob_type = &PyType_Type;
+ Py_Type(&Comptype) = &PyType_Type;
+ Py_Type(&Decomptype) = &PyType_Type;
m = Py_InitModule4("zlib", zlib_methods,
zlib_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
diff --git a/Objects/boolobject.c b/Objects/boolobject.c
index 37be295..40f860b 100644
--- a/Objects/boolobject.c
+++ b/Objects/boolobject.c
@@ -146,8 +146,7 @@ static PyNumberMethods bool_as_number = {
/* The type object for bool. Note that this cannot be subclassed! */
PyTypeObject PyBool_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"bool",
sizeof(PyIntObject),
0,
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c
index 86515ab..98be771 100644
--- a/Objects/bufferobject.c
+++ b/Objects/bufferobject.c
@@ -664,8 +664,7 @@ static PyBufferProcs buffer_as_buffer = {
};
PyTypeObject PyBuffer_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"buffer",
sizeof(PyBufferObject),
0,
diff --git a/Objects/cellobject.c b/Objects/cellobject.c
index 65a29aa..63322c1 100644
--- a/Objects/cellobject.c
+++ b/Objects/cellobject.c
@@ -99,8 +99,7 @@ static PyGetSetDef cell_getsetlist[] = {
};
PyTypeObject PyCell_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"cell",
sizeof(PyCellObject),
0,
diff --git a/Objects/cobject.c b/Objects/cobject.c
index b2cae9a..a1ee686 100644
--- a/Objects/cobject.c
+++ b/Objects/cobject.c
@@ -135,8 +135,7 @@ extension modules, so that extension modules can use the Python import\n\
mechanism to link to one another.");
PyTypeObject PyCObject_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"PyCObject", /*tp_name*/
sizeof(PyCObject), /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 89871d6..e75ab94 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -354,8 +354,7 @@ code_hash(PyCodeObject *co)
/* XXX code objects need to participate in GC? */
PyTypeObject PyCode_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"code",
sizeof(PyCodeObject),
0,
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index a8a2188..6d1dbde 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -1074,8 +1074,7 @@ static PyNumberMethods complex_as_number = {
};
PyTypeObject PyComplex_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"complex",
sizeof(PyComplexObject),
0,
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 914b6d3..ec9faa5 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -382,8 +382,7 @@ descr_traverse(PyObject *self, visitproc visit, void *arg)
}
static PyTypeObject PyMethodDescr_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"method_descriptor",
sizeof(PyMethodDescrObject),
0,
@@ -421,8 +420,7 @@ static PyTypeObject PyMethodDescr_Type = {
/* This is for METH_CLASS in C, not for "f = classmethod(f)" in Python! */
static PyTypeObject PyClassMethodDescr_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"classmethod_descriptor",
sizeof(PyMethodDescrObject),
0,
@@ -459,8 +457,7 @@ static PyTypeObject PyClassMethodDescr_Type = {
};
static PyTypeObject PyMemberDescr_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"member_descriptor",
sizeof(PyMemberDescrObject),
0,
@@ -497,8 +494,7 @@ static PyTypeObject PyMemberDescr_Type = {
};
static PyTypeObject PyGetSetDescr_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"getset_descriptor",
sizeof(PyGetSetDescrObject),
0,
@@ -535,8 +531,7 @@ static PyTypeObject PyGetSetDescr_Type = {
};
PyTypeObject PyWrapperDescr_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"wrapper_descriptor",
sizeof(PyWrapperDescrObject),
0,
@@ -825,8 +820,7 @@ proxy_richcompare(proxyobject *v, PyObject *w, int op)
}
static PyTypeObject proxytype = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dictproxy", /* tp_name */
sizeof(proxyobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1007,8 +1001,7 @@ wrapper_traverse(PyObject *self, visitproc visit, void *arg)
}
static PyTypeObject wrappertype = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"method-wrapper", /* tp_name */
sizeof(wrapperobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1238,8 +1231,7 @@ property_traverse(PyObject *self, visitproc visit, void *arg)
}
PyTypeObject PyProperty_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"property", /* tp_name */
sizeof(propertyobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index bf2a11e..30b3598 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -204,7 +204,7 @@ PyDict_New(void)
if (num_free_dicts) {
mp = free_dicts[--num_free_dicts];
assert (mp != NULL);
- assert (mp->ob_type == &PyDict_Type);
+ assert (Py_Type(mp) == &PyDict_Type);
_Py_NewReference((PyObject *)mp);
if (mp->ma_fill) {
EMPTY_TO_MINSIZE(mp);
@@ -849,10 +849,10 @@ dict_dealloc(register dictobject *mp)
}
if (mp->ma_table != mp->ma_smalltable)
PyMem_DEL(mp->ma_table);
- if (num_free_dicts < MAXFREEDICTS && mp->ob_type == &PyDict_Type)
+ if (num_free_dicts < MAXFREEDICTS && Py_Type(mp) == &PyDict_Type)
free_dicts[num_free_dicts++] = mp;
else
- mp->ob_type->tp_free((PyObject *)mp);
+ Py_Type(mp)->tp_free((PyObject *)mp);
Py_TRASHCAN_SAFE_END(mp)
}
@@ -1011,7 +1011,7 @@ dict_subscript(dictobject *mp, register PyObject *key)
if (missing_str == NULL)
missing_str =
PyString_InternFromString("__missing__");
- missing = _PyType_Lookup(mp->ob_type, missing_str);
+ missing = _PyType_Lookup(Py_Type(mp), missing_str);
if (missing != NULL)
return PyObject_CallFunctionObjArgs(missing,
(PyObject *)mp, key, NULL);
@@ -2119,8 +2119,7 @@ PyDoc_STRVAR(dictionary_doc,
" in the keyword argument list. For example: dict(one=1, two=2)");
PyTypeObject PyDict_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict",
sizeof(dictobject),
0,
@@ -2302,8 +2301,7 @@ fail:
}
PyTypeObject PyDictIterKey_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dictionary-keyiterator", /* tp_name */
sizeof(dictiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2375,8 +2373,7 @@ fail:
}
PyTypeObject PyDictIterValue_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dictionary-valueiterator", /* tp_name */
sizeof(dictiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2462,8 +2459,7 @@ fail:
}
PyTypeObject PyDictIterItem_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dictionary-itemiterator", /* tp_name */
sizeof(dictiterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index a456c9d..6997fdc 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -43,7 +43,7 @@ enum_dealloc(enumobject *en)
PyObject_GC_UnTrack(en);
Py_XDECREF(en->en_sit);
Py_XDECREF(en->en_result);
- en->ob_type->tp_free(en);
+ Py_Type(en)->tp_free(en);
}
static int
@@ -68,7 +68,7 @@ enum_next(enumobject *en)
return NULL;
}
- next_item = (*it->ob_type->tp_iternext)(it);
+ next_item = (*Py_Type(it)->tp_iternext)(it);
if (next_item == NULL)
return NULL;
@@ -105,8 +105,7 @@ PyDoc_STRVAR(enum_doc,
"for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ...");
PyTypeObject PyEnum_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"enumerate", /* tp_name */
sizeof(enumobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -195,7 +194,7 @@ reversed_dealloc(reversedobject *ro)
{
PyObject_GC_UnTrack(ro);
Py_XDECREF(ro->seq);
- ro->ob_type->tp_free(ro);
+ Py_Type(ro)->tp_free(ro);
}
static int
@@ -253,8 +252,7 @@ static PyMethodDef reversediter_methods[] = {
};
PyTypeObject PyReversed_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"reversed", /* tp_name */
sizeof(reversedobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 9bf0e1c..3d79383 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -56,7 +56,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
{
- if (!_PyArg_NoKeywords(self->ob_type->tp_name, kwds))
+ if (!_PyArg_NoKeywords(Py_Type(self)->tp_name, kwds))
return -1;
Py_DECREF(self->args);
@@ -85,7 +85,7 @@ BaseException_dealloc(PyBaseExceptionObject *self)
{
_PyObject_GC_UNTRACK(self);
BaseException_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -129,7 +129,7 @@ BaseException_repr(PyBaseExceptionObject *self)
if (!repr_suffix)
return NULL;
- name = (char *)self->ob_type->tp_name;
+ name = (char *)Py_Type(self)->tp_name;
dot = strrchr(name, '.');
if (dot != NULL) name = dot+1;
@@ -148,9 +148,9 @@ static PyObject *
BaseException_reduce(PyBaseExceptionObject *self)
{
if (self->args && self->dict)
- return PyTuple_Pack(3, self->ob_type, self->args, self->dict);
+ return PyTuple_Pack(3, Py_Type(self), self->args, self->dict);
else
- return PyTuple_Pack(2, self->ob_type, self->args);
+ return PyTuple_Pack(2, Py_Type(self), self->args);
}
/*
@@ -478,7 +478,7 @@ SystemExit_dealloc(PySystemExitObject *self)
{
_PyObject_GC_UNTRACK(self);
SystemExit_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -583,7 +583,7 @@ EnvironmentError_dealloc(PyEnvironmentErrorObject *self)
{
_PyObject_GC_UNTRACK(self);
EnvironmentError_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -725,9 +725,9 @@ EnvironmentError_reduce(PyEnvironmentErrorObject *self)
Py_INCREF(args);
if (self->dict)
- res = PyTuple_Pack(3, self->ob_type, args, self->dict);
+ res = PyTuple_Pack(3, Py_Type(self), args, self->dict);
else
- res = PyTuple_Pack(2, self->ob_type, args);
+ res = PyTuple_Pack(2, Py_Type(self), args);
Py_DECREF(args);
return res;
}
@@ -780,7 +780,7 @@ WindowsError_dealloc(PyWindowsErrorObject *self)
{
_PyObject_GC_UNTRACK(self);
WindowsError_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -1054,7 +1054,7 @@ SyntaxError_dealloc(PySyntaxErrorObject *self)
{
_PyObject_GC_UNTRACK(self);
SyntaxError_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
@@ -1532,7 +1532,7 @@ UnicodeError_dealloc(PyUnicodeErrorObject *self)
{
_PyObject_GC_UNTRACK(self);
UnicodeError_clear(self);
- self->ob_type->tp_free((PyObject *)self);
+ Py_Type(self)->tp_free((PyObject *)self);
}
static int
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index ac093ce..4c5b37d 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -406,7 +406,7 @@ file_dealloc(PyFileObject *f)
Py_XDECREF(f->f_mode);
Py_XDECREF(f->f_encoding);
drop_readahead(f);
- f->ob_type->tp_free((PyObject *)f);
+ Py_Type(f)->tp_free((PyObject *)f);
}
static PyObject *
@@ -2077,8 +2077,7 @@ PyDoc_STR(
);
PyTypeObject PyFile_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"file",
sizeof(PyFileObject),
0,
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 6d9e33f..4dd7d03 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -41,8 +41,8 @@ fill_free_list(void)
p = &((PyFloatBlock *)p)->objects[0];
q = p + N_FLOATOBJECTS;
while (--q > p)
- q->ob_type = (struct _typeobject *)(q-1);
- q->ob_type = NULL;
+ Py_Type(q) = (struct _typeobject *)(q-1);
+ Py_Type(q) = NULL;
return p + N_FLOATOBJECTS - 1;
}
@@ -56,7 +56,7 @@ PyFloat_FromDouble(double fval)
}
/* Inline PyObject_New */
op = free_list;
- free_list = (PyFloatObject *)op->ob_type;
+ free_list = (PyFloatObject *)Py_Type(op);
PyObject_INIT(op, &PyFloat_Type);
op->ob_fval = fval;
return (PyObject *) op;
@@ -175,11 +175,11 @@ static void
float_dealloc(PyFloatObject *op)
{
if (PyFloat_CheckExact(op)) {
- op->ob_type = (struct _typeobject *)free_list;
+ Py_Type(op) = (struct _typeobject *)free_list;
free_list = op;
}
else
- op->ob_type->tp_free((PyObject *)op);
+ Py_Type(op)->tp_free((PyObject *)op);
}
double
@@ -197,7 +197,7 @@ PyFloat_AsDouble(PyObject *op)
return -1;
}
- if ((nb = op->ob_type->tp_as_number) == NULL || nb->nb_float == NULL) {
+ if ((nb = Py_Type(op)->tp_as_number) == NULL || nb->nb_float == NULL) {
PyErr_SetString(PyExc_TypeError, "a float is required");
return -1;
}
@@ -986,7 +986,7 @@ float_getformat(PyTypeObject *v, PyObject* arg)
if (!PyString_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"__getformat__() argument must be string, not %.500s",
- arg->ob_type->tp_name);
+ Py_Type(arg)->tp_name);
return NULL;
}
s = PyString_AS_STRING(arg);
@@ -1152,8 +1152,7 @@ static PyNumberMethods float_as_number = {
};
PyTypeObject PyFloat_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"float",
sizeof(PyFloatObject),
0,
@@ -1265,7 +1264,7 @@ PyFloat_Fini(void)
for (i = 0, p = &list->objects[0];
i < N_FLOATOBJECTS;
i++, p++) {
- if (PyFloat_CheckExact(p) && p->ob_refcnt != 0)
+ if (PyFloat_CheckExact(p) && Py_Refcnt(p) != 0)
frem++;
}
next = list->next;
@@ -1276,8 +1275,8 @@ PyFloat_Fini(void)
i < N_FLOATOBJECTS;
i++, p++) {
if (!PyFloat_CheckExact(p) ||
- p->ob_refcnt == 0) {
- p->ob_type = (struct _typeobject *)
+ Py_Refcnt(p) == 0) {
+ Py_Type(p) = (struct _typeobject *)
free_list;
free_list = p;
}
@@ -1309,7 +1308,7 @@ PyFloat_Fini(void)
i < N_FLOATOBJECTS;
i++, p++) {
if (PyFloat_CheckExact(p) &&
- p->ob_refcnt != 0) {
+ Py_Refcnt(p) != 0) {
char buf[100];
PyFloat_AsString(buf, p);
/* XXX(twouters) cast refcount to
@@ -1318,7 +1317,7 @@ PyFloat_Fini(void)
*/
fprintf(stderr,
"# <float at %p, refcnt=%ld, val=%s>\n",
- p, (long)p->ob_refcnt, buf);
+ p, (long)Py_Refcnt(p), buf);
}
}
list = list->next;
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 2153cd8..3cb6a0d 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -509,8 +509,7 @@ frame_clear(PyFrameObject *f)
PyTypeObject PyFrame_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"frame",
sizeof(PyFrameObject),
sizeof(PyObject *),
@@ -623,7 +622,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
--numfree;
f = free_list;
free_list = free_list->f_back;
- if (f->ob_size < extras) {
+ if (Py_Size(f) < extras) {
f = PyObject_GC_Resize(PyFrameObject, f, extras);
if (f == NULL) {
Py_DECREF(builtins);
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 190765a..913c8c5 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -544,8 +544,7 @@ func_descr_get(PyObject *func, PyObject *obj, PyObject *type)
}
PyTypeObject PyFunction_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"function",
sizeof(PyFunctionObject),
0,
@@ -615,7 +614,7 @@ cm_dealloc(classmethod *cm)
{
_PyObject_GC_UNTRACK((PyObject *)cm);
Py_XDECREF(cm->cm_callable);
- cm->ob_type->tp_free((PyObject *)cm);
+ Py_Type(cm)->tp_free((PyObject *)cm);
}
static int
@@ -644,9 +643,9 @@ cm_descr_get(PyObject *self, PyObject *obj, PyObject *type)
return NULL;
}
if (type == NULL)
- type = (PyObject *)(obj->ob_type);
+ type = (PyObject *)(Py_Type(obj));
return PyMethod_New(cm->cm_callable,
- type, (PyObject *)(type->ob_type));
+ type, (PyObject *)(Py_Type(type)));
}
static int
@@ -692,8 +691,7 @@ Class methods are different than C++ or Java static methods.\n\
If you want those, see the staticmethod builtin.");
PyTypeObject PyClassMethod_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"classmethod",
sizeof(classmethod),
0,
@@ -773,7 +771,7 @@ sm_dealloc(staticmethod *sm)
{
_PyObject_GC_UNTRACK((PyObject *)sm);
Py_XDECREF(sm->sm_callable);
- sm->ob_type->tp_free((PyObject *)sm);
+ Py_Type(sm)->tp_free((PyObject *)sm);
}
static int
@@ -840,8 +838,7 @@ Static methods in Python are similar to those found in Java or C++.\n\
For a more advanced concept, see the classmethod builtin.");
PyTypeObject PyStaticMethod_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"staticmethod",
sizeof(staticmethod),
0,
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 4d0c4f6..14cc46b 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -28,7 +28,7 @@ gen_dealloc(PyGenObject *gen)
if (gen->gi_frame != NULL && gen->gi_frame->f_stacktop != NULL) {
/* Generator is paused, so we need to close */
- gen->ob_type->tp_del(self);
+ Py_Type(gen)->tp_del(self);
if (self->ob_refcnt > 0)
return; /* resurrected. :( */
}
@@ -296,8 +296,7 @@ static PyMethodDef gen_methods[] = {
};
PyTypeObject PyGen_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"generator", /* tp_name */
sizeof(PyGenObject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/intobject.c b/Objects/intobject.c
index f72aea0..c4aeed5 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -56,8 +56,8 @@ fill_free_list(void)
p = &((PyIntBlock *)p)->objects[0];
q = p + N_INTOBJECTS;
while (--q > p)
- q->ob_type = (struct _typeobject *)(q-1);
- q->ob_type = NULL;
+ Py_Type(q) = (struct _typeobject *)(q-1);
+ Py_Type(q) = NULL;
return p + N_INTOBJECTS - 1;
}
@@ -102,7 +102,7 @@ PyInt_FromLong(long ival)
}
/* Inline PyObject_New */
v = free_list;
- free_list = (PyIntObject *)v->ob_type;
+ free_list = (PyIntObject *)Py_Type(v);
PyObject_INIT(v, &PyInt_Type);
v->ob_ival = ival;
return (PyObject *) v;
@@ -128,17 +128,17 @@ static void
int_dealloc(PyIntObject *v)
{
if (PyInt_CheckExact(v)) {
- v->ob_type = (struct _typeobject *)free_list;
+ Py_Type(v) = (struct _typeobject *)free_list;
free_list = v;
}
else
- v->ob_type->tp_free((PyObject *)v);
+ Py_Type(v)->tp_free((PyObject *)v);
}
static void
int_free(PyIntObject *v)
{
- v->ob_type = (struct _typeobject *)free_list;
+ Py_Type(v) = (struct _typeobject *)free_list;
free_list = v;
}
@@ -152,7 +152,7 @@ PyInt_AsLong(register PyObject *op)
if (op && PyInt_Check(op))
return PyInt_AS_LONG((PyIntObject*) op);
- if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+ if (op == NULL || (nb = Py_Type(op)->tp_as_number) == NULL ||
nb->nb_int == NULL) {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return -1;
@@ -207,7 +207,7 @@ PyInt_AsSsize_t(register PyObject *op)
return PyInt_AsLong(op);
#else
- if ((nb = op->ob_type->tp_as_number) == NULL ||
+ if ((nb = Py_Type(op)->tp_as_number) == NULL ||
(nb->nb_int == NULL && nb->nb_long == 0)) {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return -1;
@@ -256,7 +256,7 @@ PyInt_AsUnsignedLongMask(register PyObject *op)
if (op && PyLong_Check(op))
return PyLong_AsUnsignedLongMask(op);
- if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+ if (op == NULL || (nb = Py_Type(op)->tp_as_number) == NULL ||
nb->nb_int == NULL) {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return (unsigned long)-1;
@@ -301,7 +301,7 @@ PyInt_AsUnsignedLongLongMask(register PyObject *op)
if (op && PyLong_Check(op))
return PyLong_AsUnsignedLongLongMask(op);
- if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+ if (op == NULL || (nb = Py_Type(op)->tp_as_number) == NULL ||
nb->nb_int == NULL) {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return (unsigned PY_LONG_LONG)-1;
@@ -1116,8 +1116,7 @@ static PyNumberMethods int_as_number = {
};
PyTypeObject PyInt_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"int",
sizeof(PyIntObject),
0,
@@ -1170,7 +1169,7 @@ _PyInt_Init(void)
return 0;
/* PyObject_New is inlined */
v = free_list;
- free_list = (PyIntObject *)v->ob_type;
+ free_list = (PyIntObject *)Py_Type(v);
PyObject_INIT(v, &PyInt_Type);
v->ob_ival = ival;
small_ints[ival + NSMALLNEGINTS] = v;
@@ -1223,7 +1222,7 @@ PyInt_Fini(void)
ctr++, p++) {
if (!PyInt_CheckExact(p) ||
p->ob_refcnt == 0) {
- p->ob_type = (struct _typeobject *)
+ Py_Type(p) = (struct _typeobject *)
free_list;
free_list = p;
}
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index cf839f4..9cebac9 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -94,8 +94,7 @@ static PyMethodDef seqiter_methods[] = {
};
PyTypeObject PySeqIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"iterator", /* tp_name */
sizeof(seqiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -199,8 +198,7 @@ calliter_iternext(calliterobject *it)
}
PyTypeObject PyCallIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"callable-iterator", /* tp_name */
sizeof(calliterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 2ac5e86..ac0d018 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -34,7 +34,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
*/
if (allocated >= newsize && newsize >= (allocated >> 1)) {
assert(self->ob_item != NULL || newsize == 0);
- self->ob_size = newsize;
+ Py_Size(self) = newsize;
return 0;
}
@@ -58,7 +58,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
return -1;
}
self->ob_item = items;
- self->ob_size = newsize;
+ Py_Size(self) = newsize;
self->allocated = new_allocated;
return 0;
}
@@ -114,7 +114,7 @@ PyList_New(Py_ssize_t size)
}
memset(op->ob_item, 0, nbytes);
}
- op->ob_size = size;
+ Py_Size(op) = size;
op->allocated = size;
_PyObject_GC_TRACK(op);
return (PyObject *) op;
@@ -128,7 +128,7 @@ PyList_Size(PyObject *op)
return -1;
}
else
- return ((PyListObject *)op) -> ob_size;
+ return Py_Size(op);
}
static PyObject *indexerr = NULL;
@@ -140,7 +140,7 @@ PyList_GetItem(PyObject *op, Py_ssize_t i)
PyErr_BadInternalCall();
return NULL;
}
- if (i < 0 || i >= ((PyListObject *)op) -> ob_size) {
+ if (i < 0 || i >= Py_Size(op)) {
if (indexerr == NULL)
indexerr = PyString_FromString(
"list index out of range");
@@ -161,7 +161,7 @@ PyList_SetItem(register PyObject *op, register Py_ssize_t i,
PyErr_BadInternalCall();
return -1;
}
- if (i < 0 || i >= ((PyListObject *)op) -> ob_size) {
+ if (i < 0 || i >= Py_Size(op)) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
@@ -177,7 +177,7 @@ PyList_SetItem(register PyObject *op, register Py_ssize_t i,
static int
ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
{
- Py_ssize_t i, n = self->ob_size;
+ Py_ssize_t i, n = Py_Size(self);
PyObject **items;
if (v == NULL) {
PyErr_BadInternalCall();
@@ -259,7 +259,7 @@ list_dealloc(PyListObject *op)
There's a simple test case where somehow this reduces
thrashing when a *very* large list is created and
immediately deleted. */
- i = op->ob_size;
+ i = Py_Size(op);
while (--i >= 0) {
Py_XDECREF(op->ob_item[i]);
}
@@ -268,7 +268,7 @@ list_dealloc(PyListObject *op)
if (num_free_lists < MAXFREELISTS && PyList_CheckExact(op))
free_lists[num_free_lists++] = op;
else
- op->ob_type->tp_free((PyObject *)op);
+ Py_Type(op)->tp_free((PyObject *)op);
Py_TRASHCAN_SAFE_END(op)
}
@@ -286,7 +286,7 @@ list_print(PyListObject *op, FILE *fp, int flags)
return 0;
}
fprintf(fp, "[");
- for (i = 0; i < op->ob_size; i++) {
+ for (i = 0; i < Py_Size(op); i++) {
if (i > 0)
fprintf(fp, ", ");
if (PyObject_Print(op->ob_item[i], fp, 0) != 0) {
@@ -311,7 +311,7 @@ list_repr(PyListObject *v)
return i > 0 ? PyString_FromString("[...]") : NULL;
}
- if (v->ob_size == 0) {
+ if (Py_Size(v) == 0) {
result = PyString_FromString("[]");
goto Done;
}
@@ -322,7 +322,7 @@ list_repr(PyListObject *v)
/* Do repr() on each element. Note that this may mutate the list,
so must refetch the list size on each iteration. */
- for (i = 0; i < v->ob_size; ++i) {
+ for (i = 0; i < Py_Size(v); ++i) {
int status;
s = PyObject_Repr(v->ob_item[i]);
if (s == NULL)
@@ -369,7 +369,7 @@ Done:
static Py_ssize_t
list_length(PyListObject *a)
{
- return a->ob_size;
+ return Py_Size(a);
}
static int
@@ -378,7 +378,7 @@ list_contains(PyListObject *a, PyObject *el)
Py_ssize_t i;
int cmp;
- for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
+ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(a); ++i)
cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
Py_EQ);
return cmp;
@@ -387,7 +387,7 @@ list_contains(PyListObject *a, PyObject *el)
static PyObject *
list_item(PyListObject *a, Py_ssize_t i)
{
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
if (indexerr == NULL)
indexerr = PyString_FromString(
"list index out of range");
@@ -406,12 +406,12 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
Py_ssize_t i, len;
if (ilow < 0)
ilow = 0;
- else if (ilow > a->ob_size)
- ilow = a->ob_size;
+ else if (ilow > Py_Size(a))
+ ilow = Py_Size(a);
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ else if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
len = ihigh - ilow;
np = (PyListObject *) PyList_New(len);
if (np == NULL)
@@ -451,7 +451,7 @@ list_concat(PyListObject *a, PyObject *bb)
return NULL;
}
#define b ((PyListObject *)bb)
- size = a->ob_size + b->ob_size;
+ size = Py_Size(a) + Py_Size(b);
if (size < 0)
return PyErr_NoMemory();
np = (PyListObject *) PyList_New(size);
@@ -460,14 +460,14 @@ list_concat(PyListObject *a, PyObject *bb)
}
src = a->ob_item;
dest = np->ob_item;
- for (i = 0; i < a->ob_size; i++) {
+ for (i = 0; i < Py_Size(a); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
}
src = b->ob_item;
- dest = np->ob_item + a->ob_size;
- for (i = 0; i < b->ob_size; i++) {
+ dest = np->ob_item + Py_Size(a);
+ for (i = 0; i < Py_Size(b); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
@@ -486,17 +486,17 @@ list_repeat(PyListObject *a, Py_ssize_t n)
PyObject *elem;
if (n < 0)
n = 0;
- size = a->ob_size * n;
+ size = Py_Size(a) * n;
if (size == 0)
return PyList_New(0);
- if (n && size/n != a->ob_size)
+ if (n && size/n != Py_Size(a))
return PyErr_NoMemory();
np = (PyListObject *) PyList_New(size);
if (np == NULL)
return NULL;
items = np->ob_item;
- if (a->ob_size == 1) {
+ if (Py_Size(a) == 1) {
elem = a->ob_item[0];
for (i = 0; i < n; i++) {
items[i] = elem;
@@ -507,7 +507,7 @@ list_repeat(PyListObject *a, Py_ssize_t n)
p = np->ob_item;
items = a->ob_item;
for (i = 0; i < n; i++) {
- for (j = 0; j < a->ob_size; j++) {
+ for (j = 0; j < Py_Size(a); j++) {
*p = items[j];
Py_INCREF(*p);
p++;
@@ -524,8 +524,8 @@ list_clear(PyListObject *a)
if (item != NULL) {
/* Because XDECREF can recursively invoke operations on
this list, we make it empty first. */
- i = a->ob_size;
- a->ob_size = 0;
+ i = Py_Size(a);
+ Py_Size(a) = 0;
a->ob_item = NULL;
a->allocated = 0;
while (--i >= 0) {
@@ -571,7 +571,7 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
else {
if (a == b) {
/* Special case "a[i:j] = a" -- copy b first */
- v = list_slice(b, 0, b->ob_size);
+ v = list_slice(b, 0, Py_Size(b));
if (v == NULL)
return result;
result = list_ass_slice(a, ilow, ihigh, v);
@@ -586,18 +586,18 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
}
if (ilow < 0)
ilow = 0;
- else if (ilow > a->ob_size)
- ilow = a->ob_size;
+ else if (ilow > Py_Size(a))
+ ilow = Py_Size(a);
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ else if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
norig = ihigh - ilow;
assert(norig >= 0);
d = n - norig;
- if (a->ob_size + d == 0) {
+ if (Py_Size(a) + d == 0) {
Py_XDECREF(v_as_SF);
return list_clear(a);
}
@@ -615,12 +615,12 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
if (d < 0) { /* Delete -d items */
memmove(&item[ihigh+d], &item[ihigh],
- (a->ob_size - ihigh)*sizeof(PyObject *));
- list_resize(a, a->ob_size + d);
+ (Py_Size(a) - ihigh)*sizeof(PyObject *));
+ list_resize(a, Py_Size(a) + d);
item = a->ob_item;
}
else if (d > 0) { /* Insert d items */
- k = a->ob_size;
+ k = Py_Size(a);
if (list_resize(a, k+d) < 0)
goto Error;
item = a->ob_item;
@@ -692,7 +692,7 @@ static int
list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
{
PyObject *old_value;
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
return -1;
@@ -751,7 +751,7 @@ listextend(PyListObject *self, PyObject *b)
Py_DECREF(b);
Py_RETURN_NONE;
}
- m = self->ob_size;
+ m = Py_Size(self);
if (list_resize(self, m + n) == -1) {
Py_DECREF(b);
return NULL;
@@ -789,14 +789,14 @@ listextend(PyListObject *self, PyObject *b)
PyErr_Clear();
n = 8; /* arbitrary */
}
- m = self->ob_size;
+ m = Py_Size(self);
mn = m + n;
if (mn >= m) {
/* Make room. */
if (list_resize(self, mn) == -1)
goto error;
/* Make the list sane again. */
- self->ob_size = m;
+ Py_Size(self) = m;
}
/* Else m + n overflowed; on the chance that n lied, and there really
* is enough room, ignore it. If n was telling the truth, we'll
@@ -815,10 +815,10 @@ listextend(PyListObject *self, PyObject *b)
}
break;
}
- if (self->ob_size < self->allocated) {
+ if (Py_Size(self) < self->allocated) {
/* steals ref */
- PyList_SET_ITEM(self, self->ob_size, item);
- ++self->ob_size;
+ PyList_SET_ITEM(self, Py_Size(self), item);
+ ++Py_Size(self);
}
else {
int status = app1(self, item);
@@ -829,8 +829,8 @@ listextend(PyListObject *self, PyObject *b)
}
/* Cut back result list if initial guess was too large. */
- if (self->ob_size < self->allocated)
- list_resize(self, self->ob_size); /* shrinking can't fail */
+ if (Py_Size(self) < self->allocated)
+ list_resize(self, Py_Size(self)); /* shrinking can't fail */
Py_DECREF(it);
Py_RETURN_NONE;
@@ -869,20 +869,20 @@ listpop(PyListObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|n:pop", &i))
return NULL;
- if (self->ob_size == 0) {
+ if (Py_Size(self) == 0) {
/* Special-case most common failure cause */
PyErr_SetString(PyExc_IndexError, "pop from empty list");
return NULL;
}
if (i < 0)
- i += self->ob_size;
- if (i < 0 || i >= self->ob_size) {
+ i += Py_Size(self);
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "pop index out of range");
return NULL;
}
v = self->ob_item[i];
- if (i == self->ob_size - 1) {
- status = list_resize(self, self->ob_size - 1);
+ if (i == Py_Size(self) - 1) {
+ status = list_resize(self, Py_Size(self) - 1);
assert(status >= 0);
return v; /* and v now owns the reference the list had */
}
@@ -1812,8 +1812,7 @@ static void
sortwrapper_dealloc(sortwrapperobject *);
static PyTypeObject sortwrapper_type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"sortwrapper", /* tp_name */
sizeof(sortwrapperobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -1930,8 +1929,7 @@ cmpwrapper_call(cmpwrapperobject *co, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(cmpwrapper_doc, "cmp() wrapper for sort with custom keys.");
static PyTypeObject cmpwrapper_type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"cmpwrapper", /* tp_name */
sizeof(cmpwrapperobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2014,10 +2012,10 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
* sorting (allowing mutations during sorting is a core-dump
* factory, since ob_item may change).
*/
- saved_ob_size = self->ob_size;
+ saved_ob_size = Py_Size(self);
saved_ob_item = self->ob_item;
saved_allocated = self->allocated;
- self->ob_size = 0;
+ Py_Size(self) = 0;
self->ob_item = NULL;
self->allocated = -1; /* any operation will reset it to >= 0 */
@@ -2123,8 +2121,8 @@ fail:
dsu_fail:
final_ob_item = self->ob_item;
- i = self->ob_size;
- self->ob_size = saved_ob_size;
+ i = Py_Size(self);
+ Py_Size(self) = saved_ob_size;
self->ob_item = saved_ob_item;
self->allocated = saved_allocated;
if (final_ob_item != NULL) {
@@ -2159,8 +2157,8 @@ PyList_Sort(PyObject *v)
static PyObject *
listreverse(PyListObject *self)
{
- if (self->ob_size > 1)
- reverse_slice(self->ob_item, self->ob_item + self->ob_size);
+ if (Py_Size(self) > 1)
+ reverse_slice(self->ob_item, self->ob_item + Py_Size(self));
Py_RETURN_NONE;
}
@@ -2173,8 +2171,8 @@ PyList_Reverse(PyObject *v)
PyErr_BadInternalCall();
return -1;
}
- if (self->ob_size > 1)
- reverse_slice(self->ob_item, self->ob_item + self->ob_size);
+ if (Py_Size(self) > 1)
+ reverse_slice(self->ob_item, self->ob_item + Py_Size(self));
return 0;
}
@@ -2188,7 +2186,7 @@ PyList_AsTuple(PyObject *v)
PyErr_BadInternalCall();
return NULL;
}
- n = ((PyListObject *)v)->ob_size;
+ n = Py_Size(v);
w = PyTuple_New(n);
if (w == NULL)
return NULL;
@@ -2206,7 +2204,7 @@ PyList_AsTuple(PyObject *v)
static PyObject *
listindex(PyListObject *self, PyObject *args)
{
- Py_ssize_t i, start=0, stop=self->ob_size;
+ Py_ssize_t i, start=0, stop=Py_Size(self);
PyObject *v;
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
@@ -2214,16 +2212,16 @@ listindex(PyListObject *self, PyObject *args)
_PyEval_SliceIndex, &stop))
return NULL;
if (start < 0) {
- start += self->ob_size;
+ start += Py_Size(self);
if (start < 0)
start = 0;
}
if (stop < 0) {
- stop += self->ob_size;
+ stop += Py_Size(self);
if (stop < 0)
stop = 0;
}
- for (i = start; i < stop && i < self->ob_size; i++) {
+ for (i = start; i < stop && i < Py_Size(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
return PyInt_FromSsize_t(i);
@@ -2240,7 +2238,7 @@ listcount(PyListObject *self, PyObject *v)
Py_ssize_t count = 0;
Py_ssize_t i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
count++;
@@ -2255,7 +2253,7 @@ listremove(PyListObject *self, PyObject *v)
{
Py_ssize_t i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0) {
if (list_ass_slice(self, i, i+1,
@@ -2275,7 +2273,7 @@ list_traverse(PyListObject *o, visitproc visit, void *arg)
{
Py_ssize_t i;
- for (i = o->ob_size; --i >= 0; )
+ for (i = Py_Size(o); --i >= 0; )
Py_VISIT(o->ob_item[i]);
return 0;
}
@@ -2294,7 +2292,7 @@ list_richcompare(PyObject *v, PyObject *w, int op)
vl = (PyListObject *)v;
wl = (PyListObject *)w;
- if (vl->ob_size != wl->ob_size && (op == Py_EQ || op == Py_NE)) {
+ if (Py_Size(vl) != Py_Size(wl) && (op == Py_EQ || op == Py_NE)) {
/* Shortcut: if the lengths differ, the lists differ */
PyObject *res;
if (op == Py_EQ)
@@ -2306,7 +2304,7 @@ list_richcompare(PyObject *v, PyObject *w, int op)
}
/* Search for the first index where items are different */
- for (i = 0; i < vl->ob_size && i < wl->ob_size; i++) {
+ for (i = 0; i < Py_Size(vl) && i < Py_Size(wl); i++) {
int k = PyObject_RichCompareBool(vl->ob_item[i],
wl->ob_item[i], Py_EQ);
if (k < 0)
@@ -2315,10 +2313,10 @@ list_richcompare(PyObject *v, PyObject *w, int op)
break;
}
- if (i >= vl->ob_size || i >= wl->ob_size) {
+ if (i >= Py_Size(vl) || i >= Py_Size(wl)) {
/* No more items to compare -- compare sizes */
- Py_ssize_t vs = vl->ob_size;
- Py_ssize_t ws = wl->ob_size;
+ Py_ssize_t vs = Py_Size(vl);
+ Py_ssize_t ws = Py_Size(wl);
int cmp;
PyObject *res;
switch (op) {
@@ -2362,8 +2360,8 @@ list_init(PyListObject *self, PyObject *args, PyObject *kw)
return -1;
/* Verify list invariants established by PyType_GenericAlloc() */
- assert(0 <= self->ob_size);
- assert(self->ob_size <= self->allocated || self->allocated == -1);
+ assert(0 <= Py_Size(self));
+ assert(Py_Size(self) <= self->allocated || self->allocated == -1);
assert(self->ob_item != NULL ||
self->allocated == 0 || self->allocated == -1);
@@ -2467,7 +2465,7 @@ list_subscript(PyListObject* self, PyObject* item)
PyObject* it;
PyObject **src, **dest;
- if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
&start, &stop, &step, &slicelength) < 0) {
return NULL;
}
@@ -2513,7 +2511,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
&start, &stop, &step, &slicelength) < 0) {
return -1;
}
@@ -2552,8 +2550,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
garbage[i] = PyList_GET_ITEM(self, cur);
- if (cur + step >= self->ob_size) {
- lim = self->ob_size - cur - 1;
+ if (cur + step >= Py_Size(self)) {
+ lim = Py_Size(self) - cur - 1;
}
memmove(self->ob_item + cur - i,
@@ -2562,13 +2560,13 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
}
for (cur = start + slicelength*step + 1;
- cur < self->ob_size; cur++) {
+ cur < Py_Size(self); cur++) {
PyList_SET_ITEM(self, cur - slicelength,
PyList_GET_ITEM(self, cur));
}
- self->ob_size -= slicelength;
- list_resize(self, self->ob_size);
+ Py_Size(self) -= slicelength;
+ list_resize(self, Py_Size(self));
for (i = 0; i < slicelength; i++) {
Py_DECREF(garbage[i]);
@@ -2651,8 +2649,7 @@ static PyMappingMethods list_as_mapping = {
};
PyTypeObject PyList_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"list",
sizeof(PyListObject),
0,
@@ -2717,8 +2714,7 @@ static PyMethodDef listiter_methods[] = {
};
PyTypeObject PyListIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"listiterator", /* tp_name */
sizeof(listiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2840,8 +2836,7 @@ static PySequenceMethods listreviter_as_sequence = {
};
PyTypeObject PyListRevIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"listreverseiterator", /* tp_name */
sizeof(listreviterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/longobject.c b/Objects/longobject.c
index a8663bc..abb69b0 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -50,13 +50,13 @@ static PyObject *long_format(PyObject *aa, int base, int addL);
static PyLongObject *
long_normalize(register PyLongObject *v)
{
- Py_ssize_t j = ABS(v->ob_size);
+ Py_ssize_t j = ABS(Py_Size(v));
Py_ssize_t i = j;
while (i > 0 && v->ob_digit[i-1] == 0)
--i;
if (i != j)
- v->ob_size = (v->ob_size < 0) ? -(i) : i;
+ Py_Size(v) = (Py_Size(v) < 0) ? -(i) : i;
return v;
}
@@ -147,7 +147,7 @@ PyLong_FromUnsignedLong(unsigned long ival)
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->ob_digit;
- v->ob_size = ndigits;
+ Py_Size(v) = ndigits;
while (ival) {
*p++ = (digit)(ival & MASK);
ival >>= SHIFT;
@@ -189,7 +189,7 @@ PyLong_FromDouble(double dval)
frac = ldexp(frac, SHIFT);
}
if (neg)
- v->ob_size = -(v->ob_size);
+ Py_Size(v) = -(Py_Size(v));
return (PyObject *)v;
}
@@ -323,7 +323,7 @@ PyLong_AsUnsignedLong(PyObject *vv)
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_Size(v);
x = 0;
if (i < 0) {
PyErr_SetString(PyExc_OverflowError,
@@ -381,7 +381,7 @@ _PyLong_Sign(PyObject *vv)
assert(v != NULL);
assert(PyLong_Check(v));
- return v->ob_size == 0 ? 0 : (v->ob_size < 0 ? -1 : 1);
+ return Py_Size(v) == 0 ? 0 : (Py_Size(v) < 0 ? -1 : 1);
}
size_t
@@ -393,7 +393,7 @@ _PyLong_NumBits(PyObject *vv)
assert(v != NULL);
assert(PyLong_Check(v));
- ndigits = ABS(v->ob_size);
+ ndigits = ABS(Py_Size(v));
assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
if (ndigits > 0) {
digit msd = v->ob_digit[ndigits - 1];
@@ -519,7 +519,7 @@ _PyLong_FromByteArray(const unsigned char* bytes, size_t n,
}
}
- v->ob_size = is_signed ? -idigit : idigit;
+ Py_Size(v) = is_signed ? -idigit : idigit;
return (PyObject *)long_normalize(v);
}
@@ -540,8 +540,8 @@ _PyLong_AsByteArray(PyLongObject* v,
assert(v != NULL && PyLong_Check(v));
- if (v->ob_size < 0) {
- ndigits = -(v->ob_size);
+ if (Py_Size(v) < 0) {
+ ndigits = -(Py_Size(v));
if (!is_signed) {
PyErr_SetString(PyExc_TypeError,
"can't convert negative long to unsigned");
@@ -550,7 +550,7 @@ _PyLong_AsByteArray(PyLongObject* v,
do_twos_comp = 1;
}
else {
- ndigits = v->ob_size;
+ ndigits = Py_Size(v);
do_twos_comp = 0;
}
@@ -686,7 +686,7 @@ _PyLong_AsScaledDouble(PyObject *vv, int *exponent)
return -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_Size(v);
sign = 1;
if (i < 0) {
sign = -1;
@@ -847,7 +847,7 @@ PyLong_FromLongLong(PY_LONG_LONG ival)
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->ob_digit;
- v->ob_size = negative ? -ndigits : ndigits;
+ Py_Size(v) = negative ? -ndigits : ndigits;
t = (unsigned PY_LONG_LONG)ival;
while (t) {
*p++ = (digit)(t & MASK);
@@ -875,7 +875,7 @@ PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG ival)
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->ob_digit;
- v->ob_size = ndigits;
+ Py_Size(v) = ndigits;
while (ival) {
*p++ = (digit)(ival & MASK);
ival >>= SHIFT;
@@ -1117,7 +1117,7 @@ mul1(PyLongObject *a, wdigit n)
static PyLongObject *
muladd1(PyLongObject *a, wdigit n, wdigit extra)
{
- Py_ssize_t size_a = ABS(a->ob_size);
+ Py_ssize_t size_a = ABS(Py_Size(a));
PyLongObject *z = _PyLong_New(size_a+1);
twodigits carry = extra;
Py_ssize_t i;
@@ -1163,7 +1163,7 @@ inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n)
static PyLongObject *
divrem1(PyLongObject *a, digit n, digit *prem)
{
- const Py_ssize_t size = ABS(a->ob_size);
+ const Py_ssize_t size = ABS(Py_Size(a));
PyLongObject *z;
assert(n > 0 && n <= MASK);
@@ -1194,7 +1194,7 @@ long_format(PyObject *aa, int base, int addL)
return NULL;
}
assert(base >= 2 && base <= 36);
- size_a = ABS(a->ob_size);
+ size_a = ABS(Py_Size(a));
/* Compute a rough upper bound for the length of the string */
i = base;
@@ -1597,7 +1597,7 @@ digit beyond the first.
z = _PyLong_New(size_z);
if (z == NULL)
return NULL;
- z->ob_size = 0;
+ Py_Size(z) = 0;
/* `convwidth` consecutive input digits are treated as a single
* digit in base `convmultmax`.
@@ -1627,7 +1627,7 @@ digit beyond the first.
/* Multiply z by convmult, and add c. */
pz = z->ob_digit;
- pzstop = pz + z->ob_size;
+ pzstop = pz + Py_Size(z);
for (; pz < pzstop; ++pz) {
c += (twodigits)*pz * convmult;
*pz = (digit)(c & MASK);
@@ -1636,14 +1636,14 @@ digit beyond the first.
/* carry off the current end? */
if (c) {
assert(c < BASE);
- if (z->ob_size < size_z) {
+ if (Py_Size(z) < size_z) {
*pz = (digit)c;
- ++z->ob_size;
+ ++Py_Size(z);
}
else {
PyLongObject *tmp;
/* Extremely rare. Get more space. */
- assert(z->ob_size == size_z);
+ assert(Py_Size(z) == size_z);
tmp = _PyLong_New(size_z + 1);
if (tmp == NULL) {
Py_DECREF(z);
@@ -1665,7 +1665,7 @@ digit beyond the first.
if (str == start)
goto onError;
if (sign < 0)
- z->ob_size = -(z->ob_size);
+ Py_Size(z) = -(Py_Size(z));
if (*str == 'L' || *str == 'l')
str++;
while (*str && isspace(Py_CHARMASK(*str)))
@@ -1726,7 +1726,7 @@ static int
long_divrem(PyLongObject *a, PyLongObject *b,
PyLongObject **pdiv, PyLongObject **prem)
{
- Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
PyLongObject *z;
if (size_b == 0) {
@@ -1778,7 +1778,7 @@ long_divrem(PyLongObject *a, PyLongObject *b,
static PyLongObject *
x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
{
- Py_ssize_t size_v = ABS(v1->ob_size), size_w = ABS(w1->ob_size);
+ Py_ssize_t size_v = ABS(Py_Size(v1)), size_w = ABS(Py_Size(w1));
digit d = (digit) ((twodigits)BASE / (w1->ob_digit[size_w-1] + 1));
PyLongObject *v = mul1(v1, d);
PyLongObject *w = mul1(w1, d);
@@ -1792,10 +1792,10 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
}
assert(size_v >= size_w && size_w > 1); /* Assert checks by div() */
- assert(v->ob_refcnt == 1); /* Since v will be used as accumulator! */
- assert(size_w == ABS(w->ob_size)); /* That's how d was calculated */
+ assert(Py_Refcnt(v) == 1); /* Since v will be used as accumulator! */
+ assert(size_w == ABS(Py_Size(w))); /* That's how d was calculated */
- size_v = ABS(v->ob_size);
+ size_v = ABS(Py_Size(v));
k = size_v - size_w;
a = _PyLong_New(k + 1);
@@ -1878,7 +1878,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
static void
long_dealloc(PyObject *v)
{
- v->ob_type->tp_free(v);
+ Py_Type(v)->tp_free(v);
}
static PyObject *
@@ -1898,21 +1898,21 @@ long_compare(PyLongObject *a, PyLongObject *b)
{
Py_ssize_t sign;
- if (a->ob_size != b->ob_size) {
- if (ABS(a->ob_size) == 0 && ABS(b->ob_size) == 0)
+ if (Py_Size(a) != Py_Size(b)) {
+ if (ABS(Py_Size(a)) == 0 && ABS(Py_Size(b)) == 0)
sign = 0;
else
- sign = a->ob_size - b->ob_size;
+ sign = Py_Size(a) - Py_Size(b);
}
else {
- Py_ssize_t i = ABS(a->ob_size);
+ Py_ssize_t i = ABS(Py_Size(a));
while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i])
;
if (i < 0)
sign = 0;
else {
sign = (int)a->ob_digit[i] - (int)b->ob_digit[i];
- if (a->ob_size < 0)
+ if (Py_Size(a) < 0)
sign = -sign;
}
}
@@ -1955,7 +1955,7 @@ long_hash(PyLongObject *v)
static PyLongObject *
x_add(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
PyLongObject *z;
int i;
digit carry = 0;
@@ -1989,7 +1989,7 @@ x_add(PyLongObject *a, PyLongObject *b)
static PyLongObject *
x_sub(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
PyLongObject *z;
Py_ssize_t i;
int sign = 1;
@@ -2099,15 +2099,15 @@ static PyLongObject *
x_mul(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;
- Py_ssize_t size_a = ABS(a->ob_size);
- Py_ssize_t size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(Py_Size(a));
+ Py_ssize_t size_b = ABS(Py_Size(b));
Py_ssize_t i;
z = _PyLong_New(size_a + size_b);
if (z == NULL)
return NULL;
- memset(z->ob_digit, 0, z->ob_size * sizeof(digit));
+ memset(z->ob_digit, 0, Py_Size(z) * sizeof(digit));
if (a == b) {
/* Efficient squaring per HAC, Algorithm 14.16:
* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
@@ -2191,7 +2191,7 @@ kmul_split(PyLongObject *n, Py_ssize_t size, PyLongObject **high, PyLongObject *
{
PyLongObject *hi, *lo;
Py_ssize_t size_lo, size_hi;
- const Py_ssize_t size_n = ABS(n->ob_size);
+ const Py_ssize_t size_n = ABS(Py_Size(n));
size_lo = MIN(size_n, size);
size_hi = size_n - size_lo;
@@ -2220,8 +2220,8 @@ static PyLongObject *k_lopsided_mul(PyLongObject *a, PyLongObject *b);
static PyLongObject *
k_mul(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t asize = ABS(a->ob_size);
- Py_ssize_t bsize = ABS(b->ob_size);
+ Py_ssize_t asize = ABS(Py_Size(a));
+ Py_ssize_t bsize = ABS(Py_Size(b));
PyLongObject *ah = NULL;
PyLongObject *al = NULL;
PyLongObject *bh = NULL;
@@ -2273,7 +2273,7 @@ k_mul(PyLongObject *a, PyLongObject *b)
/* Split a & b into hi & lo pieces. */
shift = bsize >> 1;
if (kmul_split(a, shift, &ah, &al) < 0) goto fail;
- assert(ah->ob_size > 0); /* the split isn't degenerate */
+ assert(Py_Size(ah) > 0); /* the split isn't degenerate */
if (a == b) {
bh = ah;
@@ -2304,20 +2304,20 @@ k_mul(PyLongObject *a, PyLongObject *b)
if (ret == NULL) goto fail;
#ifdef Py_DEBUG
/* Fill with trash, to catch reference to uninitialized digits. */
- memset(ret->ob_digit, 0xDF, ret->ob_size * sizeof(digit));
+ memset(ret->ob_digit, 0xDF, Py_Size(ret) * sizeof(digit));
#endif
/* 2. t1 <- ah*bh, and copy into high digits of result. */
if ((t1 = k_mul(ah, bh)) == NULL) goto fail;
- assert(t1->ob_size >= 0);
- assert(2*shift + t1->ob_size <= ret->ob_size);
+ assert(Py_Size(t1) >= 0);
+ assert(2*shift + Py_Size(t1) <= Py_Size(ret));
memcpy(ret->ob_digit + 2*shift, t1->ob_digit,
- t1->ob_size * sizeof(digit));
+ Py_Size(t1) * sizeof(digit));
/* Zero-out the digits higher than the ah*bh copy. */
- i = ret->ob_size - 2*shift - t1->ob_size;
+ i = Py_Size(ret) - 2*shift - Py_Size(t1);
if (i)
- memset(ret->ob_digit + 2*shift + t1->ob_size, 0,
+ memset(ret->ob_digit + 2*shift + Py_Size(t1), 0,
i * sizeof(digit));
/* 3. t2 <- al*bl, and copy into the low digits. */
@@ -2325,23 +2325,23 @@ k_mul(PyLongObject *a, PyLongObject *b)
Py_DECREF(t1);
goto fail;
}
- assert(t2->ob_size >= 0);
- assert(t2->ob_size <= 2*shift); /* no overlap with high digits */
- memcpy(ret->ob_digit, t2->ob_digit, t2->ob_size * sizeof(digit));
+ assert(Py_Size(t2) >= 0);
+ assert(Py_Size(t2) <= 2*shift); /* no overlap with high digits */
+ memcpy(ret->ob_digit, t2->ob_digit, Py_Size(t2) * sizeof(digit));
/* Zero out remaining digits. */
- i = 2*shift - t2->ob_size; /* number of uninitialized digits */
+ i = 2*shift - Py_Size(t2); /* number of uninitialized digits */
if (i)
- memset(ret->ob_digit + t2->ob_size, 0, i * sizeof(digit));
+ memset(ret->ob_digit + Py_Size(t2), 0, i * sizeof(digit));
/* 4 & 5. Subtract ah*bh (t1) and al*bl (t2). We do al*bl first
* because it's fresher in cache.
*/
- i = ret->ob_size - shift; /* # digits after shift */
- (void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, t2->ob_size);
+ i = Py_Size(ret) - shift; /* # digits after shift */
+ (void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, Py_Size(t2));
Py_DECREF(t2);
- (void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, t1->ob_size);
+ (void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, Py_Size(t1));
Py_DECREF(t1);
/* 6. t3 <- (ah+al)(bh+bl), and add into result. */
@@ -2366,12 +2366,12 @@ k_mul(PyLongObject *a, PyLongObject *b)
Py_DECREF(t1);
Py_DECREF(t2);
if (t3 == NULL) goto fail;
- assert(t3->ob_size >= 0);
+ assert(Py_Size(t3) >= 0);
/* Add t3. It's not obvious why we can't run out of room here.
* See the (*) comment after this function.
*/
- (void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, t3->ob_size);
+ (void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, Py_Size(t3));
Py_DECREF(t3);
return long_normalize(ret);
@@ -2441,8 +2441,8 @@ ah*bh and al*bl too.
static PyLongObject *
k_lopsided_mul(PyLongObject *a, PyLongObject *b)
{
- const Py_ssize_t asize = ABS(a->ob_size);
- Py_ssize_t bsize = ABS(b->ob_size);
+ const Py_ssize_t asize = ABS(Py_Size(a));
+ Py_ssize_t bsize = ABS(Py_Size(b));
Py_ssize_t nbdone; /* # of b digits already multiplied */
PyLongObject *ret;
PyLongObject *bslice = NULL;
@@ -2454,7 +2454,7 @@ k_lopsided_mul(PyLongObject *a, PyLongObject *b)
ret = _PyLong_New(asize + bsize);
if (ret == NULL)
return NULL;
- memset(ret->ob_digit, 0, ret->ob_size * sizeof(digit));
+ memset(ret->ob_digit, 0, Py_Size(ret) * sizeof(digit));
/* Successive slices of b are copied into bslice. */
bslice = _PyLong_New(asize);
@@ -2469,14 +2469,14 @@ k_lopsided_mul(PyLongObject *a, PyLongObject *b)
/* Multiply the next slice of b by a. */
memcpy(bslice->ob_digit, b->ob_digit + nbdone,
nbtouse * sizeof(digit));
- bslice->ob_size = nbtouse;
+ Py_Size(bslice) = nbtouse;
product = k_mul(a, bslice);
if (product == NULL)
goto fail;
/* Add into result. */
- (void)v_iadd(ret->ob_digit + nbdone, ret->ob_size - nbdone,
- product->ob_digit, product->ob_size);
+ (void)v_iadd(ret->ob_digit + nbdone, Py_Size(ret) - nbdone,
+ product->ob_digit, Py_Size(product));
Py_DECREF(product);
bsize -= nbtouse;
@@ -2540,8 +2540,8 @@ l_divmod(PyLongObject *v, PyLongObject *w,
if (long_divrem(v, w, &div, &mod) < 0)
return -1;
- if ((mod->ob_size < 0 && w->ob_size > 0) ||
- (mod->ob_size > 0 && w->ob_size < 0)) {
+ if ((Py_Size(mod) < 0 && Py_Size(w) > 0) ||
+ (Py_Size(mod) > 0 && Py_Size(w) < 0)) {
PyLongObject *temp;
PyLongObject *one;
temp = (PyLongObject *) long_add(mod, w);
@@ -2729,7 +2729,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
return Py_NotImplemented;
}
- if (b->ob_size < 0) { /* if exponent is negative */
+ if (Py_Size(b) < 0) { /* if exponent is negative */
if (c) {
PyErr_SetString(PyExc_TypeError, "pow() 2nd argument "
"cannot be negative when 3rd argument specified");
@@ -2748,7 +2748,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
if (c) {
/* if modulus == 0:
raise ValueError() */
- if (c->ob_size == 0) {
+ if (Py_Size(c) == 0) {
PyErr_SetString(PyExc_ValueError,
"pow() 3rd argument cannot be 0");
goto Error;
@@ -2757,7 +2757,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
/* if modulus < 0:
negativeOutput = True
modulus = -modulus */
- if (c->ob_size < 0) {
+ if (Py_Size(c) < 0) {
negativeOutput = 1;
temp = (PyLongObject *)_PyLong_Copy(c);
if (temp == NULL)
@@ -2770,7 +2770,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
/* if modulus == 1:
return 0 */
- if ((c->ob_size == 1) && (c->ob_digit[0] == 1)) {
+ if ((Py_Size(c) == 1) && (c->ob_digit[0] == 1)) {
z = (PyLongObject *)PyLong_FromLong(0L);
goto Done;
}
@@ -2778,7 +2778,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
/* if base < 0:
base = base % modulus
Having the base positive just makes things easier. */
- if (a->ob_size < 0) {
+ if (Py_Size(a) < 0) {
if (l_divmod(a, c, NULL, &temp) < 0)
goto Error;
Py_DECREF(a);
@@ -2819,10 +2819,10 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
REDUCE(result) \
}
- if (b->ob_size <= FIVEARY_CUTOFF) {
+ if (Py_Size(b) <= FIVEARY_CUTOFF) {
/* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
/* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf */
- for (i = b->ob_size - 1; i >= 0; --i) {
+ for (i = Py_Size(b) - 1; i >= 0; --i) {
digit bi = b->ob_digit[i];
for (j = 1 << (SHIFT-1); j != 0; j >>= 1) {
@@ -2839,7 +2839,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
for (i = 1; i < 32; ++i)
MULT(table[i-1], a, table[i])
- for (i = b->ob_size - 1; i >= 0; --i) {
+ for (i = Py_Size(b) - 1; i >= 0; --i) {
const digit bi = b->ob_digit[i];
for (j = SHIFT - 5; j >= 0; j -= 5) {
@@ -2852,7 +2852,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
}
}
- if (negativeOutput && (z->ob_size != 0)) {
+ if (negativeOutput && (Py_Size(z) != 0)) {
temp = (PyLongObject *)long_sub(z, c);
if (temp == NULL)
goto Error;
@@ -2869,7 +2869,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
}
/* fall through */
Done:
- if (b->ob_size > FIVEARY_CUTOFF) {
+ if (Py_Size(b) > FIVEARY_CUTOFF) {
for (i = 0; i < 32; ++i)
Py_XDECREF(table[i]);
}
@@ -2893,7 +2893,7 @@ long_invert(PyLongObject *v)
Py_DECREF(w);
if (x == NULL)
return NULL;
- x->ob_size = -(x->ob_size);
+ Py_Size(x) = -(Py_Size(x));
return (PyObject *)x;
}
@@ -2935,7 +2935,7 @@ long_abs(PyLongObject *v)
static int
long_nonzero(PyLongObject *v)
{
- return ABS(v->ob_size) != 0;
+ return ABS(Py_Size(v)) != 0;
}
static PyObject *
@@ -2949,7 +2949,7 @@ long_rshift(PyLongObject *v, PyLongObject *w)
CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
- if (a->ob_size < 0) {
+ if (Py_Size(a) < 0) {
/* Right shifting negative numbers is harder */
PyLongObject *a1, *a2;
a1 = (PyLongObject *) long_invert(a);
@@ -2973,7 +2973,7 @@ long_rshift(PyLongObject *v, PyLongObject *w)
goto rshift_error;
}
wordshift = shiftby / SHIFT;
- newsize = ABS(a->ob_size) - wordshift;
+ newsize = ABS(Py_Size(a)) - wordshift;
if (newsize <= 0) {
z = _PyLong_New(0);
Py_DECREF(a);
@@ -2987,8 +2987,8 @@ long_rshift(PyLongObject *v, PyLongObject *w)
z = _PyLong_New(newsize);
if (z == NULL)
goto rshift_error;
- if (a->ob_size < 0)
- z->ob_size = -(z->ob_size);
+ if (Py_Size(a) < 0)
+ Py_Size(z) = -(Py_Size(z));
for (i = 0, j = wordshift; i < newsize; i++, j++) {
z->ob_digit[i] = (a->ob_digit[j] >> loshift) & lomask;
if (i+1 < newsize)
@@ -3076,7 +3076,7 @@ long_bitwise(PyLongObject *a,
digit diga, digb;
PyObject *v;
- if (a->ob_size < 0) {
+ if (Py_Size(a) < 0) {
a = (PyLongObject *) long_invert(a);
if (a == NULL)
return NULL;
@@ -3086,7 +3086,7 @@ long_bitwise(PyLongObject *a,
Py_INCREF(a);
maska = 0;
}
- if (b->ob_size < 0) {
+ if (Py_Size(b) < 0) {
b = (PyLongObject *) long_invert(b);
if (b == NULL) {
Py_DECREF(a);
@@ -3135,8 +3135,8 @@ long_bitwise(PyLongObject *a,
whose length should be ignored.
*/
- size_a = a->ob_size;
- size_b = b->ob_size;
+ size_a = Py_Size(a);
+ size_b = Py_Size(b);
size_z = op == '&'
? (maska
? size_b
@@ -3343,7 +3343,7 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (tmp == NULL)
return NULL;
assert(PyLong_CheckExact(tmp));
- n = tmp->ob_size;
+ n = Py_Size(tmp);
if (n < 0)
n = -n;
newobj = (PyLongObject *)type->tp_alloc(type, n);
@@ -3352,7 +3352,7 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
assert(PyLong_Check(newobj));
- newobj->ob_size = tmp->ob_size;
+ Py_Size(newobj) = Py_Size(tmp);
for (i = 0; i < n; i++)
newobj->ob_digit[i] = tmp->ob_digit[i];
Py_DECREF(tmp);
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index ecc9a0a..00d3cfa 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -231,8 +231,7 @@ meth_hash(PyCFunctionObject *a)
PyTypeObject PyCFunction_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"builtin_function_or_method",
sizeof(PyCFunctionObject),
0,
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index e454fcf..9585795 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -176,7 +176,7 @@ module_dealloc(PyModuleObject *m)
_PyModule_Clear((PyObject *)m);
Py_DECREF(m->md_dict);
}
- m->ob_type->tp_free((PyObject *)m);
+ Py_Type(m)->tp_free((PyObject *)m);
}
static PyObject *
@@ -215,8 +215,7 @@ Create a module object.\n\
The name must be a string; the optional doc argument can have any type.");
PyTypeObject PyModule_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"module", /* tp_name */
sizeof(PyModuleObject), /* tp_size */
0, /* tp_itemsize */
diff --git a/Objects/object.c b/Objects/object.c
index 8de6723..4330b08 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -214,7 +214,7 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
if (op == NULL)
return PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
- op->ob_type = tp;
+ Py_Type(op) = tp;
_Py_NewReference(op);
return op;
}
@@ -226,7 +226,7 @@ PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
return (PyVarObject *) PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT_VAR */
op->ob_size = size;
- op->ob_type = tp;
+ Py_Type(op) = tp;
_Py_NewReference((PyObject *)op);
return op;
}
@@ -287,7 +287,7 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
universally available */
fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op);
- else if (op->ob_type->tp_print == NULL) {
+ else if (Py_Type(op)->tp_print == NULL) {
PyObject *s;
if (flags & Py_PRINT_RAW)
s = PyObject_Str(op);
@@ -302,7 +302,7 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
Py_XDECREF(s);
}
else
- ret = (*op->ob_type->tp_print)(op, fp, flags);
+ ret = (*Py_Type(op)->tp_print)(op, fp, flags);
}
if (ret == 0) {
if (ferror(fp)) {
@@ -335,7 +335,7 @@ void _PyObject_Dump(PyObject* op)
"type : %s\n"
"refcount: %ld\n"
"address : %p\n",
- op->ob_type==NULL ? "NULL" : op->ob_type->tp_name,
+ Py_Type(op)==NULL ? "NULL" : Py_Type(op)->tp_name,
(long)op->ob_refcnt,
op);
}
@@ -354,12 +354,12 @@ PyObject_Repr(PyObject *v)
#endif
if (v == NULL)
return PyString_FromString("<NULL>");
- else if (v->ob_type->tp_repr == NULL)
+ else if (Py_Type(v)->tp_repr == NULL)
return PyString_FromFormat("<%s object at %p>",
- v->ob_type->tp_name, v);
+ Py_Type(v)->tp_name, v);
else {
PyObject *res;
- res = (*v->ob_type->tp_repr)(v);
+ res = (*Py_Type(v)->tp_repr)(v);
if (res == NULL)
return NULL;
#ifdef Py_USING_UNICODE
@@ -376,7 +376,7 @@ PyObject_Repr(PyObject *v)
if (!PyString_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__repr__ returned non-string (type %.200s)",
- res->ob_type->tp_name);
+ Py_Type(res)->tp_name);
Py_DECREF(res);
return NULL;
}
@@ -401,10 +401,10 @@ _PyObject_Str(PyObject *v)
return v;
}
#endif
- if (v->ob_type->tp_str == NULL)
+ if (Py_Type(v)->tp_str == NULL)
return PyObject_Repr(v);
- res = (*v->ob_type->tp_str)(v);
+ res = (*Py_Type(v)->tp_str)(v);
if (res == NULL)
return NULL;
type_ok = PyString_Check(res);
@@ -414,7 +414,7 @@ _PyObject_Str(PyObject *v)
if (!type_ok) {
PyErr_Format(PyExc_TypeError,
"__str__ returned non-string (type %.200s)",
- res->ob_type->tp_name);
+ Py_Type(res)->tp_name);
Py_DECREF(res);
return NULL;
}
@@ -488,8 +488,8 @@ PyObject_Unicode(PyObject *v)
res = v;
}
else {
- if (v->ob_type->tp_str != NULL)
- res = (*v->ob_type->tp_str)(v);
+ if (Py_Type(v)->tp_str != NULL)
+ res = (*Py_Type(v)->tp_str)(v);
else
res = PyObject_Repr(v);
}
@@ -1062,8 +1062,8 @@ PyObject_GetAttrString(PyObject *v, const char *name)
{
PyObject *w, *res;
- if (v->ob_type->tp_getattr != NULL)
- return (*v->ob_type->tp_getattr)(v, (char*)name);
+ if (Py_Type(v)->tp_getattr != NULL)
+ return (*Py_Type(v)->tp_getattr)(v, (char*)name);
w = PyString_InternFromString(name);
if (w == NULL)
return NULL;
@@ -1090,8 +1090,8 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
PyObject *s;
int res;
- if (v->ob_type->tp_setattr != NULL)
- return (*v->ob_type->tp_setattr)(v, (char*)name, w);
+ if (Py_Type(v)->tp_setattr != NULL)
+ return (*Py_Type(v)->tp_setattr)(v, (char*)name, w);
s = PyString_InternFromString(name);
if (s == NULL)
return -1;
@@ -1103,7 +1103,7 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
PyObject *
PyObject_GetAttr(PyObject *v, PyObject *name)
{
- PyTypeObject *tp = v->ob_type;
+ PyTypeObject *tp = Py_Type(v);
if (!PyString_Check(name)) {
#ifdef Py_USING_UNICODE
@@ -1120,7 +1120,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
- name->ob_type->tp_name);
+ Py_Type(name)->tp_name);
return NULL;
}
}
@@ -1149,7 +1149,7 @@ PyObject_HasAttr(PyObject *v, PyObject *name)
int
PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
{
- PyTypeObject *tp = v->ob_type;
+ PyTypeObject *tp = Py_Type(v);
int err;
if (!PyString_Check(name)){
@@ -1167,7 +1167,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
- name->ob_type->tp_name);
+ Py_Type(name)->tp_name);
return -1;
}
}
@@ -1209,7 +1209,7 @@ PyObject **
_PyObject_GetDictPtr(PyObject *obj)
{
Py_ssize_t dictoffset;
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_Type(obj);
if (!(tp->tp_flags & Py_TPFLAGS_HAVE_CLASS))
return NULL;
@@ -1244,7 +1244,7 @@ PyObject_SelfIter(PyObject *obj)
PyObject *
PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
{
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_Type(obj);
PyObject *descr = NULL;
PyObject *res = NULL;
descrgetfunc f;
@@ -1266,7 +1266,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
- name->ob_type->tp_name);
+ Py_Type(name)->tp_name);
return NULL;
}
}
@@ -1346,7 +1346,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
}
if (f != NULL) {
- res = f(descr, obj, (PyObject *)obj->ob_type);
+ res = f(descr, obj, (PyObject *)Py_Type(obj));
Py_DECREF(descr);
goto done;
}
@@ -1368,7 +1368,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
int
PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
{
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_Type(obj);
PyObject *descr;
descrsetfunc f;
PyObject **dictptr;
@@ -1389,7 +1389,7 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
- name->ob_type->tp_name);
+ Py_Type(name)->tp_name);
return -1;
}
}
@@ -1683,7 +1683,7 @@ _dir_locals(void)
if (!PyList_Check(names)) {
PyErr_Format(PyExc_TypeError,
"dir(): expected keys() of locals to be a list, "
- "not '%.200s'", names->ob_type->tp_name);
+ "not '%.200s'", Py_Type(names)->tp_name);
Py_DECREF(names);
return NULL;
}
@@ -1818,7 +1818,7 @@ _dir_object(PyObject *obj)
if (!PyList_Check(result)) {
PyErr_Format(PyExc_TypeError,
"__dir__() must return a list, not %.200s",
- result->ob_type->tp_name);
+ Py_Type(result)->tp_name);
Py_DECREF(result);
result = NULL;
}
@@ -1880,8 +1880,7 @@ none_dealloc(PyObject* ignore)
static PyTypeObject PyNone_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"NoneType",
0,
0,
@@ -1898,7 +1897,8 @@ static PyTypeObject PyNone_Type = {
};
PyObject _Py_NoneStruct = {
- PyObject_HEAD_INIT(&PyNone_Type)
+ _PyObject_EXTRA_INIT
+ 1, &PyNone_Type
};
/* NotImplemented is an object that can be used to signal that an
@@ -1911,8 +1911,7 @@ NotImplemented_repr(PyObject *op)
}
static PyTypeObject PyNotImplemented_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"NotImplementedType",
0,
0,
@@ -1929,7 +1928,8 @@ static PyTypeObject PyNotImplemented_Type = {
};
PyObject _Py_NotImplementedStruct = {
- PyObject_HEAD_INIT(&PyNotImplemented_Type)
+ _PyObject_EXTRA_INIT
+ 1, &PyNotImplemented_Type
};
void
@@ -1997,7 +1997,7 @@ _Py_ForgetReference(register PyObject *op)
void
_Py_Dealloc(PyObject *op)
{
- destructor dealloc = op->ob_type->tp_dealloc;
+ destructor dealloc = Py_Type(op)->tp_dealloc;
_Py_ForgetReference(op);
(*dealloc)(op);
}
@@ -2028,7 +2028,7 @@ _Py_PrintReferenceAddresses(FILE *fp)
fprintf(fp, "Remaining object addresses:\n");
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next)
fprintf(fp, "%p [%" PY_FORMAT_SIZE_T "d] %s\n", op,
- op->ob_refcnt, op->ob_type->tp_name);
+ op->ob_refcnt, Py_Type(op)->tp_name);
}
PyObject *
@@ -2046,7 +2046,7 @@ _Py_GetObjects(PyObject *self, PyObject *args)
return NULL;
for (i = 0; (n == 0 || i < n) && op != &refchain; i++) {
while (op == self || op == args || op == res || op == t ||
- (t != NULL && op->ob_type != (PyTypeObject *) t)) {
+ (t != NULL && Py_Type(op) != (PyTypeObject *) t)) {
op = op->_ob_next;
if (op == &refchain)
return res;
@@ -2189,7 +2189,7 @@ _PyTrash_destroy_chain(void)
{
while (_PyTrash_delete_later) {
PyObject *op = _PyTrash_delete_later;
- destructor dealloc = op->ob_type->tp_dealloc;
+ destructor dealloc = Py_Type(op)->tp_dealloc;
_PyTrash_delete_later =
(PyObject*) _Py_AS_GC(op)->gc.gc_prev;
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 840570e..2f2b35e 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -675,8 +675,8 @@ extremely desirable that it be this fast.
/* This is only useful when running memory debuggers such as
* Purify or Valgrind. Uncomment to use.
*
-#define Py_USING_MEMORY_DEBUGGER
*/
+#define Py_USING_MEMORY_DEBUGGER
#ifdef Py_USING_MEMORY_DEBUGGER
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 208db75..f0a11ca 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -3,7 +3,7 @@
Written and maintained by Raymond D. Hettinger <python@rcn.com>
Derived from Lib/sets.py and Objects/dictobject.c.
- Copyright (c) 2003-6 Python Software Foundation.
+ Copyright (c) 2003-2007 Python Software Foundation.
All rights reserved.
*/
@@ -561,7 +561,7 @@ set_dealloc(PySetObject *so)
if (num_free_sets < MAXFREESETS && PyAnySet_CheckExact(so))
free_sets[num_free_sets++] = so;
else
- so->ob_type->tp_free(so);
+ Py_Type(so)->tp_free(so);
Py_TRASHCAN_SAFE_END(so)
}
@@ -860,8 +860,7 @@ fail:
}
static PyTypeObject PySetIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"setiterator", /* tp_name */
sizeof(setiterobject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -987,7 +986,7 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
(type == &PySet_Type || type == &PyFrozenSet_Type)) {
so = free_sets[--num_free_sets];
assert (so != NULL && PyAnySet_CheckExact(so));
- so->ob_type = type;
+ Py_Type(so) = type;
_Py_NewReference((PyObject *)so);
EMPTY_TO_MINSIZE(so);
PyObject_GC_Track(so);
@@ -1113,8 +1112,8 @@ set_swap_bodies(PySetObject *a, PySetObject *b)
memcpy(b->smalltable, tab, sizeof(tab));
}
- if (PyType_IsSubtype(a->ob_type, &PyFrozenSet_Type) &&
- PyType_IsSubtype(b->ob_type, &PyFrozenSet_Type)) {
+ if (PyType_IsSubtype(Py_Type(a), &PyFrozenSet_Type) &&
+ PyType_IsSubtype(Py_Type(b), &PyFrozenSet_Type)) {
h = a->hash; a->hash = b->hash; b->hash = h;
} else {
a->hash = -1;
@@ -1125,7 +1124,7 @@ set_swap_bodies(PySetObject *a, PySetObject *b)
static PyObject *
set_copy(PySetObject *so)
{
- return make_new_set(so->ob_type, (PyObject *)so);
+ return make_new_set(Py_Type(so), (PyObject *)so);
}
static PyObject *
@@ -1203,7 +1202,7 @@ set_intersection(PySetObject *so, PyObject *other)
if ((PyObject *)so == other)
return set_copy(so);
- result = (PySetObject *)make_new_set(so->ob_type, NULL);
+ result = (PySetObject *)make_new_set(Py_Type(so), NULL);
if (result == NULL)
return NULL;
@@ -1390,7 +1389,7 @@ set_difference(PySetObject *so, PyObject *other)
return NULL;
}
- result = make_new_set(so->ob_type, NULL);
+ result = make_new_set(Py_Type(so), NULL);
if (result == NULL)
return NULL;
@@ -1491,7 +1490,7 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other)
Py_INCREF(other);
otherset = (PySetObject *)other;
} else {
- otherset = (PySetObject *)make_new_set(so->ob_type, other);
+ otherset = (PySetObject *)make_new_set(Py_Type(so), other);
if (otherset == NULL)
return NULL;
}
@@ -1522,7 +1521,7 @@ set_symmetric_difference(PySetObject *so, PyObject *other)
PyObject *rv;
PySetObject *otherset;
- otherset = (PySetObject *)make_new_set(so->ob_type, other);
+ otherset = (PySetObject *)make_new_set(Py_Type(so), other);
if (otherset == NULL)
return NULL;
rv = set_symmetric_difference_update(otherset, (PyObject *)so);
@@ -1789,7 +1788,7 @@ set_reduce(PySetObject *so)
dict = Py_None;
Py_INCREF(dict);
}
- result = PyTuple_Pack(3, so->ob_type, args, dict);
+ result = PyTuple_Pack(3, Py_Type(so), args, dict);
done:
Py_XDECREF(args);
Py_XDECREF(keys);
@@ -1806,7 +1805,7 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
if (!PyAnySet_Check(self))
return -1;
- if (!PyArg_UnpackTuple(args, self->ob_type->tp_name, 0, 1, &iterable))
+ if (!PyArg_UnpackTuple(args, Py_Type(self)->tp_name, 0, 1, &iterable))
return -1;
set_clear_internal(self);
self->hash = -1;
@@ -1922,8 +1921,7 @@ PyDoc_STRVAR(set_doc,
Build an unordered collection of unique elements.");
PyTypeObject PySet_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"set", /* tp_name */
sizeof(PySetObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2017,8 +2015,7 @@ PyDoc_STRVAR(frozenset_doc,
Build an immutable unordered collection of unique elements.");
PyTypeObject PyFrozenSet_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"frozenset", /* tp_name */
sizeof(PySetObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2099,7 +2096,7 @@ PySet_Size(PyObject *anyset)
int
PySet_Clear(PyObject *set)
{
- if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
+ if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
PyErr_BadInternalCall();
return -1;
}
@@ -2119,7 +2116,7 @@ PySet_Contains(PyObject *anyset, PyObject *key)
int
PySet_Discard(PyObject *set, PyObject *key)
{
- if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
+ if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
PyErr_BadInternalCall();
return -1;
}
@@ -2129,7 +2126,7 @@ PySet_Discard(PyObject *set, PyObject *key)
int
PySet_Add(PyObject *set, PyObject *key)
{
- if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
+ if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
PyErr_BadInternalCall();
return -1;
}
@@ -2170,7 +2167,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
PyObject *
PySet_Pop(PyObject *set)
{
- if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
+ if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
PyErr_BadInternalCall();
return NULL;
}
@@ -2180,7 +2177,7 @@ PySet_Pop(PyObject *set)
int
_PySet_Update(PyObject *set, PyObject *iterable)
{
- if (!PyType_IsSubtype(set->ob_type, &PySet_Type)) {
+ if (!PyType_IsSubtype(Py_Type(set), &PySet_Type)) {
PyErr_BadInternalCall();
return -1;
}
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 3fb1430..d147bce 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -23,8 +23,7 @@ ellipsis_repr(PyObject *op)
}
static PyTypeObject PyEllipsis_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"ellipsis", /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
@@ -47,7 +46,8 @@ static PyTypeObject PyEllipsis_Type = {
};
PyObject _Py_EllipsisObject = {
- PyObject_HEAD_INIT(&PyEllipsis_Type)
+ _PyObject_EXTRA_INIT
+ 1, &PyEllipsis_Type
};
@@ -277,7 +277,7 @@ handling of normal slices.");
static PyObject *
slice_reduce(PySliceObject* self)
{
- return Py_BuildValue("O(OOO)", self->ob_type, self->start, self->stop, self->step);
+ return Py_BuildValue("O(OOO)", Py_Type(self), self->start, self->stop, self->step);
}
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
@@ -319,8 +319,7 @@ slice_hash(PySliceObject *v)
}
PyTypeObject PySlice_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* Number of items for varobject */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"slice", /* Name of this type */
sizeof(PySliceObject), /* Basic object size */
0, /* Item size for varobject */
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 504b119..16affdd 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -421,7 +421,7 @@ PyObject *PyString_AsDecodedString(PyObject *str,
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string object (type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
goto onError;
}
@@ -501,7 +501,7 @@ PyObject *PyString_AsEncodedString(PyObject *str,
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
goto onError;
}
@@ -521,7 +521,7 @@ string_dealloc(PyObject *op)
case SSTATE_INTERNED_MORTAL:
/* revive dead object temporarily for DelItem */
- op->ob_refcnt = 3;
+ Py_Refcnt(op) = 3;
if (PyDict_DelItem(interned, op) != 0)
Py_FatalError(
"deletion of interned string failed");
@@ -533,7 +533,7 @@ string_dealloc(PyObject *op)
default:
Py_FatalError("Inconsistent interned string state.");
}
- op->ob_type->tp_free(op);
+ Py_Type(op)->tp_free(op);
}
/* Unescape a backslash-escaped string. If unicode is non-zero,
@@ -717,7 +717,7 @@ PyString_Size(register PyObject *op)
{
if (!PyString_Check(op))
return string_getsize(op);
- return ((PyStringObject *)op) -> ob_size;
+ return Py_Size(op);
}
/*const*/ char *
@@ -750,7 +750,7 @@ PyString_AsStringAndSize(register PyObject *obj,
{
PyErr_Format(PyExc_TypeError,
"expected string or Unicode object, "
- "%.200s found", obj->ob_type->tp_name);
+ "%.200s found", Py_Type(obj)->tp_name);
return -1;
}
}
@@ -805,7 +805,7 @@ string_print(PyStringObject *op, FILE *fp, int flags)
}
if (flags & Py_PRINT_RAW) {
char *data = op->ob_sval;
- Py_ssize_t size = op->ob_size;
+ Py_ssize_t size = Py_Size(op);
while (size > INT_MAX) {
/* Very long strings cannot be written atomically.
* But don't write exactly INT_MAX bytes at a time
@@ -826,12 +826,12 @@ string_print(PyStringObject *op, FILE *fp, int flags)
/* figure out which quote to use; single is preferred */
quote = '\'';
- if (memchr(op->ob_sval, '\'', op->ob_size) &&
- !memchr(op->ob_sval, '"', op->ob_size))
+ if (memchr(op->ob_sval, '\'', Py_Size(op)) &&
+ !memchr(op->ob_sval, '"', Py_Size(op)))
quote = '"';
fputc(quote, fp);
- for (i = 0; i < op->ob_size; i++) {
+ for (i = 0; i < Py_Size(op); i++) {
c = op->ob_sval[i];
if (c == quote || c == '\\')
fprintf(fp, "\\%c", c);
@@ -854,9 +854,9 @@ PyObject *
PyString_Repr(PyObject *obj, int smartquotes)
{
register PyStringObject* op = (PyStringObject*) obj;
- size_t newsize = 2 + 4 * op->ob_size;
+ size_t newsize = 2 + 4 * Py_Size(op);
PyObject *v;
- if (newsize > PY_SSIZE_T_MAX || newsize / 4 != op->ob_size) {
+ if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(op)) {
PyErr_SetString(PyExc_OverflowError,
"string is too large to make repr");
}
@@ -873,13 +873,13 @@ PyString_Repr(PyObject *obj, int smartquotes)
/* figure out which quote to use; single is preferred */
quote = '\'';
if (smartquotes &&
- memchr(op->ob_sval, '\'', op->ob_size) &&
- !memchr(op->ob_sval, '"', op->ob_size))
+ memchr(op->ob_sval, '\'', Py_Size(op)) &&
+ !memchr(op->ob_sval, '"', Py_Size(op)))
quote = '"';
p = PyString_AS_STRING(v);
*p++ = quote;
- for (i = 0; i < op->ob_size; i++) {
+ for (i = 0; i < Py_Size(op); i++) {
/* There's at least enough room for a hex escape
and a closing quote. */
assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
@@ -928,14 +928,14 @@ string_str(PyObject *s)
else {
/* Subtype -- return genuine string with the same value. */
PyStringObject *t = (PyStringObject *) s;
- return PyString_FromStringAndSize(t->ob_sval, t->ob_size);
+ return PyString_FromStringAndSize(t->ob_sval, Py_Size(t));
}
}
static Py_ssize_t
string_length(PyStringObject *a)
{
- return a->ob_size;
+ return Py_Size(a);
}
static PyObject *
@@ -950,21 +950,21 @@ string_concat(register PyStringObject *a, register PyObject *bb)
#endif
PyErr_Format(PyExc_TypeError,
"cannot concatenate 'str' and '%.200s' objects",
- bb->ob_type->tp_name);
+ Py_Type(bb)->tp_name);
return NULL;
}
#define b ((PyStringObject *)bb)
/* Optimize cases with empty left or right operand */
- if ((a->ob_size == 0 || b->ob_size == 0) &&
+ if ((Py_Size(a) == 0 || Py_Size(b) == 0) &&
PyString_CheckExact(a) && PyString_CheckExact(b)) {
- if (a->ob_size == 0) {
+ if (Py_Size(a) == 0) {
Py_INCREF(bb);
return bb;
}
Py_INCREF(a);
return (PyObject *)a;
}
- size = a->ob_size + b->ob_size;
+ size = Py_Size(a) + Py_Size(b);
if (size < 0) {
PyErr_SetString(PyExc_OverflowError,
"strings are too large to concat");
@@ -978,8 +978,8 @@ string_concat(register PyStringObject *a, register PyObject *bb)
PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
- Py_MEMCPY(op->ob_sval, a->ob_sval, a->ob_size);
- Py_MEMCPY(op->ob_sval + a->ob_size, b->ob_sval, b->ob_size);
+ Py_MEMCPY(op->ob_sval, a->ob_sval, Py_Size(a));
+ Py_MEMCPY(op->ob_sval + Py_Size(a), b->ob_sval, Py_Size(b));
op->ob_sval[size] = '\0';
return (PyObject *) op;
#undef b
@@ -998,13 +998,13 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n)
/* watch out for overflows: the size can overflow int,
* and the # of bytes needed can overflow size_t
*/
- size = a->ob_size * n;
- if (n && size / n != a->ob_size) {
+ size = Py_Size(a) * n;
+ if (n && size / n != Py_Size(a)) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
}
- if (size == a->ob_size && PyString_CheckExact(a)) {
+ if (size == Py_Size(a) && PyString_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}
@@ -1022,14 +1022,14 @@ string_repeat(register PyStringObject *a, register Py_ssize_t n)
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
op->ob_sval[size] = '\0';
- if (a->ob_size == 1 && n > 0) {
+ if (Py_Size(a) == 1 && n > 0) {
memset(op->ob_sval, a->ob_sval[0] , n);
return (PyObject *) op;
}
i = 0;
if (i < size) {
- Py_MEMCPY(op->ob_sval, a->ob_sval, a->ob_size);
- i = a->ob_size;
+ Py_MEMCPY(op->ob_sval, a->ob_sval, Py_Size(a));
+ i = Py_Size(a);
}
while (i < size) {
j = (i <= size-i) ? i : size-i;
@@ -1050,9 +1050,9 @@ string_slice(register PyStringObject *a, register Py_ssize_t i,
i = 0;
if (j < 0)
j = 0; /* Avoid signed/unsigned bug in next line */
- if (j > a->ob_size)
- j = a->ob_size;
- if (i == 0 && j == a->ob_size && PyString_CheckExact(a)) {
+ if (j > Py_Size(a))
+ j = Py_Size(a);
+ if (i == 0 && j == Py_Size(a) && PyString_CheckExact(a)) {
/* It's the same as a */
Py_INCREF(a);
return (PyObject *)a;
@@ -1073,7 +1073,7 @@ string_contains(PyObject *str_obj, PyObject *sub_obj)
if (!PyString_Check(sub_obj)) {
PyErr_Format(PyExc_TypeError,
"'in <string>' requires string as left operand, "
- "not %.200s", sub_obj->ob_type->tp_name);
+ "not %.200s", Py_Type(sub_obj)->tp_name);
return -1;
}
}
@@ -1086,7 +1086,7 @@ string_item(PyStringObject *a, register Py_ssize_t i)
{
char pchar;
PyObject *v;
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return NULL;
}
@@ -1129,16 +1129,16 @@ string_richcompare(PyStringObject *a, PyStringObject *b, int op)
if (op == Py_EQ) {
/* Supporting Py_NE here as well does not save
much time, since Py_NE is rarely used. */
- if (a->ob_size == b->ob_size
+ if (Py_Size(a) == Py_Size(b)
&& (a->ob_sval[0] == b->ob_sval[0]
- && memcmp(a->ob_sval, b->ob_sval, a->ob_size) == 0)) {
+ && memcmp(a->ob_sval, b->ob_sval, Py_Size(a)) == 0)) {
result = Py_True;
} else {
result = Py_False;
}
goto out;
}
- len_a = a->ob_size; len_b = b->ob_size;
+ len_a = Py_Size(a); len_b = Py_Size(b);
min_len = (len_a < len_b) ? len_a : len_b;
if (min_len > 0) {
c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
@@ -1170,9 +1170,9 @@ _PyString_Eq(PyObject *o1, PyObject *o2)
{
PyStringObject *a = (PyStringObject*) o1;
PyStringObject *b = (PyStringObject*) o2;
- return a->ob_size == b->ob_size
+ return Py_Size(a) == Py_Size(b)
&& *a->ob_sval == *b->ob_sval
- && memcmp(a->ob_sval, b->ob_sval, a->ob_size) == 0;
+ && memcmp(a->ob_sval, b->ob_sval, Py_Size(a)) == 0;
}
static long
@@ -1184,12 +1184,12 @@ string_hash(PyStringObject *a)
if (a->ob_shash != -1)
return a->ob_shash;
- len = a->ob_size;
+ len = Py_Size(a);
p = (unsigned char *) a->ob_sval;
x = *p << 7;
while (--len >= 0)
x = (1000003*x) ^ *p++;
- x ^= a->ob_size;
+ x ^= Py_Size(a);
if (x == -1)
x = -2;
a->ob_shash = x;
@@ -1242,7 +1242,7 @@ string_subscript(PyStringObject* self, PyObject* item)
else {
PyErr_Format(PyExc_TypeError,
"string indices must be integers, not %.200s",
- item->ob_type->tp_name);
+ Py_Type(item)->tp_name);
return NULL;
}
}
@@ -1256,7 +1256,7 @@ string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **pt
return -1;
}
*ptr = (void *)self->ob_sval;
- return self->ob_size;
+ return Py_Size(self);
}
static Py_ssize_t
@@ -1271,7 +1271,7 @@ static Py_ssize_t
string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
{
if ( lenp )
- *lenp = self->ob_size;
+ *lenp = Py_Size(self);
return 1;
}
@@ -1284,7 +1284,7 @@ string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **pt
return -1;
}
*ptr = self->ob_sval;
- return self->ob_size;
+ return Py_Size(self);
}
static PySequenceMethods string_as_sequence = {
@@ -1373,7 +1373,7 @@ static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"};
count++; }
/* Always force the list to the expected size. */
-#define FIX_PREALLOC_SIZE(list) ((PyListObject *)list)->ob_size = count
+#define FIX_PREALLOC_SIZE(list) Py_Size(list) = count
#define SKIP_SPACE(s, i, len) { while (i<len && isspace(Py_CHARMASK(s[i]))) i++; }
#define SKIP_NONSPACE(s, i, len) { while (i<len && !isspace(Py_CHARMASK(s[i]))) i++; }
@@ -1788,7 +1788,7 @@ string_join(PyStringObject *self, PyObject *orig)
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected string,"
" %.80s found",
- i, item->ob_type->tp_name);
+ i, Py_Type(item)->tp_name);
Py_DECREF(seq);
return NULL;
}
@@ -3248,7 +3248,7 @@ string_encode(PyStringObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@@ -3285,7 +3285,7 @@ string_decode(PyStringObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@@ -3843,7 +3843,7 @@ string_splitlines(PyStringObject *self, PyObject *args)
static PyObject *
string_getnewargs(PyStringObject *v)
{
- return Py_BuildValue("(s#)", v->ob_sval, v->ob_size);
+ return Py_BuildValue("(s#)", v->ob_sval, Py_Size(v));
}
@@ -3972,8 +3972,7 @@ static PyNumberMethods string_as_number = {
PyTypeObject PyBaseString_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"basestring",
0,
0,
@@ -4021,8 +4020,7 @@ Return a nice string representation of the object.\n\
If the argument is a string, the return value is the same object.");
PyTypeObject PyString_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"str",
sizeof(PyStringObject),
sizeof(char),
@@ -4108,7 +4106,7 @@ _PyString_Resize(PyObject **pv, Py_ssize_t newsize)
register PyObject *v;
register PyStringObject *sv;
v = *pv;
- if (!PyString_Check(v) || v->ob_refcnt != 1 || newsize < 0 ||
+ if (!PyString_Check(v) || Py_Refcnt(v) != 1 || newsize < 0 ||
PyString_CHECK_INTERNED(v)) {
*pv = 0;
Py_DECREF(v);
@@ -4127,7 +4125,7 @@ _PyString_Resize(PyObject **pv, Py_ssize_t newsize)
}
_Py_NewReference(*pv);
sv = (PyStringObject *) *pv;
- sv->ob_size = newsize;
+ Py_Size(sv) = newsize;
sv->ob_sval[newsize] = '\0';
sv->ob_shash = -1; /* invalidate cached hash value */
return 0;
@@ -4175,7 +4173,7 @@ formatfloat(char *buf, size_t buflen, int flags,
x = PyFloat_AsDouble(v);
if (x == -1.0 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "float argument required, "
- "not %.200s", v->ob_type->tp_name);
+ "not %.200s", Py_Type(v)->tp_name);
return -1;
}
if (prec < 0)
@@ -4249,15 +4247,15 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
switch (type) {
case 'd':
case 'u':
- result = val->ob_type->tp_str(val);
+ result = Py_Type(val)->tp_str(val);
break;
case 'o':
- result = val->ob_type->tp_as_number->nb_oct(val);
+ result = Py_Type(val)->tp_as_number->nb_oct(val);
break;
case 'x':
case 'X':
numnondigits = 2;
- result = val->ob_type->tp_as_number->nb_hex(val);
+ result = Py_Type(val)->tp_as_number->nb_hex(val);
break;
default:
assert(!"'type' not in [duoxX]");
@@ -4272,7 +4270,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
}
/* To modify the string in-place, there can only be one reference. */
- if (result->ob_refcnt != 1) {
+ if (Py_Refcnt(result) != 1) {
PyErr_BadInternalCall();
return NULL;
}
@@ -4372,7 +4370,7 @@ formatint(char *buf, size_t buflen, int flags,
x = PyInt_AsLong(v);
if (x == -1 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "int argument required, not %.200s",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
return -1;
}
if (x < 0 && type == 'u') {
@@ -4489,7 +4487,7 @@ PyString_Format(PyObject *format, PyObject *args)
arglen = -1;
argidx = -2;
}
- if (args->ob_type->tp_as_mapping && !PyTuple_Check(args) &&
+ if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
while (--fmtcnt >= 0) {
@@ -4956,7 +4954,7 @@ PyString_InternInPlace(PyObject **p)
}
/* The two references in interned are not counted by refcnt.
The string deallocator will take care of this */
- s->ob_refcnt -= 2;
+ Py_Refcnt(s) -= 2;
PyString_CHECK_INTERNED(s) = SSTATE_INTERNED_MORTAL;
}
@@ -5023,12 +5021,12 @@ void _Py_ReleaseInternedStrings(void)
/* XXX Shouldn't happen */
break;
case SSTATE_INTERNED_IMMORTAL:
- s->ob_refcnt += 1;
- immortal_size += s->ob_size;
+ Py_Refcnt(s) += 1;
+ immortal_size += Py_Size(s);
break;
case SSTATE_INTERNED_MORTAL:
- s->ob_refcnt += 2;
- mortal_size += s->ob_size;
+ Py_Refcnt(s) += 2;
+ mortal_size += Py_Size(s);
break;
default:
Py_FatalError("Inconsistent interned string state.");
diff --git a/Objects/structseq.c b/Objects/structseq.c
index 7ac2a1f..1d5ce87 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -13,17 +13,17 @@ static char unnamed_fields_key[] = "n_unnamed_fields";
They are only allowed for indices < n_visible_fields. */
char *PyStructSequence_UnnamedField = "unnamed field";
-#define VISIBLE_SIZE(op) ((op)->ob_size)
+#define VISIBLE_SIZE(op) Py_Size(op)
#define VISIBLE_SIZE_TP(tp) PyInt_AsLong( \
PyDict_GetItemString((tp)->tp_dict, visible_length_key))
#define REAL_SIZE_TP(tp) PyInt_AsLong( \
PyDict_GetItemString((tp)->tp_dict, real_length_key))
-#define REAL_SIZE(op) REAL_SIZE_TP((op)->ob_type)
+#define REAL_SIZE(op) REAL_SIZE_TP(Py_Type(op))
#define UNNAMED_FIELDS_TP(tp) PyInt_AsLong( \
PyDict_GetItemString((tp)->tp_dict, unnamed_fields_key))
-#define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP((op)->ob_type)
+#define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_Type(op))
PyObject *
@@ -32,7 +32,7 @@ PyStructSequence_New(PyTypeObject *type)
PyStructSequence *obj;
obj = PyObject_New(PyStructSequence, type);
- obj->ob_size = VISIBLE_SIZE_TP(type);
+ Py_Size(obj) = VISIBLE_SIZE_TP(type);
return (PyObject*) obj;
}
@@ -274,12 +274,12 @@ structseq_reduce(PyStructSequence* self)
}
for (; i < n_fields; i++) {
- char *n = self->ob_type->tp_members[i-n_unnamed_fields].name;
+ char *n = Py_Type(self)->tp_members[i-n_unnamed_fields].name;
PyDict_SetItemString(dict, n,
self->ob_item[i]);
}
- result = Py_BuildValue("(O(OO))", self->ob_type, tup, dict);
+ result = Py_BuildValue("(O(OO))", Py_Type(self), tup, dict);
Py_DECREF(tup);
Py_DECREF(dict);
@@ -305,8 +305,7 @@ static PyMethodDef structseq_methods[] = {
};
static PyTypeObject _struct_sequence_template = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
NULL, /* tp_name */
0, /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index dacc3ee..4d4a9ad 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -49,8 +49,8 @@ PyTuple_New(register Py_ssize_t size)
#endif
/* Inline PyObject_InitVar */
#ifdef Py_TRACE_REFS
- op->ob_size = size;
- op->ob_type = &PyTuple_Type;
+ Py_Size(op) = size;
+ Py_Type(op) = &PyTuple_Type;
#endif
_Py_NewReference((PyObject *)op);
}
@@ -90,7 +90,7 @@ PyTuple_Size(register PyObject *op)
return -1;
}
else
- return ((PyTupleObject *)op)->ob_size;
+ return Py_Size(op);
}
PyObject *
@@ -100,7 +100,7 @@ PyTuple_GetItem(register PyObject *op, register Py_ssize_t i)
PyErr_BadInternalCall();
return NULL;
}
- if (i < 0 || i >= ((PyTupleObject *)op) -> ob_size) {
+ if (i < 0 || i >= Py_Size(op)) {
PyErr_SetString(PyExc_IndexError, "tuple index out of range");
return NULL;
}
@@ -117,7 +117,7 @@ PyTuple_SetItem(register PyObject *op, register Py_ssize_t i, PyObject *newitem)
PyErr_BadInternalCall();
return -1;
}
- if (i < 0 || i >= ((PyTupleObject *)op) -> ob_size) {
+ if (i < 0 || i >= Py_Size(op)) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError,
"tuple assignment index out of range");
@@ -160,7 +160,7 @@ static void
tupledealloc(register PyTupleObject *op)
{
register Py_ssize_t i;
- register Py_ssize_t len = op->ob_size;
+ register Py_ssize_t len = Py_Size(op);
PyObject_GC_UnTrack(op);
Py_TRASHCAN_SAFE_BEGIN(op)
if (len > 0) {
@@ -170,7 +170,7 @@ tupledealloc(register PyTupleObject *op)
#if MAXSAVESIZE > 0
if (len < MAXSAVESIZE &&
num_free_tuples[len] < MAXSAVEDTUPLES &&
- op->ob_type == &PyTuple_Type)
+ Py_Type(op) == &PyTuple_Type)
{
op->ob_item[0] = (PyObject *) free_tuples[len];
num_free_tuples[len]++;
@@ -179,7 +179,7 @@ tupledealloc(register PyTupleObject *op)
}
#endif
}
- op->ob_type->tp_free((PyObject *)op);
+ Py_Type(op)->tp_free((PyObject *)op);
done:
Py_TRASHCAN_SAFE_END(op)
}
@@ -189,13 +189,13 @@ tupleprint(PyTupleObject *op, FILE *fp, int flags)
{
Py_ssize_t i;
fprintf(fp, "(");
- for (i = 0; i < op->ob_size; i++) {
+ for (i = 0; i < Py_Size(op); i++) {
if (i > 0)
fprintf(fp, ", ");
if (PyObject_Print(op->ob_item[i], fp, 0) != 0)
return -1;
}
- if (op->ob_size == 1)
+ if (Py_Size(op) == 1)
fprintf(fp, ",");
fprintf(fp, ")");
return 0;
@@ -208,7 +208,7 @@ tuplerepr(PyTupleObject *v)
PyObject *s, *temp;
PyObject *pieces, *result = NULL;
- n = v->ob_size;
+ n = Py_Size(v);
if (n == 0)
return PyString_FromString("()");
@@ -268,7 +268,7 @@ static long
tuplehash(PyTupleObject *v)
{
register long x, y;
- register Py_ssize_t len = v->ob_size;
+ register Py_ssize_t len = Py_Size(v);
register PyObject **p;
long mult = 1000003L;
x = 0x345678L;
@@ -290,7 +290,7 @@ tuplehash(PyTupleObject *v)
static Py_ssize_t
tuplelength(PyTupleObject *a)
{
- return a->ob_size;
+ return Py_Size(a);
}
static int
@@ -299,7 +299,7 @@ tuplecontains(PyTupleObject *a, PyObject *el)
Py_ssize_t i;
int cmp;
- for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
+ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(a); ++i)
cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
Py_EQ);
return cmp;
@@ -308,7 +308,7 @@ tuplecontains(PyTupleObject *a, PyObject *el)
static PyObject *
tupleitem(register PyTupleObject *a, register Py_ssize_t i)
{
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError, "tuple index out of range");
return NULL;
}
@@ -326,11 +326,11 @@ tupleslice(register PyTupleObject *a, register Py_ssize_t ilow,
Py_ssize_t len;
if (ilow < 0)
ilow = 0;
- if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
if (ihigh < ilow)
ihigh = ilow;
- if (ilow == 0 && ihigh == a->ob_size && PyTuple_CheckExact(a)) {
+ if (ilow == 0 && ihigh == Py_Size(a) && PyTuple_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}
@@ -368,11 +368,11 @@ tupleconcat(register PyTupleObject *a, register PyObject *bb)
if (!PyTuple_Check(bb)) {
PyErr_Format(PyExc_TypeError,
"can only concatenate tuple (not \"%.200s\") to tuple",
- bb->ob_type->tp_name);
+ Py_Type(bb)->tp_name);
return NULL;
}
#define b ((PyTupleObject *)bb)
- size = a->ob_size + b->ob_size;
+ size = Py_Size(a) + Py_Size(b);
if (size < 0)
return PyErr_NoMemory();
np = (PyTupleObject *) PyTuple_New(size);
@@ -381,14 +381,14 @@ tupleconcat(register PyTupleObject *a, register PyObject *bb)
}
src = a->ob_item;
dest = np->ob_item;
- for (i = 0; i < a->ob_size; i++) {
+ for (i = 0; i < Py_Size(a); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
}
src = b->ob_item;
- dest = np->ob_item + a->ob_size;
- for (i = 0; i < b->ob_size; i++) {
+ dest = np->ob_item + Py_Size(a);
+ for (i = 0; i < Py_Size(b); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
@@ -406,18 +406,18 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n)
PyObject **p, **items;
if (n < 0)
n = 0;
- if (a->ob_size == 0 || n == 1) {
+ if (Py_Size(a) == 0 || n == 1) {
if (PyTuple_CheckExact(a)) {
/* Since tuples are immutable, we can return a shared
copy in this case */
Py_INCREF(a);
return (PyObject *)a;
}
- if (a->ob_size == 0)
+ if (Py_Size(a) == 0)
return PyTuple_New(0);
}
- size = a->ob_size * n;
- if (size/a->ob_size != n)
+ size = Py_Size(a) * n;
+ if (size/Py_Size(a) != n)
return PyErr_NoMemory();
np = (PyTupleObject *) PyTuple_New(size);
if (np == NULL)
@@ -425,7 +425,7 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n)
p = np->ob_item;
items = a->ob_item;
for (i = 0; i < n; i++) {
- for (j = 0; j < a->ob_size; j++) {
+ for (j = 0; j < Py_Size(a); j++) {
*p = items[j];
Py_INCREF(*p);
p++;
@@ -439,7 +439,7 @@ tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
{
Py_ssize_t i;
- for (i = o->ob_size; --i >= 0; )
+ for (i = Py_Size(o); --i >= 0; )
Py_VISIT(o->ob_item[i]);
return 0;
}
@@ -459,8 +459,8 @@ tuplerichcompare(PyObject *v, PyObject *w, int op)
vt = (PyTupleObject *)v;
wt = (PyTupleObject *)w;
- vlen = vt->ob_size;
- wlen = wt->ob_size;
+ vlen = Py_Size(vt);
+ wlen = Py_Size(wt);
/* Note: the corresponding code for lists has an "early out" test
* here when op is EQ or NE and the lengths differ. That pays there,
@@ -622,7 +622,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
else {
PyErr_Format(PyExc_TypeError,
"tuple indices must be integers, not %.200s",
- item->ob_type->tp_name);
+ Py_Type(item)->tp_name);
return NULL;
}
}
@@ -630,7 +630,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
static PyObject *
tuple_getnewargs(PyTupleObject *v)
{
- return Py_BuildValue("(N)", tupleslice(v, 0, v->ob_size));
+ return Py_BuildValue("(N)", tupleslice(v, 0, Py_Size(v)));
}
@@ -648,8 +648,7 @@ static PyMappingMethods tuple_as_mapping = {
static PyObject *tuple_iter(PyObject *seq);
PyTypeObject PyTuple_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"tuple",
sizeof(PyTupleObject) - sizeof(PyObject *),
sizeof(PyObject *),
@@ -707,14 +706,14 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
Py_ssize_t oldsize;
v = (PyTupleObject *) *pv;
- if (v == NULL || v->ob_type != &PyTuple_Type ||
- (v->ob_size != 0 && v->ob_refcnt != 1)) {
+ if (v == NULL || Py_Type(v) != &PyTuple_Type ||
+ (Py_Size(v) != 0 && Py_Refcnt(v) != 1)) {
*pv = 0;
Py_XDECREF(v);
PyErr_BadInternalCall();
return -1;
}
- oldsize = v->ob_size;
+ oldsize = Py_Size(v);
if (oldsize == newsize)
return 0;
@@ -838,8 +837,7 @@ static PyMethodDef tupleiter_methods[] = {
};
PyTypeObject PyTupleIter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"tupleiterator", /* tp_name */
sizeof(tupleiterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1f0204d..49b877d 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -57,7 +57,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
if (!PyString_Check(value)) {
PyErr_Format(PyExc_TypeError,
"can only assign string to %s.__name__, not '%s'",
- type->tp_name, value->ob_type->tp_name);
+ type->tp_name, Py_Type(value)->tp_name);
return -1;
}
if (strlen(PyString_AS_STRING(value))
@@ -203,7 +203,7 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
if (!PyTuple_Check(value)) {
PyErr_Format(PyExc_TypeError,
"can only assign tuple to %s.__bases__, not %s",
- type->tp_name, value->ob_type->tp_name);
+ type->tp_name, Py_Type(value)->tp_name);
return -1;
}
if (PyTuple_GET_SIZE(value) == 0) {
@@ -218,7 +218,7 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
PyErr_Format(
PyExc_TypeError,
"%s.__bases__ must be tuple of old- or new-style classes, not '%s'",
- type->tp_name, ob->ob_type->tp_name);
+ type->tp_name, Py_Type(ob)->tp_name);
return -1;
}
if (PyType_Check(ob)) {
@@ -343,8 +343,8 @@ type_get_doc(PyTypeObject *type, void *context)
result = Py_None;
Py_INCREF(result);
}
- else if (result->ob_type->tp_descr_get) {
- result = result->ob_type->tp_descr_get(result, NULL,
+ else if (Py_Type(result)->tp_descr_get) {
+ result = Py_Type(result)->tp_descr_get(result, NULL,
(PyObject *)type);
}
else {
@@ -488,7 +488,7 @@ traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
Py_ssize_t i, n;
PyMemberDef *mp;
- n = type->ob_size;
+ n = Py_Size(type);
mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
for (i = 0; i < n; i++, mp++) {
if (mp->type == T_OBJECT_EX) {
@@ -512,10 +512,10 @@ subtype_traverse(PyObject *self, visitproc visit, void *arg)
/* Find the nearest base with a different tp_traverse,
and traverse slots while we're at it */
- type = self->ob_type;
+ type = Py_Type(self);
base = type;
while ((basetraverse = base->tp_traverse) == subtype_traverse) {
- if (base->ob_size) {
+ if (Py_Size(base)) {
int err = traverse_slots(base, self, visit, arg);
if (err)
return err;
@@ -547,7 +547,7 @@ clear_slots(PyTypeObject *type, PyObject *self)
Py_ssize_t i, n;
PyMemberDef *mp;
- n = type->ob_size;
+ n = Py_Size(type);
mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
for (i = 0; i < n; i++, mp++) {
if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
@@ -569,10 +569,10 @@ subtype_clear(PyObject *self)
/* Find the nearest base with a different tp_clear
and clear slots while we're at it */
- type = self->ob_type;
+ type = Py_Type(self);
base = type;
while ((baseclear = base->tp_clear) == subtype_clear) {
- if (base->ob_size)
+ if (Py_Size(base))
clear_slots(base, self);
base = base->tp_base;
assert(base);
@@ -593,7 +593,7 @@ subtype_dealloc(PyObject *self)
destructor basedealloc;
/* Extract the type; we expect it to be a heap type */
- type = self->ob_type;
+ type = Py_Type(self);
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
/* Test whether the type has GC exactly once */
@@ -615,7 +615,7 @@ subtype_dealloc(PyObject *self)
/* Find the nearest base with a different tp_dealloc */
base = type;
while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
- assert(base->ob_size == 0);
+ assert(Py_Size(base) == 0);
base = base->tp_base;
assert(base);
}
@@ -683,7 +683,7 @@ subtype_dealloc(PyObject *self)
/* Clear slots up to the nearest base with a different tp_dealloc */
base = type;
while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
- if (base->ob_size)
+ if (Py_Size(base))
clear_slots(base, self);
base = base->tp_base;
assert(base);
@@ -877,13 +877,13 @@ lookup_maybe(PyObject *self, char *attrstr, PyObject **attrobj)
if (*attrobj == NULL)
return NULL;
}
- res = _PyType_Lookup(self->ob_type, *attrobj);
+ res = _PyType_Lookup(Py_Type(self), *attrobj);
if (res != NULL) {
descrgetfunc f;
- if ((f = res->ob_type->tp_descr_get) == NULL)
+ if ((f = Py_Type(res)->tp_descr_get) == NULL)
Py_INCREF(res);
else
- res = f(res, self, (PyObject *)(self->ob_type));
+ res = f(res, self, (PyObject *)(Py_Type(self)));
}
return res;
}
@@ -1301,7 +1301,7 @@ mro_internal(PyTypeObject *type)
PyObject *mro, *result, *tuple;
int checkit = 0;
- if (type->ob_type == &PyType_Type) {
+ if (Py_Type(type) == &PyType_Type) {
result = mro_implementation(type);
}
else {
@@ -1336,7 +1336,7 @@ mro_internal(PyTypeObject *type)
else if (!PyType_Check(cls)) {
PyErr_Format(PyExc_TypeError,
"mro() returned a non-class ('%.500s')",
- cls->ob_type->tp_name);
+ Py_Type(cls)->tp_name);
Py_DECREF(tuple);
return -1;
}
@@ -1565,7 +1565,7 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
if (value != NULL && !PyDict_Check(value)) {
PyErr_Format(PyExc_TypeError,
"__dict__ must be set to a dictionary, "
- "not a '%.200s'", value->ob_type->tp_name);
+ "not a '%.200s'", Py_Type(value)->tp_name);
return -1;
}
dict = *dictptr;
@@ -1581,16 +1581,16 @@ subtype_getweakref(PyObject *obj, void *context)
PyObject **weaklistptr;
PyObject *result;
- if (obj->ob_type->tp_weaklistoffset == 0) {
+ if (Py_Type(obj)->tp_weaklistoffset == 0) {
PyErr_SetString(PyExc_AttributeError,
"This object has no __weakref__");
return NULL;
}
- assert(obj->ob_type->tp_weaklistoffset > 0);
- assert(obj->ob_type->tp_weaklistoffset + sizeof(PyObject *) <=
- (size_t)(obj->ob_type->tp_basicsize));
+ assert(Py_Type(obj)->tp_weaklistoffset > 0);
+ assert(Py_Type(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
+ (size_t)(Py_Type(obj)->tp_basicsize));
weaklistptr = (PyObject **)
- ((char *)obj + obj->ob_type->tp_weaklistoffset);
+ ((char *)obj + Py_Type(obj)->tp_weaklistoffset);
if (*weaklistptr == NULL)
result = Py_None;
else
@@ -1630,7 +1630,7 @@ valid_identifier(PyObject *s)
if (!PyString_Check(s)) {
PyErr_Format(PyExc_TypeError,
"__slots__ items must be strings, not '%.200s'",
- s->ob_type->tp_name);
+ Py_Type(s)->tp_name);
return 0;
}
p = (unsigned char *) PyString_AS_STRING(s);
@@ -1740,8 +1740,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
PyObject *x = PyTuple_GET_ITEM(args, 0);
- Py_INCREF(x->ob_type);
- return (PyObject *) x->ob_type;
+ Py_INCREF(Py_Type(x));
+ return (PyObject *) Py_Type(x);
}
/* SF bug 475327 -- if that didn't trigger, we need 3
@@ -2176,7 +2176,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
static PyObject *
type_getattro(PyTypeObject *type, PyObject *name)
{
- PyTypeObject *metatype = type->ob_type;
+ PyTypeObject *metatype = Py_Type(type);
PyObject *meta_attribute, *attribute;
descrgetfunc meta_get;
@@ -2193,7 +2193,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
meta_attribute = _PyType_Lookup(metatype, name);
if (meta_attribute != NULL) {
- meta_get = meta_attribute->ob_type->tp_descr_get;
+ meta_get = Py_Type(meta_attribute)->tp_descr_get;
if (meta_get != NULL && PyDescr_IsData(meta_attribute)) {
/* Data descriptors implement tp_descr_set to intercept
@@ -2211,7 +2211,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
- descrgetfunc local_get = attribute->ob_type->tp_descr_get;
+ descrgetfunc local_get = Py_Type(attribute)->tp_descr_get;
Py_XDECREF(meta_attribute);
@@ -2289,7 +2289,7 @@ type_dealloc(PyTypeObject *type)
PyObject_Free((char *)type->tp_doc);
Py_XDECREF(et->ht_name);
Py_XDECREF(et->ht_slots);
- type->ob_type->tp_free((PyObject *)type);
+ Py_Type(type)->tp_free((PyObject *)type);
}
static PyObject *
@@ -2397,8 +2397,7 @@ type_is_gc(PyTypeObject *type)
}
PyTypeObject PyType_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"type", /* tp_name */
sizeof(PyHeapTypeObject), /* tp_basicsize */
sizeof(PyMemberDef), /* tp_itemsize */
@@ -2500,7 +2499,7 @@ object_init(PyObject *self, PyObject *args, PyObject *kwds)
{
int err = 0;
if (excess_args(args, kwds)) {
- PyTypeObject *type = self->ob_type;
+ PyTypeObject *type = Py_Type(self);
if (type->tp_init != object_init &&
type->tp_new != object_new)
{
@@ -2547,7 +2546,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
object_dealloc(PyObject *self)
{
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static PyObject *
@@ -2556,7 +2555,7 @@ object_repr(PyObject *self)
PyTypeObject *type;
PyObject *mod, *name, *rtn;
- type = self->ob_type;
+ type = Py_Type(self);
mod = type_module(type, NULL);
if (mod == NULL)
PyErr_Clear();
@@ -2585,7 +2584,7 @@ object_str(PyObject *self)
{
unaryfunc f;
- f = self->ob_type->tp_repr;
+ f = Py_Type(self)->tp_repr;
if (f == NULL)
f = object_repr;
return f(self);
@@ -2600,8 +2599,8 @@ object_hash(PyObject *self)
static PyObject *
object_get_class(PyObject *self, void *closure)
{
- Py_INCREF(self->ob_type);
- return (PyObject *)(self->ob_type);
+ Py_INCREF(Py_Type(self));
+ return (PyObject *)(Py_Type(self));
}
static int
@@ -2686,7 +2685,7 @@ compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, char* attr)
static int
object_set_class(PyObject *self, PyObject *value, void *closure)
{
- PyTypeObject *oldto = self->ob_type;
+ PyTypeObject *oldto = Py_Type(self);
PyTypeObject *newto;
if (value == NULL) {
@@ -2697,7 +2696,7 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
if (!PyType_Check(value)) {
PyErr_Format(PyExc_TypeError,
"__class__ must be set to new-style class, not '%s' object",
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return -1;
}
newto = (PyTypeObject *)value;
@@ -2710,7 +2709,7 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
}
if (compatible_for_assignment(newto, oldto, "__class__")) {
Py_INCREF(newto);
- self->ob_type = newto;
+ Py_Type(self) = newto;
Py_DECREF(oldto);
return 0;
}
@@ -2806,7 +2805,7 @@ reduce_2(PyObject *obj)
if (args != NULL && !PyTuple_Check(args)) {
PyErr_Format(PyExc_TypeError,
"__getnewargs__ should return a tuple, "
- "not '%.200s'", args->ob_type->tp_name);
+ "not '%.200s'", Py_Type(args)->tp_name);
goto end;
}
}
@@ -3018,8 +3017,7 @@ static PyMethodDef object_methods[] = {
PyTypeObject PyBaseObject_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"object", /* tp_name */
sizeof(PyObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3461,8 +3459,8 @@ PyType_Ready(PyTypeObject *type)
NULL when type is &PyBaseObject_Type, and we know its ob_type is
not NULL (it's initialized to &PyType_Type). But coverity doesn't
know that. */
- if (type->ob_type == NULL && base != NULL)
- type->ob_type = base->ob_type;
+ if (Py_Type(type) == NULL && base != NULL)
+ Py_Type(type) = Py_Type(base);
/* Initialize tp_bases */
bases = type->tp_bases;
@@ -3822,7 +3820,7 @@ getindex(PyObject *self, PyObject *arg)
if (i == -1 && PyErr_Occurred())
return -1;
if (i < 0) {
- PySequenceMethods *sq = self->ob_type->tp_as_sequence;
+ PySequenceMethods *sq = Py_Type(self)->tp_as_sequence;
if (sq && sq->sq_length) {
Py_ssize_t n = (*sq->sq_length)(self);
if (n < 0)
@@ -3998,14 +3996,14 @@ wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped)
if (!check_num_args(args, 1))
return NULL;
other = PyTuple_GET_ITEM(args, 0);
- if (other->ob_type->tp_compare != func &&
- !PyType_IsSubtype(other->ob_type, self->ob_type)) {
+ if (Py_Type(other)->tp_compare != func &&
+ !PyType_IsSubtype(Py_Type(other), Py_Type(self))) {
PyErr_Format(
PyExc_TypeError,
"%s.__cmp__(x,y) requires y to be a '%s', not a '%s'",
- self->ob_type->tp_name,
- self->ob_type->tp_name,
- other->ob_type->tp_name);
+ Py_Type(self)->tp_name,
+ Py_Type(self)->tp_name,
+ Py_Type(other)->tp_name);
return NULL;
}
res = (*func)(self, other);
@@ -4019,7 +4017,7 @@ wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped)
static int
hackcheck(PyObject *self, setattrofunc func, char *what)
{
- PyTypeObject *type = self->ob_type;
+ PyTypeObject *type = Py_Type(self);
while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE)
type = type->tp_base;
/* If type is NULL now, this is a really weird type.
@@ -4219,7 +4217,7 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
PyErr_Format(PyExc_TypeError,
"%s.__new__(X): X is not a type object (%s)",
type->tp_name,
- arg0->ob_type->tp_name);
+ Py_Type(arg0)->tp_name);
return NULL;
}
subtype = (PyTypeObject *)arg0;
@@ -4310,14 +4308,14 @@ method_is_overloaded(PyObject *left, PyObject *right, char *name)
PyObject *a, *b;
int ok;
- b = PyObject_GetAttrString((PyObject *)(right->ob_type), name);
+ b = PyObject_GetAttrString((PyObject *)(Py_Type(right)), name);
if (b == NULL) {
PyErr_Clear();
/* If right doesn't have it, it's not overloaded */
return 0;
}
- a = PyObject_GetAttrString((PyObject *)(left->ob_type), name);
+ a = PyObject_GetAttrString((PyObject *)(Py_Type(left)), name);
if (a == NULL) {
PyErr_Clear();
Py_DECREF(b);
@@ -4342,14 +4340,14 @@ static PyObject * \
FUNCNAME(PyObject *self, PyObject *other) \
{ \
static PyObject *cache_str, *rcache_str; \
- int do_other = self->ob_type != other->ob_type && \
- other->ob_type->tp_as_number != NULL && \
- other->ob_type->tp_as_number->SLOTNAME == TESTFUNC; \
- if (self->ob_type->tp_as_number != NULL && \
- self->ob_type->tp_as_number->SLOTNAME == TESTFUNC) { \
+ int do_other = Py_Type(self) != Py_Type(other) && \
+ Py_Type(other)->tp_as_number != NULL && \
+ Py_Type(other)->tp_as_number->SLOTNAME == TESTFUNC; \
+ if (Py_Type(self)->tp_as_number != NULL && \
+ Py_Type(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
PyObject *r; \
if (do_other && \
- PyType_IsSubtype(other->ob_type, self->ob_type) && \
+ PyType_IsSubtype(Py_Type(other), Py_Type(self)) && \
method_is_overloaded(self, other, ROPSTR)) { \
r = call_maybe( \
other, ROPSTR, &rcache_str, "(O)", self); \
@@ -4361,7 +4359,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
r = call_maybe( \
self, OPSTR, &cache_str, "(O)", other); \
if (r != Py_NotImplemented || \
- other->ob_type == self->ob_type) \
+ Py_Type(other) == Py_Type(self)) \
return r; \
Py_DECREF(r); \
} \
@@ -4419,12 +4417,12 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
if (getitem_str == NULL)
return NULL;
}
- func = _PyType_Lookup(self->ob_type, getitem_str);
+ func = _PyType_Lookup(Py_Type(self), getitem_str);
if (func != NULL) {
- if ((f = func->ob_type->tp_descr_get) == NULL)
+ if ((f = Py_Type(func)->tp_descr_get) == NULL)
Py_INCREF(func);
else {
- func = f(func, self, (PyObject *)(self->ob_type));
+ func = f(func, self, (PyObject *)(Py_Type(self)));
if (func == NULL) {
return NULL;
}
@@ -4563,8 +4561,8 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
/* Three-arg power doesn't use __rpow__. But ternary_op
can call this when the second argument's type uses
slot_nb_power, so check before calling self.__pow__. */
- if (self->ob_type->tp_as_number != NULL &&
- self->ob_type->tp_as_number->nb_power == slot_nb_power) {
+ if (Py_Type(self)->tp_as_number != NULL &&
+ Py_Type(self)->tp_as_number->nb_power == slot_nb_power) {
return call_method(self, "__pow__", &pow_str,
"(OO)", other, modulus);
}
@@ -4754,12 +4752,12 @@ _PyObject_SlotCompare(PyObject *self, PyObject *other)
{
int c;
- if (self->ob_type->tp_compare == _PyObject_SlotCompare) {
+ if (Py_Type(self)->tp_compare == _PyObject_SlotCompare) {
c = half_compare(self, other);
if (c <= 1)
return c;
}
- if (other->ob_type->tp_compare == _PyObject_SlotCompare) {
+ if (Py_Type(other)->tp_compare == _PyObject_SlotCompare) {
c = half_compare(other, self);
if (c < -1)
return -2;
@@ -4784,7 +4782,7 @@ slot_tp_repr(PyObject *self)
}
PyErr_Clear();
return PyString_FromFormat("<%s object at %p>",
- self->ob_type->tp_name, self);
+ Py_Type(self)->tp_name, self);
}
static PyObject *
@@ -4893,7 +4891,7 @@ slot_tp_getattro(PyObject *self, PyObject *name)
static PyObject *
slot_tp_getattr_hook(PyObject *self, PyObject *name)
{
- PyTypeObject *tp = self->ob_type;
+ PyTypeObject *tp = Py_Type(self);
PyObject *getattr, *getattribute, *res;
static PyObject *getattribute_str = NULL;
static PyObject *getattr_str = NULL;
@@ -4917,7 +4915,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
}
getattribute = _PyType_Lookup(tp, getattribute_str);
if (getattribute == NULL ||
- (getattribute->ob_type == &PyWrapperDescr_Type &&
+ (Py_Type(getattribute) == &PyWrapperDescr_Type &&
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
(void *)PyObject_GenericGetAttr))
res = PyObject_GenericGetAttr(self, name);
@@ -4986,13 +4984,13 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
{
PyObject *res;
- if (self->ob_type->tp_richcompare == slot_tp_richcompare) {
+ if (Py_Type(self)->tp_richcompare == slot_tp_richcompare) {
res = half_richcompare(self, other, op);
if (res != Py_NotImplemented)
return res;
Py_DECREF(res);
}
- if (other->ob_type->tp_richcompare == slot_tp_richcompare) {
+ if (Py_Type(other)->tp_richcompare == slot_tp_richcompare) {
res = half_richcompare(other, self, _Py_SwappedOp[op]);
if (res != Py_NotImplemented) {
return res;
@@ -5025,7 +5023,7 @@ slot_tp_iter(PyObject *self)
if (func == NULL) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object is not iterable",
- self->ob_type->tp_name);
+ Py_Type(self)->tp_name);
return NULL;
}
Py_DECREF(func);
@@ -5042,7 +5040,7 @@ slot_tp_iternext(PyObject *self)
static PyObject *
slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
- PyTypeObject *tp = self->ob_type;
+ PyTypeObject *tp = Py_Type(self);
PyObject *get;
static PyObject *get_str = NULL;
@@ -5100,7 +5098,7 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
if (res != Py_None) {
PyErr_Format(PyExc_TypeError,
"__init__() should return None, not '%.200s'",
- res->ob_type->tp_name);
+ Py_Type(res)->tp_name);
Py_DECREF(res);
return -1;
}
@@ -5185,7 +5183,7 @@ slot_tp_del(PyObject *self)
_Py_NewReference(self);
self->ob_refcnt = refcnt;
}
- assert(!PyType_IS_GC(self->ob_type) ||
+ assert(!PyType_IS_GC(Py_Type(self)) ||
_Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
/* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
* we need to undo that. */
@@ -5197,8 +5195,8 @@ slot_tp_del(PyObject *self)
* undone.
*/
#ifdef COUNT_ALLOCS
- --self->ob_type->tp_frees;
- --self->ob_type->tp_allocs;
+ --Py_Type(self)->tp_frees;
+ --Py_Type(self)->tp_allocs;
#endif
}
@@ -5560,7 +5558,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
descr = _PyType_Lookup(type, p->name_strobj);
if (descr == NULL)
continue;
- if (descr->ob_type == &PyWrapperDescr_Type) {
+ if (Py_Type(descr) == &PyWrapperDescr_Type) {
void **tptr = resolve_slotdups(type, p->name_strobj);
if (tptr == NULL || tptr == ptr)
generic = p->function;
@@ -5575,7 +5573,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
use_generic = 1;
}
}
- else if (descr->ob_type == &PyCFunction_Type &&
+ else if (Py_Type(descr) == &PyCFunction_Type &&
PyCFunction_GET_FUNCTION(descr) ==
(PyCFunction)tp_new_wrapper &&
strcmp(p->name, "__new__") == 0)
@@ -5846,7 +5844,7 @@ super_dealloc(PyObject *self)
Py_XDECREF(su->obj);
Py_XDECREF(su->type);
Py_XDECREF(su->obj_type);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
static PyObject *
@@ -5911,7 +5909,7 @@ super_getattro(PyObject *self, PyObject *name)
res = PyDict_GetItem(dict, name);
if (res != NULL) {
Py_INCREF(res);
- f = res->ob_type->tp_descr_get;
+ f = Py_Type(res)->tp_descr_get;
if (f != NULL) {
tmp = f(res,
/* Only pass 'obj' param if
@@ -5947,7 +5945,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
the normal case; the return value is obj.__class__.
But... when obj is an instance, we want to allow for the case where
- obj->ob_type is not a subclass of type, but obj.__class__ is!
+ Py_Type(obj) is not a subclass of type, but obj.__class__ is!
This will allow using super() with a proxy for obj.
*/
@@ -5958,9 +5956,9 @@ supercheck(PyTypeObject *type, PyObject *obj)
}
/* Normal case */
- if (PyType_IsSubtype(obj->ob_type, type)) {
- Py_INCREF(obj->ob_type);
- return obj->ob_type;
+ if (PyType_IsSubtype(Py_Type(obj), type)) {
+ Py_INCREF(Py_Type(obj));
+ return Py_Type(obj);
}
else {
/* Try the slow way */
@@ -5977,7 +5975,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
if (class_attr != NULL &&
PyType_Check(class_attr) &&
- (PyTypeObject *)class_attr != obj->ob_type)
+ (PyTypeObject *)class_attr != Py_Type(obj))
{
int ok = PyType_IsSubtype(
(PyTypeObject *)class_attr, type);
@@ -6008,10 +6006,10 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
Py_INCREF(self);
return self;
}
- if (su->ob_type != &PySuper_Type)
+ if (Py_Type(su) != &PySuper_Type)
/* If su is an instance of a (strict) subclass of super,
call its type */
- return PyObject_CallFunctionObjArgs((PyObject *)su->ob_type,
+ return PyObject_CallFunctionObjArgs((PyObject *)Py_Type(su),
su->type, obj, NULL);
else {
/* Inline the common case */
@@ -6080,8 +6078,7 @@ super_traverse(PyObject *self, visitproc visit, void *arg)
}
PyTypeObject PySuper_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"super", /* tp_name */
sizeof(superobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 85804f1..1a532c9 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -312,7 +312,7 @@ void unicode_dealloc(register PyUnicodeObject *unicode)
else {
PyMem_DEL(unicode->str);
Py_XDECREF(unicode->defenc);
- unicode->ob_type->tp_free((PyObject *)unicode);
+ Py_Type(unicode)->tp_free((PyObject *)unicode);
}
}
@@ -326,7 +326,7 @@ int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
return -1;
}
v = (PyUnicodeObject *)*unicode;
- if (v == NULL || !PyUnicode_Check(v) || v->ob_refcnt != 1 || length < 0) {
+ if (v == NULL || !PyUnicode_Check(v) || Py_Refcnt(v) != 1 || length < 0) {
PyErr_BadInternalCall();
return -1;
}
@@ -554,7 +554,7 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
PyErr_Format(PyExc_TypeError,
"coercing to Unicode: need string or buffer, "
"%.80s found",
- obj->ob_type->tp_name);
+ Py_Type(obj)->tp_name);
goto onError;
}
@@ -604,7 +604,7 @@ PyObject *PyUnicode_Decode(const char *s,
if (!PyUnicode_Check(unicode)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return an unicode object (type=%.400s)",
- unicode->ob_type->tp_name);
+ Py_Type(unicode)->tp_name);
Py_DECREF(unicode);
goto onError;
}
@@ -714,7 +714,7 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode,
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
goto onError;
}
@@ -3242,8 +3242,7 @@ encoding_map_dealloc(PyObject* o)
}
static PyTypeObject EncodingMapType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"EncodingMap", /*tp_name*/
sizeof(struct encoding_map), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -3502,7 +3501,7 @@ charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping,
char *outstart;
Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
- if (mapping->ob_type == &EncodingMapType) {
+ if (Py_Type(mapping) == &EncodingMapType) {
int res = encoding_map_lookup(c, mapping);
Py_ssize_t requiredsize = *outpos+1;
if (res == -1)
@@ -3574,7 +3573,7 @@ int charmap_encoding_error(
/* find all unencodable characters */
while (collendpos < size) {
PyObject *rep;
- if (mapping->ob_type == &EncodingMapType) {
+ if (Py_Type(mapping) == &EncodingMapType) {
int res = encoding_map_lookup(p[collendpos], mapping);
if (res != -1)
break;
@@ -4632,7 +4631,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected string or Unicode,"
" %.80s found",
- i, item->ob_type->tp_name);
+ i, Py_Type(item)->tp_name);
goto onError;
}
item = PyUnicode_FromObject(item);
@@ -5632,7 +5631,7 @@ unicode_encode(PyUnicodeObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"encoder did not return a string/unicode object "
"(type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@@ -5668,7 +5667,7 @@ unicode_decode(PyUnicodeObject *self, PyObject *args)
PyErr_Format(PyExc_TypeError,
"decoder did not return a string/unicode object "
"(type=%.400s)",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
Py_DECREF(v);
return NULL;
}
@@ -7499,7 +7498,7 @@ PyObject *PyUnicode_Format(PyObject *format,
arglen = -1;
argidx = -2;
}
- if (args->ob_type->tp_as_mapping && !PyTuple_Check(args) &&
+ if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
@@ -7963,8 +7962,7 @@ encoding defaults to the current default string encoding.\n\
errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.");
PyTypeObject PyUnicode_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"unicode", /* tp_name */
sizeof(PyUnicodeObject), /* tp_size */
0, /* tp_itemsize */
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index a404f29..d26d5d1 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -105,7 +105,7 @@ weakref_dealloc(PyObject *self)
{
PyObject_GC_UnTrack(self);
clear_weakref((PyWeakReference *) self);
- self->ob_type->tp_free(self);
+ Py_Type(self)->tp_free(self);
}
@@ -172,7 +172,7 @@ weakref_repr(PyWeakReference *self)
name ? "<weakref at %p; to '%.50s' at %p (%s)>"
: "<weakref at %p; to '%.50s' at %p>",
self,
- PyWeakref_GET_OBJECT(self)->ob_type->tp_name,
+ Py_Type(PyWeakref_GET_OBJECT(self))->tp_name,
PyWeakref_GET_OBJECT(self),
name);
Py_XDECREF(nameobj);
@@ -274,10 +274,10 @@ weakref___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyWeakReference *ref, *proxy;
PyWeakReference **list;
- if (!PyType_SUPPORTS_WEAKREFS(ob->ob_type)) {
+ if (!PyType_SUPPORTS_WEAKREFS(Py_Type(ob))) {
PyErr_Format(PyExc_TypeError,
"cannot create weak reference to '%s' object",
- ob->ob_type->tp_name);
+ Py_Type(ob)->tp_name);
return NULL;
}
if (callback == Py_None)
@@ -332,8 +332,7 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs)
PyTypeObject
_PyWeakref_RefType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"weakref",
sizeof(PyWeakReference),
0,
@@ -447,7 +446,7 @@ proxy_repr(PyWeakReference *proxy)
char buf[160];
PyOS_snprintf(buf, sizeof(buf),
"<weakproxy at %p to %.100s at %p>", proxy,
- PyWeakref_GET_OBJECT(proxy)->ob_type->tp_name,
+ Py_Type(PyWeakref_GET_OBJECT(proxy))->tp_name,
PyWeakref_GET_OBJECT(proxy));
return PyString_FromString(buf);
}
@@ -646,8 +645,7 @@ static PyMappingMethods proxy_as_mapping = {
PyTypeObject
_PyWeakref_ProxyType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"weakproxy",
sizeof(PyWeakReference),
0,
@@ -681,8 +679,7 @@ _PyWeakref_ProxyType = {
PyTypeObject
_PyWeakref_CallableProxyType = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"weakcallableproxy",
sizeof(PyWeakReference),
0,
@@ -722,10 +719,10 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
PyWeakReference **list;
PyWeakReference *ref, *proxy;
- if (!PyType_SUPPORTS_WEAKREFS(ob->ob_type)) {
+ if (!PyType_SUPPORTS_WEAKREFS(Py_Type(ob))) {
PyErr_Format(PyExc_TypeError,
"cannot create weak reference to '%s' object",
- ob->ob_type->tp_name);
+ Py_Type(ob)->tp_name);
return NULL;
}
list = GET_WEAKREFS_LISTPTR(ob);
@@ -781,10 +778,10 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
PyWeakReference **list;
PyWeakReference *ref, *proxy;
- if (!PyType_SUPPORTS_WEAKREFS(ob->ob_type)) {
+ if (!PyType_SUPPORTS_WEAKREFS(Py_Type(ob))) {
PyErr_Format(PyExc_TypeError,
"cannot create weak reference to '%s' object",
- ob->ob_type->tp_name);
+ Py_Type(ob)->tp_name);
return NULL;
}
list = GET_WEAKREFS_LISTPTR(ob);
@@ -807,9 +804,9 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
PyWeakReference *prev;
if (PyCallable_Check(ob))
- result->ob_type = &_PyWeakref_CallableProxyType;
+ Py_Type(result) = &_PyWeakref_CallableProxyType;
else
- result->ob_type = &_PyWeakref_ProxyType;
+ Py_Type(result) = &_PyWeakref_ProxyType;
get_basic_refs(*list, &ref, &proxy);
if (callback == NULL) {
if (proxy != NULL) {
@@ -874,7 +871,7 @@ PyObject_ClearWeakRefs(PyObject *object)
PyWeakReference **list;
if (object == NULL
- || !PyType_SUPPORTS_WEAKREFS(object->ob_type)
+ || !PyType_SUPPORTS_WEAKREFS(Py_Type(object))
|| object->ob_refcnt != 0) {
PyErr_BadInternalCall();
return;
diff --git a/PC/_msi.c b/PC/_msi.c
index f4af92a..7d60d08 100644
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -417,8 +417,7 @@ static PyMethodDef record_methods[] = {
};
static PyTypeObject record_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_msi.Record", /*tp_name*/
sizeof(msiobj), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -584,8 +583,7 @@ static PyMethodDef summary_methods[] = {
};
static PyTypeObject summary_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_msi.SummaryInformation", /*tp_name*/
sizeof(msiobj), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -733,8 +731,7 @@ static PyMethodDef view_methods[] = {
};
static PyTypeObject msiview_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_msi.View", /*tp_name*/
sizeof(msiobj), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -851,8 +848,7 @@ static PyMethodDef db_methods[] = {
};
static PyTypeObject msidb_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_msi.Database", /*tp_name*/
sizeof(msiobj), /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/PC/_winreg.c b/PC/_winreg.c
index 920e1d1..9ddbb23 100644
--- a/PC/_winreg.c
+++ b/PC/_winreg.c
@@ -460,8 +460,7 @@ static PyObject *PyHKEY_getattr(PyObject *self, const char *name);
/* The type itself */
PyTypeObject PyHKEY_Type =
{
- PyObject_HEAD_INIT(0) /* fill in type at module init */
- 0,
+ PyVarObject_HEAD_INIT(0, 0) /* fill in type at module init */
"PyHKEY",
sizeof(PyHKEYObject),
0,
diff --git a/Python/ceval.c b/Python/ceval.c
index c547c37..8ed65a4 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3655,7 +3655,7 @@ fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)
}
if (argdefs != NULL) {
d = &PyTuple_GET_ITEM(argdefs, 0);
- nd = ((PyTupleObject *)argdefs)->ob_size;
+ nd = Py_Size(argdefs);
}
return PyEval_EvalCodeEx(co, globals,
(PyObject *)NULL, (*pp_stack)-n, na,
diff --git a/Python/import.c b/Python/import.c
index 038c856..678a30b 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3030,8 +3030,7 @@ static PyMethodDef NullImporter_methods[] = {
static PyTypeObject NullImporterType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"imp.NullImporter", /*tp_name*/
sizeof(NullImporter), /*tp_basicsize*/
0, /*tp_itemsize*/
diff --git a/Python/symtable.c b/Python/symtable.c
index 05d504c..1e1279a 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -117,8 +117,7 @@ static PyMemberDef ste_memberlist[] = {
};
PyTypeObject PySTEntry_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"symtable entry",
sizeof(PySTEntryObject),
0,
diff --git a/Python/traceback.c b/Python/traceback.c
index 4ddee2c..d6f68ab 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -52,8 +52,7 @@ tb_clear(PyTracebackObject *tb)
}
PyTypeObject PyTraceBack_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"traceback",
sizeof(PyTracebackObject),
0,