bpo-46417: Add _PyType_CAST() macro (GH-30760)

In debug mode, the macro makes sure that its argument is a type using
an assertion.
This commit is contained in:
Victor Stinner 2022-01-21 21:39:01 +01:00 committed by GitHub
parent 60705cff70
commit bc67f189fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 58 deletions

View file

@ -755,6 +755,8 @@ static inline int _PyType_Check(PyObject *op) {
}
#define PyType_Check(op) _PyType_Check(_PyObject_CAST(op))
#define _PyType_CAST(op) (assert(PyType_Check(op)), (PyTypeObject*)(op))
static inline int _PyType_CheckExact(PyObject *op) {
return Py_IS_TYPE(op, &PyType_Type);
}