diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
| commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
| tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Objects/funcobject.c | |
| parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Objects/funcobject.c')
| -rw-r--r-- | contrib/tools/python3/src/Objects/funcobject.c | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/contrib/tools/python3/src/Objects/funcobject.c b/contrib/tools/python3/src/Objects/funcobject.c index 5b792dc3ed6..2c60275d906 100644 --- a/contrib/tools/python3/src/Objects/funcobject.c +++ b/contrib/tools/python3/src/Objects/funcobject.c @@ -2,10 +2,10 @@ /* Function object implementation */ #include "Python.h" -#include "pycore_object.h" -#include "pycore_tupleobject.h" +#include "pycore_object.h" +#include "pycore_tupleobject.h" #include "code.h" -#include "structmember.h" // PyMemberDef +#include "structmember.h" // PyMemberDef PyObject * PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname) @@ -20,23 +20,23 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname return NULL; } - /* __module__: If module name is in globals, use it. - Otherwise, use None. */ - module = PyDict_GetItemWithError(globals, __name__); - if (module) { - Py_INCREF(module); - } - else if (PyErr_Occurred()) { - return NULL; - } - + /* __module__: If module name is in globals, use it. + Otherwise, use None. */ + module = PyDict_GetItemWithError(globals, __name__); + if (module) { + Py_INCREF(module); + } + else if (PyErr_Occurred()) { + return NULL; + } + op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); - if (op == NULL) { - Py_XDECREF(module); + if (op == NULL) { + Py_XDECREF(module); return NULL; - } - /* Note: No failures from this point on, since func_dealloc() does not - expect a partially-created object. */ + } + /* Note: No failures from this point on, since func_dealloc() does not + expect a partially-created object. */ op->func_weakreflist = NULL; Py_INCREF(code); @@ -48,8 +48,8 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname op->func_defaults = NULL; /* No default arguments */ op->func_kwdefaults = NULL; /* No keyword only defaults */ op->func_closure = NULL; - op->vectorcall = _PyFunction_Vectorcall; - op->func_module = module; + op->vectorcall = _PyFunction_Vectorcall; + op->func_module = module; consts = ((PyCodeObject *)code)->co_consts; if (PyTuple_Size(consts) >= 1) { @@ -197,7 +197,7 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure) else { PyErr_Format(PyExc_SystemError, "expected tuple for closure, got '%.100s'", - Py_TYPE(closure)->tp_name); + Py_TYPE(closure)->tp_name); return -1; } Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); @@ -240,20 +240,20 @@ PyFunction_SetAnnotations(PyObject *op, PyObject *annotations) #define OFF(x) offsetof(PyFunctionObject, x) static PyMemberDef func_memberlist[] = { - {"__closure__", T_OBJECT, OFF(func_closure), READONLY}, - {"__doc__", T_OBJECT, OFF(func_doc), 0}, - {"__globals__", T_OBJECT, OFF(func_globals), READONLY}, - {"__module__", T_OBJECT, OFF(func_module), 0}, + {"__closure__", T_OBJECT, OFF(func_closure), READONLY}, + {"__doc__", T_OBJECT, OFF(func_doc), 0}, + {"__globals__", T_OBJECT, OFF(func_globals), READONLY}, + {"__module__", T_OBJECT, OFF(func_module), 0}, {NULL} /* Sentinel */ }; static PyObject * func_get_code(PyFunctionObject *op, void *Py_UNUSED(ignored)) { - if (PySys_Audit("object.__getattr__", "Os", op, "__code__") < 0) { - return NULL; - } - + if (PySys_Audit("object.__getattr__", "Os", op, "__code__") < 0) { + return NULL; + } + Py_INCREF(op->func_code); return op->func_code; } @@ -270,12 +270,12 @@ func_set_code(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored)) "__code__ must be set to a code object"); return -1; } - - if (PySys_Audit("object.__setattr__", "OsO", - op, "__code__", value) < 0) { - return -1; - } - + + if (PySys_Audit("object.__setattr__", "OsO", + op, "__code__", value) < 0) { + return -1; + } + nfree = PyCode_GetNumFree((PyCodeObject *)value); nclosure = (op->func_closure == NULL ? 0 : PyTuple_GET_SIZE(op->func_closure)); @@ -339,9 +339,9 @@ func_set_qualname(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored static PyObject * func_get_defaults(PyFunctionObject *op, void *Py_UNUSED(ignored)) { - if (PySys_Audit("object.__getattr__", "Os", op, "__defaults__") < 0) { - return NULL; - } + if (PySys_Audit("object.__getattr__", "Os", op, "__defaults__") < 0) { + return NULL; + } if (op->func_defaults == NULL) { Py_RETURN_NONE; } @@ -361,16 +361,16 @@ func_set_defaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored "__defaults__ must be set to a tuple object"); return -1; } - if (value) { - if (PySys_Audit("object.__setattr__", "OsO", - op, "__defaults__", value) < 0) { - return -1; - } - } else if (PySys_Audit("object.__delattr__", "Os", - op, "__defaults__") < 0) { - return -1; - } - + if (value) { + if (PySys_Audit("object.__setattr__", "OsO", + op, "__defaults__", value) < 0) { + return -1; + } + } else if (PySys_Audit("object.__delattr__", "Os", + op, "__defaults__") < 0) { + return -1; + } + Py_XINCREF(value); Py_XSETREF(op->func_defaults, value); return 0; @@ -379,10 +379,10 @@ func_set_defaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignored static PyObject * func_get_kwdefaults(PyFunctionObject *op, void *Py_UNUSED(ignored)) { - if (PySys_Audit("object.__getattr__", "Os", - op, "__kwdefaults__") < 0) { - return NULL; - } + if (PySys_Audit("object.__getattr__", "Os", + op, "__kwdefaults__") < 0) { + return NULL; + } if (op->func_kwdefaults == NULL) { Py_RETURN_NONE; } @@ -402,16 +402,16 @@ func_set_kwdefaults(PyFunctionObject *op, PyObject *value, void *Py_UNUSED(ignor "__kwdefaults__ must be set to a dict object"); return -1; } - if (value) { - if (PySys_Audit("object.__setattr__", "OsO", - op, "__kwdefaults__", value) < 0) { - return -1; - } - } else if (PySys_Audit("object.__delattr__", "Os", - op, "__kwdefaults__") < 0) { - return -1; - } - + if (value) { + if (PySys_Audit("object.__setattr__", "OsO", + op, "__kwdefaults__", value) < 0) { + return -1; + } + } else if (PySys_Audit("object.__delattr__", "Os", + op, "__kwdefaults__") < 0) { + return -1; + } + Py_XINCREF(value); Py_XSETREF(op->func_kwdefaults, value); return 0; @@ -540,13 +540,13 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, if (!PyCell_Check(o)) { return PyErr_Format(PyExc_TypeError, "arg 5 (closure) expected cell, found %s", - Py_TYPE(o)->tp_name); + Py_TYPE(o)->tp_name); } } } - if (PySys_Audit("function.__new__", "O", code) < 0) { - return NULL; - } + if (PySys_Audit("function.__new__", "O", code) < 0) { + return NULL; + } newfunc = (PyFunctionObject *)PyFunction_New((PyObject *)code, globals); @@ -569,31 +569,31 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, return (PyObject *)newfunc; } -static int -func_clear(PyFunctionObject *op) -{ - Py_CLEAR(op->func_code); - Py_CLEAR(op->func_globals); - Py_CLEAR(op->func_module); - Py_CLEAR(op->func_name); - Py_CLEAR(op->func_defaults); - Py_CLEAR(op->func_kwdefaults); - Py_CLEAR(op->func_doc); - Py_CLEAR(op->func_dict); - Py_CLEAR(op->func_closure); - Py_CLEAR(op->func_annotations); - Py_CLEAR(op->func_qualname); - return 0; -} - +static int +func_clear(PyFunctionObject *op) +{ + Py_CLEAR(op->func_code); + Py_CLEAR(op->func_globals); + Py_CLEAR(op->func_module); + Py_CLEAR(op->func_name); + Py_CLEAR(op->func_defaults); + Py_CLEAR(op->func_kwdefaults); + Py_CLEAR(op->func_doc); + Py_CLEAR(op->func_dict); + Py_CLEAR(op->func_closure); + Py_CLEAR(op->func_annotations); + Py_CLEAR(op->func_qualname); + return 0; +} + static void func_dealloc(PyFunctionObject *op) { _PyObject_GC_UNTRACK(op); - if (op->func_weakreflist != NULL) { + if (op->func_weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject *) op); - } - (void)func_clear(op); + } + (void)func_clear(op); PyObject_GC_Del(op); } @@ -638,26 +638,26 @@ PyTypeObject PyFunction_Type = { sizeof(PyFunctionObject), 0, (destructor)func_dealloc, /* tp_dealloc */ - offsetof(PyFunctionObject, vectorcall), /* tp_vectorcall_offset */ + offsetof(PyFunctionObject, vectorcall), /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ (reprfunc)func_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ - PyVectorcall_Call, /* tp_call */ + PyVectorcall_Call, /* tp_call */ 0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | - Py_TPFLAGS_HAVE_VECTORCALL | - Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_HAVE_VECTORCALL | + Py_TPFLAGS_METHOD_DESCRIPTOR, /* tp_flags */ func_new__doc__, /* tp_doc */ (traverseproc)func_traverse, /* tp_traverse */ - (inquiry)func_clear, /* tp_clear */ + (inquiry)func_clear, /* tp_clear */ 0, /* tp_richcompare */ offsetof(PyFunctionObject, func_weakreflist), /* tp_weaklistoffset */ 0, /* tp_iter */ @@ -740,10 +740,10 @@ cm_descr_get(PyObject *self, PyObject *obj, PyObject *type) } if (type == NULL) type = (PyObject *)(Py_TYPE(obj)); - if (Py_TYPE(cm->cm_callable)->tp_descr_get != NULL) { - return Py_TYPE(cm->cm_callable)->tp_descr_get(cm->cm_callable, type, - NULL); - } + if (Py_TYPE(cm->cm_callable)->tp_descr_get != NULL) { + return Py_TYPE(cm->cm_callable)->tp_descr_get(cm->cm_callable, type, + NULL); + } return PyMethod_New(cm->cm_callable, type); } @@ -817,10 +817,10 @@ PyTypeObject PyClassMethod_Type = { sizeof(classmethod), 0, (destructor)cm_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -877,8 +877,8 @@ PyClassMethod_New(PyObject *callable) ... It can be called either on the class (e.g. C.f()) or on an instance - (e.g. C().f()). Both the class and the instance are ignored, and - neither is passed implicitly as the first argument to the method. + (e.g. C().f()). Both the class and the instance are ignored, and + neither is passed implicitly as the first argument to the method. Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see class methods above. @@ -985,8 +985,8 @@ To declare a static method, use this idiom:\n\ ...\n\ \n\ It can be called either on the class (e.g. C.f()) or on an instance\n\ -(e.g. C().f()). Both the class and the instance are ignored, and\n\ -neither is passed implicitly as the first argument to the method.\n\ +(e.g. C().f()). Both the class and the instance are ignored, and\n\ +neither is passed implicitly as the first argument to the method.\n\ \n\ Static methods in Python are similar to those found in Java or C++.\n\ For a more advanced concept, see the classmethod builtin."); @@ -997,10 +997,10 @@ PyTypeObject PyStaticMethod_Type = { sizeof(staticmethod), 0, (destructor)sm_dealloc, /* tp_dealloc */ - 0, /* tp_vectorcall_offset */ + 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_as_async */ + 0, /* tp_as_async */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ |
