diff --git a/dtool/src/dtoolutil/filename_ext.cxx b/dtool/src/dtoolutil/filename_ext.cxx index c7b7e30606..86d521a9a9 100644 --- a/dtool/src/dtoolutil/filename_ext.cxx +++ b/dtool/src/dtoolutil/filename_ext.cxx @@ -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; diff --git a/dtool/src/interrogatedb/py_compat.h b/dtool/src/interrogatedb/py_compat.h index 65ef2ec39a..e1ee9dd7bb 100644 --- a/dtool/src/interrogatedb/py_compat.h +++ b/dtool/src/interrogatedb/py_compat.h @@ -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 diff --git a/dtool/src/interrogatedb/py_panda.cxx b/dtool/src/interrogatedb/py_panda.cxx index 1ce7da8328..541b7a6381 100644 --- a/dtool/src/interrogatedb/py_panda.cxx +++ b/dtool/src/interrogatedb/py_panda.cxx @@ -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; } diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index b6f540fbdf..8395bd5adc 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -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