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 — bpo-46836: Add Doc/c-api/frame.rst by vstinner · Pull Request #32051 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Mar 22, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Reorganize the documentation of the PyFrameObject C API.

https://bugs.python.org/issue46836

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
bpo-46836: Add Doc/c-api/frame.rst
58aedac
Reorganize the documentation of the PyFrameObject C API.
@vstinner vstinner added the skip news label Mar 22, 2022
@bedevere-bot bedevere-bot added the awaiting core review label Mar 22, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 22, 2022
@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Mar 22, 2022
@vstinner

vstinner commented Mar 22, 2022

Copy link
Copy Markdown
Member Author

My previous attempt to document PyFrameObject, in 2013: https://bugs.python.org/issue19431

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Mar 22, 2022

Copy link
Copy Markdown
Member

@markshannon ^^

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Mar 22, 2022
C API for the frame stack faster-cpython/ideas#309
Closed
@vstinner
Fix Sphinx syntax
675ffd6
markshannon
markshannon reviewed Mar 22, 2022
View reviewed changes

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

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.

Thanks, it makes sense to more all the Frame API docs to one place.

I'd really like discourage extension code from accessing the internals of the frame, as the integrity of the VM relies on it in subtle ways.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/c-api/frame.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/frame.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/frame.rst Outdated
.. versionchanged:: 3.11
The structure moved to the internal C API headers.

Public members:

@markshannon markshannon Mar 22, 2022

Copy link
Copy Markdown
Member

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.

It would be much safer to just say "don't access fields directly".

For example, f_lineno is not valid most of the time, we use it as an internal cache when tracing. f_back can be NULL even if the Python attribute is not None. Setting f_trace_lines or f_trace_opcodes may not do anything, as the change won't visible to the VM.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Mar 22, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

I updated the PR to clarify that these members are part of the Python API. My idea is just to explain that the Python API can be accessed in C as well.

Setting f_trace_lines or f_trace_opcodes may not do anything, as the change won't visible to the VM.

Well, it's technically possible to do that in pure Python. If there is a bug, it should be either documented or fixed. For example, disallow setting f_trace_lines and f_trace_opcodes.

Currently, f_trace_lines and f_trace_opcodes are not documented. IMO it's better to document them. If there are limits, we can document them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@markshannon markshannon Mar 22, 2022

Copy link
Copy Markdown
Member

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.

The struct fields cannot be safely accessed by C code. The limit is that you can't do it.
The Python attributes can be safely modified by PyObject_GetAttr etc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/c-api/frame.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner added 2 commits March 22, 2022 18:38
@vstinner
Clarify that members are part of the Python API
0d422ed
@vstinner
Address Mark's review
71c167d
markshannon
markshannon reviewed Mar 22, 2022
View reviewed changes
Comment thread Doc/c-api/frame.rst Outdated
The structure moved to the internal C API headers.

Public members of the Python API can be get and set with the
:c:func:`PyObject_GetAttrString` and :c:func:`PyObject_SetAttrString`

@markshannon markshannon Mar 22, 2022

Copy link
Copy Markdown
Member

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.

Given that this is the C API docs, any reference to Python attributes is likely to be misread as referring to C struct fields, so it is best not to list the Python attributes here.

Could you list the C API functions, PyFrame_GetLineNumber, etc, first?
I'll add docs to the new accessors here, as I add them.

Then add a comment that Python-level attributes can be accessed by PyObject_GetAttr[String] and PyObject_SetAttr[String] with an example:

E.g. PyObject_GetAttrString(frame, "f_lineno") is equivalent to PyFrame_GetLineNumber(frame)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon

markshannon commented Mar 23, 2022

Copy link
Copy Markdown
Member

@vstinner
I'd like to get at least a minimal version of this merged, so I have somewhere to put the docs for new PyFrame C-API functions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Don't document members for now
c524e8d
@markshannon

markshannon commented Mar 23, 2022

Copy link
Copy Markdown
Member

Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon markshannon mentioned this pull request Mar 23, 2022
bpo-42197: Don't create f_locals dictionary unless we actually need it. #32055
Merged
@vstinner
vstinner merged commit b0f886d into python:main Mar 23, 2022
@bedevere-bot bedevere-bot removed the awaiting core review label Mar 23, 2022
@vstinner
vstinner deleted the frame_doc branch March 23, 2022 12:19
@vstinner

vstinner commented Mar 23, 2022

Copy link
Copy Markdown
Member Author

@kumaraditya303: Can you please propose a PR for your changes?

Mark needed this PR for his PR #32055 and so I merged my PR.

I removed the whole section about "public members" since they are confusing. I will propose a second PR to find a way to document them.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303

kumaraditya303 commented Mar 23, 2022

Copy link
Copy Markdown
Contributor

@kumaraditya303: Can you please propose a PR for your changes?

Sure, seems like github removed my comments as I was still adding suggestions and the PR got merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request May 2, 2022
[C API] Move PyFrameObject to the internal C API #90992
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon markshannon left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@vstinner @gvanrossum @markshannon @kumaraditya303 @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.