Skip to content
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
3 changes: 0 additions & 3 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,6 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
/* Trampoline frame */
frame = frame->previous;
}
if (frame == NULL) {
Copy link
Contributor

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?

Copy link
Contributor Author

@rruuaanng rruuaanng Sep 20, 2024

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

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.

Copy link
Contributor Author

@rruuaanng rruuaanng Sep 20, 2024

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.

cpython/Python/traceback.c

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.

break;
}
/* Can't have more than one shim frame in a row */
assert(frame->owner != FRAME_OWNED_BY_CSTACK);
depth++;
Expand Down
Loading