bpo-39573: Use Py_TYPE() macro in Modules directory (GH-18393)

Replace direct access to PyObject.ob_type with Py_TYPE().
This commit is contained in:
Victor Stinner 2020-02-07 03:37:06 +01:00 committed by GitHub
parent 58ac700fb0
commit daa9756cb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 40 additions and 40 deletions

View File

@ -539,7 +539,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_TYPE(other)->tp_name);
}
return NULL;
}
@ -2395,7 +2395,7 @@ tuplegetter_descr_get(PyObject *self, PyObject *obj, PyObject *type)
"descriptor for index '%zd' for tuple subclasses "
"doesn't apply to '%s' object",
index,
obj->ob_type->tp_name);
Py_TYPE(obj)->tp_name);
return NULL;
}

View File

@ -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_TYPE(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_TYPE(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_TYPE(seq)->tp_name);
/* Join all fields in internal buffer.
*/

View File

@ -274,7 +274,7 @@ static void
PyCField_dealloc(PyObject *self)
{
PyCField_clear((CFieldObject *)self);
self->ob_type->tp_free((PyObject *)self);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static PyObject *
@ -1175,7 +1175,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_TYPE(value)->tp_name);
return NULL;
} else
Py_INCREF(value);
@ -1234,7 +1234,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_TYPE(value)->tp_name);
return NULL;
}
@ -1289,7 +1289,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_TYPE(value)->tp_name);
return NULL;
}
@ -1334,7 +1334,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_TYPE(value)->tp_name);
return NULL;
}
@ -1373,7 +1373,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_TYPE(value)->tp_name);
return NULL;
}
@ -1416,7 +1416,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_TYPE(value)->tp_name);
return NULL;
}

View File

@ -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_TYPE(v) == &PyCStgDict_Type)
#define PyCStgDict_Check(v) PyObject_TypeCheck(v, &PyCStgDict_Type)
extern int PyCStructUnionType_update_stgdict(PyObject *fields, PyObject *type, int isStruct);
@ -314,7 +314,7 @@ struct tagPyCArgObject {
};
extern PyTypeObject PyCArg_Type;
#define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type)
#define PyCArg_CheckExact(v) (Py_TYPE(v) == &PyCArg_Type)
extern PyCArgObject *PyCArgObject_new(void);
extern PyObject *

View File

@ -190,7 +190,7 @@ PyType_stgdict(PyObject *obj)
StgDictObject *
PyObject_stgdict(PyObject *self)
{
PyTypeObject *type = self->ob_type;
PyTypeObject *type = Py_TYPE(self);
if (!type->tp_dict || !PyCStgDict_CheckExact(type->tp_dict))
return NULL;
return (StgDictObject *)type->tp_dict;

View File

@ -2924,7 +2924,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_TYPE(data)->tp_name);
Py_DECREF(data);
goto error;
}

View File

@ -1810,7 +1810,7 @@ checked_divmod(PyObject *a, PyObject *b)
if (!PyTuple_Check(result)) {
PyErr_Format(PyExc_TypeError,
"divmod() returned non-tuple (type %.200s)",
result->ob_type->tp_name);
Py_TYPE(result)->tp_name);
Py_DECREF(result);
return NULL;
}

View File

@ -255,7 +255,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_TYPE(arg)->tp_name);
return -1;
}
else {

View File

@ -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_TYPE(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_TYPE(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_TYPE(v)->tp_name);
}
else {
Py_INCREF(Py_NotImplemented);

View File

@ -349,7 +349,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_TYPE(arg)->tp_name);
return -1;
}
else {

View File

@ -544,7 +544,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_TYPE(item)->tp_name);
}
finish:

View File

@ -1094,7 +1094,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_TYPE(errors)->tp_name);
return -1;
}
else if (io_check_errors(errors)) {

View File

@ -1617,7 +1617,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_TYPE(key)->tp_name);
goto bail;
}

View File

@ -1976,7 +1976,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_TYPE(obj)->tp_name, obj);
self->fast_nesting = -1;
return 0;
}

View File

@ -84,7 +84,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_TYPE(obj), proto);
if (!key) {
return NULL;
}

View File

@ -1854,7 +1854,7 @@ ndarray_subscript(NDArrayObject *self, PyObject *key)
type_error:
PyErr_Format(PyExc_TypeError,
"cannot index memory using \"%.200s\"",
key->ob_type->tp_name);
Py_TYPE(key)->tp_name);
err_occurred:
Py_DECREF(nd);
return NULL;

View File

@ -274,7 +274,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_TYPE(arg)->tp_name);
return NULL;
}
@ -2724,7 +2724,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_TYPE(fn)->tp_name);
return NULL;
}

View File

@ -833,7 +833,7 @@ typedef struct {
} PyTclObject;
static PyObject *PyTclObject_Type;
#define PyTclObject_Check(v) ((v)->ob_type == (PyTypeObject *) PyTclObject_Type)
#define PyTclObject_Check(v) (Py_TYPE(v) == (PyTypeObject *) PyTclObject_Type)
static PyObject *
newPyTclObject(Tcl_Obj *arg)
@ -1734,7 +1734,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_TYPE(in)->tp_name);
return 0;
}

View File

@ -1428,7 +1428,7 @@ channel_id_converter(PyObject *arg, void *ptr)
else {
PyErr_Format(PyExc_TypeError,
"channel ID must be an int, got %.100s",
arg->ob_type->tp_name);
Py_TYPE(arg)->tp_name);
return 0;
}
*(int64_t *)ptr = cid;

View File

@ -1450,7 +1450,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
PyErr_Format(PyExc_TypeError,
"stream function returned a "
"non-bytes object (%.100s)",
cres->ob_type->tp_name);
Py_TYPE(cres)->tp_name);
goto errorexit;
}

View File

@ -65,7 +65,7 @@ typedef struct {
MultibyteCodec *codec;
} MultibyteCodecObject;
#define MultibyteCodec_Check(op) ((op)->ob_type == &MultibyteCodec_Type)
#define MultibyteCodec_Check(op) (Py_TYPE(op) == &MultibyteCodec_Type)
#define _MultibyteStatefulCodec_HEAD \
PyObject_HEAD \

View File

@ -653,7 +653,7 @@ untrack_dicts(PyGC_Head *head)
static int
has_legacy_finalizer(PyObject *op)
{
return op->ob_type->tp_del != NULL;
return Py_TYPE(op)->tp_del != NULL;
}
/* Move the objects in unreachable with tp_del slots into `finalizers`.

View File

@ -116,7 +116,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_TYPE(id)->tp_name) < 0) {
return NULL;
}
py_int_id = PyNumber_Long(id);

View File

@ -256,7 +256,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_TYPE(v) == &PyST_Type)
static int
parser_compare_nodes(node *left, node *right)

View File

@ -478,7 +478,7 @@ SHA512Type_copy_impl(SHAobject *self)
{
SHAobject *newobj;
if (((PyObject*)self)->ob_type == &SHA512type) {
if (Py_TYPE((PyObject*)self) == &SHA512type) {
if ( (newobj = newSHA512object())==NULL)
return NULL;
} else {

View File

@ -1670,7 +1670,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_TYPE(obj)->tp_name);
return 0;
}
if (strlen(data->buf) != len) {