Skip to content

Commit af9df82

Browse files
committed
FrameLocalsProxy AC vectorcall
1 parent 1cc5802 commit af9df82

2 files changed

Lines changed: 85 additions & 33 deletions

File tree

‎Objects/clinic/frameobject.c.h‎

Lines changed: 60 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/frameobject.c‎

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class frame "PyFrameObject *" "&PyFrame_Type"
4040
[clinic start generated code]*/
4141
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2d1dbf2e06cf351f]*/
4242

43+
/*[clinic input]
44+
class FrameLocalsProxy "PyFrameLocalsProxyObject *" "&PyFrameLocalsProxy_Type"
45+
[clinic start generated code]*/
46+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b877b1c7551e6925]*/
47+
4348

4449
// Returns new reference or NULL
4550
static PyObject *
@@ -452,36 +457,32 @@ framelocalsproxy_dealloc(PyObject *self)
452457
Py_TYPE(self)->tp_free(self);
453458
}
454459

460+
/*[clinic input]
461+
@vectorcall
462+
@classmethod
463+
FrameLocalsProxy.__new__ as framelocalsproxy_new
464+
frame: object
465+
/
466+
467+
Create a write-through view of the locals dictionary for a frame.
468+
469+
frame
470+
the frame object to wrap.
471+
[clinic start generated code]*/
472+
455473
static PyObject *
456-
framelocalsproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
474+
framelocalsproxy_new_impl(PyTypeObject *type, PyObject *frame)
475+
/*[clinic end generated code: output=803b377132a928b9 input=5ab4ffd26ec8e290]*/
457476
{
458-
if (PyTuple_GET_SIZE(args) != 1) {
459-
PyErr_Format(PyExc_TypeError,
460-
"FrameLocalsProxy expected 1 argument, got %zd",
461-
PyTuple_GET_SIZE(args));
477+
if (!PyFrame_Check(frame)) {
478+
PyErr_Format(PyExc_TypeError, "expect frame, not %T", frame);
462479
return NULL;
463480
}
464-
PyObject *item = PyTuple_GET_ITEM(args, 0);
465-
466-
if (!PyFrame_Check(item)) {
467-
PyErr_Format(PyExc_TypeError, "expect frame, not %T", item);
468-
return NULL;
469-
}
470-
PyFrameObject *frame = (PyFrameObject*)item;
471-
472-
if (kwds != NULL && PyDict_Size(kwds) != 0) {
473-
PyErr_SetString(PyExc_TypeError,
474-
"FrameLocalsProxy takes no keyword arguments");
475-
return 0;
476-
}
477-
478481
PyFrameLocalsProxyObject *self = (PyFrameLocalsProxyObject *)type->tp_alloc(type, 0);
479482
if (self == NULL) {
480483
return NULL;
481484
}
482-
483-
((PyFrameLocalsProxyObject*)self)->frame = (PyFrameObject*)Py_NewRef(frame);
484-
485+
self->frame = (PyFrameObject *)Py_NewRef(frame);
485486
return (PyObject *)self;
486487
}
487488

@@ -988,15 +989,6 @@ static PyMethodDef framelocalsproxy_methods[] = {
988989
{NULL, NULL} /* sentinel */
989990
};
990991

991-
PyDoc_STRVAR(framelocalsproxy_doc,
992-
"FrameLocalsProxy($frame)\n"
993-
"--\n"
994-
"\n"
995-
"Create a write-through view of the locals dictionary for a frame.\n"
996-
"\n"
997-
" frame\n"
998-
" the frame object to wrap.");
999-
1000992
PyTypeObject PyFrameLocalsProxy_Type = {
1001993
PyVarObject_HEAD_INIT(&PyType_Type, 0)
1002994
.tp_name = "FrameLocalsProxy",
@@ -1017,7 +1009,8 @@ PyTypeObject PyFrameLocalsProxy_Type = {
10171009
.tp_alloc = PyType_GenericAlloc,
10181010
.tp_new = framelocalsproxy_new,
10191011
.tp_free = PyObject_GC_Del,
1020-
.tp_doc = framelocalsproxy_doc,
1012+
.tp_doc = framelocalsproxy_new__doc__,
1013+
.tp_vectorcall = framelocalsproxy_vectorcall,
10211014
};
10221015

10231016
PyObject *

0 commit comments

Comments
 (0)