Skip to content

Commit 8875af1

Browse files
committed
recover clinic position
1 parent a15bb57 commit 8875af1

File tree

1 file changed

+112
-113
lines changed

1 file changed

+112
-113
lines changed

Objects/funcobject.c

Lines changed: 112 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ _PyFunction_LookupByVersion(uint32_t version, PyObject **p_code)
397397
uint32_t
398398
_PyFunction_GetVersionForCurrentState(PyFunctionObject *func)
399399
{
400-
return FT_ATOMIC_LOAD_UINT32_RELAXED(func->func_version);
400+
return func->func_version;
401401
}
402402

403403
PyObject *
@@ -413,7 +413,7 @@ PyFunction_GetCode(PyObject *op)
413413
PyErr_BadInternalCall();
414414
return NULL;
415415
}
416-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_code);
416+
return ((PyFunctionObject *) op) -> func_code;
417417
}
418418

419419
PyObject *
@@ -423,7 +423,7 @@ PyFunction_GetGlobals(PyObject *op)
423423
PyErr_BadInternalCall();
424424
return NULL;
425425
}
426-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_globals);
426+
return ((PyFunctionObject *) op) -> func_globals;
427427
}
428428

429429
PyObject *
@@ -433,7 +433,7 @@ PyFunction_GetModule(PyObject *op)
433433
PyErr_BadInternalCall();
434434
return NULL;
435435
}
436-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_module);
436+
return ((PyFunctionObject *) op) -> func_module;
437437
}
438438

439439
PyObject *
@@ -443,7 +443,7 @@ PyFunction_GetDefaults(PyObject *op)
443443
PyErr_BadInternalCall();
444444
return NULL;
445445
}
446-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_defaults);
446+
return ((PyFunctionObject *) op) -> func_defaults;
447447
}
448448

449449
int
@@ -657,114 +657,6 @@ class function "PyFunctionObject *" "&PyFunction_Type"
657657

658658
#include "clinic/funcobject.c.h"
659659

660-
/* function.__new__() maintains the following invariants for closures.
661-
The closure must correspond to the free variables of the code object.
662-
663-
if len(code.co_freevars) == 0:
664-
closure = NULL
665-
else:
666-
len(closure) == len(code.co_freevars)
667-
for every elt in closure, type(elt) == cell
668-
*/
669-
670-
/*[clinic input]
671-
@classmethod
672-
function.__new__ as func_new
673-
code: object(type="PyCodeObject *", subclass_of="&PyCode_Type")
674-
a code object
675-
globals: object(subclass_of="&PyDict_Type")
676-
the globals dictionary
677-
name: object = None
678-
a string that overrides the name from the code object
679-
argdefs as defaults: object = None
680-
a tuple that specifies the default argument values
681-
closure: object = None
682-
a tuple that supplies the bindings for free variables
683-
kwdefaults: object = None
684-
a dictionary that specifies the default keyword argument values
685-
686-
Create a function object.
687-
[clinic start generated code]*/
688-
689-
static PyObject *
690-
func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
691-
PyObject *name, PyObject *defaults, PyObject *closure,
692-
PyObject *kwdefaults)
693-
/*[clinic end generated code: output=de72f4c22ac57144 input=20c9c9f04ad2d3f2]*/
694-
{
695-
PyFunctionObject *newfunc;
696-
Py_ssize_t nclosure;
697-
698-
if (name != Py_None && !PyUnicode_Check(name)) {
699-
PyErr_SetString(PyExc_TypeError,
700-
"arg 3 (name) must be None or string");
701-
return NULL;
702-
}
703-
if (defaults != Py_None && !PyTuple_Check(defaults)) {
704-
PyErr_SetString(PyExc_TypeError,
705-
"arg 4 (defaults) must be None or tuple");
706-
return NULL;
707-
}
708-
if (!PyTuple_Check(closure)) {
709-
if (code->co_nfreevars && closure == Py_None) {
710-
PyErr_SetString(PyExc_TypeError,
711-
"arg 5 (closure) must be tuple");
712-
return NULL;
713-
}
714-
else if (closure != Py_None) {
715-
PyErr_SetString(PyExc_TypeError,
716-
"arg 5 (closure) must be None or tuple");
717-
return NULL;
718-
}
719-
}
720-
if (kwdefaults != Py_None && !PyDict_Check(kwdefaults)) {
721-
PyErr_SetString(PyExc_TypeError,
722-
"arg 6 (kwdefaults) must be None or dict");
723-
return NULL;
724-
}
725-
726-
/* check that the closure is well-formed */
727-
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
728-
if (code->co_nfreevars != nclosure)
729-
return PyErr_Format(PyExc_ValueError,
730-
"%U requires closure of length %zd, not %zd",
731-
code->co_name, code->co_nfreevars, nclosure);
732-
if (nclosure) {
733-
Py_ssize_t i;
734-
for (i = 0; i < nclosure; i++) {
735-
PyObject *o = PyTuple_GET_ITEM(closure, i);
736-
if (!PyCell_Check(o)) {
737-
return PyErr_Format(PyExc_TypeError,
738-
"arg 5 (closure) expected cell, found %s",
739-
Py_TYPE(o)->tp_name);
740-
}
741-
}
742-
}
743-
if (PySys_Audit("function.__new__", "O", code) < 0) {
744-
return NULL;
745-
}
746-
747-
newfunc = (PyFunctionObject *)PyFunction_New((PyObject *)code,
748-
globals);
749-
if (newfunc == NULL) {
750-
return NULL;
751-
}
752-
if (name != Py_None) {
753-
Py_SETREF(newfunc->func_name, Py_NewRef(name));
754-
}
755-
if (defaults != Py_None) {
756-
newfunc->func_defaults = Py_NewRef(defaults);
757-
}
758-
if (closure != Py_None) {
759-
newfunc->func_closure = Py_NewRef(closure);
760-
}
761-
if (kwdefaults != Py_None) {
762-
newfunc->func_kwdefaults = Py_NewRef(kwdefaults);
763-
}
764-
765-
return (PyObject *)newfunc;
766-
}
767-
768660
/*[clinic input]
769661
@critical_section
770662
@getter
@@ -1185,6 +1077,113 @@ static PyGetSetDef func_getsetlist[] = {
11851077
{NULL} /* Sentinel */
11861078
};
11871079

