8000 gh-128421: Add locking to most frame object functions by colesbury · Pull Request #131479 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128421: Add locking to most frame object functions #131479

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

Merged
merged 6 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Add additional locks
  • Loading branch information
colesbury committed Mar 21, 2025
commit 3cd5cf49c40a2aff6d972a68daf9e5f197946b31
26 changes: 22 additions & 4 deletions Objects/clinic/frameobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ static PyMemberDef frame_memberlist[] = {
};

/*[clinic input]
@critical_section
@getter
frame.f_locals as frame_locals

Expand All @@ -927,7 +928,7 @@ Return the mapping used by the frame to look up local variables.

static PyObject *
frame_locals_get_impl(PyFrameObject *self)
/*[clinic end generated code: output=b4ace8bb4cae71f4 input=badf3ad13216129f]*/
/*[clinic end generated code: output=b4ace8bb4cae71f4 input=7bd444d0dc8ddf44]*/
{
assert(!_PyFrame_IsIncomplete(self->f_frame));

Expand Down Expand Up @@ -989,6 +990,7 @@ frame_lineno_get_impl(PyFrameObject *self)
}

/*[clinic input]
@critical_section
@getter
frame.f_lasti as frame_lasti

Expand All @@ -997,7 +999,7 @@ Return the index of the last attempted instruction in the frame.

static PyObject *
frame_lasti_get_impl(PyFrameObject *self)
/*[clinic end generated code: output=03275b4f0327d1a2 input=50404c3d0708e39e]*/
/*[clinic end generated code: output=03275b4f0327d1a2 input=0225ed49cb1fbeeb]*/
{
int lasti = _PyInterpreterFrame_LASTI(self->f_frame);
if (lasti < 0) {
Expand Down Expand Up @@ -1982,14 +1984,15 @@ frame_clear_impl(PyFrameObject *self)
}

/*[clinic input]
@critical_section
frame.__sizeof__

Return the size of the frame in memory, in bytes.
[clinic start generated code]*/

static PyObject *
frame___sizeof___impl(PyFrameObject *self)
/*[clinic end generated code: output=82948688e81078e2 input=1a07b2d6a8e166a5]*/
/*[clinic end generated code: output=82948688e81078e2 input=908f90a83e73131d]*/
{
Py_ssize_t res;
res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus);
Expand Down Expand Up @@ -2379,21 +2382,18 @@ PyFrame_GetBuiltins(PyFrameObject *frame)
int
PyFrame_GetLasti(PyFrameObject *frame)
{
int ret;
Py_BEGIN_CRITICAL_SECTION(frame);
assert(!_PyFrame_IsIncomplete(frame->f_frame));
int lasti = _PyInterpreterFrame_LASTI(frame->f_frame);
if (lasti < 0) {
return -1;
}
return lasti * sizeof(_Py_CODEUNIT);
ret = lasti < 0 ? -1 : lasti * sizeof(_Py_CODEUNIT);
Py_END_CRITICAL_SECTION();
return ret;
}

PyObject *
PyFrame_GetGenerator(PyFrameObject *frame)
{
assert(!_PyFrame_IsIncomplete(frame->f_frame));
if (frame->f_frame->owner != FRAME_OWNED_BY_GENERATOR) {
return NULL;
}
PyGenObject *gen = _PyGen_GetGeneratorFromFrame(frame->f_frame);
return Py_NewRef(gen);
return frame_generator_get((PyObject *)frame, NULL);
}
Loading
0