static PyObject *
type_error(const char *msg, PyObject *obj)
{
- PyErr_Format(PyExc_TypeError, msg, obj->ob_type->tp_name);
+ PyErr_Format(PyExc_TypeError, msg, Py_TYPE(obj)->tp_name);
return NULL;
}
return null_error();
}
- v = (PyObject *)o->ob_type;
+ v = (PyObject *)Py_TYPE(o);
Py_INCREF(v);
return v;
}
return -1;
}
- m = o->ob_type->tp_as_sequence;
+ m = Py_TYPE(o)->tp_as_sequence;
if (m && m->sq_length) {
Py_ssize_t len = m->sq_length(o);
assert(len >= 0 || PyErr_Occurred());
return null_error();
}
- m = o->ob_type->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_subscript) {
PyObject *item = m->mp_subscript(o, key);
assert((item != NULL) ^ (PyErr_Occurred() != NULL));
return item;
}
- ms = o->ob_type->tp_as_sequence;
+ ms = Py_TYPE(o)->tp_as_sequence;
if (ms && ms->sq_item) {
if (PyIndex_Check(key)) {
Py_ssize_t key_value;
null_error();
return -1;
}
- m = o->ob_type->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_ass_subscript)
return m->mp_ass_subscript(o, key, value);
- if (o->ob_type->tp_as_sequence) {
+ if (Py_TYPE(o)->tp_as_sequence) {
if (PyIndex_Check(key)) {
Py_ssize_t key_value;
key_value = PyNumber_AsSsize_t(key, PyExc_IndexError);
return -1;
return PySequence_SetItem(o, key_value, value);
}
- else if (o->ob_type->tp_as_sequence->sq_ass_item) {
+ else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) {
type_error("sequence index must be "
"integer, not '%.200s'", key);
return -1;
null_error();
return -1;
}
- m = o->ob_type->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_ass_subscript)
return m->mp_ass_subscript(o, key, (PyObject*)NULL);
- if (o->ob_type->tp_as_sequence) {
+ if (Py_TYPE(o)->tp_as_sequence) {
if (PyIndex_Check(key)) {
Py_ssize_t key_value;
key_value = PyNumber_AsSsize_t(key, PyExc_IndexError);
return -1;
return PySequence_DelItem(o, key_value);
}
- else if (o->ob_type->tp_as_sequence->sq_ass_item) {
+ else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) {
type_error("sequence index must be "
"integer, not '%.200s'", key);
return -1;
int
PyObject_CheckReadBuffer(PyObject *obj)
{
- PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
+ PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer;
Py_buffer view;
if (pb == NULL ||
null_error();
return -1;
}
- pb = obj->ob_type->tp_as_buffer;
+ pb = Py_TYPE(obj)->tp_as_buffer;
if (pb == NULL ||
pb->bf_getbuffer == NULL ||
((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) {
int
PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
{
- PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
+ PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer;
if (pb == NULL || pb->bf_getbuffer == NULL) {
PyErr_Format(PyExc_TypeError,
int
PyNumber_Check(PyObject *o)
{
- return o && o->ob_type->tp_as_number &&
- (o->ob_type->tp_as_number->nb_index ||
- o->ob_type->tp_as_number->nb_int ||
- o->ob_type->tp_as_number->nb_float);
+ return o && Py_TYPE(o)->tp_as_number &&
+ (Py_TYPE(o)->tp_as_number->nb_index ||
+ Py_TYPE(o)->tp_as_number->nb_int ||
+ Py_TYPE(o)->tp_as_number->nb_float);
}
/* Binary operators */
Order operations are tried until either a valid result or error:
w.op(v,w)[*], v.op(v,w), w.op(v,w)
- [*] only when v->ob_type != w->ob_type && w->ob_type is a subclass of
- v->ob_type
+ [*] only when Py_TYPE(v) != Py_TYPE(w) && Py_TYPE(w) is a subclass of
+ Py_TYPE(v)
*/
static PyObject *
binaryfunc slotv = NULL;
binaryfunc slotw = NULL;
- if (v->ob_type->tp_as_number != NULL)
- slotv = NB_BINOP(v->ob_type->tp_as_number, op_slot);
- if (w->ob_type != v->ob_type &&
- w->ob_type->tp_as_number != NULL) {
- slotw = NB_BINOP(w->ob_type->tp_as_number, op_slot);
+ if (Py_TYPE(v)->tp_as_number != NULL)
+ slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot);
+ if (Py_TYPE(w) != Py_TYPE(v) &&
+ Py_TYPE(w)->tp_as_number != NULL) {
+ slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot);
if (slotw == slotv)
slotw = NULL;
}
if (slotv) {
- if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
+ if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) {
x = slotw(v, w);
if (x != Py_NotImplemented)
return x;
"unsupported operand type(s) for %.100s: "
"'%.100s' and '%.100s'",
op_name,
- v->ob_type->tp_name,
- w->ob_type->tp_name);
+ Py_TYPE(v)->tp_name,
+ Py_TYPE(w)->tp_name);
return NULL;
}
"'%.100s' and '%.100s'. Did you mean \"print(<message>, "
"file=<output_stream>)\"?",
op_name,
- v->ob_type->tp_name,
- w->ob_type->tp_name);
+ Py_TYPE(v)->tp_name,
+ Py_TYPE(w)->tp_name);
return NULL;
}
ternaryfunc slotw = NULL;
ternaryfunc slotz = NULL;
- mv = v->ob_type->tp_as_number;
- mw = w->ob_type->tp_as_number;
+ mv = Py_TYPE(v)->tp_as_number;
+ mw = Py_TYPE(w)->tp_as_number;
if (mv != NULL)
slotv = NB_TERNOP(mv, op_slot);
- if (w->ob_type != v->ob_type &&
+ if (Py_TYPE(w) != Py_TYPE(v) &&
mw != NULL) {
slotw = NB_TERNOP(mw, op_slot);
if (slotw == slotv)
slotw = NULL;
}
if (slotv) {
- if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
+ if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) {
x = slotw(v, w, z);
if (x != Py_NotImplemented)
return x;
return x;
Py_DECREF(x); /* can't do it */
}
- mz = z->ob_type->tp_as_number;
+ mz = Py_TYPE(z)->tp_as_number;
if (mz != NULL) {
slotz = NB_TERNOP(mz, op_slot);
if (slotz == slotv || slotz == slotw)
PyExc_TypeError,
"unsupported operand type(s) for ** or pow(): "
"'%.100s' and '%.100s'",
- v->ob_type->tp_name,
- w->ob_type->tp_name);
+ Py_TYPE(v)->tp_name,
+ Py_TYPE(w)->tp_name);
else
PyErr_Format(
PyExc_TypeError,
"unsupported operand type(s) for pow(): "
"'%.100s', '%.100s', '%.100s'",
- v->ob_type->tp_name,
- w->ob_type->tp_name,
- z->ob_type->tp_name);
+ Py_TYPE(v)->tp_name,
+ Py_TYPE(w)->tp_name,
+ Py_TYPE(z)->tp_name);
return NULL;
}
{
PyObject *result = binary_op1(v, w, NB_SLOT(nb_add));
if (result == Py_NotImplemented) {
- PySequenceMethods *m = v->ob_type->tp_as_sequence;
+ PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence;
Py_DECREF(result);
if (m && m->sq_concat) {
return (*m->sq_concat)(v, w);
{
PyObject *result = binary_op1(v, w, NB_SLOT(nb_multiply));
if (result == Py_NotImplemented) {
- PySequenceMethods *mv = v->ob_type->tp_as_sequence;
- PySequenceMethods *mw = w->ob_type->tp_as_sequence;
+ PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence;
+ PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence;
Py_DECREF(result);
if (mv && mv->sq_repeat) {
return sequence_repeat(mv->sq_repeat, v, w);
static PyObject *
binary_iop1(PyObject *v, PyObject *w, const int iop_slot, const int op_slot)
{
- PyNumberMethods *mv = v->ob_type->tp_as_number;
+ PyNumberMethods *mv = Py_TYPE(v)->tp_as_number;
if (mv != NULL) {
binaryfunc slot = NB_BINOP(mv, iop_slot);
if (slot) {
PyObject *result = binary_iop1(v, w, NB_SLOT(nb_inplace_add),
NB_SLOT(nb_add));
if (result == Py_NotImplemented) {
- PySequenceMethods *m = v->ob_type->tp_as_sequence;
+ PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence;
Py_DECREF(result);
if (m != NULL) {
binaryfunc f = NULL;
NB_SLOT(nb_multiply));
if (result == Py_NotImplemented) {
ssizeargfunc f = NULL;
- PySequenceMethods *mv = v->ob_type->tp_as_sequence;
- PySequenceMethods *mw = w->ob_type->tp_as_sequence;
+ PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence;
+ PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence;
Py_DECREF(result);
if (mv != NULL) {
f = mv->sq_inplace_repeat;
PyObject *
PyNumber_InPlacePower(PyObject *v, PyObject *w, PyObject *z)
{
- if (v->ob_type->tp_as_number &&
- v->ob_type->tp_as_number->nb_inplace_power != NULL) {
+ if (Py_TYPE(v)->tp_as_number &&
+ Py_TYPE(v)->tp_as_number->nb_inplace_power != NULL) {
return ternary_op(v, w, z, NB_SLOT(nb_inplace_power), "**=");
}
else {
return null_error();
}
- m = o->ob_type->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_negative)
return (*m->nb_negative)(o);
return null_error();
}
- m = o->ob_type->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_positive)
return (*m->nb_positive)(o);
return null_error();
}
- m = o->ob_type->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_invert)
return (*m->nb_invert)(o);
return null_error();
}
- m = o->ob_type->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_absolute)
return m->nb_absolute(o);
int
PyIndex_Check(PyObject *obj)
{
- return obj->ob_type->tp_as_number != NULL &&
- obj->ob_type->tp_as_number->nb_index != NULL;
+ return Py_TYPE(obj)->tp_as_number != NULL &&
+ Py_TYPE(obj)->tp_as_number->nb_index != NULL;
}
/* Return a Python int from the object item.
if (!PyIndex_Check(item)) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object cannot be interpreted "
- "as an integer", item->ob_type->tp_name);
+ "as an integer", Py_TYPE(item)->tp_name);
return NULL;
}
- result = item->ob_type->tp_as_number->nb_index(item);
+ result = Py_TYPE(item)->tp_as_number->nb_index(item);
if (!result || PyLong_CheckExact(result))
return result;
if (!PyLong_Check(result)) {
PyErr_Format(PyExc_TypeError,
"__index__ returned non-int (type %.200s)",
- result->ob_type->tp_name);
+ Py_TYPE(result)->tp_name);
Py_DECREF(result);
return NULL;
}
"__index__ returned non-int (type %.200s). "
"The ability to return an instance of a strict subclass of int "
"is deprecated, and may be removed in a future version of Python.",
- result->ob_type->tp_name)) {
+ Py_TYPE(result)->tp_name)) {
Py_DECREF(result);
return NULL;
}
/* Otherwise replace the error with caller's error object. */
PyErr_Format(err,
"cannot fit '%.200s' into an index-sized integer",
- item->ob_type->tp_name);
+ Py_TYPE(item)->tp_name);
}
finish:
Py_INCREF(o);
return o;
}
- m = o->ob_type->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_int) { /* This should include subclasses of int */
result = _PyLong_FromNbInt(o);
if (result != NULL && !PyLong_CheckExact(result)) {
}
/* __trunc__ is specified to return an Integral type,
but int() needs to return an int. */
- m = result->ob_type->tp_as_number;
+ m = Py_TYPE(result)->tp_as_number;
if (m == NULL || (m->nb_index == NULL && m->nb_int == NULL)) {
PyErr_Format(
PyExc_TypeError,
"__trunc__ returned non-Integral (type %.200s)",
- result->ob_type->tp_name);
+ Py_TYPE(result)->tp_name);
Py_DECREF(result);
return NULL;
}
Py_INCREF(o);
return o;
}
- m = o->ob_type->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_float) { /* This should include subclasses of float */
PyObject *res = m->nb_float(o);
double val;
if (!PyFloat_Check(res)) {
PyErr_Format(PyExc_TypeError,
"%.50s.__float__ returned non-float (type %.50s)",
- o->ob_type->tp_name, res->ob_type->tp_name);
+ Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name);
Py_DECREF(res);
return NULL;
}
"%.50s.__float__ returned non-float (type %.50s). "
"The ability to return an instance of a strict subclass of float "
"is deprecated, and may be removed in a future version of Python.",
- o->ob_type->tp_name, res->ob_type->tp_name)) {
+ Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name)) {
Py_DECREF(res);
return NULL;
}
{
if (PyDict_Check(s))
return 0;
- return s->ob_type->tp_as_sequence &&
- s->ob_type->tp_as_sequence->sq_item != NULL;
+ return Py_TYPE(s)->tp_as_sequence &&
+ Py_TYPE(s)->tp_as_sequence->sq_item != NULL;
}
Py_ssize_t
return -1;
}
- m = s->ob_type->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_length) {
Py_ssize_t len = m->sq_length(s);
assert(len >= 0 || PyErr_Occurred());
return len;
}
- if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_length) {
+ if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) {
type_error("%.200s is not a sequence", s);
return -1;
}
return null_error();
}
- m = s->ob_type->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_concat)
return m->sq_concat(s, o);
return null_error();
}
- m = o->ob_type->tp_as_sequence;
+ m = Py_TYPE(o)->tp_as_sequence;
if (m && m->sq_repeat)
return m->sq_repeat(o, count);
return null_error();
}
- m = s->ob_type->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_inplace_concat)
return m->sq_inplace_concat(s, o);
if (m && m->sq_concat)
return null_error();
}
- m = o->ob_type->tp_as_sequence;
+ m = Py_TYPE(o)->tp_as_sequence;
if (m && m->sq_inplace_repeat)
return m->sq_inplace_repeat(o, count);
if (m && m->sq_repeat)
return null_error();
}
- m = s->ob_type->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_item) {
if (i < 0) {
if (m->sq_length) {
return m->sq_item(s, i);
}
- if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_subscript) {
+ if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_subscript) {
return type_error("%.200s is not a sequence", s);
}
return type_error("'%.200s' object does not support indexing", s);
return null_error();
}
- mp = s->ob_type->tp_as_mapping;
+ mp = Py_TYPE(s)->tp_as_mapping;
if (mp && mp->mp_subscript) {
PyObject *res;
PyObject *slice = _PySlice_FromIndices(i1, i2);
return -1;
}
- m = s->ob_type->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
return m->sq_ass_item(s, i, o);
}
- if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_ass_subscript) {
+ if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) {
type_error("%.200s is not a sequence", s);
return -1;
}
return -1;
}
- m = s->ob_type->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
return m->sq_ass_item(s, i, (PyObject *)NULL);
}
- if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_ass_subscript) {
+ if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) {
type_error("%.200s is not a sequence", s);
return -1;
}
return -1;
}
- mp = s->ob_type->tp_as_mapping;
+ mp = Py_TYPE(s)->tp_as_mapping;
if (mp && mp->mp_ass_subscript) {
int res;
PyObject *slice = _PySlice_FromIndices(i1, i2);
return -1;
}
- mp = s->ob_type->tp_as_mapping;
+ mp = Py_TYPE(s)->tp_as_mapping;
if (mp && mp->mp_ass_subscript) {
int res;
PyObject *slice = _PySlice_FromIndices(i1, i2);
PySequence_Contains(PyObject *seq, PyObject *ob)
{
Py_ssize_t result;
- PySequenceMethods *sqm = seq->ob_type->tp_as_sequence;
+ PySequenceMethods *sqm = Py_TYPE(seq)->tp_as_sequence;
if (sqm != NULL && sqm->sq_contains != NULL)
return (*sqm->sq_contains)(seq, ob);
result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS);
int
PyMapping_Check(PyObject *o)
{
- return o && o->ob_type->tp_as_mapping &&
- o->ob_type->tp_as_mapping->mp_subscript;
+ return o && Py_TYPE(o)->tp_as_mapping &&
+ Py_TYPE(o)->tp_as_mapping->mp_subscript;
}
Py_ssize_t
return -1;
}
- m = o->ob_type->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_length) {
Py_ssize_t len = m->mp_length(o);
assert(len >= 0 || PyErr_Occurred());
return len;
}
- if (o->ob_type->tp_as_sequence && o->ob_type->tp_as_sequence->sq_length) {
+ if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_length) {
type_error("%.200s is not a mapping", o);
return -1;
}
if (retval == 0) {
retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls);
if (icls != NULL) {
- if (icls != (PyObject *)(inst->ob_type) && PyType_Check(icls)) {
+ if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) {
retval = PyType_IsSubtype(
(PyTypeObject *)icls,
(PyTypeObject *)cls);
PyObject *
PyObject_GetIter(PyObject *o)
{
- PyTypeObject *t = o->ob_type;
+ PyTypeObject *t = Py_TYPE(o);
getiterfunc f;
f = t->tp_iter;
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;
}
int PyIter_Check(PyObject *obj)
{
- return obj->ob_type->tp_iternext != NULL &&
- obj->ob_type->tp_iternext != &_PyObject_NextNotImplemented;
+ return Py_TYPE(obj)->tp_iternext != NULL &&
+ Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented;
}
/* Return next item.
PyIter_Next(PyObject *iter)
{
PyObject *result;
- result = (*iter->ob_type->tp_iternext)(iter);
+ result = (*Py_TYPE(iter)->tp_iternext)(iter);
if (result == NULL &&
PyErr_Occurred() &&
PyErr_ExceptionMatches(PyExc_StopIteration))