-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
bpo-40521: [subinterpreters] Make dtoa bigint free list per-interpreter #24821
Conversation
Include/internal/pycore_dtoa.h
Outdated
|
||
typedef uint32_t ULong; | ||
typedef int32_t Long; | ||
typedef uint64_t ULLong; |
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.
Many C files include directly or indirectly pycore_interp.h which includes pycore_dtoa.h. I would prefer to not pollule their namespaces with names like Kmax, ULong, Long, UULong which can clash with other names.
I see different options:
- Don't fix dtoa.c for now
- Add a prefix to all these names in the header file (ex: "PyDtoa") and create aliases in dtoa.c (ex:
#define Kmax _PyDtoa_Kmax
). - Add an API like PyInterpreterState.dict to have per-interpreter variables: the freelist would be dynamically allocated on the heap memory, and stored as a raw pointer in PyInterpreterState. Or if you don't want to add a whole API, just expose the cache as a "void *" in the structure, and add init/fini functions to allocate/free this structure (free list).
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 your review. I chose the second option to fix this problem.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
I have removed the news. But I don't know how to make bedevere/news — No news entry in Misc/NEWS.d/next/ or "skip news" label found check success. |
Include/internal/pycore_dtoa.h
Outdated
_PyDtoa_ULong x[1]; | ||
}; | ||
|
||
typedef struct Bigint Bigint; |
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.
This typedef is not needed in pycore_interp.h, please move it into dtoa.c.
Include/internal/pycore_dtoa.h
Outdated
struct | ||
Bigint { | ||
struct Bigint *next; |
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.
struct | |
Bigint { | |
struct Bigint *next; | |
struct _PyDtoa_Bigint { | |
struct _PyDtoa_Bigint *next; |
Include/internal/pycore_interp.h
Outdated
@@ -321,6 +322,7 @@ struct _is { | |||
|
|||
struct ast_state ast; | |||
struct type_cache type_cache; | |||
Bigint *bigint_freelist[_PyDtoa_Kmax+1]; |
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.
Bigint *bigint_freelist[_PyDtoa_Kmax+1]; | |
struct _PyDtoa_Bigint *dtoa_freelist[_PyDtoa_Kmax + 1]; |
Python/dtoa.c
Outdated
|
||
if (k <= Kmax && (rv = freelist[k])) | ||
freelist[k] = rv->next; | ||
PyInterpreterState *is = PyInterpreterState_Get(); |
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 would prefer to add a helper function get_freelist().
I suggest to use _PyInterpreterState_GET() which is faster than PyInterpreterState_Get().
Python/dtoa.c
Outdated
#define Kmax _PyDtoa_Kmax | ||
#define ULong _PyDtoa_ULong | ||
#define Long _PyDtoa_Long | ||
#define ULLong _PyDtoa_ULLong |
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.
#define Kmax _PyDtoa_Kmax | |
#define ULong _PyDtoa_ULong | |
#define Long _PyDtoa_Long | |
#define ULLong _PyDtoa_ULLong | |
#define ULong _PyDtoa_ULong | |
#define Long _PyDtoa_Long | |
#define ULLong _PyDtoa_ULLong | |
#define Kmax _PyDtoa_Kmax | |
typedef struct _PyDtoa_Bigint Bigint; |
Include/internal/pycore_dtoa.h
Outdated
@@ -1,4 +1,6 @@ | |||
#ifndef PY_NO_SHORT_FLOAT_REPR | |||
#ifndef Py_CORE_DTOA_H |
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.
To follow other files, you should use "INTERNAL" instead: #ifndef Py_INTERNAL_DTOA_H
.
Include/internal/pycore_interp.h
Outdated
@@ -321,6 +322,7 @@ struct _is { | |||
|
|||
struct ast_state ast; | |||
struct type_cache type_cache; | |||
Bigint *bigint_freelist[_PyDtoa_Kmax+1]; |
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.
You need to add:
#ifndef PY_NO_SHORT_FLOAT_REPR
...
#endif
If the PY_NO_SHORT_FLOAT_REPR macro is defined, dtoa.c is not used.
Thank vstinner, for your very detailed review. I did not consider these details before. |
I have made the requested changes; please review again |
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
Python/dtoa.c
Outdated
|
||
/* Get Bigint freelist from interpreter */ | ||
static Bigint ** | ||
get_freelist() { |
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.
See "function declaration isn’t a prototype [-Wstrict-prototypes]" compiler warning:
get_freelist() { | |
get_freelist(void) { |
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.
Thank you for your review, sorry I didn't pay attention to the warning.
I have made the requested changes; please review again |
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
Can you please build Python with PY_NO_SHORT_FLOAT_REPR macro defined? For example, add -DPY_NO_SHORT_FLOAT_REPR=1 flag in CFLAGS. |
@vstinner Thank you for your reminder, I added
After I revert my commit and run the unit test as well, there will still be these errors. |
I merged your PR thanks.
I just wanted to check if it's possible to build Python in the PY_NO_SHORT_FLOAT_REPR macro defined: it's the case, thanks. I'm not interetesed by test_configparser failures. Platforms where PY_NO_SHORT_FLOAT_REPR macro is defined are rare. If an user of one of such platform is impacted, they can report an issue. |
https://bugs.python.org/issue40521
Make dtoa bigint free list per-interpreter
https://bugs.python.org/issue40521