-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements #21850
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
Conversation
cc4e135
to
dbeef01
Compare
if (elements == 0xFFFF) { | ||
if (!compiler_subdict(c, e, i - elements, i)) { | ||
if (elements == USHRT_MAX) { | ||
if (!compiler_subdict(c, e, i - elements, i + 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.
I just made the minimum edit to fix the problem but I would just remove this checkpoint and simply keep incrementing elements
and leave the last check fill the dict, which is simpler and less error prone. Any reason we want to flush when we are in USHRT_MAX
elements @markshannon ?
To be clear, this is what I propose:
diff --git a/Python/compile.c b/Python/compile.c
index b2beef9327..a348b13676 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3893,19 +3893,7 @@ compiler_dict(struct compiler *c, expr_ty e)
ADDOP_I(c, DICT_UPDATE, 1);
}
else {
- if (elements == USHRT_MAX) {
- if (!compiler_subdict(c, e, i - elements, i + 1)) {
- return 0;
- }
- if (have_dict) {
- ADDOP_I(c, DICT_UPDATE, 1);
- }
- have_dict = 1;
- elements = 0;
- }
- else {
elements++;
- }
}
}
if (elements) {
My guess is that the I'm merging this as it fixes the issue and adds a test. |
Thanks @pablogsal for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
GH-21853 is a backport of this pull request to the 3.9 branch. |
…ments (pythonGH-21850) (cherry picked from commit c51db0e) Co-authored-by: Pablo Galindo <[email protected]>
@pablogsal Thanks for the fix. I like the test :) |
Seems that this logic was introduced in this commit:
|
Thanks @pablogsal for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
…ments (pythonGH-21850) (cherry picked from commit c51db0e) Co-authored-by: Pablo Galindo <[email protected]>
GH-22105 is a backport of this pull request to the 3.9 branch. |
Thanks @pablogsal for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry @pablogsal and @markshannon, I had trouble checking out the |
Thanks @pablogsal for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
…ments (pythonGH-21850) (cherry picked from commit c51db0e) Co-authored-by: Pablo Galindo <[email protected]>
GH-22107 is a backport of this pull request to the 3.9 branch. |
…ments (GH-21850) (GH-22107) (cherry picked from commit c51db0e) Co-authored-by: Pablo Galindo <[email protected]>
https://bugs.python.org/issue41531