Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
14 changes: 7 additions & 7 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/_ctypes/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 *
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/stgdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_gdbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_testbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/multibytecodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion Modules/gcmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion Modules/grpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/parsermodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Modules/sha512module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down