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 vstinner
Recipients Mark.Shannon, kj, vstinner
Date 2022-03-30.14:00:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648648823.85.0.831736930555.issue47164@roundup.psfhosted.org>
In-reply-to
Content
> I think that adding macros makes readability worse.

See the attached PRs, I can remove multiple layers of parenthesis in macros by using CAST macros.

> ```
> PyObject *func = ...;
> int flags = PyCFunction_GET_FLAGS(func);
> ```
>
> is dangerous.

Right.

PEP 670 proposes to remove the cast, but only in the limited C API version 3.11 or newer. Sadly, I don't think that we can remove the cast in the general Python C API, it would simply add too many compiler warnings in existing C extensions which previously built without warnings. (See also PEP 670 discussions on python-dev).

Currently, PyCFunction_GET_FLAGS() doesn't check its argument. The macro documentation is quite explicit about it:

/* Macros for direct access to these values. Type checks are *not*
   done, so use with care. */

My GH-32190 PR adds a check in debug mode. So using PyCFunction_GET_FLAGS() in debug mode is safer with this PR.
History
Date User Action Args
2022-03-30 14:00:23vstinnersetrecipients: + vstinner, Mark.Shannon, kj
2022-03-30 14:00:23vstinnersetmessageid: <1648648823.85.0.831736930555.issue47164@roundup.psfhosted.org>
2022-03-30 14:00:23vstinnerlinkissue47164 messages
2022-03-30 14:00:23vstinnercreate