Mark Shannon <[email protected]> added the comment:
The problem in the example you give is the need for the cast in the first
place. If `func` were a `PyCFunctionObject *` instead of a `PyObject *`, then
there would be no cast.
Making the casts explicit serves as a reminder that a type check is needed.
```
PyObject *func = ...;
int flags = PyCFunction_GET_FLAGS(func);
```
is dangerous.
```
PyObject *obj = ...;
if (PyCFunction_Check(obj)) {
PyCFunctionObject *func = (PyCFunctionObject *)obj;
int flags = func->m_ml->ml_flags;
```
is safe.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue47164>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com