Conversation
Initialize all fields in the macro. Otherwise, g++ -Wall -Wextra complains that some fields are not initialized [-Werror=missing-field-initializers]: error: missing initializer for member ‘PySlot::sl_flags’ error: missing initializer for member ‘PySlot::<anonymous>’ error: missing initializer for member ‘PySlot::<anonymous>’
|
Note: I found this issue while working on adding support for the limited C API to pythoncapi-compat which builds its C/C++ extension with |
|
I created this PR to just fix I also prepared draft PR #158867 which enables |
| {.sl_id=(NAME), .sl_flags=PySlot_STATIC, .sl_ptr=(VALUE)} | ||
|
|
||
| #define PySlot_END {0} | ||
| #define PySlot_END {0, 0, {0}, {0}} |
There was a problem hiding this comment.
I'm not 100% sure that this syntax works on all C/C++ compilers. In C, it's common to use {0}. A more ugly alternative is to have a separated implementation for C++:
#ifdef __cplusplus
# define PySlot_END {0, 0, {0}, {0}}
#else
# define PySlot_END {0}
#endif
There was a problem hiding this comment.
Maybe use NULL?
| #define PySlot_END {0, 0, {0}, {0}} | |
| #define PySlot_END {0, 0, {0}, {NULL}} |
Not sure if compilers warn about this, but I heard that C++ is stricter about nullptr↔int casts.
|
I updated the branch to retrieve the MSan fix. |
|
cc @encukou |
Initialize all fields in the macro. Otherwise, g++ -Wall -Wextra complains that some fields are not initialized
[-Werror=missing-field-initializers]:
error: missing initializer for member ‘PySlot::sl_flags’
error: missing initializer for member ‘PySlot::’
error: missing initializer for member ‘PySlot::’