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

gh-74929: Implement PEP 667 #115153

Merged
merged 44 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
42d7186
Basic prototype for frame proxy
gaogaotiantian Feb 7, 2024
7eeab1b
Fix some lint and remove oprun check
gaogaotiantian Feb 8, 2024
60e70e7
Not entirely work yet
gaogaotiantian Feb 8, 2024
1454ce4
Fix a bug
gaogaotiantian Feb 8, 2024
0045274
Change code style and add GC
gaogaotiantian Feb 13, 2024
de73bc9
Clean up code
gaogaotiantian Feb 13, 2024
ca92393
Disable all fast/local functions
gaogaotiantian Mar 1, 2024
ff886ff
Update tests for the new f_locals
gaogaotiantian Mar 2, 2024
9690a2d
Comment out the pop for now
gaogaotiantian Mar 2, 2024
6e9848a
Convert f_locals to dict first
gaogaotiantian Mar 2, 2024
b84b0df
Add static to static functions, add interface for new C API
gaogaotiantian Apr 24, 2024
bebff28
Add some tests and a few methods
gaogaotiantian Apr 26, 2024
d846de9
Implement all methods
gaogaotiantian Apr 27, 2024
d00a742
Make f_extra_locals extra lazy
gaogaotiantian Apr 27, 2024
1a4344d
Merge branch 'main' into pep667
gaogaotiantian Apr 27, 2024
f720e12
Fix typo
gaogaotiantian Apr 27, 2024
64d3772
Remove print debugging
gaogaotiantian Apr 27, 2024
2eadbf0
Fix some styling issue
gaogaotiantian Apr 27, 2024
cbae199
Update generated files for cAPI
gaogaotiantian Apr 27, 2024
9e7edf8
Remove f_fast_as_locals and useless calls for sys.settrace
gaogaotiantian Apr 27, 2024
523cb75
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 27, 2024
4b83311
Add the new type to static types
gaogaotiantian Apr 27, 2024
ae2db7c
Remove internal APIs for fast locals
gaogaotiantian Apr 27, 2024
bf45c02
Add extra tests for closure
gaogaotiantian Apr 27, 2024
026e15e
Add the type to globals-to-fix
gaogaotiantian Apr 27, 2024
f42980d
Add CAapi test
gaogaotiantian Apr 27, 2024
e693ad0
Polish lint
gaogaotiantian Apr 27, 2024
5dd045b
Apply some simple changes
gaogaotiantian Apr 28, 2024
30ecd4d
Update Misc/NEWS.d/next/Core and Builtins/2024-04-27-21-44-40.gh-issu…
gaogaotiantian Apr 28, 2024
f35c5e3
Abstract the key index part
gaogaotiantian Apr 28, 2024
5844fb4
Fix error handling
gaogaotiantian Apr 28, 2024
06277f9
Make key index work better
gaogaotiantian Apr 28, 2024
e1c3f56
Add comments for GetHiddenLocals
gaogaotiantian Apr 30, 2024
b672d84
Add global test
gaogaotiantian Apr 30, 2024
3e32572
Remove unsupported methods
gaogaotiantian May 2, 2024
8dc4664
Support non-string keys
gaogaotiantian May 2, 2024
652f641
Use static function for setitem
gaogaotiantian May 2, 2024
f29e6a3
Fix the list comp
gaogaotiantian May 3, 2024
e0ca4fe
Fix mapping check
gaogaotiantian May 3, 2024
f78156a
Fix frame_getlocals
gaogaotiantian May 3, 2024
4503145
Fix test error
gaogaotiantian May 3, 2024
cdac22c
Change the new ref for getcode
gaogaotiantian May 3, 2024
49287ff
Avoid creating the frame object if possible
gaogaotiantian May 3, 2024
378aacf
Remove a single blank line
gaogaotiantian May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Include/cpython/frameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ PyAPI_FUNC(int) _PyFrame_IsEntryFrame(PyFrameObject *frame);

PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
ncoghlan marked this conversation as resolved.
Show resolved Hide resolved


typedef struct {
PyObject_HEAD
PyFrameObject* frame;
} PyFrameLocalsProxyObject;
2 changes: 2 additions & 0 deletions Include/cpython/pyframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#endif

PyAPI_DATA(PyTypeObject) PyFrame_Type;
PyAPI_DATA(PyTypeObject) PyFrameLocalsProxy_Type;

#define PyFrame_Check(op) Py_IS_TYPE((op), &PyFrame_Type)
#define PyFrameLocalsProxy_Check(op) Py_IS_TYPE((op), &PyFrameLocalsProxy_Type)

PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
PyAPI_FUNC(PyObject *) PyFrame_GetLocals(PyFrameObject *frame);
Expand Down
6 changes: 6 additions & 0 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct _PyInterpreterFrame {
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
PyObject *f_extra_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
gaogaotiantian marked this conversation as resolved.
Show resolved Hide resolved
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
_Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */
int stacktop; /* Offset of TOS from localsplus */
Expand Down Expand Up @@ -126,6 +127,7 @@ _PyFrame_Initialize(
frame->f_builtins = func->func_builtins;
frame->f_globals = func->func_globals;
frame->f_locals = locals;
frame->f_extra_locals = PyDict_New();
gaogaotiantian marked this conversation as resolved.
Show resolved Hide resolved
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->instr_ptr = _PyCode_CODE(code);
Expand Down Expand Up @@ -235,6 +237,9 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg);
PyObject *
_PyFrame_GetLocals(_PyInterpreterFrame *frame, int include_hidden);

PyObject *
_PyFrame_GetHiddenLocals(_PyInterpreterFrame *frame);

int
_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);

Expand Down Expand Up @@ -289,6 +294,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
frame->f_globals = NULL;
#endif
frame->f_locals = NULL;
frame->f_extra_locals = NULL;
frame->stacktop = code->co_nlocalsplus + stackdepth;
frame->frame_obj = NULL;
frame->instr_ptr = _PyCode_CODE(code);
Expand Down
Loading
Loading