This no-op change makes 2.7 more consistent with 3.x to ease comparison and backports.
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)
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
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 */
};
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 */
}
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 */
}
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 */
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 */
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 */
");
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 */
Py_XDECREF(self->statements);
Py_XDECREF(self->cursors);
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
/*
PyObject_ClearWeakRefs((PyObject*)self);
}
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
PyObject* _pysqlite_get_converter(PyObject* key)
};
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 */
};
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 */
* 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 */
};
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 */
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;
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,
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 {
{
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;
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 */
};
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 */
};
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 */
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");
(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");
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");
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
}
PyTypeObject PyClass_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"classobj",
sizeof(PyClassObject),
0,
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);
/* 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
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. */
* 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
}
}
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));
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");
}
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);
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;
}
};
PyTypeObject PyInstance_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"instance",
sizeof(PyInstanceObject),
0,
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)) {
}
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;
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);
}
PyTypeObject PyMethod_Type = {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
"instancemethod",
sizeof(PyMethodObject),
0,
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*/
*/
#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, \
#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, \
#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, \
}
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,
}
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,
}
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,
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.");
return DBL_MIN;
}
-static PyTypeObject FloatInfoType = {0, 0, 0, 0, 0, 0};
+static PyTypeObject FloatInfoType;
PyDoc_STRVAR(floatinfo__doc__,
"sys.float_info\n\
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;
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;
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;
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];
}
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);
return -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
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;
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = v->ob_size;
+ i = Py_SIZE(v);
sign = 1;
x = 0;
if (i < 0) {
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");
*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) {
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;
}
/* 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) {
}
assert(borrow == 0);
if (sign < 0)
- z->ob_size = -(z->ob_size);
+ Py_SIZE(z) = -(Py_SIZE(z));
return long_normalize(z);
}
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);
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);
/* 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)
/* 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
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;
Py_DECREF(c);
c = temp;
temp = NULL;
- c->ob_size = - c->ob_size;
+ Py_SIZE(c) = - Py_SIZE(c);
}
/* if modulus == 1:
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);
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;
{
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);
}
};
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 */
};
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 */
};
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 */
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
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);
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:
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;
}
if (object == NULL
|| !PyType_SUPPORTS_WEAKREFS(Py_TYPE(object))
- || object->ob_refcnt != 0) {
+ || Py_REFCNT(object) != 0) {
PyErr_BadInternalCall();
return;
}
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);
}
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);