Skip to content

gh-149044: Fix PySlot_END macro for C++ - #158866

Open
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:pyslot_end
Open

vstinner wants to merge 2 commits into
python:mainfrom
vstinner:pyslot_end

Conversation

@vstinner

@vstinner vstinner commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

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::’

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>’
@vstinner vstinner added topic-C-API needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Oct 5, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 5, 2026
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

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 -Wall -Wextra. See python/pythoncapi-compat#184.

@vstinner vstinner removed the type-feature A feature request or enhancement label Oct 5, 2026
@vstinner

vstinner commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

I created this PR to just fix PySlot_END so it can be easily backported.

I also prepared draft PR #158867 which enables -Wall -Wextra in test_cext for the main branch.

Comment thread Include/slots.h
{.sl_id=(NAME), .sl_flags=PySlot_STATIC, .sl_ptr=(VALUE)}

#define PySlot_END {0}
#define PySlot_END {0, 0, {0}, {0}}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.15 pre-release feature fixes, bugs and security fixes topic-C-API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant