-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
gh-115304: Add doc for initialize PyMutex as global variables #115305
Conversation
aisk
commented
Feb 11, 2024
•
edited
Loading
edited
- Issue: The typical initialization of PyMutex in its comment document cannot be compiled on Windows #115304
… comment document
Include/internal/pycore_lock.h
Outdated
@@ -26,7 +26,7 @@ extern "C" { | |||
// 0b11: locked and has parked threads | |||
// | |||
// Typical initialization: | |||
// PyMutex m = (PyMutex){0}; | |||
// PyMutex m = {0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should make this change. The comment is for variables that need explicit initialization, such as local variables and fields in heap allocated structures. Static variables are implicitly initialized to zero in C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead we can add an additional example of statically initializing the PyMutex
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! For local variables, should we remove the cast (PyMutex)
? Seems it is needless in modern C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most commonly, we are initializing fields in a struct like:
self->mutex = (PyMutex){0};
You can't write:
self->mutex = {0}; // INVALID!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I've got the point!
Co-authored-by: Sam Gross <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!