[issue47164] [C API] Add private "CAST" macros to clean up casts in C code

Ken Jin report at bugs.python.org
Wed Mar 30 09:52:27 EDT 2022


Ken Jin <kenjin4096 at gmail.com> added the comment:

> tiny inline function obscures the meaning of code

Sadly I have to agree with Mark for that specific case. I've had to debug a segfault before only because the inline function implicitly cast its arguments, and it was accessing a non-existent member. If it were a macro it would access the struct member directly, and the compiler would be able to catch that and warn me before runtime.

However, for the case of _PyCFunctionObject_CAST, I'm not against it. The assert(PyCFunction_Check) pattern has genuinely helped me catch problems in the case of similar macros.

----------
nosy: +kj

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47164>
_______________________________________


More information about the Python-bugs-list mailing list