commit 1cd453e103aaa77380be0a7b29e16425d948cb42 Author: Neil Schemenauer Date: Wed Sep 12 14:51:49 2018 -0700 Introduce Py_TP(), use it rather than ->ob_type. diff --git a/Include/abstract.h b/Include/abstract.h index 85550a34ca..81f68ec9de 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -509,8 +509,8 @@ PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj, /* 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_TP(obj)->tp_as_buffer != NULL) && \ + (Py_TP(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 @@ -596,8 +596,8 @@ PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); PyAPI_FUNC(int) PyIter_Check(PyObject *); #ifndef Py_LIMITED_API #define PyIter_Check(obj) \ - ((obj)->ob_type->tp_iternext != NULL && \ - (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented) + (Py_TP(obj)->tp_iternext != NULL && \ + Py_TP(obj)->tp_iternext != &_PyObject_NextNotImplemented) #endif /* Takes an iterator object and calls its tp_iternext slot, @@ -721,8 +721,8 @@ PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); PyAPI_FUNC(int) PyIndex_Check(PyObject *); #ifndef Py_LIMITED_API #define PyIndex_Check(obj) \ - ((obj)->ob_type->tp_as_number != NULL && \ - (obj)->ob_type->tp_as_number->nb_index != NULL) + (Py_TP(obj)->tp_as_number != NULL && \ + Py_TP(obj)->tp_as_number->nb_index != NULL) #endif /* Returns the object 'o' converted to a Python int, or NULL with an exception diff --git a/Include/classobject.h b/Include/classobject.h index 209f0f4a28..cbda3cc8d0 100644 --- a/Include/classobject.h +++ b/Include/classobject.h @@ -18,7 +18,7 @@ typedef struct { PyAPI_DATA(PyTypeObject) PyMethod_Type; -#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type) +#define PyMethod_Check(op) (Py_TP(op) == &PyMethod_Type) PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *); @@ -41,7 +41,7 @@ typedef struct { PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type; -#define PyInstanceMethod_Check(op) ((op)->ob_type == &PyInstanceMethod_Type) +#define PyInstanceMethod_Check(op) (Py_TP(op) == &PyInstanceMethod_Type) PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *); PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *); diff --git a/Include/object.h b/Include/object.h index c772deaf57..84849ee656 100644 --- a/Include/object.h +++ b/Include/object.h @@ -115,7 +115,8 @@ typedef struct { } PyVarObject; #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) +#define Py_TP(ob) ((ob)->ob_type) +#define Py_TYPE(ob) (Py_TP((PyObject*)(ob))) #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) #ifndef Py_LIMITED_API diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 4e2995469f..912717bb4d 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -140,14 +140,14 @@ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); 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_TP(x), Py_TPFLAGS_BASE_EXC_SUBCLASS) PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *); #ifndef Py_LIMITED_API #define PyExceptionClass_Name(x) (((PyTypeObject*)(x))->tp_name) #endif -#define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type)) +#define PyExceptionInstance_Class(x) ((PyObject*)Py_TP(x)) /* Predefined exceptions */ diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 935b4348a8..9f71c276af 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -531,7 +531,7 @@ deque_concat(dequeobject *deque, PyObject *other) if (rv == 0) { PyErr_Format(PyExc_TypeError, "can only concatenate deque (not \"%.200s\") to deque", - other->ob_type->tp_name); + Py_TP(other)->tp_name); } return NULL; } diff --git a/Modules/_csv.c b/Modules/_csv.c index 4cc1f7c88d..a162ad8db0 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -236,7 +236,7 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt) if (!PyUnicode_Check(src)) { PyErr_Format(PyExc_TypeError, "\"%s\" must be string, not %.200s", name, - src->ob_type->tp_name); + Py_TP(src)->tp_name); return -1; } len = PyUnicode_GetLength(src); @@ -807,7 +807,7 @@ Reader_iternext(ReaderObj *self) "iterator should return strings, " "not %.200s " "(did you open the file in text mode?)", - lineobj->ob_type->tp_name + Py_TP(lineobj)->tp_name ); Py_DECREF(lineobj); return NULL; @@ -1168,7 +1168,7 @@ csv_writerow(WriterObj *self, PyObject *seq) if (iter == NULL) return PyErr_Format(_csvstate_global->error_obj, "iterable expected, not %.200s", - seq->ob_type->tp_name); + Py_TP(seq)->tp_name); /* Join all fields in internal buffer. */ diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index e2b9aa8ed1..971b0aceb8 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -275,7 +275,7 @@ static void PyCField_dealloc(PyObject *self) { PyCField_clear((CFieldObject *)self); - self->ob_type->tp_free((PyObject *)self); + Py_TP(self)->tp_free((PyObject *)self); } static PyObject * @@ -1176,7 +1176,7 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size) if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "unicode string expected instead of %s instance", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return NULL; } else Py_INCREF(value); @@ -1238,7 +1238,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length) if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "unicode string expected instead of %s instance", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return NULL; } @@ -1288,7 +1288,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length) if(!PyBytes_Check(value)) { PyErr_Format(PyExc_TypeError, "expected bytes, %s found", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return NULL; } @@ -1333,7 +1333,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size) } PyErr_Format(PyExc_TypeError, "bytes or integer address expected instead of %s instance", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return NULL; } @@ -1372,7 +1372,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "unicode string or integer address expected instead of %s instance", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return NULL; } @@ -1415,7 +1415,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size) } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, "unicode string expected instead of %s instance", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return NULL; } diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 5d3b966338..0c91f58c60 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -68,7 +68,7 @@ typedef struct { ffi_type *atypes[1]; } CThunkObject; extern PyTypeObject PyCThunk_Type; -#define CThunk_CheckExact(v) ((v)->ob_type == &PyCThunk_Type) +#define CThunk_CheckExact(v) (Py_TP(v) == &PyCThunk_Type) typedef struct { /* First part identical to tagCDataObject */ @@ -102,7 +102,7 @@ typedef struct { } PyCFuncPtrObject; extern PyTypeObject PyCStgDict_Type; -#define PyCStgDict_CheckExact(v) ((v)->ob_type == &PyCStgDict_Type) +#define PyCStgDict_CheckExact(v) (Py_TP(v) == &PyCStgDict_Type) #define PyCStgDict_Check(v) PyObject_TypeCheck(v, &PyCStgDict_Type) extern int PyCStructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct); @@ -112,12 +112,12 @@ extern int PyObject_stginfo(PyObject *self, Py_ssize_t *psize, Py_ssize_t *palig extern PyTypeObject PyCData_Type; -#define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) +#define CDataObject_CheckExact(v) (Py_TP(v) == &PyCData_Type) #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) #define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) extern PyTypeObject PyCSimpleType_Type; -#define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) +#define PyCSimpleTypeObject_CheckExact(v) (Py_TP(v) == &PyCSimpleType_Type) #define PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyCSimpleType_Type) extern PyTypeObject PyCField_Type; @@ -312,7 +312,7 @@ struct tagPyCArgObject { }; extern PyTypeObject PyCArg_Type; -#define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type) +#define PyCArg_CheckExact(v) (Py_TP(v) == &PyCArg_Type) extern PyCArgObject *PyCArgObject_new(void); extern PyObject * diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 25656ff878..8dd21bbf59 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -190,7 +190,7 @@ PyType_stgdict(PyObject *obj) StgDictObject * PyObject_stgdict(PyObject *self) { - PyTypeObject *type = self->ob_type; + PyTypeObject *type = Py_TP(self); if (!type->tp_dict || !PyCStgDict_CheckExact(type->tp_dict)) return NULL; return (StgDictObject *)type->tp_dict; diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index a728a24f6c..89d8dd425c 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -2912,7 +2912,7 @@ _curses_getwin(PyObject *module, PyObject *file) if (!PyBytes_Check(data)) { PyErr_Format(PyExc_TypeError, "f.read() returned %.100s instead of bytes", - data->ob_type->tp_name); + Py_TP(data)->tp_name); Py_DECREF(data); goto error; } diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c index 65761d83d3..f7791df3fb 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -246,7 +246,7 @@ dbm_contains(PyObject *self, PyObject *arg) else if (!PyBytes_Check(arg)) { PyErr_Format(PyExc_TypeError, "dbm key must be bytes or string, not %.100s", - arg->ob_type->tp_name); + Py_TP(arg)->tp_name); return -1; } else { diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 5bce780cb7..e01568fc90 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -2584,7 +2584,7 @@ PyDecType_FromObjectExact(PyTypeObject *type, PyObject *v, PyObject *context) else { PyErr_Format(PyExc_TypeError, "conversion from %s to Decimal is not supported", - v->ob_type->tp_name); + Py_TP(v)->tp_name); return NULL; } } @@ -2633,7 +2633,7 @@ PyDec_FromObject(PyObject *v, PyObject *context) else { PyErr_Format(PyExc_TypeError, "conversion from %s to Decimal is not supported", - v->ob_type->tp_name); + Py_TP(v)->tp_name); return NULL; } } @@ -2696,7 +2696,7 @@ convert_op(int type_err, PyObject **conv, PyObject *v, PyObject *context) if (type_err) { PyErr_Format(PyExc_TypeError, "conversion from %s to Decimal is not supported", - v->ob_type->tp_name); + Py_TP(v)->tp_name); } else { Py_INCREF(Py_NotImplemented); diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 10560040e4..134fa4ef16 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -326,7 +326,7 @@ dbm_contains(PyObject *self, PyObject *arg) else if (!PyBytes_Check(arg)) { PyErr_Format(PyExc_TypeError, "gdbm key must be bytes or string, not %.100s", - arg->ob_type->tp_name); + Py_TP(arg)->tp_name); return -1; } else { diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 0d8a638f40..b28ee48a83 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -533,7 +533,7 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err) /* Otherwise replace the error with caller's error object. */ PyErr_Format(err, "cannot fit '%.200s' into an offset-sized integer", - item->ob_type->tp_name); + Py_TP(item)->tp_name); } finish: diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index a466d3a03a..04335285be 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1045,7 +1045,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, PyErr_Format( PyExc_TypeError, "TextIOWrapper() argument 'errors' must be str or None, not %.50s", - errors->ob_type->tp_name); + Py_TP(errors)->tp_name); return -1; } diff --git a/Modules/_json.c b/Modules/_json.c index 5a9464e34f..476fc92e98 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1652,7 +1652,7 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc, else { PyErr_Format(PyExc_TypeError, "keys must be str, int, float, bool or None, " - "not %.100s", key->ob_type->tp_name); + "not %.100s", Py_TP(key)->tp_name); goto bail; } diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 2de70f5d94..4d604ab86b 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1856,7 +1856,7 @@ fast_save_enter(PicklerObject *self, PyObject *obj) PyErr_Format(PyExc_ValueError, "fast mode: can't pickle cyclic objects " "including object type %.200s at %p", - obj->ob_type->tp_name, obj); + Py_TP(obj)->tp_name, obj); self->fast_nesting = -1; return 0; } diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c index 3d01872322..9ab254e454 100644 --- a/Modules/_sqlite/microprotocols.c +++ b/Modules/_sqlite/microprotocols.c @@ -82,7 +82,7 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) way to get a quotable object to be its instance */ /* look for an adapter in the registry */ - key = Py_BuildValue("(OO)", (PyObject*)obj->ob_type, proto); + key = Py_BuildValue("(OO)", (PyObject*) Py_TP(obj), proto); if (!key) { return NULL; } diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c index b1b8ff3701..75760dd7d9 100644 --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -1856,7 +1856,7 @@ ndarray_subscript(NDArrayObject *self, PyObject *key) type_error: PyErr_Format(PyExc_TypeError, "cannot index memory using \"%.200s\"", - key->ob_type->tp_name); + Py_TP(key)->tp_name); err_occurred: Py_DECREF(nd); return NULL; diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index add642f223..25538b0b7b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -263,7 +263,7 @@ dict_hassplittable(PyObject *self, PyObject *arg) if (!PyDict_Check(arg)) { PyErr_Format(PyExc_TypeError, "dict_hassplittable() argument must be dict, not '%s'", - arg->ob_type->tp_name); + Py_TP(arg)->tp_name); return NULL; } @@ -2375,7 +2375,7 @@ test_thread_state(PyObject *self, PyObject *args) if (!PyCallable_Check(fn)) { PyErr_Format(PyExc_TypeError, "'%s' object is not callable", - fn->ob_type->tp_name); + Py_TP(fn)->tp_name); return NULL; } diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 93d4dbc5f6..8ea17c9c10 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -793,7 +793,7 @@ typedef struct { } PyTclObject; static PyObject *PyTclObject_Type; -#define PyTclObject_Check(v) ((v)->ob_type == (PyTypeObject *) PyTclObject_Type) +#define PyTclObject_Check(v) (Py_TP((v)) == (PyTypeObject *) PyTclObject_Type) static PyObject * newPyTclObject(Tcl_Obj *arg) @@ -1701,7 +1701,7 @@ varname_converter(PyObject *in, void *_out) } PyErr_Format(PyExc_TypeError, "must be str, bytes or Tcl_Obj, not %.50s", - in->ob_type->tp_name); + Py_TP(in)->tp_name); return 0; } diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 22172b043b..7165e459a9 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -1285,7 +1285,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self, PyErr_Format(PyExc_TypeError, "stream function returned a " "non-bytes object (%.100s)", - cres->ob_type->tp_name); + Py_TP(cres)->tp_name); goto errorexit; } diff --git a/Modules/cjkcodecs/multibytecodec.h b/Modules/cjkcodecs/multibytecodec.h index 5b8c22276b..3d37863b53 100644 --- a/Modules/cjkcodecs/multibytecodec.h +++ b/Modules/cjkcodecs/multibytecodec.h @@ -62,7 +62,7 @@ typedef struct { MultibyteCodec *codec; } MultibyteCodecObject; -#define MultibyteCodec_Check(op) ((op)->ob_type == &MultibyteCodec_Type) +#define MultibyteCodec_Check(op) (Py_TP(op) == &MultibyteCodec_Type) #define _MultibyteStatefulCodec_HEAD \ PyObject_HEAD \ diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index e3e290cf97..7a1ffba5d4 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -571,7 +571,7 @@ untrack_dicts(PyGC_Head *head) static int has_legacy_finalizer(PyObject *op) { - return op->ob_type->tp_del != NULL; + return Py_TP(op)->tp_del != NULL; } /* Move the objects in unreachable with tp_del slots into `finalizers`. diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c index 74286ab397..9db36185af 100644 --- a/Modules/grpmodule.c +++ b/Modules/grpmodule.c @@ -111,7 +111,7 @@ grp_getgrgid_impl(PyObject *module, PyObject *id) PyErr_Clear(); if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "group id must be int, not %.200", - id->ob_type->tp_name) < 0) { + Py_TP(id)->tp_name) < 0) { return NULL; } py_int_id = PyNumber_Long(id); diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 38e5f750d5..0dc67dc2b6 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -260,7 +260,7 @@ PyTypeObject PyST_Type = { /* PyST_Type isn't subclassable, so just check ob_type */ -#define PyST_Object_Check(v) ((v)->ob_type == &PyST_Type) +#define PyST_Object_Check(v) (Py_TP((v)) == &PyST_Type) static int parser_compare_nodes(node *left, node *right) diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index c8a01d4e08..869a1bfa37 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1369,7 +1369,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); return -1; } if (v == NULL) { diff --git a/Modules/sha512module.c b/Modules/sha512module.c index d8c846a450..db697c632d 100644 --- a/Modules/sha512module.c +++ b/Modules/sha512module.c @@ -478,7 +478,7 @@ SHA512Type_copy_impl(SHAobject *self) { SHAobject *newobj; - if (((PyObject*)self)->ob_type == &SHA512type) { + if (Py_TP(((PyObject *)self)) == &SHA512type) { if ( (newobj = newSHA512object())==NULL) return NULL; } else { diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 8aadc780ff..f59114db2c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1565,7 +1565,7 @@ idna_converter(PyObject *obj, struct maybe_idna *data) } else { PyErr_Format(PyExc_TypeError, "str, bytes or bytearray expected, not %s", - obj->ob_type->tp_name); + Py_TP(obj)->tp_name); return 0; } if (strlen(data->buf) != len) { diff --git a/Objects/abstract.c b/Objects/abstract.c index 305910c358..c5c972f6c0 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -13,7 +13,7 @@ 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_TP(obj)->tp_name); return NULL; } @@ -37,7 +37,7 @@ PyObject_Type(PyObject *o) return null_error(); } - v = (PyObject *)o->ob_type; + v = (PyObject *) Py_TP(o); Py_INCREF(v); return v; } @@ -52,7 +52,7 @@ PyObject_Size(PyObject *o) return -1; } - m = o->ob_type->tp_as_sequence; + m = Py_TP(o)->tp_as_sequence; if (m && m->sq_length) { Py_ssize_t len = m->sq_length(o); assert(len >= 0 || PyErr_Occurred()); @@ -148,14 +148,14 @@ PyObject_GetItem(PyObject *o, PyObject *key) return null_error(); } - m = o->ob_type->tp_as_mapping; + m = Py_TP(o)->tp_as_mapping; if (m && m->mp_subscript) { PyObject *item = m->mp_subscript(o, key); assert((item != NULL) ^ (PyErr_Occurred() != NULL)); return item; } - if (o->ob_type->tp_as_sequence) { + if (Py_TP(o)->tp_as_sequence) { if (PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); @@ -163,7 +163,7 @@ PyObject_GetItem(PyObject *o, PyObject *key) return NULL; return PySequence_GetItem(o, key_value); } - else if (o->ob_type->tp_as_sequence->sq_item) + else if (Py_TP(o)->tp_as_sequence->sq_item) return type_error("sequence index must " "be integer, not '%.200s'", key); } @@ -193,11 +193,11 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value) null_error(); return -1; } - m = o->ob_type->tp_as_mapping; + m = Py_TP(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_TP(o)->tp_as_sequence) { if (PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); @@ -205,7 +205,7 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value) return -1; return PySequence_SetItem(o, key_value, value); } - else if (o->ob_type->tp_as_sequence->sq_ass_item) { + else if (Py_TP(o)->tp_as_sequence->sq_ass_item) { type_error("sequence index must be " "integer, not '%.200s'", key); return -1; @@ -225,11 +225,11 @@ PyObject_DelItem(PyObject *o, PyObject *key) null_error(); return -1; } - m = o->ob_type->tp_as_mapping; + m = Py_TP(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_TP(o)->tp_as_sequence) { if (PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); @@ -237,7 +237,7 @@ PyObject_DelItem(PyObject *o, PyObject *key) return -1; return PySequence_DelItem(o, key_value); } - else if (o->ob_type->tp_as_sequence->sq_ass_item) { + else if (Py_TP(o)->tp_as_sequence->sq_ass_item) { type_error("sequence index must be " "integer, not '%.200s'", key); return -1; @@ -272,7 +272,7 @@ PyObject_DelItemString(PyObject *o, const char *key) int PyObject_CheckReadBuffer(PyObject *obj) { - PyBufferProcs *pb = obj->ob_type->tp_as_buffer; + PyBufferProcs *pb = Py_TP(obj)->tp_as_buffer; Py_buffer view; if (pb == NULL || @@ -330,7 +330,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, null_error(); return -1; } - pb = obj->ob_type->tp_as_buffer; + pb = Py_TP(obj)->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL || ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) { @@ -350,7 +350,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { - PyBufferProcs *pb = obj->ob_type->tp_as_buffer; + PyBufferProcs *pb = Py_TP(obj)->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL) { PyErr_Format(PyExc_TypeError, @@ -755,9 +755,9 @@ done: int PyNumber_Check(PyObject *o) { - return o && o->ob_type->tp_as_number && - (o->ob_type->tp_as_number->nb_int || - o->ob_type->tp_as_number->nb_float); + return o && Py_TP(o)->tp_as_number && + (Py_TP(o)->tp_as_number->nb_int || + Py_TP(o)->tp_as_number->nb_float); } /* Binary operators */ @@ -785,16 +785,16 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot) 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_TP(v)->tp_as_number != NULL) + slotv = NB_BINOP(Py_TP(v)->tp_as_number, op_slot); + if (Py_TP(w) != Py_TP(v) && + Py_TP(w)->tp_as_number != NULL) { + slotw = NB_BINOP(Py_TP(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_TP(w), Py_TP(v))) { x = slotw(v, w); if (x != Py_NotImplemented) return x; @@ -822,8 +822,8 @@ binop_type_error(PyObject *v, PyObject *w, const char *op_name) "unsupported operand type(s) for %.100s: " "'%.100s' and '%.100s'", op_name, - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TP(v)->tp_name, + Py_TP(w)->tp_name); return NULL; } @@ -843,8 +843,8 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name) "'%.100s' and '%.100s'. Did you mean \"print(, " "file=)\"?", op_name, - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TP(v)->tp_name, + Py_TP(w)->tp_name); return NULL; } @@ -874,18 +874,18 @@ ternary_op(PyObject *v, ternaryfunc slotw = NULL; ternaryfunc slotz = NULL; - mv = v->ob_type->tp_as_number; - mw = w->ob_type->tp_as_number; + mv = Py_TP(v)->tp_as_number; + mw = Py_TP(w)->tp_as_number; if (mv != NULL) slotv = NB_TERNOP(mv, op_slot); - if (w->ob_type != v->ob_type && + if (Py_TP(w) != Py_TP(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_TP(w), Py_TP(v))) { x = slotw(v, w, z); if (x != Py_NotImplemented) return x; @@ -903,7 +903,7 @@ ternary_op(PyObject *v, return x; Py_DECREF(x); /* can't do it */ } - mz = z->ob_type->tp_as_number; + mz = Py_TP(z)->tp_as_number; if (mz != NULL) { slotz = NB_TERNOP(mz, op_slot); if (slotz == slotv || slotz == slotw) @@ -921,16 +921,16 @@ ternary_op(PyObject *v, PyExc_TypeError, "unsupported operand type(s) for ** or pow(): " "'%.100s' and '%.100s'", - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TP(v)->tp_name, + Py_TP(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_TP(v)->tp_name, + Py_TP(w)->tp_name, + Py_TP(z)->tp_name); return NULL; } @@ -953,7 +953,7 @@ PyNumber_Add(PyObject *v, PyObject *w) { 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_TP(v)->tp_as_sequence; Py_DECREF(result); if (m && m->sq_concat) { return (*m->sq_concat)(v, w); @@ -984,8 +984,8 @@ PyNumber_Multiply(PyObject *v, PyObject *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_TP(v)->tp_as_sequence; + PySequenceMethods *mw = Py_TP(w)->tp_as_sequence; Py_DECREF(result); if (mv && mv->sq_repeat) { return sequence_repeat(mv->sq_repeat, v, w); @@ -1047,7 +1047,7 @@ PyNumber_Power(PyObject *v, PyObject *w, PyObject *z) 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_TP(v)->tp_as_number; if (mv != NULL) { binaryfunc slot = NB_BINOP(mv, iop_slot); if (slot) { @@ -1107,7 +1107,7 @@ PyNumber_InPlaceAdd(PyObject *v, PyObject *w) 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_TP(v)->tp_as_sequence; Py_DECREF(result); if (m != NULL) { binaryfunc f = NULL; @@ -1129,8 +1129,8 @@ PyNumber_InPlaceMultiply(PyObject *v, PyObject *w) 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_TP(v)->tp_as_sequence; + PySequenceMethods *mw = Py_TP(w)->tp_as_sequence; Py_DECREF(result); if (mv != NULL) { f = mv->sq_inplace_repeat; @@ -1168,8 +1168,8 @@ PyNumber_InPlaceRemainder(PyObject *v, PyObject *w) 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_TP(v)->tp_as_number && + Py_TP(v)->tp_as_number->nb_inplace_power != NULL) { return ternary_op(v, w, z, NB_SLOT(nb_inplace_power), "**="); } else { @@ -1189,7 +1189,7 @@ PyNumber_Negative(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TP(o)->tp_as_number; if (m && m->nb_negative) return (*m->nb_negative)(o); @@ -1205,7 +1205,7 @@ PyNumber_Positive(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TP(o)->tp_as_number; if (m && m->nb_positive) return (*m->nb_positive)(o); @@ -1221,7 +1221,7 @@ PyNumber_Invert(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TP(o)->tp_as_number; if (m && m->nb_invert) return (*m->nb_invert)(o); @@ -1237,7 +1237,7 @@ PyNumber_Absolute(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TP(o)->tp_as_number; if (m && m->nb_absolute) return m->nb_absolute(o); @@ -1249,8 +1249,8 @@ PyNumber_Absolute(PyObject *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_TP(obj)->tp_as_number != NULL && + Py_TP(obj)->tp_as_number->nb_index != NULL; } /* Return a Python int from the object item. @@ -1272,16 +1272,16 @@ PyNumber_Index(PyObject *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_TP(item)->tp_name); return NULL; } - result = item->ob_type->tp_as_number->nb_index(item); + result = Py_TP(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_TP(result)->tp_name); Py_DECREF(result); return NULL; } @@ -1290,7 +1290,7 @@ PyNumber_Index(PyObject *item) "__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_TP(result)->tp_name)) { Py_DECREF(result); return NULL; } @@ -1335,7 +1335,7 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) /* 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_TP(item)->tp_name); } finish: @@ -1361,7 +1361,7 @@ PyNumber_Long(PyObject *o) Py_INCREF(o); return o; } - m = o->ob_type->tp_as_number; + m = Py_TP(o)->tp_as_number; if (m && m->nb_int) { /* This should include subclasses of int */ result = (PyObject *)_PyLong_FromNbInt(o); if (result != NULL && !PyLong_CheckExact(result)) { @@ -1382,12 +1382,12 @@ PyNumber_Long(PyObject *o) } /* __trunc__ is specified to return an Integral type, but int() needs to return an int. */ - m = result->ob_type->tp_as_number; + m = Py_TP(result)->tp_as_number; if (m == NULL || m->nb_int == NULL) { PyErr_Format( PyExc_TypeError, "__trunc__ returned non-Integral (type %.200s)", - result->ob_type->tp_name); + Py_TP(result)->tp_name); Py_DECREF(result); return NULL; } @@ -1449,7 +1449,7 @@ PyNumber_Float(PyObject *o) Py_INCREF(o); return o; } - m = o->ob_type->tp_as_number; + m = Py_TP(o)->tp_as_number; if (m && m->nb_float) { /* This should include subclasses of float */ PyObject *res = m->nb_float(o); double val; @@ -1459,7 +1459,7 @@ PyNumber_Float(PyObject *o) 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_TP(o)->tp_name, Py_TP(res)->tp_name); Py_DECREF(res); return NULL; } @@ -1468,7 +1468,7 @@ PyNumber_Float(PyObject *o) "%.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_TP(o)->tp_name, Py_TP(res)->tp_name)) { Py_DECREF(res); return NULL; } @@ -1510,8 +1510,8 @@ PySequence_Check(PyObject *s) { if (PyDict_Check(s)) return 0; - return s->ob_type->tp_as_sequence && - s->ob_type->tp_as_sequence->sq_item != NULL; + return Py_TP(s)->tp_as_sequence && + Py_TP(s)->tp_as_sequence->sq_item != NULL; } Py_ssize_t @@ -1524,14 +1524,14 @@ PySequence_Size(PyObject *s) return -1; } - m = s->ob_type->tp_as_sequence; + m = Py_TP(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_TP(s)->tp_as_mapping && Py_TP(s)->tp_as_mapping->mp_length) { type_error("%.200s is not a sequence", s); return -1; } @@ -1556,7 +1556,7 @@ PySequence_Concat(PyObject *s, PyObject *o) return null_error(); } - m = s->ob_type->tp_as_sequence; + m = Py_TP(s)->tp_as_sequence; if (m && m->sq_concat) return m->sq_concat(s, o); @@ -1581,7 +1581,7 @@ PySequence_Repeat(PyObject *o, Py_ssize_t count) return null_error(); } - m = o->ob_type->tp_as_sequence; + m = Py_TP(o)->tp_as_sequence; if (m && m->sq_repeat) return m->sq_repeat(o, count); @@ -1611,7 +1611,7 @@ PySequence_InPlaceConcat(PyObject *s, PyObject *o) return null_error(); } - m = s->ob_type->tp_as_sequence; + m = Py_TP(s)->tp_as_sequence; if (m && m->sq_inplace_concat) return m->sq_inplace_concat(s, o); if (m && m->sq_concat) @@ -1636,7 +1636,7 @@ PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count) return null_error(); } - m = o->ob_type->tp_as_sequence; + m = Py_TP(o)->tp_as_sequence; if (m && m->sq_inplace_repeat) return m->sq_inplace_repeat(o, count); if (m && m->sq_repeat) @@ -1666,7 +1666,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return null_error(); } - m = s->ob_type->tp_as_sequence; + m = Py_TP(s)->tp_as_sequence; if (m && m->sq_item) { if (i < 0) { if (m->sq_length) { @@ -1681,7 +1681,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return m->sq_item(s, i); } - if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_subscript) { + if (Py_TP(s)->tp_as_mapping && Py_TP(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); @@ -1696,7 +1696,7 @@ PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2) return null_error(); } - mp = s->ob_type->tp_as_mapping; + mp = Py_TP(s)->tp_as_mapping; if (mp && mp->mp_subscript) { PyObject *res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -1720,7 +1720,7 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) return -1; } - m = s->ob_type->tp_as_sequence; + m = Py_TP(s)->tp_as_sequence; if (m && m->sq_ass_item) { if (i < 0) { if (m->sq_length) { @@ -1735,7 +1735,7 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) 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_TP(s)->tp_as_mapping && Py_TP(s)->tp_as_mapping->mp_ass_subscript) { type_error("%.200s is not a sequence", s); return -1; } @@ -1753,7 +1753,7 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) return -1; } - m = s->ob_type->tp_as_sequence; + m = Py_TP(s)->tp_as_sequence; if (m && m->sq_ass_item) { if (i < 0) { if (m->sq_length) { @@ -1768,7 +1768,7 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) 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_TP(s)->tp_as_mapping && Py_TP(s)->tp_as_mapping->mp_ass_subscript) { type_error("%.200s is not a sequence", s); return -1; } @@ -1786,7 +1786,7 @@ PySequence_SetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2, PyObject *o) return -1; } - mp = s->ob_type->tp_as_mapping; + mp = Py_TP(s)->tp_as_mapping; if (mp && mp->mp_ass_subscript) { int res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -1811,7 +1811,7 @@ PySequence_DelSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2) return -1; } - mp = s->ob_type->tp_as_mapping; + mp = Py_TP(s)->tp_as_mapping; if (mp && mp->mp_ass_subscript) { int res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -2061,7 +2061,7 @@ int PySequence_Contains(PyObject *seq, PyObject *ob) { Py_ssize_t result; - PySequenceMethods *sqm = seq->ob_type->tp_as_sequence; + PySequenceMethods *sqm = Py_TP(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); @@ -2087,8 +2087,8 @@ PySequence_Index(PyObject *s, PyObject *o) int PyMapping_Check(PyObject *o) { - return o && o->ob_type->tp_as_mapping && - o->ob_type->tp_as_mapping->mp_subscript; + return o && Py_TP(o)->tp_as_mapping && + Py_TP(o)->tp_as_mapping->mp_subscript; } Py_ssize_t @@ -2101,14 +2101,14 @@ PyMapping_Size(PyObject *o) return -1; } - m = o->ob_type->tp_as_mapping; + m = Py_TP(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_TP(o)->tp_as_sequence && Py_TP(o)->tp_as_sequence->sq_length) { type_error("%.200s is not a mapping", o); return -1; } @@ -2368,7 +2368,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls) 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_TP(inst)) && PyType_Check(icls)) { retval = PyType_IsSubtype( (PyTypeObject *)icls, (PyTypeObject *)cls); @@ -2541,7 +2541,7 @@ _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls) PyObject * PyObject_GetIter(PyObject *o) { - PyTypeObject *t = o->ob_type; + PyTypeObject *t = Py_TP(o); getiterfunc f; f = t->tp_iter; @@ -2556,7 +2556,7 @@ PyObject_GetIter(PyObject *o) PyErr_Format(PyExc_TypeError, "iter() returned non-iterator " "of type '%.100s'", - res->ob_type->tp_name); + Py_TP(res)->tp_name); Py_DECREF(res); res = NULL; } @@ -2568,8 +2568,8 @@ PyObject_GetIter(PyObject *o) int PyIter_Check(PyObject *obj) { - return obj->ob_type->tp_iternext != NULL && - obj->ob_type->tp_iternext != &_PyObject_NextNotImplemented; + return Py_TP(obj)->tp_iternext != NULL && + Py_TP(obj)->tp_iternext != &_PyObject_NextNotImplemented; } /* Return next item. @@ -2583,7 +2583,7 @@ PyObject * PyIter_Next(PyObject *iter) { PyObject *result; - result = (*iter->ob_type->tp_iternext)(iter); + result = (*Py_TP(iter)->tp_iternext)(iter); if (result == NULL && PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index fb344c1896..6c8a25dd50 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2782,7 +2782,7 @@ PyBytes_FromObject(PyObject *x) PyErr_Format(PyExc_TypeError, "cannot convert '%.200s' object to bytes", - x->ob_type->tp_name); + Py_TP(x)->tp_name); return NULL; } diff --git a/Objects/call.c b/Objects/call.c index 1937a8b227..963355efc8 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -105,10 +105,10 @@ _PyObject_FastCallDict(PyObject *callable, PyObject *const *args, Py_ssize_t nar ternaryfunc call; /* Slow-path: build a temporary tuple */ - call = callable->ob_type->tp_call; + call = Py_TP(callable)->tp_call; if (call == NULL) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable", - callable->ob_type->tp_name); + Py_TP(callable)->tp_name); return NULL; } @@ -167,10 +167,10 @@ _PyObject_FastCallKeywords(PyObject *callable, PyObject *const *stack, Py_ssize_ nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); assert((nargs == 0 && nkwargs == 0) || stack != NULL); - call = callable->ob_type->tp_call; + call = Py_TP(callable)->tp_call; if (call == NULL) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable", - callable->ob_type->tp_name); + Py_TP(callable)->tp_name); return NULL; } @@ -232,10 +232,10 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs) return PyCFunction_Call(callable, args, kwargs); } else { - call = callable->ob_type->tp_call; + call = Py_TP(callable)->tp_call; if (call == NULL) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable", - callable->ob_type->tp_name); + Py_TP(callable)->tp_name); return NULL; } diff --git a/Objects/cellobject.c b/Objects/cellobject.c index 7b05e61ce4..0c45ddd94e 100644 --- a/Objects/cellobject.c +++ b/Objects/cellobject.c @@ -80,7 +80,7 @@ cell_repr(PyCellObject *op) return PyUnicode_FromFormat("", op); return PyUnicode_FromFormat("", - op, op->ob_ref->ob_type->tp_name, + op, Py_TP(op->ob_ref)->tp_name, op->ob_ref); } diff --git a/Objects/classobject.c b/Objects/classobject.c index a193ada6d4..34f9844a1c 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -136,7 +136,7 @@ static PyObject * method_getattro(PyObject *obj, PyObject *name) { PyMethodObject *im = (PyMethodObject *)obj; - PyTypeObject *tp = obj->ob_type; + PyTypeObject *tp = Py_TP(obj); PyObject *descr = NULL; { @@ -148,9 +148,9 @@ method_getattro(PyObject *obj, PyObject *name) } if (descr != NULL) { - descrgetfunc f = TP_DESCR_GET(descr->ob_type); + descrgetfunc f = TP_DESCR_GET(Py_TP(descr)); if (f != NULL) - return f(descr, obj, (PyObject *)obj->ob_type); + return f(descr, obj, (PyObject *) Py_TP(obj)); else { Py_INCREF(descr); return descr; @@ -447,7 +447,7 @@ static PyGetSetDef instancemethod_getset[] = { static PyObject * instancemethod_getattro(PyObject *self, PyObject *name) { - PyTypeObject *tp = self->ob_type; + PyTypeObject *tp = Py_TP(self); PyObject *descr = NULL; if (tp->tp_dict == NULL) { @@ -457,9 +457,9 @@ instancemethod_getattro(PyObject *self, PyObject *name) descr = _PyType_Lookup(tp, name); if (descr != NULL) { - descrgetfunc f = TP_DESCR_GET(descr->ob_type); + descrgetfunc f = TP_DESCR_GET(Py_TP(descr)); if (f != NULL) - return f(descr, self, (PyObject *)self->ob_type); + return f(descr, self, (PyObject *) Py_TP(self)); else { Py_INCREF(descr); return descr; diff --git a/Objects/codeobject.c b/Objects/codeobject.c index cedf11ee8a..9be92a83dd 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -316,7 +316,7 @@ validate_and_copy_tuple(PyObject *tup) PyExc_TypeError, "name tuples must contain only " "strings, not '%.500s'", - item->ob_type->tp_name); + Py_TP(item)->tp_name); Py_DECREF(newtuple); return NULL; } diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 6e3d47b62d..2c0bfe27f4 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -289,7 +289,7 @@ try_complex_special_method(PyObject *op) if (!PyComplex_Check(res)) { PyErr_Format(PyExc_TypeError, "__complex__ returned non-complex (type %.200s)", - res->ob_type->tp_name); + Py_TP(res)->tp_name); Py_DECREF(res); return NULL; } @@ -298,7 +298,7 @@ try_complex_special_method(PyObject *op) "__complex__ returned non-complex (type %.200s). " "The ability to return an instance of a strict subclass of complex " "is deprecated, and may be removed in a future version of Python.", - res->ob_type->tp_name)) { + Py_TP(res)->tp_name)) { Py_DECREF(res); return NULL; } @@ -346,7 +346,7 @@ PyComplex_AsCComplex(PyObject *op) static void complex_dealloc(PyObject *op) { - op->ob_type->tp_free(op); + Py_TP(op)->tp_free(op); } static PyObject * @@ -989,7 +989,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) return NULL; } - nbr = r->ob_type->tp_as_number; + nbr = Py_TP(r)->tp_as_number; if (nbr == NULL || nbr->nb_float == NULL) { PyErr_Format(PyExc_TypeError, "complex() first argument must be a string or a number, " @@ -1001,7 +1001,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) return NULL; } if (i != NULL) { - nbi = i->ob_type->tp_as_number; + nbi = Py_TP(i)->tp_as_number; if (nbi == NULL || nbi->nb_float == NULL) { PyErr_Format(PyExc_TypeError, "complex() second argument must be a number, " diff --git a/Objects/descrobject.c b/Objects/descrobject.c index b1bee904ec..5ada577ab3 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -80,7 +80,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyObject **pres) "doesn't apply to '%s' object", descr_name((PyDescrObject *)descr), "?", descr->d_type->tp_name, - obj->ob_type->tp_name); + Py_TP(obj)->tp_name); *pres = NULL; return 1; } @@ -93,7 +93,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) /* Ensure a valid type. Class methods ignore obj. */ if (type == NULL) { if (obj != NULL) - type = (PyObject *)obj->ob_type; + type = (PyObject *) Py_TP(obj); else { /* Wot - no type?! */ PyErr_Format(PyExc_TypeError, @@ -110,7 +110,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) "needs a type, not a '%s' as arg 2", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - type->ob_type->tp_name); + Py_TP(type)->tp_name); return NULL; } if (!PyType_IsSubtype((PyTypeObject *)type, PyDescr_TYPE(descr))) { @@ -182,7 +182,7 @@ descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value, "doesn't apply to '%.100s' object", descr_name(descr), "?", descr->d_type->tp_name, - obj->ob_type->tp_name); + Py_TP(obj)->tp_name); *pres = -1; return 1; } @@ -242,7 +242,7 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwargs) "but received a '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - self->ob_type->tp_name); + Py_TP(self)->tp_name); return NULL; } @@ -281,7 +281,7 @@ _PyMethodDescr_FastCallKeywords(PyObject *descrobj, "but received a '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - self->ob_type->tp_name); + Py_TP(self)->tp_name); return NULL; } @@ -316,7 +316,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, "but received a '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - self->ob_type->tp_name); + Py_TP(self)->tp_name); return NULL; } if (!PyType_IsSubtype((PyTypeObject *)self, PyDescr_TYPE(descr))) { @@ -326,7 +326,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, "but received '%.100s", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - self->ob_type->tp_name); + Py_TP(self)->tp_name); return NULL; } @@ -383,7 +383,7 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) "but received a '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - self->ob_type->tp_name); + Py_TP(self)->tp_name); return NULL; } @@ -1078,7 +1078,7 @@ wrapper_repr(wrapperobject *wp) { return PyUnicode_FromFormat("", wp->descr->d_base->name, - wp->self->ob_type->tp_name, + Py_TP(wp->self)->tp_name, wp->self); } @@ -1325,7 +1325,7 @@ property_dealloc(PyObject *self) Py_XDECREF(gs->prop_set); Py_XDECREF(gs->prop_del); Py_XDECREF(gs->prop_doc); - self->ob_type->tp_free(self); + Py_TP(self)->tp_free(self); } static PyObject * diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 413557d667..6a2b980760 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -3747,7 +3747,7 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type) /* XXX Get rid of this restriction later */ PyErr_Format(PyExc_TypeError, "%s() requires a dict argument, not '%s'", - type->tp_name, dict->ob_type->tp_name); + type->tp_name, Py_TP(dict)->tp_name); return NULL; } dv = PyObject_GC_New(_PyDictViewObject, type); diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 67f9e5d5b4..4cd14fef55 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -247,7 +247,7 @@ PyFloat_AsDouble(PyObject *op) nb = Py_TYPE(op)->tp_as_number; if (nb == NULL || nb->nb_float == NULL) { PyErr_Format(PyExc_TypeError, "must be real number, not %.50s", - op->ob_type->tp_name); + Py_TP(op)->tp_name); return -1; } @@ -259,7 +259,7 @@ PyFloat_AsDouble(PyObject *op) if (!PyFloat_Check(res)) { PyErr_Format(PyExc_TypeError, "%.50s.__float__ returned non-float (type %.50s)", - op->ob_type->tp_name, res->ob_type->tp_name); + Py_TP(op)->tp_name, Py_TP(res)->tp_name); Py_DECREF(res); return -1; } @@ -267,7 +267,7 @@ PyFloat_AsDouble(PyObject *op) "%.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.", - op->ob_type->tp_name, res->ob_type->tp_name)) { + Py_TP(op)->tp_name, Py_TP(res)->tp_name)) { Py_DECREF(res); return -1; } diff --git a/Objects/funcobject.c b/Objects/funcobject.c index c2f79c05db..6a7b463b7d 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -189,7 +189,7 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure) else { PyErr_Format(PyExc_SystemError, "expected tuple for closure, got '%.100s'", - closure->ob_type->tp_name); + Py_TP(closure)->tp_name); return -1; } Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); @@ -497,7 +497,7 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, if (!PyCell_Check(o)) { return PyErr_Format(PyExc_TypeError, "arg 5 (closure) expected cell, found %s", - o->ob_type->tp_name); + Py_TP(o)->tp_name); } } } diff --git a/Objects/listobject.c b/Objects/listobject.c index 3d4a187f69..91454d7047 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -490,7 +490,7 @@ list_concat(PyListObject *a, PyObject *bb) if (!PyList_Check(bb)) { PyErr_Format(PyExc_TypeError, "can only concatenate list (not \"%.200s\") to list", - bb->ob_type->tp_name); + Py_TP(bb)->tp_name); return NULL; } #define b ((PyListObject *)bb) @@ -889,7 +889,7 @@ list_extend(PyListObject *self, PyObject *iterable) it = PyObject_GetIter(iterable); if (it == NULL) return NULL; - iternext = *it->ob_type->tp_iternext; + iternext = *Py_TP(it)->tp_iternext; /* Guess a result list size. */ n = PyObject_LengthHint(iterable, 8); @@ -2016,7 +2016,7 @@ unsafe_object_compare(PyObject *v, PyObject *w, MergeState *ms) PyObject *res_obj; int res; /* No assumptions, because we check first: */ - if (v->ob_type->tp_richcompare != ms->key_richcompare) + if (Py_TP(v)->tp_richcompare != ms->key_richcompare) return PyObject_RichCompareBool(v, w, Py_LT); assert(ms->key_richcompare != NULL); @@ -2053,8 +2053,8 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms) int res; /* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyUnicode_Type); + assert(Py_TP(v) == Py_TP(w)); + assert(Py_TP(v) == &PyUnicode_Type); assert(PyUnicode_KIND(v) == PyUnicode_KIND(w)); assert(PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND); @@ -2076,8 +2076,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms) PyLongObject *vl, *wl; sdigit v0, w0; int res; /* Modified from Objects/longobject.c:long_compare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyLong_Type); + assert(Py_TP(v) == Py_TP(w)); + assert(Py_TP(v) == &PyLong_Type); assert(Py_ABS(Py_SIZE(v)) <= 1); assert(Py_ABS(Py_SIZE(w)) <= 1); @@ -2104,8 +2104,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, MergeState *ms) int res; /* Modified from Objects/floatobject.c:float_richcompare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyFloat_Type); + assert(Py_TP(v) == Py_TP(w)); + assert(Py_TP(v) == &PyFloat_Type); res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w); assert(res == PyObject_RichCompareBool(v, w, Py_LT)); @@ -2126,8 +2126,8 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms) int k; /* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyTuple_Type); + assert(Py_TP(v) == Py_TP(w)); + assert(Py_TP(v) == &PyTuple_Type); assert(Py_SIZE(v) > 0); assert(Py_SIZE(w) > 0); @@ -2241,12 +2241,12 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) * set ms appropriately. */ if (saved_ob_size > 1) { /* Assume the first element is representative of the whole list. */ - int keys_are_in_tuples = (lo.keys[0]->ob_type == &PyTuple_Type && + int keys_are_in_tuples = (Py_TP(lo.keys[0]) == &PyTuple_Type && Py_SIZE(lo.keys[0]) > 0); PyTypeObject* key_type = (keys_are_in_tuples ? - PyTuple_GET_ITEM(lo.keys[0], 0)->ob_type : - lo.keys[0]->ob_type); + Py_TP(PyTuple_GET_ITEM(lo.keys[0], 0)) : + Py_TP(lo.keys[0])); int keys_are_all_same_type = 1; int strings_are_latin = 1; @@ -2257,7 +2257,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) for (i=0; i < saved_ob_size; i++) { if (keys_are_in_tuples && - !(lo.keys[i]->ob_type == &PyTuple_Type && Py_SIZE(lo.keys[i]) != 0)) { + !(Py_TP(lo.keys[i]) == &PyTuple_Type && Py_SIZE(lo.keys[i]) != 0)) { keys_are_in_tuples = 0; keys_are_all_same_type = 0; break; @@ -2270,7 +2270,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) PyTuple_GET_ITEM(lo.keys[i], 0) : lo.keys[i]); - if (key->ob_type != key_type) { + if (Py_TP(key) != key_type) { keys_are_all_same_type = 0; break; } @@ -2777,7 +2777,7 @@ list_subscript(PyListObject* self, PyObject* item) else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - item->ob_type->tp_name); + Py_TP(item)->tp_name); return NULL; } } @@ -2939,7 +2939,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - item->ob_type->tp_name); + Py_TP(item)->tp_name); return -1; } } diff --git a/Objects/longobject.c b/Objects/longobject.c index 399d354270..9d1a0022d0 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -168,7 +168,7 @@ _PyLong_FromNbInt(PyObject *integral) if (!PyLong_Check(result)) { PyErr_Format(PyExc_TypeError, "__int__ returned non-int (type %.200s)", - result->ob_type->tp_name); + Py_TP(result)->tp_name); Py_DECREF(result); return NULL; } @@ -177,7 +177,7 @@ _PyLong_FromNbInt(PyObject *integral) "__int__ 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_TP(result)->tp_name)) { Py_DECREF(result); return NULL; } diff --git a/Objects/methodobject.c b/Objects/methodobject.c index a7042ca39e..3a7fd15b13 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -217,7 +217,7 @@ meth_repr(PyCFunctionObject *m) m->m_ml->ml_name); return PyUnicode_FromFormat("", m->m_ml->ml_name, - m->m_self->ob_type->tp_name, + Py_TP(m->m_self)->tp_name, m->m_self); } diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index 0b90269384..7b357fb466 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -73,7 +73,7 @@ namespace_repr(PyObject *ns) const char * name; name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace" - : ns->ob_type->tp_name; + : Py_TP(ns)->tp_name; i = Py_ReprEnter(ns); if (i != 0) { diff --git a/Objects/object.c b/Objects/object.c index 6498756c92..1bcdb4692e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -386,7 +386,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) else { PyErr_Format(PyExc_TypeError, "str() or repr() returned '%.100s'", - s->ob_type->tp_name); + Py_TP(s)->tp_name); ret = -1; } Py_XDECREF(s); @@ -455,7 +455,7 @@ PyObject_Repr(PyObject *v) return PyUnicode_FromString(""); if (Py_TYPE(v)->tp_repr == NULL) return PyUnicode_FromFormat("<%s object at %p>", - v->ob_type->tp_name, v); + Py_TP(v)->tp_name, v); #ifdef Py_DEBUG /* PyObject_Repr() must not be called with an exception set, @@ -468,14 +468,14 @@ PyObject_Repr(PyObject *v) infinitely. */ if (Py_EnterRecursiveCall(" while getting the repr of an object")) return NULL; - res = (*v->ob_type->tp_repr)(v); + res = (*Py_TP(v)->tp_repr)(v); Py_LeaveRecursiveCall(); if (res == NULL) return NULL; if (!PyUnicode_Check(res)) { PyErr_Format(PyExc_TypeError, "__repr__ returned non-string (type %.200s)", - res->ob_type->tp_name); + Py_TP(res)->tp_name); Py_DECREF(res); return NULL; } @@ -645,22 +645,22 @@ do_richcompare(PyObject *v, PyObject *w, int op) PyObject *res; int checked_reverse_op = 0; - if (v->ob_type != w->ob_type && - PyType_IsSubtype(w->ob_type, v->ob_type) && - (f = w->ob_type->tp_richcompare) != NULL) { + if (Py_TP(v) != Py_TP(w) && + PyType_IsSubtype(Py_TP(w), Py_TP(v)) && + (f = Py_TP(w)->tp_richcompare) != NULL) { checked_reverse_op = 1; res = (*f)(w, v, _Py_SwappedOp[op]); if (res != Py_NotImplemented) return res; Py_DECREF(res); } - if ((f = v->ob_type->tp_richcompare) != NULL) { + if ((f = Py_TP(v)->tp_richcompare) != NULL) { res = (*f)(v, w, op); if (res != Py_NotImplemented) return res; Py_DECREF(res); } - if (!checked_reverse_op && (f = w->ob_type->tp_richcompare) != NULL) { + if (!checked_reverse_op && (f = Py_TP(w)->tp_richcompare) != NULL) { res = (*f)(w, v, _Py_SwappedOp[op]); if (res != Py_NotImplemented) return res; @@ -679,8 +679,8 @@ do_richcompare(PyObject *v, PyObject *w, int op) PyErr_Format(PyExc_TypeError, "'%s' not supported between instances of '%.100s' and '%.100s'", opstrings[op], - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TP(v)->tp_name, + Py_TP(w)->tp_name); return NULL; } Py_INCREF(res); @@ -866,7 +866,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); return NULL; } if (tp->tp_getattro != NULL) @@ -891,7 +891,7 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); *result = NULL; return -1; } @@ -967,7 +967,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); return -1; } Py_INCREF(name); @@ -1109,9 +1109,9 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) (Py_TYPE(descr) == &PyMethodDescr_Type)) { meth_found = 1; } else { - f = descr->ob_type->tp_descr_get; + f = Py_TP(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { - *method = f(descr, obj, (PyObject *)obj->ob_type); + *method = f(descr, obj, (PyObject *) Py_TP(obj)); Py_DECREF(descr); return 0; } @@ -1176,7 +1176,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, if (!PyUnicode_Check(name)){ PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); return NULL; } Py_INCREF(name); @@ -1191,9 +1191,9 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, f = NULL; if (descr != NULL) { Py_INCREF(descr); - f = descr->ob_type->tp_descr_get; + f = Py_TP(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { - res = f(descr, obj, (PyObject *)obj->ob_type); + res = f(descr, obj, (PyObject *) Py_TP(obj)); if (res == NULL && suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); @@ -1280,7 +1280,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, if (!PyUnicode_Check(name)){ PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); return -1; } @@ -1293,7 +1293,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, if (descr != NULL) { Py_INCREF(descr); - f = descr->ob_type->tp_descr_set; + f = Py_TP(descr)->tp_descr_set; if (f != NULL) { res = f(descr, obj, value); goto done; @@ -1378,15 +1378,15 @@ PyObject_IsTrue(PyObject *v) return 0; if (v == Py_None) return 0; - else if (v->ob_type->tp_as_number != NULL && - v->ob_type->tp_as_number->nb_bool != NULL) - res = (*v->ob_type->tp_as_number->nb_bool)(v); - else if (v->ob_type->tp_as_mapping != NULL && - v->ob_type->tp_as_mapping->mp_length != NULL) - res = (*v->ob_type->tp_as_mapping->mp_length)(v); - else if (v->ob_type->tp_as_sequence != NULL && - v->ob_type->tp_as_sequence->sq_length != NULL) - res = (*v->ob_type->tp_as_sequence->sq_length)(v); + else if (Py_TP(v)->tp_as_number != NULL && + Py_TP(v)->tp_as_number->nb_bool != NULL) + res = (*Py_TP(v)->tp_as_number->nb_bool)(v); + else if (Py_TP(v)->tp_as_mapping != NULL && + Py_TP(v)->tp_as_mapping->mp_length != NULL) + res = (*Py_TP(v)->tp_as_mapping->mp_length)(v); + else if (Py_TP(v)->tp_as_sequence != NULL && + Py_TP(v)->tp_as_sequence->sq_length != NULL) + res = (*Py_TP(v)->tp_as_sequence->sq_length)(v); else return 1; /* if it is negative, it should be either -1 or -2 */ @@ -1413,7 +1413,7 @@ PyCallable_Check(PyObject *x) { if (x == NULL) return 0; - return x->ob_type->tp_call != NULL; + return Py_TP(x)->tp_call != NULL; } diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 2b00a17425..ef85b46877 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -614,7 +614,7 @@ range_subscript(rangeobject* self, PyObject* item) } PyErr_Format(PyExc_TypeError, "range indices must be integers or slices, not %.200s", - item->ob_type->tp_name); + Py_TP(item)->tp_name); return NULL; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index b9e69bf1bd..1b2145cb74 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3150,7 +3150,7 @@ type_getattro(PyTypeObject *type, PyObject *name) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TP(name)->tp_name); return NULL; } @@ -3792,12 +3792,12 @@ object_richcompare(PyObject *self, PyObject *other, int op) case Py_NE: /* By default, __ne__() delegates to __eq__() and inverts the result, unless the latter returns NotImplemented. */ - if (self->ob_type->tp_richcompare == NULL) { + if (Py_TP(self)->tp_richcompare == NULL) { res = Py_NotImplemented; Py_INCREF(res); break; } - res = (*self->ob_type->tp_richcompare)(self, other, Py_EQ); + res = (*Py_TP(self)->tp_richcompare)(self, other, Py_EQ); if (res != NULL && res != Py_NotImplemented) { int ok = PyObject_IsTrue(res); Py_DECREF(res); @@ -4114,7 +4114,7 @@ _PyObject_GetState(PyObject *obj, int required) if (getstate == NULL) { PyObject *slotnames; - if (required && obj->ob_type->tp_itemsize) { + if (required && Py_TP(obj)->tp_itemsize) { PyErr_Format(PyExc_TypeError, "can't pickle %.200s objects", Py_TYPE(obj)->tp_name); @@ -4147,13 +4147,13 @@ _PyObject_GetState(PyObject *obj, int required) assert(slotnames == Py_None || PyList_Check(slotnames)); if (required) { Py_ssize_t basicsize = PyBaseObject_Type.tp_basicsize; - if (obj->ob_type->tp_dictoffset) + if (Py_TP(obj)->tp_dictoffset) basicsize += sizeof(PyObject *); - if (obj->ob_type->tp_weaklistoffset) + if (Py_TP(obj)->tp_weaklistoffset) basicsize += sizeof(PyObject *); if (slotnames != Py_None) basicsize += sizeof(PyObject *) * PyList_GET_SIZE(slotnames); - if (obj->ob_type->tp_basicsize > basicsize) { + if (Py_TP(obj)->tp_basicsize > basicsize) { Py_DECREF(slotnames); Py_DECREF(state); PyErr_Format(PyExc_TypeError, @@ -4626,7 +4626,7 @@ object___format___impl(PyObject *self, PyObject *format_spec) if (PyUnicode_GET_LENGTH(format_spec) > 0) { PyErr_Format(PyExc_TypeError, "unsupported format string passed to %.200s.__format__", - self->ob_type->tp_name); + Py_TP(self)->tp_name); return NULL; } return PyObject_Str(self); @@ -4645,10 +4645,10 @@ object___sizeof___impl(PyObject *self) Py_ssize_t res, isize; res = 0; - isize = self->ob_type->tp_itemsize; + isize = Py_TP(self)->tp_itemsize; if (isize > 0) res = Py_SIZE(self) * isize; - res += self->ob_type->tp_basicsize; + res += Py_TP(self)->tp_basicsize; return PyLong_FromSsize_t(res); } @@ -7277,7 +7277,7 @@ set_names(PyTypeObject *type) _PyErr_FormatFromCause(PyExc_RuntimeError, "Error calling __set_name__ on '%.100s' instance %R " "in '%.100s'", - value->ob_type->tp_name, key, type->tp_name); + Py_TP(value)->tp_name, key, type->tp_name); Py_DECREF(names_to_set); return -1; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3e61c9c370..df28f743e6 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8303,7 +8303,7 @@ charmapencode_lookup(Py_UCS4 c, PyObject *mapping) /* wrong return value */ PyErr_Format(PyExc_TypeError, "character mapping must return integer, bytes or None, not %.400s", - x->ob_type->tp_name); + Py_TP(x)->tp_name); Py_DECREF(x); return NULL; } @@ -10941,8 +10941,8 @@ PyUnicode_Compare(PyObject *left, PyObject *right) } PyErr_Format(PyExc_TypeError, "Can't compare %.100s and %.100s", - left->ob_type->tp_name, - right->ob_type->tp_name); + Py_TP(left)->tp_name, + Py_TP(right)->tp_name); return -1; } @@ -11212,7 +11212,7 @@ PyUnicode_Concat(PyObject *left, PyObject *right) if (!PyUnicode_Check(right)) { PyErr_Format(PyExc_TypeError, "can only concatenate str (not \"%.200s\") to str", - right->ob_type->tp_name); + Py_TP(right)->tp_name); return NULL; } if (PyUnicode_READY(right) < 0) diff --git a/PC/_msi.c b/PC/_msi.c index 024b2d3c9f..c68131cc6b 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -143,7 +143,7 @@ static FNFCIGETNEXTCABINET(cb_getnextcabinet) if (!PyBytes_Check(result)) { PyErr_Format(PyExc_TypeError, "Incorrect return type %s from getnextcabinet", - result->ob_type->tp_name); + Py_TP(result)->tp_name); Py_DECREF(result); return FALSE; } @@ -718,7 +718,7 @@ view_execute(msiobj *view, PyObject*args) return NULL; if (oparams != Py_None) { - if (oparams->ob_type != &record_Type) { + if (Py_TP(oparams) != &record_Type) { PyErr_SetString(PyExc_TypeError, "Execute argument must be a record"); return NULL; } @@ -774,7 +774,7 @@ view_modify(msiobj *view, PyObject *args) if (!PyArg_ParseTuple(args, "iO:Modify", &kind, &data)) return NULL; - if (data->ob_type != &record_Type) { + if (Py_TP(data) != &record_Type) { PyErr_SetString(PyExc_TypeError, "Modify expects a record object"); return NULL; } diff --git a/PC/winreg.c b/PC/winreg.c index 78864b1a69..539c71aaf7 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -110,7 +110,7 @@ typedef struct { HKEY hkey; } PyHKEYObject; -#define PyHKEY_Check(op) ((op)->ob_type == &PyHKEY_Type) +#define PyHKEY_Check(op) (Py_TP((op)) == &PyHKEY_Type) static char *failMsg = "bad operand type"; @@ -675,7 +675,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) PyErr_Format(PyExc_TypeError, "Objects of type '%s' can not " "be used as binary registry values", - value->ob_type->tp_name); + Py_TP(value)->tp_name); return FALSE; } diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 44e3d40c61..85a6223ec2 100644 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -524,7 +524,7 @@ class Obj2ModVisitor(PickleVisitor): self.emit("Py_ssize_t i;", depth+1) self.emit("if (!PyList_Check(tmp)) {", depth+1) self.emit("PyErr_Format(PyExc_TypeError, \"%s field \\\"%s\\\" must " - "be a list, not a %%.200s\", tmp->ob_type->tp_name);" % + "be a list, not a %%.200s\", Py_TP(tmp)->tp_name);" % (name, field.name), depth+2, reflow=False) self.emit("goto failed;", depth+2) diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 6a2f28e0e7..c59d88fd97 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -3969,7 +3969,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4010,7 +4010,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4075,7 +4075,7 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4192,7 +4192,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4222,7 +4222,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4307,7 +4307,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4337,7 +4337,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4409,7 +4409,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4439,7 +4439,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4469,7 +4469,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4499,7 +4499,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4565,7 +4565,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4607,7 +4607,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4809,7 +4809,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4839,7 +4839,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4909,7 +4909,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4939,7 +4939,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4995,7 +4995,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5025,7 +5025,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5081,7 +5081,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5111,7 +5111,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5153,7 +5153,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5183,7 +5183,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5225,7 +5225,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5255,7 +5255,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5337,7 +5337,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5367,7 +5367,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5397,7 +5397,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5427,7 +5427,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5507,7 +5507,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5563,7 +5563,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5617,7 +5617,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5658,7 +5658,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -5813,7 +5813,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6035,7 +6035,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6065,7 +6065,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6106,7 +6106,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6161,7 +6161,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6216,7 +6216,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6285,7 +6285,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6340,7 +6340,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6468,7 +6468,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6498,7 +6498,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6554,7 +6554,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6584,7 +6584,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -6726,7 +6726,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7030,7 +7030,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7085,7 +7085,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7267,7 +7267,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7639,7 +7639,7 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7763,7 +7763,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7815,7 +7815,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7858,7 +7858,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7888,7 +7888,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -7931,7 +7931,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) Py_ssize_t len; Py_ssize_t i; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", Py_TP(tmp)->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); diff --git a/Python/_warnings.c b/Python/_warnings.c index 2229206b25..b7c53708d2 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -504,7 +504,7 @@ warn_explicit(PyObject *category, PyObject *message, text = PyObject_Str(message); if (text == NULL) goto cleanup; - category = (PyObject*)message->ob_type; + category = (PyObject*) Py_TP(message); } else { text = message; @@ -749,7 +749,7 @@ get_category(PyObject *message, PyObject *category) return NULL; if (rc == 1) - category = (PyObject*)message->ob_type; + category = (PyObject*) Py_TP(message); else if (category == NULL || category == Py_None) category = PyExc_UserWarning; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index a23bdc1078..0a36ce8ca8 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -169,7 +169,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, /* else get the type of the first base */ else { PyObject *base0 = PyTuple_GET_ITEM(bases, 0); - meta = (PyObject *) (base0->ob_type); + meta = (PyObject *) (Py_TP(base0)); } Py_INCREF(meta); isclass = 1; /* meta is really a class */ @@ -1021,13 +1021,13 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, if (!PyDict_Check(globals)) { PyErr_Format(PyExc_TypeError, "exec() globals must be a dict, not %.100s", - globals->ob_type->tp_name); + Py_TP(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_TP(locals)->tp_name); return NULL; } if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) { @@ -1386,11 +1386,11 @@ builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (!PyIter_Check(it)) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not an iterator", - it->ob_type->tp_name); + Py_TP(it)->tp_name); return NULL; } - res = (*it->ob_type->tp_iternext)(it); + res = (*Py_TP(it)->tp_iternext)(it); if (res != NULL) { return res; } else if (def != NULL) { @@ -1783,7 +1783,7 @@ builtin_ord(PyObject *module, PyObject *c) else { PyErr_Format(PyExc_TypeError, "ord() expected string of length 1, but " \ - "%.200s found", c->ob_type->tp_name); + "%.200s found", Py_TP(c)->tp_name); return NULL; } @@ -1850,7 +1850,7 @@ builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject 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_TP(sep)->tp_name); return NULL; } if (end == Py_None) { @@ -1859,7 +1859,7 @@ builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject 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_TP(end)->tp_name); return NULL; } diff --git a/Python/ceval.c b/Python/ceval.c index f3a74b00a2..26c6cba39b 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2583,7 +2583,7 @@ main_loop: if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not a mapping", - arg->ob_type->tp_name); + Py_TP(arg)->tp_name); } Py_DECREF(sum); goto error; @@ -2902,7 +2902,7 @@ main_loop: TARGET(FOR_ITER) { /* before: [iter]; after: [iter, iter()] *or* [] */ PyObject *iter = TOP(); - PyObject *next = (*iter->ob_type->tp_iternext)(iter); + PyObject *next = (*Py_TP(iter)->tp_iternext)(iter); if (next != NULL) { PUSH(next); PREDICT(STORE_FAST); @@ -4119,11 +4119,11 @@ unpack_iterable(PyObject *v, int argcnt, int argcntafter, PyObject **sp) it = PyObject_GetIter(v); if (it == NULL) { if (PyErr_ExceptionMatches(PyExc_TypeError) && - v->ob_type->tp_iter == NULL && !PySequence_Check(v)) + Py_TP(v)->tp_iter == NULL && !PySequence_Check(v)) { PyErr_Format(PyExc_TypeError, "cannot unpack non-iterable %.200s object", - v->ob_type->tp_name); + Py_TP(v)->tp_name); } return 0; } @@ -4508,7 +4508,7 @@ PyEval_GetFuncName(PyObject *func) else if (PyCFunction_Check(func)) return ((PyCFunctionObject*)func)->m_ml->ml_name; else - return func->ob_type->tp_name; + return Py_TP(func)->tp_name; } const char * @@ -4957,13 +4957,13 @@ import_all_from(PyObject *locals, PyObject *v) static int check_args_iterable(PyObject *func, PyObject *args) { - if (args->ob_type->tp_iter == NULL && !PySequence_Check(args)) { + if (Py_TP(args)->tp_iter == NULL && !PySequence_Check(args)) { PyErr_Format(PyExc_TypeError, "%.200s%.200s argument after * " "must be an iterable, not %.200s", PyEval_GetFuncName(func), PyEval_GetFuncDesc(func), - args->ob_type->tp_name); + Py_TP(args)->tp_name); return -1; } return 0; @@ -4977,7 +4977,7 @@ format_kwargs_mapping_error(PyObject *func, PyObject *kwargs) "must be a mapping, not %.200s", PyEval_GetFuncName(func), PyEval_GetFuncDesc(func), - kwargs->ob_type->tp_name); + Py_TP(kwargs)->tp_name); } static void diff --git a/Python/codecs.c b/Python/codecs.c index 4062429fe3..2155fa37c0 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -658,7 +658,7 @@ static void wrong_exception_type(PyObject *exc) { PyErr_Format(PyExc_TypeError, "don't know how to handle %.200s in error callback", - exc->ob_type->tp_name); + Py_TP(exc)->tp_name); } PyObject *PyCodec_StrictErrors(PyObject *exc) diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 71e673d9f8..0661ebfc68 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -1428,7 +1428,7 @@ _PyUnicode_FormatAdvancedWriter(_PyUnicodeWriter *writer, 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_TP(obj)->tp_name); return -1; } } @@ -1486,7 +1486,7 @@ _PyLong_FormatAdvancedWriter(_PyUnicodeWriter *writer, default: /* unknown */ - unknown_presentation_type(format.type, obj->ob_type->tp_name); + unknown_presentation_type(format.type, Py_TP(obj)->tp_name); goto done; } @@ -1530,7 +1530,7 @@ _PyFloat_FormatAdvancedWriter(_PyUnicodeWriter *writer, default: /* unknown */ - unknown_presentation_type(format.type, obj->ob_type->tp_name); + unknown_presentation_type(format.type, Py_TP(obj)->tp_name); return -1; } } @@ -1568,7 +1568,7 @@ _PyComplex_FormatAdvancedWriter(_PyUnicodeWriter *writer, default: /* unknown */ - unknown_presentation_type(format.type, obj->ob_type->tp_name); + unknown_presentation_type(format.type, Py_TP(obj)->tp_name); return -1; } } diff --git a/Python/getargs.c b/Python/getargs.c index 98823f22ed..e251f42924 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -530,7 +530,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags, 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_TP(arg)->tp_name); return msgbuf; } @@ -621,7 +621,7 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize) 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_TP(arg)->tp_name); } return msgbuf; } @@ -1284,7 +1284,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, type = va_arg(*p_va, PyTypeObject*); p = va_arg(*p_va, PyObject **); format++; - if (PyType_IsSubtype(arg->ob_type, type)) + if (PyType_IsSubtype(Py_TP(arg), type)) *p = arg; else return converterr(type->tp_name, arg, msgbuf, bufsize); diff --git a/Python/marshal.c b/Python/marshal.c index 21cdd60c7e..098ba807dd 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1689,7 +1689,7 @@ marshal_load(PyObject *module, PyObject *file) if (!PyBytes_Check(data)) { PyErr_Format(PyExc_TypeError, "file.read() returned not bytes but %.100s", - data->ob_type->tp_name); + Py_TP(data)->tp_name); result = NULL; } else { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 58ea60595c..a2ce23adac 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -429,7 +429,7 @@ sys_intern(PyObject *self, PyObject *args) } else { PyErr_Format(PyExc_TypeError, - "can't intern %.400s", s->ob_type->tp_name); + "can't intern %.400s", Py_TP(s)->tp_name); return NULL; } }