Skip to content

Commit 941d705

Browse files
authored
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).
1 parent 069c96f commit 941d705

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Include/boolobject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ PyAPI_DATA(PyLongObject) _Py_FalseStruct;
1919
PyAPI_DATA(PyLongObject) _Py_TrueStruct;
2020

2121
/* Use these macros */
22-
#define Py_False ((PyObject *) &_Py_FalseStruct)
23-
#define Py_True ((PyObject *) &_Py_TrueStruct)
22+
#define Py_False _PyObject_CAST(&_Py_FalseStruct)
23+
#define Py_True _PyObject_CAST(&_Py_TrueStruct)
2424

2525
// Test if an object is the True singleton, the same as "x is True" in Python.
2626
PyAPI_FUNC(int) Py_IsTrue(PyObject *x);

Include/ceval.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
3131

3232
/* Deprecated since PyEval_CallObjectWithKeywords is deprecated */
3333
#define PyEval_CallObject(callable, arg) \
34-
PyEval_CallObjectWithKeywords(callable, arg, (PyObject *)NULL)
34+
PyEval_CallObjectWithKeywords(callable, arg, _PyObject_CAST(_Py_NULL))
3535

3636
Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallFunction(
3737
PyObject *callable, const char *format, ...);

Include/pyerrors.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
6262

6363
PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);
6464

65-
#define PyExceptionInstance_Class(x) ((PyObject*)Py_TYPE(x))
65+
#define PyExceptionInstance_Class(x) _PyObject_CAST(Py_TYPE(x))
6666

6767
#define _PyBaseExceptionGroup_Check(x) \
6868
PyObject_TypeCheck(x, (PyTypeObject *)PyExc_BaseExceptionGroup)

0 commit comments

Comments
 (0)