[Python-checkins] gh-91320: Fix more old-style cast warnings in C++ (#93285)

vstinner webhook-mailer at python.org
Thu Jun 2 19:00:02 EDT 2022


https://github.com/python/cpython/commit/941d7054c1f73aa097bdc4e55ede819c8f123819
commit: 941d7054c1f73aa097bdc4e55ede819c8f123819
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-06-03T00:59:57+02:00
summary:

gh-91320: Fix more old-style cast warnings in C++ (#93285)

Use _PyObject_CAST() in the public C API to fix C++ compiler
warnings: "use of old-style cast" (clang -Wold-style-cast).

files:
M Include/boolobject.h
M Include/ceval.h
M Include/pyerrors.h

diff --git a/Include/boolobject.h b/Include/boolobject.h
index 28068d1cbe593..0a661ffa75487 100644
--- a/Include/boolobject.h
+++ b/Include/boolobject.h
@@ -19,8 +19,8 @@ PyAPI_DATA(PyLongObject) _Py_FalseStruct;
 PyAPI_DATA(PyLongObject) _Py_TrueStruct;
 
 /* Use these macros */
-#define Py_False ((PyObject *) &_Py_FalseStruct)
-#define Py_True ((PyObject *) &_Py_TrueStruct)
+#define Py_False _PyObject_CAST(&_Py_FalseStruct)
+#define Py_True _PyObject_CAST(&_Py_TrueStruct)
 
 // Test if an object is the True singleton, the same as "x is True" in Python.
 PyAPI_FUNC(int) Py_IsTrue(PyObject *x);
diff --git a/Include/ceval.h b/Include/ceval.h
index 1b57f6ea20f6f..a5387bd1f1211 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -31,7 +31,7 @@ Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
 
 /* Deprecated since PyEval_CallObjectWithKeywords is deprecated */
 #define PyEval_CallObject(callable, arg) \
-    PyEval_CallObjectWithKeywords(callable, arg, (PyObject *)NULL)
+    PyEval_CallObjectWithKeywords(callable, arg, _PyObject_CAST(_Py_NULL))
 
 Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallFunction(
     PyObject *callable, const char *format, ...);
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 34e3de3328f41..4944feecd8a6b 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -62,7 +62,7 @@ PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
 
 PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);
 
-#define PyExceptionInstance_Class(x) ((PyObject*)Py_TYPE(x))
+#define PyExceptionInstance_Class(x) _PyObject_CAST(Py_TYPE(x))
 
 #define _PyBaseExceptionGroup_Check(x)                   \
     PyObject_TypeCheck(x, (PyTypeObject *)PyExc_BaseExceptionGroup)



More information about the Python-checkins mailing list