Introduce Py_IS_TYPE, use for Py_TYPE comparisons

This commit is contained in:
rdb 2024-10-30 13:06:36 +01:00
parent 64454b1c9f
commit 0ba2aadcd6
4 changed files with 9 additions and 5 deletions

View File

@ -56,7 +56,7 @@ __init__(PyObject *path) {
return;
}
if (Py_TYPE(path) == &Dtool_Filename._PyType) {
if (Py_IS_TYPE(path, Dtool_GetPyTypeObject(&Dtool_Filename))) {
// Copy constructor.
*_this = *(Filename *)DtoolInstance_VOID_PTR(path);
return;

View File

@ -217,8 +217,12 @@ INLINE PyObject *_PyLong_Lshift(PyObject *a, size_t shiftby) {
/* Python 3.9 */
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE)
# define Py_IS_TYPE(ob, type) (Py_TYPE((PyObject *)ob) == type)
#endif
#ifndef PyCFunction_CheckExact
# define PyCFunction_CheckExact(op) (Py_TYPE(op) == &PyCFunction_Type)
# define PyCFunction_CheckExact(op) (Py_IS_TYPE(op, &PyCFunction_Type))
#endif
#if PY_VERSION_HEX < 0x03090000

View File

@ -300,7 +300,7 @@ static PyObject *Dtool_EnumType_New(PyTypeObject *subtype, PyObject *args, PyObj
subtype->tp_name);
}
if (Py_TYPE(arg) == subtype) {
if (Py_IS_TYPE(arg, subtype)) {
Py_INCREF(arg);
return arg;
}

View File

@ -590,7 +590,7 @@ do_python_task() {
_retrieved_exception = false;
if (task_cat.is_debug()) {
if (_exception != nullptr && Py_TYPE(_exception) == &PyType_Type) {
if (_exception != nullptr && Py_IS_TYPE(_exception, &PyType_Type)) {
task_cat.debug()
<< *this << " received " << ((PyTypeObject *)_exception)->tp_name << " from coroutine.\n";
} else {
@ -741,7 +741,7 @@ do_python_task() {
if (PyCFunction_Check(result)) {
meth = ((PyCFunctionObject *)result)->m_ml;
#if PY_MAJOR_VERSION >= 3
} else if (Py_TYPE(result) == &PyMethodDescr_Type) {
} else if (Py_IS_TYPE(result, &PyMethodDescr_Type)) {
#else
} else if (strcmp(Py_TYPE(result)->tp_name, "method_descriptor") == 0) {
#endif