1080+
/* function.__new__() maintains the following invariants for closures.
1081+
The closure must correspond to the free variables of the code object.
1082+
1083+
if len(code.co_freevars) == 0:
1084+
closure = NULL
1085+
else:
1086+
len(closure) == len(code.co_freevars)
1087+
for every elt in closure, type(elt) == cell
1088+
*/
1089+
1090+
/*[clinic input]
1091+
@classmethod
1092+
function.__new__ as func_new
1093+
code: object(type="PyCodeObject *", subclass_of="&PyCode_Type")
1094+
a code object
1095+
globals: object(subclass_of="&PyDict_Type")
1096+
the globals dictionary
1097+
name: object = None
1098+
a string that overrides the name from the code object
1099+
argdefs as defaults: object = None
1100+
a tuple that specifies the default argument values
1101+
closure: object = None
1102+
a tuple that supplies the bindings for free variables
1103+
kwdefaults: object = None
1104+
a dictionary that specifies the default keyword argument values
1105+
1106+
Create a function object.
1107+
[clinic start generated code]*/
1108+
1109+
static PyObject *
1110+
func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
1111+
PyObject *name, PyObject *defaults, PyObject *closure,
1112+
PyObject *kwdefaults)
1113+
/*[clinic end generated code: output=de72f4c22ac57144 input=20c9c9f04ad2d3f2]*/
1114+
{
1115+
PyFunctionObject *newfunc;
1116+
Py_ssize_t nclosure;
1117+
1118+
if (name != Py_None && !PyUnicode_Check(name)) {
1119+
PyErr_SetString(PyExc_TypeError,
1120+
"arg 3 (name) must be None or string");
1121+
return NULL;
1122+
}
1123+
if (defaults != Py_None && !PyTuple_Check(defaults)) {
1124+
PyErr_SetString(PyExc_TypeError,
1125+
"arg 4 (defaults) must be None or tuple");
1126+
return NULL;
1127+
}
1128+
if (!PyTuple_Check(closure)) {
1129+
if (code->co_nfreevars && closure == Py_None) {
1130+
PyErr_SetString(PyExc_TypeError,
1131+
"arg 5 (closure) must be tuple");
1132+
return NULL;
1133+
}
1134+
else if (closure != Py_None) {
1135+
PyErr_SetString(PyExc_TypeError,
1136+
"arg 5 (closure) must be None or tuple");
1137+
return NULL;
1138+
}
1139+
}
1140+
if (kwdefaults != Py_None && !PyDict_Check(kwdefaults)) {
1141+
PyErr_SetString(PyExc_TypeError,
1142+
"arg 6 (kwdefaults) must be None or dict");
1143+
return NULL;
1144+
}
1145+
1146+
/* check that the closure is well-formed */
1147+
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
1148+
if (code->co_nfreevars != nclosure)
1149+
return PyErr_Format(PyExc_ValueError,
1150+
"%U requires closure of length %zd, not %zd",
1151+
code->co_name, code->co_nfreevars, nclosure);
1152+
if (nclosure) {
1153+
Py_ssize_t i;
1154+
for (i = 0; i < nclosure; i++) {
1155+
PyObject *o = PyTuple_GET_ITEM(closure, i);
1156+
if (!PyCell_Check(o)) {
1157+
return PyErr_Format(PyExc_TypeError,
1158+
"arg 5 (closure) expected cell, found %s",
1159+
Py_TYPE(o)->tp_name);
1160+
}
1161+
}
1162+
}
1163+
if (PySys_Audit("function.__new__", "O", code) < 0) {
1164+
return NULL;
1165+
}
1166+
1167+
newfunc = (PyFunctionObject *)PyFunction_New((PyObject *)code,
1168+
globals);
1169+
if (newfunc == NULL) {
1170+
return NULL;
1171+
}
1172+
if (name != Py_None) {
1173+
Py_SETREF(newfunc->func_name, Py_NewRef(name));
1174+
}
1175+
if (defaults != Py_None) {
1176+
newfunc->func_defaults = Py_NewRef(defaults);
1177+
}
1178+
if (closure != Py_None) {
1179+
newfunc->func_closure = Py_NewRef(closure);
1180+
}
1181+
if (kwdefaults != Py_None) {
1182+
newfunc->func_kwdefaults = Py_NewRef(kwdefaults);
1183+
}
1184+
1185+
return (PyObject *)newfunc;
1186+
}
11881187

11891188
static int
11901189
func_clear(PyObject *self)

0 commit comments

Comments
 (0)