]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91320: Fix more old-style cast warnings in C++ (#93285)
authorVictor Stinner <vstinner@python.org>
Thu, 2 Jun 2022 22:59:57 +0000 (00:59 +0200)
committerGitHub <noreply@github.com>
Thu, 2 Jun 2022 22:59:57 +0000 (00:59 +0200)
Use _PyObject_CAST() in the public C API to fix C++ compiler
warnings: "use of old-style cast" (clang -Wold-style-cast).

Include/boolobject.h
Include/ceval.h
Include/pyerrors.h

index 28068d1cbe593933dcbd5525e1cfad80956ca243..0a661ffa75487dbceb98fc2084bc943b7a8e7628 100644 (file)
@@ -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);
index 1b57f6ea20f6f069bb71a3b2191f955ac56f0fac..a5387bd1f121180b9483f329e7be7e7fc94a6eae 100644 (file)
@@ -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, ...);
index 34e3de3328f4108a387cf4f6b006e93cbf31577b..4944feecd8a6b0e5e8243aa4dd50623abbc86b55 100644 (file)
@@ -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)