This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Mark.Shannon
Recipients Mark.Shannon, vstinner
Date 2022-03-30.13:20:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648646434.7.0.019781167108.issue47164@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-03-30 13:20:34Mark.Shannonsetrecipients: + Mark.Shannon, vstinner
2022-03-30 13:20:34Mark.Shannonsetmessageid: <1648646434.7.0.019781167108.issue47164@roundup.psfhosted.org>
2022-03-30 13:20:34Mark.Shannonlinkissue47164 messages
2022-03-30 13:20:34Mark.Shannoncreate