Skip to content
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
3 changes: 1 addition & 2 deletions Include/py_curses.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,7 +64,7 @@ typedef struct {
char *encoding;
} PyCursesWindowObject;

#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
#define PyCursesWindow_Check(v) Py_IS_TYPE(v, &PyCursesWindow_Type)

#define PyCurses_CAPSULE_NAME "_curses._C_API"

Expand DownExpand Up@@ -97,4 +97,3 @@ static const char catchall_NULL[] = "curses function returned NULL";

#endif /* !defined(Py_CURSES_H) */


2 changes: 1 addition & 1 deletion Modules/_asynciomodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -572,7 +572,7 @@ future_set_exception(FutureObj *fut, PyObject *exc)
PyErr_SetString(PyExc_TypeError, "invalid exception object");
return NULL;
}
if ((PyObject*)Py_TYPE(exc_val) == PyExc_StopIteration) {
if (Py_IS_TYPE(exc_val, (PyTypeObject *)PyExc_StopIteration)) {
Py_DECREF(exc_val);
PyErr_SetString(PyExc_TypeError,
"StopIteration interacts badly with generators "
Expand Down
2 changes: 1 addition & 1 deletion Modules/_collectionsmodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,7 +489,7 @@ deque_copy(PyObject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *result;
dequeobject *old_deque = (dequeobject *)deque;
if (Py_TYPE(deque) == &deque_type) {
if (Py_IS_TYPE(deque, &deque_type)) {
dequeobject *new_deque;
PyObject *rv;

Expand Down
2 changes: 1 addition & 1 deletion Modules/_elementtree.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -2366,7 +2366,7 @@ typedef struct {
char insert_pis;
} TreeBuilderObject;

#define TreeBuilder_CheckExact(op) (Py_TYPE(op) == &TreeBuilder_Type)
#define TreeBuilder_CheckExact(op) Py_IS_TYPE((op), &TreeBuilder_Type)

/* -------------------------------------------------------------------- */
/* constructor and destructor */
Expand Down
12 changes: 6 additions & 6 deletions Modules/_io/bufferedio.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -1449,8 +1449,8 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
return -1;
_bufferedreader_reset_buf(self);

self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedReader_Type &&
Py_TYPE(raw) == &PyFileIO_Type);
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedReader_Type) &&
Py_IS_TYPE(raw, &PyFileIO_Type));

self->ok = 1;
return 0;
Expand DownExpand Up@@ -1795,8 +1795,8 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
_bufferedwriter_reset_buf(self);
self->pos = 0;

self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedWriter_Type &&
Py_TYPE(raw) == &PyFileIO_Type);
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedWriter_Type) &&
Py_IS_TYPE(raw, &PyFileIO_Type));

self->ok = 1;
return 0;
Expand DownExpand Up@@ -2309,8 +2309,8 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
_bufferedwriter_reset_buf(self);
self->pos = 0;

self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedRandom_Type &&
Py_TYPE(raw) == &PyFileIO_Type);
self->fast_closed_checks = (Py_IS_TYPE(self, &PyBufferedRandom_Type) &&
Py_IS_TYPE(raw, &PyFileIO_Type));

self->ok = 1;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/stringio.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -402,7 +402,7 @@ stringio_iternext(stringio *self)
CHECK_CLOSED(self);
ENSURE_REALIZED(self);

