Replace direct access to PyObject.ob_type with Py_TYPE().
PyAPI_DATA(PyTypeObject) PyMethod_Type;
-#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
+#define PyMethod_Check(op) (Py_TYPE(op)== &PyMethod_Type)
PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *);
PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type;
-#define PyInstanceMethod_Check(op) ((op)->ob_type == &PyInstanceMethod_Type)
+#define PyInstanceMethod_Check(op) (Py_TYPE(op) == &PyInstanceMethod_Type)
PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *);
PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
/* Return 1 if the getbuffer function is available, otherwise return 0. */
#define PyObject_CheckBuffer(obj) \
- (((obj)->ob_type->tp_as_buffer != NULL) && \
- ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
+ ((Py_TYPE(obj)->tp_as_buffer != NULL) && \
+ (Py_TYPE(obj)->tp_as_buffer->bf_getbuffer != NULL))
/* This is a C-API version of the getbuffer function call. It checks
to make sure object has the required function pointer and issues the
/* ==== Iterators ================================================ */
#define PyIter_Check(obj) \
- ((obj)->ob_type->tp_iternext != NULL && \
- (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
+ (Py_TYPE(obj)->tp_iternext != NULL && \
+ Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented)
/* === Number Protocol ================================================== */
#define PyIndex_Check(obj) \
- ((obj)->ob_type->tp_as_number != NULL && \
- (obj)->ob_type->tp_as_number->nb_index != NULL)
+ (Py_TYPE(obj)->tp_as_number != NULL && \
+ Py_TYPE(obj)->tp_as_number->nb_index != NULL)
/* === Sequence protocol ================================================ */
PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
#define PyExceptionInstance_Check(x) \
- PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
+ PyType_FastSubclass(Py_TYPE(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)
PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);
-#define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type))
+#define PyExceptionInstance_Class(x) ((PyObject*)Py_TYPE(x))
/* Predefined exceptions */
text = PyObject_Str(message);
if (text == NULL)
goto cleanup;
- category = (PyObject*)message->ob_type;
+ category = (PyObject*)Py_TYPE(message);
}
else {
text = message;
return NULL;
if (rc == 1)
- category = (PyObject*)message->ob_type;
+ category = (PyObject*)Py_TYPE(message);
else if (category == NULL || category == Py_None)
category = PyExc_UserWarning;
/* else get the type of the first base */
else {
PyObject *base0 = PyTuple_GET_ITEM(bases, 0);
- meta = (PyObject *) (base0->ob_type);
+ meta = (PyObject *)Py_TYPE(base0);
}
Py_INCREF(meta);
isclass = 1; /* meta is really a class */
if (!PyDict_Check(globals)) {
PyErr_Format(PyExc_TypeError, "exec() globals must be a dict, not %.100s",
- globals->ob_type->tp_name);
+ Py_TYPE(globals)->tp_name);
return NULL;
}
if (!PyMapping_Check(locals)) {
PyErr_Format(PyExc_TypeError,
"locals must be a mapping or None, not %.100s",
- locals->ob_type->tp_name);
+ Py_TYPE(locals)->tp_name);
return NULL;
}
if (_PyDict_GetItemIdWithError(globals, &PyId___builtins__) == NULL) {
if (!PyIter_Check(it)) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object is not an iterator",
- it->ob_type->tp_name);
+ Py_TYPE(it)->tp_name);
return NULL;
}
- res = (*it->ob_type->tp_iternext)(it);
+ res = (*Py_TYPE(it)->tp_iternext)(it);
if (res != NULL) {
return res;
} else if (nargs > 1) {
else {
PyErr_Format(PyExc_TypeError,
"ord() expected string of length 1, but " \
- "%.200s found", c->ob_type->tp_name);
+ "%.200s found", Py_TYPE(c)->tp_name);
return NULL;
}
else if (sep && !PyUnicode_Check(sep)) {
PyErr_Format(PyExc_TypeError,
"sep must be None or a string, not %.200s",
- sep->ob_type->tp_name);
+ Py_TYPE(sep)->tp_name);
return NULL;
}
if (end == Py_None) {
else if (end && !PyUnicode_Check(end)) {
PyErr_Format(PyExc_TypeError,
"end must be None or a string, not %.200s",
- end->ob_type->tp_name);
+ Py_TYPE(end)->tp_name);
return NULL;
}
PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable);
if (none_val == NULL) {
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
- (iterable->ob_type->tp_iter == NULL && !PySequence_Check(iterable)))
+ (Py_TYPE(iterable)->tp_iter == NULL && !PySequence_Check(iterable)))
{
_PyErr_Clear(tstate);
_PyErr_Format(tstate, PyExc_TypeError,
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object is not a mapping",
- update->ob_type->tp_name);
+ Py_TYPE(update)->tp_name);
}
Py_DECREF(update);
goto error;
PREDICTED(FOR_ITER);
/* before: [iter]; after: [iter, iter()] *or* [] */
PyObject *iter = TOP();
- PyObject *next = (*iter->ob_type->tp_iternext)(iter);
+ PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
if (next != NULL) {
PUSH(next);
PREDICT(STORE_FAST);
it = PyObject_GetIter(v);
if (it == NULL) {
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
- v->ob_type->tp_iter == NULL && !PySequence_Check(v))
+ Py_TYPE(v)->tp_iter == NULL && !PySequence_Check(v))
{
_PyErr_Format(tstate, PyExc_TypeError,
"cannot unpack non-iterable %.200s object",
- v->ob_type->tp_name);
+ Py_TYPE(v)->tp_name);
}
return 0;
}
else if (PyCFunction_Check(func))
return ((PyCFunctionObject*)func)->m_ml->ml_name;
else
- return func->ob_type->tp_name;
+ return Py_TYPE(func)->tp_name;
}
const char *
static int
check_args_iterable(PyThreadState *tstate, PyObject *func, PyObject *args)
{
- if (args->ob_type->tp_iter == NULL && !PySequence_Check(args)) {
+ if (Py_TYPE(args)->tp_iter == NULL && !PySequence_Check(args)) {
/* check_args_iterable() may be called with a live exception:
* clear it to prevent calling _PyObject_FunctionStr() with an
* exception set. */
{
PyErr_Format(PyExc_TypeError,
"don't know how to handle %.200s in error callback",
- exc->ob_type->tp_name);
+ Py_TYPE(exc)->tp_name);
}
PyObject *PyCodec_StrictErrors(PyObject *exc)
case FormattedValue_kind:
return &PyUnicode_Type;
case Constant_kind:
- return e->v.Constant.value->ob_type;
+ return Py_TYPE(e->v.Constant.value);
default:
return NULL;
}
return format_string_internal(obj, &format, writer);
default:
/* unknown */
- unknown_presentation_type(format.type, obj->ob_type->tp_name);
+ unknown_presentation_type(format.type, Py_TYPE(obj)->tp_name);
return -1;
}
}
default:
/* unknown */
- unknown_presentation_type(format.type, obj->ob_type->tp_name);
+ unknown_presentation_type(format.type, Py_TYPE(obj)->tp_name);
goto done;
}
default:
/* unknown */
- unknown_presentation_type(format.type, obj->ob_type->tp_name);
+ unknown_presentation_type(format.type, Py_TYPE(obj)->tp_name);
return -1;
}
}
default:
/* unknown */
- unknown_presentation_type(format.type, obj->ob_type->tp_name);
+ unknown_presentation_type(format.type, Py_TYPE(obj)->tp_name);
return -1;
}
}
toplevel ? "expected %d arguments, not %.50s" :
"must be %d-item sequence, not %.50s",
n,
- arg == Py_None ? "None" : arg->ob_type->tp_name);
+ arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
return msgbuf;
}
PyErr_Format(PyExc_TypeError,
"%.200s() %.200s must be %.50s, not %.50s",
fname, displayname, expected,
- arg == Py_None ? "None" : arg->ob_type->tp_name);
+ arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
}
static const char *
else {
PyOS_snprintf(msgbuf, bufsize,
"must be %.50s, not %.50s", expected,
- arg == Py_None ? "None" : arg->ob_type->tp_name);
+ arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
}
return msgbuf;
}
type = va_arg(*p_va, PyTypeObject*);
p = va_arg(*p_va, PyObject **);
format++;
- if (PyType_IsSubtype(arg->ob_type, type))
+ if (PyType_IsSubtype(Py_TYPE(arg), type))
*p = arg;
else
return converterr(type->tp_name, arg, msgbuf, bufsize);
if (!PyBytes_Check(data)) {
PyErr_Format(PyExc_TypeError,
"file.read() returned not bytes but %.100s",
- data->ob_type->tp_name);
+ Py_TYPE(data)->tp_name);
result = NULL;
}
else {
}
else {
_PyErr_Format(tstate, PyExc_TypeError,
- "can't intern %.400s", s->ob_type->tp_name);
+ "can't intern %.400s", Py_TYPE(s)->tp_name);
return NULL;
}
}