consistently use Py_TYPE, Py_REFCNT, and correct initializer macros (#3563)
This no-op change makes 2.7 more consistent with 3.x to ease comparison and backports.
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 17e7679..8439081 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -54,7 +54,7 @@
PyAPI_DATA(PyTypeObject) PyFrame_Type;
-#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
+#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
#define PyFrame_IsRestricted(f) \
((f)->f_builtins != (f)->f_tstate->interp->builtins)
diff --git a/Include/intobject.h b/Include/intobject.h
index 252eea9..59d0616 100644
--- a/Include/intobject.h
+++ b/Include/intobject.h
@@ -28,8 +28,8 @@
PyAPI_DATA(PyTypeObject) PyInt_Type;
#define PyInt_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
-#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
+ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS)
+#define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
#ifdef Py_USING_UNICODE
diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h
index b21fe92..12b56c4 100644
--- a/Modules/_ctypes/ctypes.h
+++ b/Modules/_ctypes/ctypes.h
@@ -108,7 +108,7 @@
ffi_type *atypes[1];
} CThunkObject;
extern PyTypeObject PyCThunk_Type;
-#define CThunk_CheckExact(v) ((v)->ob_type == &PyCThunk_Type)
+#define CThunk_CheckExact(v) (Py_TYPE(v) == &PyCThunk_Type)
typedef struct {
/* First part identical to tagCDataObject */
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 929616f..b52402f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1661,8 +1661,8 @@
};
statichere PyTypeObject Element_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "Element", sizeof(ElementObject), 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "Element", sizeof(ElementObject), 0,
/* methods */
(destructor)element_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -2031,8 +2031,8 @@
}
statichere PyTypeObject TreeBuilder_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "TreeBuilder", sizeof(TreeBuilderObject), 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "TreeBuilder", sizeof(TreeBuilderObject), 0,
/* methods */
(destructor)treebuilder_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -2897,8 +2897,8 @@
}
statichere PyTypeObject XMLParser_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "XMLParser", sizeof(XMLParserObject), 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "XMLParser", sizeof(XMLParserObject), 0,
/* methods */
(destructor)xmlparser_dealloc, /* tp_dealloc */
0, /* tp_print */
diff --git a/Modules/_json.c b/Modules/_json.c
index be1e079..39ec467 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1767,8 +1767,7 @@
static
PyTypeObject PyScannerType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* tp_internal */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_json.Scanner", /* tp_name */
sizeof(PyScannerObject), /* tp_basicsize */
0, /* tp_itemsize */
@@ -2344,8 +2343,7 @@
static
PyTypeObject PyEncoderType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* tp_internal */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_json.Encoder", /* tp_name */
sizeof(PyEncoderObject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index 049c94d..6090c7d 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -817,8 +817,7 @@
");
statichere PyTypeObject PyProfiler_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"_lsprof.Profiler", /* tp_name */
sizeof(ProfilerObject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 237d6e4..439542e 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -293,7 +293,7 @@
Py_XDECREF(self->statements);
Py_XDECREF(self->cursors);
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
/*
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index db36004..ad607d9 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -135,7 +135,7 @@
PyObject_ClearWeakRefs((PyObject*)self);
}
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
PyObject* _pysqlite_get_converter(PyObject* key)
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 6fd3aff..94b3d50 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -2712,8 +2712,8 @@
};
statichere PyTypeObject Pattern_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "_" SRE_MODULE ".SRE_Pattern",
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "_" SRE_MODULE ".SRE_Pattern",
sizeof(PatternObject), sizeof(SRE_CODE),
(destructor)pattern_dealloc, /*tp_dealloc*/
0, /* tp_print */
@@ -3952,8 +3952,8 @@
};
statichere PyTypeObject Scanner_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, "_" SRE_MODULE ".SRE_Scanner",
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "_" SRE_MODULE ".SRE_Scanner",
sizeof(ScannerObject), 0,
(destructor)scanner_dealloc, /*tp_dealloc*/
0, /* tp_print */
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index ecc473c..7691b51 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -187,8 +187,7 @@
* PyType_Ready if it hasn't already been called
*/
static PyTypeObject _HashInheritanceTester_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* Number of items for varobject */
+ PyVarObject_HEAD_INIT(NULL, 0)
"hashinheritancetester", /* Name of this type */
sizeof(PyObject), /* Basic object size */
0, /* Item size for varobject */
@@ -315,8 +314,7 @@
};
static PyTypeObject _MemoryViewTester_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* Number of items for varobject */
+ PyVarObject_HEAD_INIT(NULL, 0)
"memoryviewtester", /* Name of this type */
sizeof(PyObject), /* Basic object size */
0, /* Item size for varobject */
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index f6f597a..5bd3a42 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1292,9 +1292,9 @@
PyErr_SetString(PyExc_TypeError, "arg must be open file");
return NULL;
}
- if (self->ob_size > 0) {
+ if (Py_SIZE(self) > 0) {
if (fwrite(self->ob_item, self->ob_descr->itemsize,
- self->ob_size, fp) != (size_t)self->ob_size) {
+ Py_SIZE(self), fp) != (size_t)Py_SIZE(self)) {
PyErr_SetFromErrno(PyExc_IOError);
clearerr(fp);
return NULL;
@@ -1348,7 +1348,7 @@
if ((*self->ob_descr->setitem)(self,
Py_SIZE(self) - n + i, v) != 0) {
Py_SIZE(self) -= n;
- if (itemsize && (self->ob_size > PY_SSIZE_T_MAX / itemsize)) {
+ if (itemsize && (Py_SIZE(self) > PY_SSIZE_T_MAX / itemsize)) {
return PyErr_NoMemory();
}
PyMem_RESIZE(item, char,
@@ -1444,7 +1444,7 @@
static PyObject *
array_tostring(arrayobject *self, PyObject *unused)
{
- if (self->ob_size <= PY_SSIZE_T_MAX / self->ob_descr->itemsize) {
+ if (Py_SIZE(self) <= PY_SSIZE_T_MAX / self->ob_descr->itemsize) {
return PyString_FromStringAndSize(self->ob_item,
Py_SIZE(self) * self->ob_descr->itemsize);
} else {
@@ -2289,8 +2289,8 @@
{
PyObject *m;
- Arraytype.ob_type = &PyType_Type;
- PyArrayIter_Type.ob_type = &PyType_Type;
+ Py_TYPE(&Arraytype) = &PyType_Type;
+ Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
m = Py_InitModule3("array", a_methods, module_doc);
if (m == NULL)
return;
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 4573637..34b8ed4 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -3039,8 +3039,7 @@
PyDoc_STR("Abstract base class for time zone info objects.");
statichere PyTypeObject PyDateTime_TZInfoType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.tzinfo", /* tp_name */
sizeof(PyDateTime_TZInfo), /* tp_basicsize */
0, /* tp_itemsize */
@@ -3564,8 +3563,7 @@
};
statichere PyTypeObject PyDateTime_TimeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.time", /* tp_name */
sizeof(PyDateTime_Time), /* tp_basicsize */
0, /* tp_itemsize */
@@ -4692,8 +4690,7 @@
};
statichere PyTypeObject PyDateTime_DateTimeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"datetime.datetime", /* tp_name */
sizeof(PyDateTime_DateTime), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c
index 65857bf..d2297f3 100644
--- a/Objects/bufferobject.c
+++ b/Objects/bufferobject.c
@@ -34,7 +34,7 @@
else {
Py_ssize_t count, offset;
readbufferproc proc = 0;
- PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
+ PyBufferProcs *bp = Py_TYPE(self->b_base)->tp_as_buffer;
if ((*bp->bf_getsegcount)(self->b_base, NULL) != 1) {
PyErr_SetString(PyExc_TypeError,
"single-segment buffer object expected");
@@ -47,7 +47,7 @@
(buffer_type == ANY_BUFFER))
proc = (readbufferproc)bp->bf_getwritebuffer;
else if (buffer_type == CHAR_BUFFER) {
- if (!PyType_HasFeature(self->ob_type,
+ if (!PyType_HasFeature(Py_TYPE(self),
Py_TPFLAGS_HAVE_GETCHARBUFFER)) {
PyErr_SetString(PyExc_TypeError,
"Py_TPFLAGS_HAVE_GETCHARBUFFER needed");
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 738e613..5b64578 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -88,9 +88,9 @@
base = PyTuple_GET_ITEM(bases, i);
if (!PyClass_Check(base)) {
if (PyCallable_Check(
- (PyObject *) base->ob_type))
+ (PyObject *) Py_TYPE(base)))
return PyObject_CallFunctionObjArgs(
- (PyObject *) base->ob_type,
+ (PyObject *) Py_TYPE(base),
name, bases, dict, NULL);
PyErr_SetString(PyExc_TypeError,
"PyClass_New: base must be a class");
@@ -265,7 +265,7 @@
PyString_AS_STRING(op->cl_name), sname);
return NULL;
}
- f = TP_DESCR_GET(v->ob_type);
+ f = TP_DESCR_GET(Py_TYPE(v));
if (f == NULL)
Py_INCREF(v);
else
@@ -442,8 +442,7 @@
}
PyTypeObject PyClass_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"classobj",
sizeof(PyClassObject),
0,
@@ -639,9 +638,9 @@
PyObject_ClearWeakRefs((PyObject *) inst);
/* Temporarily resurrect the object. */
- assert(inst->ob_type == &PyInstance_Type);
- assert(inst->ob_refcnt == 0);
- inst->ob_refcnt = 1;
+ assert(Py_TYPE(inst) == &PyInstance_Type);
+ assert(Py_REFCNT(inst) == 0);
+ Py_REFCNT(inst) = 1;
/* Save the current exception, if any. */
PyErr_Fetch(&error_type, &error_value, &error_traceback);
@@ -665,8 +664,8 @@
/* Undo the temporary resurrection; can't use DECREF here, it would
* cause a recursive call.
*/
- assert(inst->ob_refcnt > 0);
- if (--inst->ob_refcnt == 0) {
+ assert(Py_REFCNT(inst) > 0);
+ if (--Py_REFCNT(inst) == 0) {
/* New weakrefs could be created during the finalizer call.
If this occurs, clear them out without calling their
@@ -682,12 +681,12 @@
PyObject_GC_Del(inst);
}
else {
- Py_ssize_t refcnt = inst->ob_refcnt;
+ Py_ssize_t refcnt = Py_REFCNT(inst);
/* __del__ resurrected it! Make it look like the original
* Py_DECREF never happened.
*/
_Py_NewReference((PyObject *)inst);
- inst->ob_refcnt = refcnt;
+ Py_REFCNT(inst) = refcnt;
_PyObject_GC_TRACK(inst);
/* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
* we need to undo that. */
@@ -699,8 +698,8 @@
* undone.
*/
#ifdef COUNT_ALLOCS
- --inst->ob_type->tp_frees;
- --inst->ob_type->tp_allocs;
+ --Py_TYPE(inst)->tp_frees;
+ --Py_TYPE(inst)->tp_allocs;
#endif
}
}
@@ -756,7 +755,7 @@
v = class_lookup(inst->in_class, name, &klass);
if (v != NULL) {
Py_INCREF(v);
- f = TP_DESCR_GET(v->ob_type);
+ f = TP_DESCR_GET(Py_TYPE(v));
if (f != NULL) {
PyObject *w = f(v, (PyObject *)inst,
(PyObject *)(inst->in_class));
@@ -1012,7 +1011,7 @@
return -1;
if (PyInt_Check(res) || PyLong_Check(res))
/* This already converts a -1 result to -2. */
- outcome = res->ob_type->tp_hash(res);
+ outcome = Py_TYPE(res)->tp_hash(res);
else {
PyErr_SetString(PyExc_TypeError,
"__hash__() should return an int");
@@ -1500,7 +1499,7 @@
}
v1 = PyTuple_GetItem(coerced, 0);
w = PyTuple_GetItem(coerced, 1);
- if (v1->ob_type == v->ob_type && PyInstance_Check(v)) {
+ if (Py_TYPE(v1) == Py_TYPE(v) && PyInstance_Check(v)) {
/* prevent recursion if __coerce__ returns self as the first
* argument */
result = generic_binary_op(v1, w, opname);
@@ -2077,7 +2076,7 @@
PyErr_Format(PyExc_TypeError,
"__iter__ returned non-iterator "
"of type '%.100s'",
- res->ob_type->tp_name);
+ Py_TYPE(res)->tp_name);
Py_DECREF(res);
res = NULL;
}
@@ -2201,8 +2200,7 @@
};
PyTypeObject PyInstance_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"instance",
sizeof(PyInstanceObject),
0,
@@ -2321,7 +2319,7 @@
instancemethod_getattro(PyObject *obj, PyObject *name)
{
PyMethodObject *im = (PyMethodObject *)obj;
- PyTypeObject *tp = obj->ob_type;
+ PyTypeObject *tp = Py_TYPE(obj);
PyObject *descr = NULL;
if (PyType_HasFeature(tp, Py_TPFLAGS_HAVE_CLASS)) {
@@ -2333,9 +2331,9 @@
}
if (descr != NULL) {
- descrgetfunc f = TP_DESCR_GET(descr->ob_type);
+ descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr));
if (f != NULL)
- return f(descr, obj, (PyObject *)obj->ob_type);
+ return f(descr, obj, (PyObject *)Py_TYPE(obj));
else {
Py_INCREF(descr);
return descr;
@@ -2538,7 +2536,7 @@
if (klass == NULL) {
/* This function cannot return an exception */
PyErr_Clear();
- klass = (PyObject *)(inst->ob_type);
+ klass = (PyObject *)Py_TYPE(inst);
Py_INCREF(klass);
}
getclassname(klass, buf, bufsize);
@@ -2631,8 +2629,7 @@
}
PyTypeObject PyMethod_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"instancemethod",
sizeof(PyMethodObject),
0,
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 1929777..224d1ba 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -368,8 +368,7 @@
static PyTypeObject _PyExc_BaseException = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
EXC_MODULE_NAME "BaseException", /*tp_name*/
sizeof(PyBaseExceptionObject), /*tp_basicsize*/
0, /*tp_itemsize*/
@@ -419,8 +418,7 @@
*/
#define SimpleExtendsException(EXCBASE, EXCNAME, EXCDOC) \
static PyTypeObject _PyExc_ ## EXCNAME = { \
- PyObject_HEAD_INIT(NULL) \
- 0, \
+ PyVarObject_HEAD_INIT(NULL, 0) \
EXC_MODULE_NAME # EXCNAME, \
sizeof(PyBaseExceptionObject), \
0, (destructor)BaseException_dealloc, 0, 0, 0, 0, 0, 0, 0, \
@@ -435,8 +433,7 @@
#define MiddlingExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDOC) \
static PyTypeObject _PyExc_ ## EXCNAME = { \
- PyObject_HEAD_INIT(NULL) \
- 0, \
+ PyVarObject_HEAD_INIT(NULL, 0) \
EXC_MODULE_NAME # EXCNAME, \
sizeof(Py ## EXCSTORE ## Object), \
0, (destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -451,8 +448,7 @@
#define ComplexExtendsException(EXCBASE, EXCNAME, EXCSTORE, EXCDEALLOC, EXCMETHODS, EXCMEMBERS, EXCSTR, EXCDOC) \
static PyTypeObject _PyExc_ ## EXCNAME = { \
- PyObject_HEAD_INIT(NULL) \
- 0, \
+ PyVarObject_HEAD_INIT(NULL, 0) \
EXC_MODULE_NAME # EXCNAME, \
sizeof(Py ## EXCSTORE ## Object), 0, \
(destructor)EXCSTORE ## _dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -1679,8 +1675,7 @@
}
static PyTypeObject _PyExc_UnicodeEncodeError = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
EXC_MODULE_NAME "UnicodeEncodeError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1764,8 +1759,7 @@
}
static PyTypeObject _PyExc_UnicodeDecodeError = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
EXC_MODULE_NAME "UnicodeDecodeError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1862,8 +1856,7 @@
}
static PyTypeObject _PyExc_UnicodeTranslateError = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
EXC_MODULE_NAME "UnicodeTranslateError",
sizeof(PyUnicodeErrorObject), 0,
(destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index a7d64ba..7e07a53 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -427,7 +427,7 @@
if (local_fp != NULL) {
local_close = f->f_close;
if (local_close != NULL && f->unlocked_count > 0) {
- if (f->ob_refcnt > 0) {
+ if (Py_REFCNT(f) > 0) {
PyErr_SetString(PyExc_IOError,
"close() called during concurrent "
"operation on the same file object.");
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 801f286..360ef94 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -65,7 +65,7 @@
return DBL_MIN;
}
-static PyTypeObject FloatInfoType = {0, 0, 0, 0, 0, 0};
+static PyTypeObject FloatInfoType;
PyDoc_STRVAR(floatinfo__doc__,
"sys.float_info\n\
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 04e4d29..3ab00af 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -1486,7 +1486,7 @@
for (i = 0, p = &list->objects[0];
i < N_INTOBJECTS;
i++, p++) {
- if (PyInt_CheckExact(p) && p->ob_refcnt != 0)
+ if (PyInt_CheckExact(p) && Py_REFCNT(p) != 0)
u++;
}
next = list->next;
@@ -1497,7 +1497,7 @@
i < N_INTOBJECTS;
i++, p++) {
if (!PyInt_CheckExact(p) ||
- p->ob_refcnt == 0) {
+ Py_REFCNT(p) == 0) {
Py_TYPE(p) = (struct _typeobject *)
free_list;
free_list = p;
@@ -1560,14 +1560,14 @@
for (i = 0, p = &list->objects[0];
i < N_INTOBJECTS;
i++, p++) {
- if (PyInt_CheckExact(p) && p->ob_refcnt != 0)
+ if (PyInt_CheckExact(p) && Py_REFCNT(p) != 0)
/* XXX(twouters) cast refcount to
long until %zd is universally
available
*/
fprintf(stderr,
"# <int at %p, refcnt=%ld, val=%ld>\n",
- p, (long)p->ob_refcnt,
+ p, (long)Py_REFCNT(p),
p->ob_ival);
}
list = list->next;
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 768a92a..5d6ce70 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -83,12 +83,12 @@
Py_ssize_t i;
assert(src != NULL);
- i = src->ob_size;
+ i = Py_SIZE(src);
if (i < 0)
i = -(i);
result = _PyLong_New(i);
if (result != NULL) {
- result->ob_size = src->ob_size;
+ Py_SIZE(result) = Py_SIZE(src);
while (--i >= 0)
result->ob_digit[i] = src->ob_digit[i];
}
@@ -129,7 +129,7 @@
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 = abs_ival;
while (t) {
*p++ = (digit)(t & PyLong_MASK);
@@ -372,7 +372,7 @@
return -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
@@ -464,7 +464,7 @@
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
@@ -951,7 +951,7 @@
PyObject *io;
if (PyInt_Check(vv))
return (PY_LONG_LONG)PyInt_AsLong(vv);
- if ((nb = vv->ob_type->tp_as_number) == NULL ||
+ if ((nb = Py_TYPE(vv)->tp_as_number) == NULL ||
nb->nb_int == NULL) {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return -1;
@@ -1025,7 +1025,7 @@
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
@@ -1068,7 +1068,7 @@
if (!PyLong_Check(vv)) {
PyNumberMethods *nb;
- nb = vv->ob_type->tp_as_number;
+ nb = Py_TYPE(vv)->tp_as_number;
if (nb == NULL || nb->nb_int == NULL) {
PyErr_SetString(PyExc_TypeError,
"an integer is required");
@@ -1495,10 +1495,10 @@
*p = '\0';
if (addL)
*--p = 'L';
- if (a->ob_size < 0)
+ if (Py_SIZE(a) < 0)
sign = '-';
- if (a->ob_size == 0) {
+ if (Py_SIZE(a) == 0) {
*--p = '0';
}
else if ((base & (base - 1)) == 0) {
@@ -2063,10 +2063,10 @@
The quotient z has the sign of a*b;
the remainder r has the sign of a,
so a = b*z + r. */
- if ((a->ob_size < 0) != (b->ob_size < 0))
- z->ob_size = -(z->ob_size);
- if (a->ob_size < 0 && (*prem)->ob_size != 0)
- (*prem)->ob_size = -((*prem)->ob_size);
+ if ((Py_SIZE(a) < 0) != (Py_SIZE(b) < 0))
+ Py_SIZE(z) = -(Py_SIZE(z));
+ if (Py_SIZE(a) < 0 && Py_SIZE(*prem) != 0)
+ Py_SIZE(*prem) = -Py_SIZE(*prem);
*pdiv = z;
return 0;
}
@@ -2398,7 +2398,7 @@
/* This is designed so that Python ints and longs with the
same value hash to the same value, otherwise comparisons
of mapping keys will turn out weird */
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
@@ -2510,7 +2510,7 @@
}
assert(borrow == 0);
if (sign < 0)
- z->ob_size = -(z->ob_size);
+ Py_SIZE(z) = -(Py_SIZE(z));
return long_normalize(z);
}
@@ -2521,17 +2521,17 @@
CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
- if (a->ob_size < 0) {
- if (b->ob_size < 0) {
+ if (Py_SIZE(a) < 0) {
+ if (Py_SIZE(b) < 0) {
z = x_add(a, b);
- if (z != NULL && z->ob_size != 0)
- z->ob_size = -(z->ob_size);
+ if (z != NULL && Py_SIZE(z) != 0)
+ Py_SIZE(z) = -(Py_SIZE(z));
}
else
z = x_sub(b, a);
}
else {
- if (b->ob_size < 0)
+ if (Py_SIZE(b) < 0)
z = x_sub(a, b);
else
z = x_add(a, b);
@@ -2548,16 +2548,16 @@
CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
- if (a->ob_size < 0) {
- if (b->ob_size < 0)
+ if (Py_SIZE(a) < 0) {
+ if (Py_SIZE(b) < 0)
z = x_sub(a, b);
else
z = x_add(a, b);
- if (z != NULL && z->ob_size != 0)
- z->ob_size = -(z->ob_size);
+ if (z != NULL && Py_SIZE(z) != 0)
+ Py_SIZE(z) = -(Py_SIZE(z));
}
else {
- if (b->ob_size < 0)
+ if (Py_SIZE(b) < 0)
z = x_add(a, b);
else
z = x_sub(a, b);
@@ -2742,7 +2742,7 @@
/* If a is small compared to b, splitting on b gives a degenerate
* case with ah==0, and Karatsuba may be (even much) less efficient
* than "grade school" then. However, we can still win, by viewing
- * b as a string of "big digits", each of width a->ob_size. That
+ * b as a string of "big digits", each of width Py_SIZE(a). That
* leads to a sequence of balanced calls to k_mul.
*/
if (2 * asize <= bsize)
@@ -2910,7 +2910,7 @@
/* b has at least twice the digits of a, and a is big enough that Karatsuba
* would pay off *if* the inputs had balanced sizes. View b as a sequence
- * of slices, each with a->ob_size digits, and multiply the slices by a,
+ * of slices, each with Py_SIZE(a) digits, and multiply the slices by a,
* one at a time. This gives k_mul balanced inputs to work with, and is
* also cache-friendly (we compute one double-width slice of the result
* at a time, then move on, never backtracking except for the helpful
@@ -2982,8 +2982,8 @@
z = k_mul(a, b);
/* Negate if exactly one of the inputs is negative. */
- if (((a->ob_size ^ b->ob_size) < 0) && z)
- z->ob_size = -(z->ob_size);
+ if (((Py_SIZE(a) ^ Py_SIZE(b)) < 0) && z)
+ Py_SIZE(z) = -(Py_SIZE(z));
Py_DECREF(a);
Py_DECREF(b);
return (PyObject *)z;
@@ -3464,7 +3464,7 @@
Py_DECREF(c);
c = temp;
temp = NULL;
- c->ob_size = - c->ob_size;
+ Py_SIZE(c) = - Py_SIZE(c);
}
/* if modulus == 1:
@@ -3608,21 +3608,21 @@
long_neg(PyLongObject *v)
{
PyLongObject *z;
- if (v->ob_size == 0 && PyLong_CheckExact(v)) {
+ if (Py_SIZE(v) == 0 && PyLong_CheckExact(v)) {
/* -0 == 0 */
Py_INCREF(v);
return (PyObject *) v;
}
z = (PyLongObject *)_PyLong_Copy(v);
if (z != NULL)
- z->ob_size = -(v->ob_size);
+ Py_SIZE(z) = -(Py_SIZE(v));
return (PyObject *)z;
}
static PyObject *
long_abs(PyLongObject *v)
{
- if (v->ob_size < 0)
+ if (Py_SIZE(v) < 0)
return long_neg(v);
else
return long_long((PyObject *)v);
@@ -3725,15 +3725,15 @@
wordshift = shiftby / PyLong_SHIFT;
remshift = shiftby - wordshift * PyLong_SHIFT;
- oldsize = ABS(a->ob_size);
+ oldsize = ABS(Py_SIZE(a));
newsize = oldsize + wordshift;
if (remshift)
++newsize;
z = _PyLong_New(newsize);
if (z == NULL)
goto out;
- 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; i < wordshift; i++)
z->ob_digit[i] = 0;
accum = 0;
@@ -4142,7 +4142,7 @@
{
Py_ssize_t res;
- res = v->ob_type->tp_basicsize + ABS(Py_SIZE(v))*sizeof(digit);
+ res = Py_TYPE(v)->tp_basicsize + ABS(Py_SIZE(v))*sizeof(digit);
return PyInt_FromSsize_t(res);
}
@@ -4314,8 +4314,7 @@
};
PyTypeObject PyLong_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"long", /* tp_name */
offsetof(PyLongObject, ob_digit), /* tp_basicsize */
sizeof(digit), /* tp_itemsize */
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index baa8dee..888069a 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -183,8 +183,7 @@
};
PyTypeObject PyRange_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* Number of items for varobject */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"xrange", /* Name of this type */
sizeof(rangeobject), /* Basic object size */
0, /* Item size for varobject */
@@ -256,8 +255,7 @@
};
static PyTypeObject Pyrangeiter_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"rangeiterator", /* tp_name */
sizeof(rangeiterobject), /* tp_basicsize */
0, /* tp_itemsize */
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 0c69fac..154be43 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -583,13 +583,13 @@
if (status < 0)
return status;
Py_BEGIN_ALLOW_THREADS
- fprintf(fp, "%s(...)", so->ob_type->tp_name);
+ fprintf(fp, "%s(...)", Py_TYPE(so)->tp_name);
Py_END_ALLOW_THREADS
return 0;
}
Py_BEGIN_ALLOW_THREADS
- fprintf(fp, "%s([", so->ob_type->tp_name);
+ fprintf(fp, "%s([", Py_TYPE(so)->tp_name);
Py_END_ALLOW_THREADS
while (set_next(so, &pos, &entry)) {
Py_BEGIN_ALLOW_THREADS
@@ -617,7 +617,7 @@
if (status != 0) {
if (status < 0)
return NULL;
- return PyString_FromFormat("%s(...)", so->ob_type->tp_name);
+ return PyString_FromFormat("%s(...)", Py_TYPE(so)->tp_name);
}
keys = PySequence_List((PyObject *)so);
@@ -628,7 +628,7 @@
if (listrepr == NULL)
goto done;
- result = PyString_FromFormat("%s(%s)", so->ob_type->tp_name,
+ result = PyString_FromFormat("%s(%s)", Py_TYPE(so)->tp_name,
PyString_AS_STRING(listrepr));
Py_DECREF(listrepr);
done:
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index 2eb4fe0..344e6f2 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -196,7 +196,7 @@
static PyObject *
weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
{
- if ((op != Py_EQ && op != Py_NE) || self->ob_type != other->ob_type) {
+ if ((op != Py_EQ && op != Py_NE) || Py_TYPE(self) != Py_TYPE(other)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
@@ -914,7 +914,7 @@
if (object == NULL
|| !PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))
- || object->ob_refcnt != 0) {
+ || Py_REFCNT(object) != 0) {
PyErr_BadInternalCall();
return;
}
@@ -937,7 +937,7 @@
current->wr_callback = NULL;
clear_weakref(current);
if (callback != NULL) {
- if (current->ob_refcnt > 0)
+ if (Py_REFCNT(current) > 0)
handle_callback(current, callback);
Py_DECREF(callback);
}
@@ -955,7 +955,7 @@
for (i = 0; i < count; ++i) {
PyWeakReference *next = current->wr_next;
- if (current->ob_refcnt > 0)
+ if (Py_REFCNT(current) > 0)
{
Py_INCREF(current);
PyTuple_SET_ITEM(tuple, i * 2, (PyObject *) current);