Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Inconsistencies in error propagation after calling_PyFrame_GetFrameObject #144693

Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@taegyunkim

Description

@taegyunkim

Bug report

Bug description:

There are 3 callers of_PyFrame_GetFrameObject which explicitly clear error when it returns NULL.

  1. take_ownership
    PyFrameObject*back=_PyFrame_GetFrameObject(prev);
    if (back==NULL) {
    /* Memory error here. */
    assert(PyErr_ExceptionMatches(PyExc_MemoryError));
    /* Nothing we can do about it */
    PyErr_Clear();
  2. PyEval_GetFrame

    cpython/Python/ceval.c

    Lines 2562 to 2564 inb67a64d

    PyFrameObject*f=_PyFrame_GetFrameObject(frame);
    if (f==NULL) {
    PyErr_Clear();
  3. PyThreadState_GetFrame

    cpython/Python/pystate.c

    Lines 2101 to 2103 inb67a64d

    PyFrameObject*frame=_PyFrame_GetFrameObject(f);
    if (frame==NULL) {
    PyErr_Clear();

PyEval_GetFrame andPyThreadState_GetFrame docs say that NULL is returned when "no frame is currently executing", and doesn't say anything about any error (probably as they explicitly clear it?).

I wonder whetherPyFrame_GetBack also would want to clear error

if (prev) {
back=_PyFrame_GetFrameObject(prev);
}

PyFrame_GetBack's documentation doesn't say anything aboutMemoryError which can be set by its internal API callshttps://docs.python.org/3.15/c-api/frame.html#c.PyFrame_GetBack

The rest of the_PyFrame_GetFrameObject callers that don't clear error includingPyFrame_GetBack are

AndPyEval_GetLocals andPyFrame_GetBack are public C APIs that don't check for NULL and don't clear the error. I guess the internals are ok to propagate the errors?

Can someone explain whetherPyFrame_GetBack not clearing error on null is ok/intended or it's a discrepancy/bug?

I would preferPyFrame_GetBack to not propagate an error given that its documentation doesn't say anything about MemoryError.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp