summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-01-21 20:39:01 (GMT)
committerGitHub <noreply@github.com>2022-01-21 20:39:01 (GMT)
commitbc67f189fdd62ed42013fa05cd0ef2df498f5967 (patch)
treefdec1f248f48b03bbeed0eadce53f63081773b3f /Include
parent60705cff70576482fea31dcafbf8a37cbb751ea5 (diff)
downloadcpython-bc67f189fdd62ed42013fa05cd0ef2df498f5967.zip
cpython-bc67f189fdd62ed42013fa05cd0ef2df498f5967.tar.gz
cpython-bc67f189fdd62ed42013fa05cd0ef2df498f5967.tar.bz2
bpo-46417: Add _PyType_CAST() macro (GH-30760)
In debug mode, the macro makes sure that its argument is a type using an assertion.
Diffstat (limited to 'Include')
-rw-r--r--Include/object.h2
-rw-r--r--Include/py_curses.h2
2 files changed, 3 insertions, 1 deletions
diff --git a/Include/object.h b/Include/object.h
index e5544e8..4fd1661 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -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);
}
diff --git a/Include/py_curses.h b/Include/py_curses.h
index b70252d..b2c7f1b 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -77,7 +77,7 @@ typedef struct {
static void **PyCurses_API;
-#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
+#define PyCursesWindow_Type (*_PyType_CAST(PyCurses_API[0]))
#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}