if (Py_TYPE(self) == &PyStringIO_Type) {
if (Py_IS_TYPE(self, &PyStringIO_Type)) {
/* Skip method call overhead for speed */
line = _stringio_readline(self, -1);
}
Expand Down
16 changes: 8 additions & 8 deletions Modules/_io/textio.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -897,7 +897,7 @@ _textiowrapper_decode(PyObject *decoder, PyObject *bytes, int eof)
{
PyObject *chars;

if (Py_TYPE(decoder) == &PyIncrementalNewlineDecoder_Type)
if (Py_IS_TYPE(decoder, &PyIncrementalNewlineDecoder_Type))
chars = _PyIncrementalNewlineDecoder_decode(decoder, bytes, eof);
else
chars = PyObject_CallMethodObjArgs(decoder, _PyIO_str_decode, bytes,
Expand DownExpand Up@@ -1226,15 +1226,15 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
/* Finished sorting out the codec details */
Py_CLEAR(codec_info);

if (Py_TYPE(buffer) == &PyBufferedReader_Type ||
Py_TYPE(buffer) == &PyBufferedWriter_Type ||
Py_TYPE(buffer) == &PyBufferedRandom_Type)
if (Py_IS_TYPE(buffer, &PyBufferedReader_Type) ||
Py_IS_TYPE(buffer, &PyBufferedWriter_Type) ||
Py_IS_TYPE(buffer, &PyBufferedRandom_Type))
{
if (_PyObject_LookupAttrId(buffer, &PyId_raw, &raw) < 0)
goto error;
/* Cache the raw FileIO object to speed up 'closed' checks */
if (raw != NULL) {
if (Py_TYPE(raw) == &PyFileIO_Type)
if (Py_IS_TYPE(raw, &PyFileIO_Type))
self->raw = raw;
else
Py_DECREF(raw);
Expand DownExpand Up@@ -1466,7 +1466,7 @@ textiowrapper_closed_get(textio *self, void *context);
do { \
int r; \
PyObject *_res; \
if (Py_TYPE(self) == &PyTextIOWrapper_Type) { \
if (Py_IS_TYPE(self, &PyTextIOWrapper_Type)) { \
if (self->raw != NULL) \
r = _PyFileIO_closed(self->raw); \
else { \
Expand DownExpand Up@@ -1937,7 +1937,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
if (bytes == NULL)
goto fail;

if (Py_TYPE(self->decoder) == &PyIncrementalNewlineDecoder_Type)
if (Py_IS_TYPE(self->decoder, &PyIncrementalNewlineDecoder_Type))
decoded = _PyIncrementalNewlineDecoder_decode(self->decoder,
bytes, 1);
else
Expand DownExpand Up@@ -3079,7 +3079,7 @@ textiowrapper_iternext(textio *self)
CHECK_ATTACHED(self);

self->telling = 0;
if (Py_TYPE(self) == &PyTextIOWrapper_Type) {
if (Py_IS_TYPE(self, &PyTextIOWrapper_Type)) {
/* Skip method call overhead for speed */
line = _textiowrapper_readline(self, -1);
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_pickle.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -4943,7 +4943,7 @@ Pickler_set_memo(PicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored))
return -1;
}

if (Py_TYPE(obj) == &PicklerMemoProxyType) {
if (Py_IS_TYPE(obj, &PicklerMemoProxyType)) {
PicklerObject *pickler =
((PicklerMemoProxyObject *)obj)->pickler;

Expand DownExpand Up@@ -7488,7 +7488,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
return -1;
}

if (Py_TYPE(obj) == &UnpicklerMemoProxyType) {
if (Py_IS_TYPE(obj, &UnpicklerMemoProxyType)) {
UnpicklerObject *unpickler =
((UnpicklerMemoProxyObject *)obj)->unpickler;

Expand Down
4 changes: 2 additions & 2 deletions Modules/_threadmodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -844,7 +844,7 @@ _ldict(localobject *self)
}
}
else {
assert(Py_TYPE(dummy) == &localdummytype);
assert(Py_IS_TYPE(dummy, &localdummytype));
ldict = ((localdummyobject *) dummy)->localdict;
}

Expand DownExpand Up@@ -1209,7 +1209,7 @@ release_sentinel(void *wr_raw)
PyObject *obj = PyWeakref_GET_OBJECT(wr);
lockobject *lock;
if (obj != Py_None) {
assert(Py_TYPE(obj) == &Locktype);
assert(Py_IS_TYPE(obj, &Locktype));
lock = (lockobject *) obj;
if (lock->locked) {
PyThread_release_lock(lock->lock_lock);
Expand Down
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/multibytecodec.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,7 @@ typedef struct {
MultibyteCodec *codec;
} MultibyteCodecObject;

#define MultibyteCodec_Check(op) (Py_TYPE(op) == &MultibyteCodec_Type)
#define MultibyteCodec_Check(op) Py_IS_TYPE((op), &MultibyteCodec_Type)

#define _MultibyteStatefulCodec_HEAD \
PyObject_HEAD \
Expand Down
2 changes: 1 addition & 1 deletion Modules/itertoolsmodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -527,7 +527,7 @@ teedataobject_traverse(teedataobject *tdo, visitproc visit, void * arg)
static void
teedataobject_safe_decref(PyObject *obj)
{
while (obj && Py_TYPE(obj) == &teedataobject_type &&
while (obj && Py_IS_TYPE(obj, &teedataobject_type) &&
Py_REFCNT(obj) == 1) {
PyObject *nextlink = ((teedataobject *)obj)->nextlink;
((teedataobject *)obj)->nextlink = NULL;
Expand Down
2 changes: 1 addition & 1 deletion Objects/abstract.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -2466,7 +2466,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
_Py_IDENTIFIER(__instancecheck__);

/* Quick test for an exact match */
if (Py_TYPE(inst) == (PyTypeObject *)cls) {
if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) {
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions Objects/descrobject.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -1178,7 +1178,7 @@ typedef struct {
PyObject *self;
} wrapperobject;

#define Wrapper_Check(v) (Py_TYPE(v) == &_PyMethodWrapper_Type)
#define Wrapper_Check(v) Py_IS_TYPE(v, &_PyMethodWrapper_Type)

static void
wrapper_dealloc(wrapperobject *wp)
Expand DownExpand Up@@ -1628,7 +1628,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
if (rc <= 0) {
return rc;
}
if (Py_TYPE(self) == &PyProperty_Type) {
if (Py_IS_TYPE(self, &PyProperty_Type)) {
Py_XSETREF(self->prop_doc, get_doc);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions Objects/exceptions.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -875,7 +875,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,

/* self->filename will remain Py_None otherwise */
if (filename && filename != Py_None) {
if (Py_TYPE(self) == (PyTypeObject *) PyExc_BlockingIOError &&
if (Py_IS_TYPE(self, (PyTypeObject *) PyExc_BlockingIOError) &&
PyNumber_Check(filename)) {
/* BlockingIOError's 3rd argument can be the number of
* characters written.
Expand DownExpand Up@@ -1379,7 +1379,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
* Only applies to SyntaxError instances, not to subclasses such
* as TabError or IndentationError (see issue #31161)
*/
if ((PyObject*)Py_TYPE(self) == PyExc_SyntaxError &&
if (Py_IS_TYPE(self, (PyTypeObject *)PyExc_SyntaxError) &&
self->text && PyUnicode_Check(self->text) &&
_report_missing_parentheses(self) < 0) {
return -1;
Expand Down
6 changes: 3 additions & 3 deletions Objects/genobject.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -1216,10 +1216,10 @@ static PyAsyncGenASend *ag_asend_freelist[_PyAsyncGen_MAXFREELIST];
static int ag_asend_freelist_free = 0;

#define _PyAsyncGenWrappedValue_CheckExact(o) \
(Py_TYPE(o) == &_PyAsyncGenWrappedValue_Type)
Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type)

#define PyAsyncGenASend_CheckExact(o) \
(Py_TYPE(o) == &_PyAsyncGenASend_Type)
Py_IS_TYPE(o, &_PyAsyncGenASend_Type)


static int
Expand DownExpand Up@@ -1442,7 +1442,7 @@ PyAsyncGen_ClearFreeLists(void)
while (ag_asend_freelist_free) {
PyAsyncGenASend *o;
o = ag_asend_freelist[--ag_asend_freelist_free];
assert(Py_TYPE(o) == &_PyAsyncGenASend_Type);
assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type));
PyObject_GC_Del(o);
}

Expand Down
22 changes: 11 additions & 11 deletions Objects/listobject.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -2052,8 +2052,8 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms)
int res;

/* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */
assert(Py_TYPE(v) == Py_TYPE(w));
assert(Py_TYPE(v) == &PyUnicode_Type);
assert(Py_IS_TYPE(v, &PyUnicode_Type));
assert(Py_IS_TYPE(w, &PyUnicode_Type));
assert(PyUnicode_KIND(v) == PyUnicode_KIND(w));
assert(PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND);

Expand All@@ -2075,8 +2075,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(Py_TYPE(v) == Py_TYPE(w));
assert(Py_TYPE(v) == &PyLong_Type);
assert(Py_IS_TYPE(v, &PyLong_Type));
assert(Py_IS_TYPE(w, &PyLong_Type));
assert(Py_ABS(Py_SIZE(v)) <= 1);
assert(Py_ABS(Py_SIZE(w)) <= 1);

Expand All@@ -2103,8 +2103,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, MergeState *ms)
int res;

/* Modified from Objects/floatobject.c:float_richcompare, assuming: */
assert(Py_TYPE(v) == Py_TYPE(w));
assert(Py_TYPE(v) == &PyFloat_Type);
assert(Py_IS_TYPE(v, &PyFloat_Type));
assert(Py_IS_TYPE(w, &PyFloat_Type));

res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w);
assert(res == PyObject_RichCompareBool(v, w, Py_LT));
Expand All@@ -2125,8 +2125,8 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms)
int k;

/* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */
assert(Py_TYPE(v) == Py_TYPE(w));
assert(Py_TYPE(v) == &PyTuple_Type);
assert(Py_IS_TYPE(v, &PyTuple_Type));
assert(Py_IS_TYPE(w, &PyTuple_Type));
assert(Py_SIZE(v) > 0);
assert(Py_SIZE(w) > 0);

Expand DownExpand Up@@ -2247,7 +2247,7 @@ 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 = (Py_TYPE(lo.keys[0]) == &PyTuple_Type &&
int keys_are_in_tuples = (Py_IS_TYPE(lo.keys[0], &PyTuple_Type) &&
Py_SIZE(lo.keys[0]) > 0);

PyTypeObject* key_type = (keys_are_in_tuples ?
Expand All@@ -2262,7 +2262,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
for (i=0; i < saved_ob_size; i++) {

if (keys_are_in_tuples &&
!(Py_TYPE(lo.keys[i]) == &PyTuple_Type && Py_SIZE(lo.keys[i]) != 0)) {
!(Py_IS_TYPE(lo.keys[i], &PyTuple_Type) && Py_SIZE(lo.keys[i]) != 0)) {
keys_are_in_tuples = 0;
keys_are_all_same_type = 0;
break;
Expand All@@ -2275,7 +2275,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
PyTuple_GET_ITEM(lo.keys[i], 0) :
lo.keys[i]);

if (Py_TYPE(key) != key_type) {
if (!Py_IS_TYPE(key, key_type)) {
keys_are_all_same_type = 0;
/* If keys are in tuple we must loop over the whole list to make
sure all items are tuples */
Expand Down
2 changes: 1 addition & 1 deletion Objects/namespaceobject.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,7 +72,7 @@ namespace_repr(PyObject *ns)
PyObject *separator, *pairsrepr, *repr = NULL;
const char * name;

name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace"
name = Py_IS_TYPE(ns, &_PyNamespace_Type) ? "namespace"
: Py_TYPE(ns)->tp_name;

i = Py_ReprEnter(ns);
Expand Down
2 changes: 1 addition & 1 deletion Objects/tupleobject.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -237,7 +237,7 @@ tupledealloc(PyTupleObject *op)
#if PyTuple_MAXSAVESIZE > 0
if (len < PyTuple_MAXSAVESIZE &&
numfree[len] < PyTuple_MAXFREELIST &&
Py_TYPE(op) == &PyTuple_Type)
Py_IS_TYPE(op, &PyTuple_Type))
{
op->ob_item[0] = (PyObject *) free_list[len];
numfree[len]++;
Expand Down
8 changes: 4 additions & 4 deletions Objects/typeobject.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -5335,7 +5335,7 @@ PyType_Ready(PyTypeObject *type)
NULL when type is &PyBaseObject_Type, and we know its ob_type is
not NULL (it's initialized to &PyType_Type). But coverity doesn't
know that. */
if (Py_TYPE(type) == NULL && base != NULL) {
if (Py_IS_TYPE(type, NULL) && base != NULL) {
Py_SET_TYPE(type, Py_TYPE(base));
}

Expand DownExpand Up@@ -6645,7 +6645,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
needed, with call_attribute. */
getattribute = _PyType_LookupId(tp, &PyId___getattribute__);
if (getattribute == NULL ||
(Py_TYPE(getattribute) == &PyWrapperDescr_Type &&
(Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
(void *)PyObject_GenericGetAttr))
res = PyObject_GenericGetAttr(self, name);
Expand DownExpand Up@@ -7352,7 +7352,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
}
continue;
}
if (Py_TYPE(descr) == &PyWrapperDescr_Type &&
if (Py_IS_TYPE(descr, &PyWrapperDescr_Type) &&
((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
void **tptr = resolve_slotdups(type, p->name_strobj);
if (tptr == NULL || tptr == ptr)
Expand All@@ -7375,7 +7375,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
use_generic = 1;
}
}
else if (Py_TYPE(descr) == &PyCFunction_Type &&
else if (Py_IS_TYPE(descr, &PyCFunction_Type) &&
PyCFunction_GET_FUNCTION(descr) ==
(PyCFunction)(void(*)(void))tp_new_wrapper &&
ptr == (void**)&type->tp_new)
Expand Down
Loading