GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Expose _PyInterpreterFrame_GetLine in the private API · Issue #96803 · python/cpython

Expose _PyInterpreterFrame_GetLine in the private API #96803

New issue
Copy link
New issue
Copy link
Closed
Closed
Expose _PyInterpreterFrame_GetLine in the private API#96803
Copy link
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@pablogsal
pablogsal
opened on Sep 13, 2022
Issue body actions

In 3.11 we are using now an opaque pointer to _PyInterpreterFrame in the eval function. The problem is that for PEP 523's APIs, we changed the type of _PyFrameEvalFunction to be PyObject *(*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag) but there is no way to do anything with _PyInterpreterFrame because is opaque. Even if the extension defines PY_BUILD_CORE the symbols are not exposed in the executable/libpython, which means that including the headers is insufficient.

This is a problem because it really limits what users of PEP 523 can do with the frame object that they receive, even if is opaque. Most profilers using PEP 523 API do it for speed reasons and the only thing they need is to get the line number, but that is now impossible because the pointer is opaque and we don't offer any exposed APIs.

Linked PRs

  • GH-96803: Add three C-API functions to make _PyInterpreterFrame less opaque for users of PEP 523. #96849
  • GH-96803: Document and test new unstable internal frame API functions #104211
  • GH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h #107188
  • [3.12] GH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h (GH-107188) #107195
Reacted by Gregory P. Smith

Activity

Next
  1. pablogsal
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on Sep 13, 2022
  2. pablogsal commented on Sep 13, 2022

    @pablogsal
    pablogsal
    on Sep 13, 2022
    MemberAuthor
    More actions

    CC: @markshannon @brandtbucher @iritkatriel @ericsnowcurrently

  3. ericsnowcurrently commented on Sep 13, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Sep 13, 2022
    Member
    More actions

    CC @mdboom

  4. markshannon commented on Sep 14, 2022

    @markshannon
    markshannon
    on Sep 14, 2022
    Member
    More actions

    I see your point, but I don't think that _PyInterpreterFrame_GetLine() is the right API.
    I think the pair of _PyInterpreterFrame_GetCode() and _PyInterpreterFrame_GetLasti() would be better.
    Getting the offset is much cheaper than computing the line number.
    The line number can be computed, if needed.
    Other information to be extracted from the code object, such as the filename and function name.

    Reacted by Pablo Galindo Salgado
  5. markshannon
    assigned
    markshannon
    and unassigned
    markshannon
    on Sep 14, 2022
  6. pablogsal commented on Sep 15, 2022

    @pablogsal
    pablogsal
    on Sep 15, 2022
    MemberAuthor
    More actions

    I started exposing _PyInterpreterFrame_GetCode and _PyInterpreterFrame_GetLasti but then I realized that neither _PyInterpreterFrame_GetCode and _PyInterpreterFrame_GetLasti are in 3.12 so exposing those is going to be more chaotic than just exposing _PyInterpreterFrame_GetLine. Notice that if the application defines PY_BUILD_CORE it can already access f_code and f_lasti manually from the struct.

    As there can be arbitrary logic in _PyInterpreterFrame_GetLine I still think is a better idea to export _PyInterpreterFrame_GetLine.

  7. pablogsal
    added a commit that references this issue on Sep 15, 2022

    pythongh-96803: Export _PyInterpreterFrame_GetLine as a private API s…

    0bedc88
  8. markshannon commented on Sep 15, 2022

    @markshannon
    markshannon
    on Sep 15, 2022
    Member
    More actions

    It still think that the pair of _PyInterpreterFrame_GetCode and _PyInterpreterFrame_GetLasti is a better interface.

    If you think that doing that would be too disruptive for 3.11, we can add them for 3.12, and just expose _PyInterpreterFrame_GetLine for 3.11.

  9. pablogsal commented on Sep 15, 2022

    @pablogsal
    pablogsal
    on Sep 15, 2022
    MemberAuthor
    More actions

    If you think that doing that would be too disruptive for 3.11, we can add them for 3.12, and just expose

    In 3.12 they are already exposed if the user calls PY_BUILD_CORE because one is a macro and the other can be basically substituted by frame->f_code because the struct definition is available if PY_BUILD_CORE is defined. The problem here is having to re-implement _PyInterpreterFrame_GetLine.

    Exposing _PyInterpreterFrame_GetCode and _PyInterpreterFrame_GetLasti doesn't give the user anything that cannot be achieved by just calling frame->f_code and frame->f_lasti after defining PY_BUILD_CORE

  10. markshannon commented on Sep 15, 2022

    @markshannon
    markshannon
    on Sep 15, 2022
    Member
    More actions

    _PyInterpreterFrame_GetLine is quite simple once we have the other two functions. There is no harm in exposing it as well.

    the struct definition is available if PY_BUILD_CORE is defined.

    All that does is expose the existence of a field call f_code. It doesn't say anything about its meaning or when it is valid.

    In general, frame->f_code cannot be substituted for _PyInterpreterFrame_GetCode() as the meaning of frame->f_code is not defined. E.g. we might make it such that f_code is only valid for some frames faster-cpython/ideas#111

  11. pablogsal commented on Sep 15, 2022

    @pablogsal
    pablogsal
    on Sep 15, 2022
    MemberAuthor
    More actions

    Ok, I am convinced. I will expose _PyInterpreterFrame_GetCode and _PyInterpreterFrame_GetLasti

  12. pablogsal
    added a commit that references this issue on Sep 15, 2022

    pythongh-96803: Export _PyInterpreterFrame_GetLine as a private API s…

    7c6a288
  13. 4 remaining items

  14. markshannon
    added a commit that references this issue on May 5, 2023

    GH-96803: Add three C-API functions to make _PyInterpreterFrame less …

    a0df9ee
  15. erlend-aasland commented on May 5, 2023

    @erlend-aasland
    erlend-aasland
    on May 5, 2023
    Contributor
    More actions

    gh-96849 added new APIs, but no documentation was added. Mentioning it here, so we don't forget before we close this issue.

  16. carljm
    added a commit that references this issue on May 5, 2023

    Merge branch 'main' into inlinecomp2

    baacf5f
  17. jbower-fb
    added a commit that references this issue on May 8, 2023

    pythonGH-96803: Add three C-API functions to make _PyInterpreterFrame…

    5405b60
  18. encukou commented on May 9, 2023

    @encukou
    encukou
    on May 9, 2023
    Member
    More actions

    Note that even unstable API needs tests as well as documentation.

    Reacted by Erlend E. Aasland
  19. markshannon
    added a commit that references this issue on May 18, 2023

    GH-96803: Document and test new unstable internal frame API functions (…

    cfa517d
  20. carljm
    added a commit that references this issue on May 18, 2023

    Merge branch 'main' into nestedcomps

    54095f0
  21. vstinner
    added 3 commits that reference this issue on Jul 24, 2023

    pythonGH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h

    dda1d19

    pythonGH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h

    debe329

    GH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h (#10…

    837fa5c
  22. miss-islington
    added a commit that references this issue on Jul 24, 2023

    pythonGH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h (

    89ff7bd
  23. vstinner
    added a commit that references this issue on Jul 24, 2023

    [3.12] GH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python…

    f573a6a
  24. jtcave
    added a commit that references this issue on Jul 27, 2023

    pythonGH-96803: Move PyUnstable_InterpreterFrame_GetCode() to Python.h (

    654956f
  25. iritkatriel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Nov 26, 2023
  26. hugovk
    closed this as completedon Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.