Skip to content

bpo-44032: Move pointer to code object from frame-object to frame specials array. - #26771

Merged
markshannon merged 2 commits into
python:mainfrom
faster-cpython:add-code-to-specials
Jun 18, 2021
Merged

markshannon merged 2 commits into
python:mainfrom
faster-cpython:add-code-to-specials

Conversation

@markshannon

@markshannon markshannon commented Jun 17, 2021 •

Copy link
Copy Markdown
Member

The f_code field is the last field in the frame object that cannot be lazily evaluated if we want to lazily create frame objects, or ignore them in the interpreter.

https://bugs.python.org/issue44032

@markshannon

Copy link
Copy Markdown
Member Author

Skipping news as this is just making f_code consistent with f_globals and f_builtins.

@ericsnowcurrently ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I left one minor suggestion for simplifying the GDB tooling. Otherwise this looks ready to go.

Comment thread Tools/gdb/libpython.py Outdated
Comment on lines +904 to +906
f_valuestack = self.field('f_valuestack')
code = f_valuestack[FRAME_SPECIALS_CODE_OFFSET - FRAME_SPECIALS_SIZE]
return PyCodeObjectPtr.from_pyobject_ptr(code)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it doesn't matter much but it's too bad you can't use self._f_specials() here. With a small adjustment to _f_specials() this code becomes simpler and more uniform.

For example, let the caller pass the wrapper to use (and default to PyObjectPtr):

Suggested change
f_valuestack = self.field('f_valuestack')
code = f_valuestack[FRAME_SPECIALS_CODE_OFFSET - FRAME_SPECIALS_SIZE]
return PyCodeObjectPtr.from_pyobject_ptr(code)
return self._f_specials(FRAME_SPECIALS_CODE_OFFSET, PyCodeObjectPtr)

...or let _f_specials() decide based on the index (since this code is already so specific and tightly coupled):

Suggested change
f_valuestack = self.field('f_valuestack')
code = f_valuestack[FRAME_SPECIALS_CODE_OFFSET - FRAME_SPECIALS_SIZE]
return PyCodeObjectPtr.from_pyobject_ptr(code)
return self._f_specials(FRAME_SPECIALS_CODE_OFFSET)
@markshannon
markshannon merged commit 0982ded into python:main Jun 18, 2021
jdevries3133 pushed a commit to jdevries3133/cpython that referenced this pull request Jun 19, 2021
@nedbat

nedbat commented Jul 8, 2021

Copy link
Copy Markdown
Member

I'm confused about how I'm meant to access the code for a frame now? The struct member is gone, and the accessor function has a leading underscore. Is there a supported way to get to the code for a frame?

@nedbat

nedbat commented Jul 8, 2021

Copy link
Copy Markdown
Member

Oh, sorry, PyFrame_GetCode, got it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants