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 — Add PyFrame_SetLineNumber() for Cython · Issue #118720 · python/cpython

Add PyFrame_SetLineNumber() for Cython #118720

New issue
Copy link
New issue
Copy link
Open
Open
Add PyFrame_SetLineNumber() for Cython#118720
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

Description

@methane
methane
opened on May 7, 2024
Issue body actions

Feature or enhancement

Proposal:

CPython hides PyFrameObject internals so Cython include pycore_frame.h to set f_lineno.
Let's provide PyFrame_SetLineNumber() for Cython.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

#117551 (comment)

Linked PRs

  • gh-118720: Add PyFrame_SetLineNumber() function #131246

Activity

  1. methane
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-C-API
    on May 7, 2024
  2. Ben4C commented on Aug 14, 2024

    @Ben4C
    Ben4C
    on Aug 14, 2024
    More actions

    Hello, I've been working on this for a little while, but I'm a bit lost on implementing the changes.

    From what I understand think I'm supposed to create a public API to set the f_fileno variable so I used PyAPI_FUNC(int) PyFrame_SetLineNumber(PyFrameObject *f, int lineno) in Include/cpython/frameobject.h which uses frame_setlineno from frameobject.c to change the f_lineno. I've been trying to get a test to pass to verify that this works in
    Lib/test/test_frame.py but I'm not sure if my approach or logic is correct.

    This is what I have so far: Ben4C@1e82093

    Reacted by Inada Naoki
  3. vstinner
    added 3 commits that reference this issue on Mar 14, 2025

    pythongh-118720: Add PyFrame_SetLineNumber() function

    9a8d371

    pythongh-118720: Add PyFrame_SetLineNumber() function

    09cbced

    pythongh-118720: Add PyFrame_SetLineNumber() function

    dcf27bf
  4. vstinner commented on Mar 14, 2025

    @vstinner
    vstinner
    on Mar 14, 2025
    Member
    More actions

    This function was also discussed at #130931.

  5. vstinner commented on Mar 14, 2025

    @vstinner
    vstinner
    on Mar 14, 2025
    Member
    More actions

    I wrote PR gh-131246 to add PyFrame_SetLineNumber().

  6. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 14, 2025
  7. markshannon commented on Mar 17, 2025

    @markshannon
    markshannon
    on Mar 17, 2025
    Member
    More actions

    I think is going to be very confusing if PyFrame_SetLineNumber has different behavior from setting the line number in Python frame.f_lineno = ....

    The f_lineno field in the the frame object is a cache for the computed line number.
    It may overwritten by the interpreter, so setting it will not work reliably.

  8. vstinner commented on Mar 17, 2025

    @vstinner
    vstinner
    on Mar 17, 2025
    Member
    More actions

    I wrote this function to replace the Cython macro:

    #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)

    I suppose that Cython sets f_lineno to produce a traceback with specific line number.

    cc @scoder @da-woods

  9. da-woods commented on Mar 17, 2025

    @da-woods
    da-woods
    on Mar 17, 2025
    Contributor
    More actions

    I suppose that Cython sets f_lineno to produce a traceback with specific line number.

    Yes - it's used directly after creating a frame for that purpose.

    (It's also used in the old, pre-sys-monitoring code. I would not worry about replacing that usage because I think that's only on older Python versions)

  10. markshannon commented on Mar 18, 2025

    @markshannon
    markshannon
    on Mar 18, 2025
    Member
    More actions

    So what are the proposed semantics of PyFrame_SetLineNumber(), how do we test it?

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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — 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.