Skip to content

bpo-31828: make Py_tss_NEEDS_INIT usable in non-static initialisers #4060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct _Py_tss_t {
#undef NATIVE_TSS_KEY_T

/* When static allocation, you must initialize with Py_tss_NEEDS_INIT. */
#define Py_tss_NEEDS_INIT {0}
#define Py_tss_NEEDS_INIT ((Py_tss_t) {0})
Copy link
Contributor

@ma8ma ma8ma Oct 20, 2017

Choose a reason for hiding this comment

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

Sadly, the compound literals is not compatible with C++ standard 😣 (it's a C99 feature)
A similar issue of the C-API header was pointed out at related #1362 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, then ... should we just distinguish the C and C++ cases? And maybe even MSVC from the real compilers, as usual?

I mean, this is a public header file. It's fairly annoying if it constrains the applicability of its definitions. I guess I'll have to open a new ticket for this one after all...

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, we've solved an initialization issue of a TSS key by using temporary variables. #1362 (comment)

cpython/Python/pystate.c

Lines 49 to 54 in 731e189

/* A TSS key must be initialized with Py_tss_NEEDS_INIT
in accordance with the specification. */
{
Py_tss_t initial = Py_tss_NEEDS_INIT;
runtime->gilstate.autoTSSkey = initial;
}

#endif /* !Py_LIMITED_API */

PyAPI_FUNC(Py_tss_t *) PyThread_tss_alloc(void);
Expand Down