Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 18, 2021

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Jun 17, 2021

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
Member Author

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

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

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 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
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
Copy link
Member

nedbat commented Jul 8, 2021

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
Copy link
Member

nedbat commented Jul 8, 2021

Oh, sorry, PyFrame_GetCode, got it :)

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

Successfully merging this pull request may close these issues.

5 participants