-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-124265: Remove redundant if statements in traceback.c #124272
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
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
/* Trampoline frame */ | ||
frame = frame->previous; | ||
} | ||
if (frame == NULL) { |
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.
Why, but why do you think that frame->previous
on L981 is not NULL
?
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.
If frame is part of a chain and there might be a situation where it’s traversed backwards, then at that point in the code
Line 975 in 7a2d77c
frame = frame->previous; |
It should break out. That’s what I think.
I’m not sure if my description is accurate. it’s just how I imagine the situation.
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.
static void
dump_traceback(int fd, PyThreadState *tstate, int write_header)
{
if (write_header) {
PUTS(fd, "Stack (most recent call first):\n");
}
if (tstate_is_freed(tstate)) {
PUTS(fd, " <tstate is freed>\n");
return;
}
_PyInterpreterFrame *frame = tstate->current_frame;
if (frame == NULL) {
PUTS(fd, " <no Python frame>\n");
return;
}
unsigned int depth = 0;
while (1) {
if (MAX_FRAME_DEPTH <= depth) {
if (MAX_FRAME_DEPTH < depth) {
PUTS(fd, "plus ");
_Py_DumpDecimal(fd, depth);
PUTS(fd, " frames\n");
}
break;
}
dump_frame(fd, frame);
frame = frame->previous;
if (frame == NULL) {
break;
}
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
/* Trampoline frame */
frame = frame->previous;
}
// if (frame == NULL) {
// break;
// }
/* Can't have more than one shim frame in a row */
assert(frame->owner != FRAME_OWNED_BY_CSTACK);
depth++;
}
}
I hid the targets I needed to modify by commenting them out.
Lines 983 to 985 in 7a2d77c
if (frame == NULL) { | |
break; | |
} |
Then run PCbuild/build.bat
, I then ran the tests using ./python Lib\test\test_traceback.py
.
It seemed to run well as it passed all 347 tests in about 8.3 seconds.
PS E:\code\cc\cpython\alpha\cpython-main> ./python .\Lib\test\test_traceback.py
Running Debug|x64 interpreter...
...........................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 347 tests in 8.303s
OK
But I can't understand why it fails on CI. Maybe I ran the test incorrectly.
Hmm, failures seems to be related to the pr. |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Well, maybe my guess is wrong. |
I ran the test file which gave an error on ci, but the result seemed to be correct.
|
I got locally same result as for hypothesis tests, maybe it depends on the system:
Sorry, but your patch clearly triggers CI failures. |
For the specific reasoning, please refer to #124265.
If there are any issues with my reasoning, I will close this PR.