From 084dfb9a7405ab145c1cf4670aa0ad4bf5f85ea2 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Mar 2021 10:01:37 +0100 Subject: [PATCH 1/3] bpo-43502: Convert PyExceptionClass_Check from macro to static inline function --- Include/cpython/pyerrors.h | 5 +++++ Include/pyerrors.h | 6 +----- .../next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst diff --git a/Include/cpython/pyerrors.h b/Include/cpython/pyerrors.h index 6711e8be68ffeb..582ee38281719b 100644 --- a/Include/cpython/pyerrors.h +++ b/Include/cpython/pyerrors.h @@ -74,6 +74,11 @@ PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate); PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); +static inline int _PyExceptionClass_Check(PyObject *exc) { + return (PyType_Check(exc) && + PyType_FastSubclass((PyTypeObject *)(exc), Py_TPFLAGS_BASE_EXC_SUBCLASS)); +} + /* Context manipulation (PEP 3134) */ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 14129d3533cbef..dbfce0b191edd1 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -47,11 +47,7 @@ PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *); PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *); -/* */ - -#define PyExceptionClass_Check(x) \ - (PyType_Check((x)) && \ - PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)) +#define PyExceptionClass_Check(exc) _PyExceptionClass_Check(_PyObject_CAST(exc)) #define PyExceptionInstance_Check(x) \ PyType_FastSubclass(Py_TYPE(x), Py_TPFLAGS_BASE_EXC_SUBCLASS) diff --git a/Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst b/Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst new file mode 100644 index 00000000000000..3b8719a55a510b --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst @@ -0,0 +1,2 @@ +Convert ``PyExceptionClass_Check`` from macro to static inline function. +Patch by Erlend E. Aasland. From a6b67e65c308379f90ac28d5d541ddb1fc0e8f79 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Mar 2021 20:17:04 +0100 Subject: [PATCH 2/3] Address review: Move _PyExceptionClass_Check to limited API --- Include/cpython/pyerrors.h | 5 ----- Include/pyerrors.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Include/cpython/pyerrors.h b/Include/cpython/pyerrors.h index 582ee38281719b..6711e8be68ffeb 100644 --- a/Include/cpython/pyerrors.h +++ b/Include/cpython/pyerrors.h @@ -74,11 +74,6 @@ PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate); PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); -static inline int _PyExceptionClass_Check(PyObject *exc) { - return (PyType_Check(exc) && - PyType_FastSubclass((PyTypeObject *)(exc), Py_TPFLAGS_BASE_EXC_SUBCLASS)); -} - /* Context manipulation (PEP 3134) */ PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); diff --git a/Include/pyerrors.h b/Include/pyerrors.h index dbfce0b191edd1..15a91408f293b6 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -47,6 +47,10 @@ PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *); PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *); +static inline int _PyExceptionClass_Check(PyObject *exc) { + return (PyType_Check(exc) && + PyType_FastSubclass((PyTypeObject *)(exc), Py_TPFLAGS_BASE_EXC_SUBCLASS)); +} #define PyExceptionClass_Check(exc) _PyExceptionClass_Check(_PyObject_CAST(exc)) #define PyExceptionInstance_Check(x) \ From fe5b0ff58033f96f1cc7a05598e371266dde0d1d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Mar 2021 23:55:49 +0100 Subject: [PATCH 3/3] Remove NEWS entry --- Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst diff --git a/Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst b/Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst deleted file mode 100644 index 3b8719a55a510b..00000000000000 --- a/Misc/NEWS.d/next/C API/2021-03-15-15-06-16.bpo-43502.G-uhre.rst +++ /dev/null @@ -1,2 +0,0 @@ -Convert ``PyExceptionClass_Check`` from macro to static inline function. -Patch by Erlend E. Aasland.