Spaces:
Build error
Build error
| //////////////////// CythonFunctionShared.proto //////////////////// | |
| typedef struct { | |
| PyObject_HEAD | |
| // We can't "inherit" from func, but we can use it as a data store | |
| PyObject *func; | |
| PyCFunctionObject func; | |
| // PEP-573: PyCFunctionObject + mm_class | |
| PyCMethodObject func; | |
| __pyx_vectorcallfunc func_vectorcall; | |
| PyObject *func_weakreflist; | |
| PyObject *func_dict; | |
| PyObject *func_name; | |
| PyObject *func_qualname; | |
| PyObject *func_doc; | |
| PyObject *func_globals; | |
| PyObject *func_code; | |
| PyObject *func_closure; | |
| // No-args super() class cell | |
| PyObject *func_classobj; | |
| // Dynamic default args and annotations | |
| void *defaults; | |
| int defaults_pyobjects; | |
| size_t defaults_size; /* used by FusedFunction for copying defaults */ | |
| int flags; | |
| // Defaults info | |
| PyObject *defaults_tuple; /* Const defaults tuple */ | |
| PyObject *defaults_kwdict; /* Const kwonly defaults dict */ | |
| PyObject *(*defaults_getter)(PyObject *); | |
| PyObject *func_annotations; /* function annotations dict */ | |
| // Coroutine marker | |
| PyObject *func_is_coroutine; | |
| } __pyx_CyFunctionObject; | |
| static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc);/*proto*/ | |
| static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, | |
| int flags, PyObject* qualname, | |
| PyObject *closure, | |
| PyObject *module, PyObject *globals, | |
| PyObject* code); | |
| static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); | |
| static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, | |
| size_t size, | |
| int pyobjects); | |
| static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, | |
| PyObject *tuple); | |
| static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, | |
| PyObject *dict); | |
| static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, | |
| PyObject *dict); | |
| static int __pyx_CyFunction_init(PyObject *module); | |
| static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); | |
| static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); | |
| static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); | |
| static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); | |
| //////////////////// CythonFunctionShared //////////////////// | |
| //@substitute: naming | |
| //@requires: CommonStructures.c::FetchCommonType | |
| //@requires: ObjectHandling.c::PyMethodNew | |
| //@requires: ObjectHandling.c::PyVectorcallFastCallDict | |
| //@requires: ModuleSetupCode.c::IncludeStructmemberH | |
| //@requires: ObjectHandling.c::PyObjectGetAttrStr | |
| static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { | |
| if (__Pyx_CyFunction_Check(func)) { | |
| return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; | |
| } else if (PyCFunction_Check(func)) { | |
| return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; | |
| } | |
| return 0; | |
| } | |
| static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { | |
| return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; | |
| } | |
| static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { | |
| __Pyx_Py_XDECREF_SET( | |
| __Pyx_CyFunction_GetClassObj(f), | |
| ((classobj) ? __Pyx_NewRef(classobj) : NULL)); | |
| __Pyx_Py_XDECREF_SET( | |
| // assigning to "mm_class", which is a "PyTypeObject*" | |
| ((PyCMethodObject *) (f))->mm_class, | |
| (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) | |
| { | |
| CYTHON_UNUSED_VAR(closure); | |
| if (unlikely(op->func_doc == NULL)) { | |
| op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); | |
| if (unlikely(!op->func_doc)) return NULL; | |
| if (((PyCFunctionObject*)op)->m_ml->ml_doc) { | |
| op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); | |
| op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); | |
| if (unlikely(op->func_doc == NULL)) | |
| return NULL; | |
| } else { | |
| Py_INCREF(Py_None); | |
| return Py_None; | |
| } | |
| } | |
| Py_INCREF(op->func_doc); | |
| return op->func_doc; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| if (value == NULL) { | |
| // Mark as deleted | |
| value = Py_None; | |
| } | |
| Py_INCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->func_doc, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(op->func_name == NULL)) { | |
| op->func_name = PyObject_GetAttrString(op->func, "__name__"); | |
| op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); | |
| op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); | |
| if (unlikely(op->func_name == NULL)) | |
| return NULL; | |
| } | |
| Py_INCREF(op->func_name); | |
| return op->func_name; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(value == NULL || !PyUnicode_Check(value))) | |
| if (unlikely(value == NULL || !PyString_Check(value))) | |
| { | |
| PyErr_SetString(PyExc_TypeError, | |
| "__name__ must be set to a string object"); | |
| return -1; | |
| } | |
| Py_INCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->func_name, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| Py_INCREF(op->func_qualname); | |
| return op->func_qualname; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(value == NULL || !PyUnicode_Check(value))) | |
| if (unlikely(value == NULL || !PyString_Check(value))) | |
| { | |
| PyErr_SetString(PyExc_TypeError, | |
| "__qualname__ must be set to a string object"); | |
| return -1; | |
| } | |
| Py_INCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->func_qualname, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(op->func_dict == NULL)) { | |
| op->func_dict = PyDict_New(); | |
| if (unlikely(op->func_dict == NULL)) | |
| return NULL; | |
| } | |
| Py_INCREF(op->func_dict); | |
| return op->func_dict; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(value == NULL)) { | |
| PyErr_SetString(PyExc_TypeError, | |
| "function's dictionary may not be deleted"); | |
| return -1; | |
| } | |
| if (unlikely(!PyDict_Check(value))) { | |
| PyErr_SetString(PyExc_TypeError, | |
| "setting function's dictionary to a non-dict"); | |
| return -1; | |
| } | |
| Py_INCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->func_dict, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(context); | |
| Py_INCREF(op->func_globals); | |
| return op->func_globals; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) | |
| { | |
| CYTHON_UNUSED_VAR(op); | |
| CYTHON_UNUSED_VAR(context); | |
| Py_INCREF(Py_None); | |
| return Py_None; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) | |
| { | |
| PyObject* result = (op->func_code) ? op->func_code : Py_None; | |
| CYTHON_UNUSED_VAR(context); | |
| Py_INCREF(result); | |
| return result; | |
| } | |
| static int | |
| __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { | |
| int result = 0; | |
| PyObject *res = op->defaults_getter((PyObject *) op); | |
| if (unlikely(!res)) | |
| return -1; | |
| // Cache result | |
| op->defaults_tuple = PyTuple_GET_ITEM(res, 0); | |
| Py_INCREF(op->defaults_tuple); | |
| op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); | |
| Py_INCREF(op->defaults_kwdict); | |
| op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); | |
| if (unlikely(!op->defaults_tuple)) result = -1; | |
| else { | |
| op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); | |
| if (unlikely(!op->defaults_kwdict)) result = -1; | |
| } | |
| Py_DECREF(res); | |
| return result; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { | |
| CYTHON_UNUSED_VAR(context); | |
| if (!value) { | |
| // del => explicit None to prevent rebuilding | |
| value = Py_None; | |
| } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { | |
| PyErr_SetString(PyExc_TypeError, | |
| "__defaults__ must be set to a tuple object"); | |
| return -1; | |
| } | |
| PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " | |
| "currently affect the values used in function calls", 1); | |
| Py_INCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { | |
| PyObject* result = op->defaults_tuple; | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(!result)) { | |
| if (op->defaults_getter) { | |
| if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; | |
| result = op->defaults_tuple; | |
| } else { | |
| result = Py_None; | |
| } | |
| } | |
| Py_INCREF(result); | |
| return result; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { | |
| CYTHON_UNUSED_VAR(context); | |
| if (!value) { | |
| // del => explicit None to prevent rebuilding | |
| value = Py_None; | |
| } else if (unlikely(value != Py_None && !PyDict_Check(value))) { | |
| PyErr_SetString(PyExc_TypeError, | |
| "__kwdefaults__ must be set to a dict object"); | |
| return -1; | |
| } | |
| PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " | |
| "currently affect the values used in function calls", 1); | |
| Py_INCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { | |
| PyObject* result = op->defaults_kwdict; | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(!result)) { | |
| if (op->defaults_getter) { | |
| if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; | |
| result = op->defaults_kwdict; | |
| } else { | |
| result = Py_None; | |
| } | |
| } | |
| Py_INCREF(result); | |
| return result; | |
| } | |
| static int | |
| __Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { | |
| CYTHON_UNUSED_VAR(context); | |
| if (!value || value == Py_None) { | |
| value = NULL; | |
| } else if (unlikely(!PyDict_Check(value))) { | |
| PyErr_SetString(PyExc_TypeError, | |
| "__annotations__ must be set to a dict object"); | |
| return -1; | |
| } | |
| Py_XINCREF(value); | |
| __Pyx_Py_XDECREF_SET(op->func_annotations, value); | |
| return 0; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { | |
| PyObject* result = op->func_annotations; | |
| CYTHON_UNUSED_VAR(context); | |
| if (unlikely(!result)) { | |
| result = PyDict_New(); | |
| if (unlikely(!result)) return NULL; | |
| op->func_annotations = result; | |
| } | |
| Py_INCREF(result); | |
| return result; | |
| } | |
| static PyObject * | |
| __Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { | |
| int is_coroutine; | |
| CYTHON_UNUSED_VAR(context); | |
| if (op->func_is_coroutine) { | |
| return __Pyx_NewRef(op->func_is_coroutine); | |
| } | |
| is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; | |
| if (is_coroutine) { | |
| PyObject *module, *fromlist, *marker = PYIDENT("_is_coroutine"); | |
| fromlist = PyList_New(1); | |
| if (unlikely(!fromlist)) return NULL; | |
| Py_INCREF(marker); | |
| PyList_SET_ITEM(fromlist, 0, marker); | |
| if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { | |
| Py_DECREF(marker); | |
| Py_DECREF(fromlist); | |
| return NULL; | |
| } | |
| module = PyImport_ImportModuleLevelObject(PYIDENT("asyncio.coroutines"), NULL, NULL, fromlist, 0); | |
| Py_DECREF(fromlist); | |
| if (unlikely(!module)) goto ignore; | |
| op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker); | |
| Py_DECREF(module); | |
| if (likely(op->func_is_coroutine)) { | |
| return __Pyx_NewRef(op->func_is_coroutine); | |
| } | |
| ignore: | |
| PyErr_Clear(); | |
| } | |
| op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine); | |
| return __Pyx_NewRef(op->func_is_coroutine); | |
| } | |
| //#if PY_VERSION_HEX >= 0x030400C1 | |
| //static PyObject * | |
| //__Pyx_CyFunction_get_signature(__pyx_CyFunctionObject *op, void *context) { | |
| // PyObject *inspect_module, *signature_class, *signature; | |
| // CYTHON_UNUSED_VAR(context); | |
| // // from inspect import Signature | |
| // inspect_module = PyImport_ImportModuleLevelObject(PYIDENT("inspect"), NULL, NULL, NULL, 0); | |
| // if (unlikely(!inspect_module)) | |
| // goto bad; | |
| // signature_class = __Pyx_PyObject_GetAttrStr(inspect_module, PYIDENT("Signature")); | |
| // Py_DECREF(inspect_module); | |
| // if (unlikely(!signature_class)) | |
| // goto bad; | |
| // // return Signature.from_function(op) | |
| // signature = PyObject_CallMethodObjArgs(signature_class, PYIDENT("from_function"), op, NULL); | |
| // Py_DECREF(signature_class); | |
| // if (likely(signature)) | |
| // return signature; | |
| //bad: | |
| // // make sure we raise an AttributeError from this property on any errors | |
| // if (!PyErr_ExceptionMatches(PyExc_AttributeError)) | |
| // PyErr_SetString(PyExc_AttributeError, "failed to calculate __signature__"); | |
| // return NULL; | |
| //} | |
| //#endif | |
| static PyObject * | |
| __Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { | |
| CYTHON_UNUSED_VAR(context); | |
| return PyObject_GetAttrString(op->func, "__module__"); | |
| } | |
| static int | |
| __Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { | |
| CYTHON_UNUSED_VAR(context); | |
| return PyObject_SetAttrString(op->func, "__module__", value); | |
| } | |
| static PyGetSetDef __pyx_CyFunction_getsets[] = { | |
| {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, | |
| {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, | |
| {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, | |
| {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, | |
| {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, | |
| {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, | |
| {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, | |
| {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, | |
| {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, | |
| {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, | |
| {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, | |
| {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, | |
| {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, | |
| {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, | |
| {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, | |
| {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, | |
| {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, | |
| {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, | |
| //#if PY_VERSION_HEX >= 0x030400C1 | |
| // {(char *) "__signature__", (getter)__Pyx_CyFunction_get_signature, 0, 0, 0}, | |
| //#endif | |
| {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, | |
| {0, 0, 0, 0, 0} | |
| }; | |
| static PyMemberDef __pyx_CyFunction_members[] = { | |
| {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, | |
| {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, | |
| {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, | |
| {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, | |
| {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, | |
| {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, | |
| {0, 0, 0, 0, 0} | |
| }; | |
| static PyObject * | |
| __Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) | |
| { | |
| CYTHON_UNUSED_VAR(args); | |
| Py_INCREF(m->func_qualname); | |
| return m->func_qualname; | |
| return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name); | |
| } | |
| static PyMethodDef __pyx_CyFunction_methods[] = { | |
| {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, | |
| {0, 0, 0, 0} | |
| }; | |
| static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, | |
| PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { | |
| PyCFunctionObject *cf = (PyCFunctionObject*) op; | |
| if (unlikely(op == NULL)) | |
| return NULL; | |
| // Note that we end up with a circular reference to op. This isn't | |
| // a disaster, but in an ideal world it'd be nice to avoid it. | |
| op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); | |
| if (unlikely(!op->func)) return NULL; | |
| op->flags = flags; | |
| __Pyx_CyFunction_weakreflist(op) = NULL; | |
| cf->m_ml = ml; | |
| cf->m_self = (PyObject *) op; | |
| Py_XINCREF(closure); | |
| op->func_closure = closure; | |
| Py_XINCREF(module); | |
| cf->m_module = module; | |
| op->func_dict = NULL; | |
| op->func_name = NULL; | |
| Py_INCREF(qualname); | |
| op->func_qualname = qualname; | |
| op->func_doc = NULL; | |
| op->func_classobj = NULL; | |
| ((PyCMethodObject*)op)->mm_class = NULL; | |
| op->func_globals = globals; | |
| Py_INCREF(op->func_globals); | |
| Py_XINCREF(code); | |
| op->func_code = code; | |
| // Dynamic Default args | |
| op->defaults_pyobjects = 0; | |
| op->defaults_size = 0; | |
| op->defaults = NULL; | |
| op->defaults_tuple = NULL; | |
| op->defaults_kwdict = NULL; | |
| op->defaults_getter = NULL; | |
| op->func_annotations = NULL; | |
| op->func_is_coroutine = NULL; | |
| switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { | |
| case METH_NOARGS: | |
| __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; | |
| break; | |
| case METH_O: | |
| __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; | |
| break; | |
| // case METH_FASTCALL is not used | |
| case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: | |
| __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; | |
| break; | |
| case METH_FASTCALL | METH_KEYWORDS: | |
| __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; | |
| break; | |
| // case METH_VARARGS is not used | |
| case METH_VARARGS | METH_KEYWORDS: | |
| __Pyx_CyFunction_func_vectorcall(op) = NULL; | |
| break; | |
| default: | |
| PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); | |
| Py_DECREF(op); | |
| return NULL; | |
| } | |
| return (PyObject *) op; | |
| } | |
| static int | |
| __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) | |
| { | |
| Py_CLEAR(m->func_closure); | |
| Py_CLEAR(m->func); | |
| Py_CLEAR(((PyCFunctionObject*)m)->m_module); | |
| Py_CLEAR(m->func_dict); | |
| Py_CLEAR(m->func_name); | |
| Py_CLEAR(m->func_qualname); | |
| Py_CLEAR(m->func_doc); | |
| Py_CLEAR(m->func_globals); | |
| Py_CLEAR(m->func_code); | |
| Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); | |
| { | |
| PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; | |
| ((PyCMethodObject *) (m))->mm_class = NULL; | |
| Py_XDECREF(cls); | |
| } | |
| Py_CLEAR(m->defaults_tuple); | |
| Py_CLEAR(m->defaults_kwdict); | |
| Py_CLEAR(m->func_annotations); | |
| Py_CLEAR(m->func_is_coroutine); | |
| if (m->defaults) { | |
| PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); | |
| int i; | |
| for (i = 0; i < m->defaults_pyobjects; i++) | |
| Py_XDECREF(pydefaults[i]); | |
| PyObject_Free(m->defaults); | |
| m->defaults = NULL; | |
| } | |
| return 0; | |
| } | |
| static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) | |
| { | |
| if (__Pyx_CyFunction_weakreflist(m) != NULL) | |
| PyObject_ClearWeakRefs((PyObject *) m); | |
| __Pyx_CyFunction_clear(m); | |
| __Pyx_PyHeapTypeObject_GC_Del(m); | |
| } | |
| static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) | |
| { | |
| PyObject_GC_UnTrack(m); | |
| __Pyx__CyFunction_dealloc(m); | |
| } | |
| static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) | |
| { | |
| Py_VISIT(m->func_closure); | |
| Py_VISIT(m->func); | |
| Py_VISIT(((PyCFunctionObject*)m)->m_module); | |
| Py_VISIT(m->func_dict); | |
| Py_VISIT(m->func_name); | |
| Py_VISIT(m->func_qualname); | |
| Py_VISIT(m->func_doc); | |
| Py_VISIT(m->func_globals); | |
| Py_VISIT(m->func_code); | |
| Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); | |
| Py_VISIT(m->defaults_tuple); | |
| Py_VISIT(m->defaults_kwdict); | |
| Py_VISIT(m->func_is_coroutine); | |
| if (m->defaults) { | |
| PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); | |
| int i; | |
| for (i = 0; i < m->defaults_pyobjects; i++) | |
| Py_VISIT(pydefaults[i]); | |
| } | |
| return 0; | |
| } | |
| static PyObject* | |
| __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) | |
| { | |
| return PyUnicode_FromFormat("<cyfunction %U at %p>", | |
| op->func_qualname, (void *)op); | |
| return PyString_FromFormat("<cyfunction %s at %p>", | |
| PyString_AsString(op->func_qualname), (void *)op); | |
| } | |
| static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { | |
| // originally copied from PyCFunction_Call() in CPython's Objects/methodobject.c | |
| PyObject *f = ((__pyx_CyFunctionObject*)func)->func; | |
| PyObject *py_name = NULL; | |
| PyCFunction meth; | |
| int flags; | |
| meth = PyCFunction_GetFunction(f); | |
| if (unlikely(!meth)) return NULL; | |
| flags = PyCFunction_GetFlags(f); | |
| if (unlikely(flags < 0)) return NULL; | |
| PyCFunctionObject* f = (PyCFunctionObject*)func; | |
| PyCFunction meth = f->m_ml->ml_meth; | |
| int flags = f->m_ml->ml_flags; | |
| Py_ssize_t size; | |
| switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { | |
| case METH_VARARGS: | |
| if (likely(kw == NULL || PyDict_Size(kw) == 0)) | |
| return (*meth)(self, arg); | |
| break; | |
| case METH_VARARGS | METH_KEYWORDS: | |
| return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw); | |
| case METH_NOARGS: | |
| if (likely(kw == NULL || PyDict_Size(kw) == 0)) { | |
| size = PyTuple_GET_SIZE(arg); | |
| size = PyTuple_Size(arg); | |
| if (unlikely(size < 0)) return NULL; | |
| if (likely(size == 0)) | |
| return (*meth)(self, NULL); | |
| py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); | |
| if (!py_name) return NULL; | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", | |
| py_name, size); | |
| Py_DECREF(py_name); | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", | |
| f->m_ml->ml_name, size); | |
| return NULL; | |
| } | |
| break; | |
| case METH_O: | |
| if (likely(kw == NULL || PyDict_Size(kw) == 0)) { | |
| size = PyTuple_GET_SIZE(arg); | |
| size = PyTuple_Size(arg); | |
| if (unlikely(size < 0)) return NULL; | |
| if (likely(size == 1)) { | |
| PyObject *result, *arg0; | |
| arg0 = PyTuple_GET_ITEM(arg, 0); | |
| arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; | |
| result = (*meth)(self, arg0); | |
| Py_DECREF(arg0); | |
| return result; | |
| } | |
| py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); | |
| if (!py_name) return NULL; | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", | |
| py_name, size); | |
| Py_DECREF(py_name); | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", | |
| f->m_ml->ml_name, size); | |
| return NULL; | |
| } | |
| break; | |
| default: | |
| PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); | |
| return NULL; | |
| } | |
| py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); | |
| if (!py_name) return NULL; | |
| PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments", | |
| py_name); | |
| Py_DECREF(py_name); | |
| PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", | |
| f->m_ml->ml_name); | |
| return NULL; | |
| } | |
| static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { | |
| PyObject *self, *result; | |
| // PyCFunction_GetSelf returns a borrowed reference | |
| self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); | |
| if (unlikely(!self) && PyErr_Occurred()) return NULL; | |
| self = ((PyCFunctionObject*)func)->m_self; | |
| result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); | |
| return result; | |
| } | |
| static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { | |
| PyObject *result; | |
| __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; | |
| // Prefer vectorcall if available. This is not the typical case, as | |
| // CPython would normally use vectorcall directly instead of tp_call. | |
| __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); | |
| if (vc) { | |
| return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); | |
| // avoid unused function warning | |
| (void) &__Pyx_PyVectorcall_FastCallDict; | |
| return PyVectorcall_Call(func, args, kw); | |
| } | |
| if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { | |
| Py_ssize_t argc; | |
| PyObject *new_args; | |
| PyObject *self; | |
| argc = PyTuple_GET_SIZE(args); | |
| argc = PyTuple_Size(args); | |
| if (unlikely(!argc) < 0) return NULL; | |
| new_args = PyTuple_GetSlice(args, 1, argc); | |
| if (unlikely(!new_args)) | |
| return NULL; | |
| self = PyTuple_GetItem(args, 0); | |
| if (unlikely(!self)) { | |
| Py_DECREF(new_args); | |
| PyErr_Format(PyExc_TypeError, | |
| "unbound method %.200S() needs an argument", | |
| cyfunc->func_qualname); | |
| // %S doesn't work in PyErr_Format on Py2 and replicating | |
| // the formatting seems more trouble than it's worth | |
| // (so produce a less useful error message). | |
| PyErr_SetString(PyExc_TypeError, | |
| "unbound method needs an argument"); | |
| return NULL; | |
| } | |
| result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); | |
| Py_DECREF(new_args); | |
| } else { | |
| result = __Pyx_CyFunction_Call(func, args, kw); | |
| } | |
| return result; | |
| } | |
| // Check that kwnames is empty (if you want to allow keyword arguments, | |
| // simply pass kwnames=NULL) and figure out what to do with "self". | |
| // Return value: | |
| // 1: self = args[0] | |
| // 0: self = cyfunc->func.m_self | |
| // -1: error | |
| static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) | |
| { | |
| int ret = 0; | |
| if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { | |
| if (unlikely(nargs < 1)) { | |
| PyErr_Format(PyExc_TypeError, "%.200s() needs an argument", | |
| ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); | |
| return -1; | |
| } | |
| ret = 1; | |
| } | |
| if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) { | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); | |
| return -1; | |
| } | |
| return ret; | |
| } | |
| static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) | |
| { | |
| __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; | |
| PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; | |
| Py_ssize_t nargs = (Py_ssize_t)nargsf; | |
| Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); | |
| PyObject *self; | |
| switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { | |
| case 1: | |
| self = args[0]; | |
| args += 1; | |
| nargs -= 1; | |
| break; | |
| case 0: | |
| self = ((PyCFunctionObject*)cyfunc)->m_self; | |
| break; | |
| default: | |
| return NULL; | |
| } | |
| if (unlikely(nargs != 0)) { | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", | |
| def->ml_name, nargs); | |
| return NULL; | |
| } | |
| return def->ml_meth(self, NULL); | |
| } | |
| static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) | |
| { | |
| __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; | |
| PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; | |
| Py_ssize_t nargs = (Py_ssize_t)nargsf; | |
| Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); | |
| PyObject *self; | |
| switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { | |
| case 1: | |
| self = args[0]; | |
| args += 1; | |
| nargs -= 1; | |
| break; | |
| case 0: | |
| self = ((PyCFunctionObject*)cyfunc)->m_self; | |
| break; | |
| default: | |
| return NULL; | |
| } | |
| if (unlikely(nargs != 1)) { | |
| PyErr_Format(PyExc_TypeError, | |
| "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", | |
| def->ml_name, nargs); | |
| return NULL; | |
| } | |
| return def->ml_meth(self, args[0]); | |
| } | |
| static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) | |
| { | |
| __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; | |
| PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; | |
| Py_ssize_t nargs = (Py_ssize_t)nargsf; | |
| Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); | |
| PyObject *self; | |
| switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { | |
| case 1: | |
| self = args[0]; | |
| args += 1; | |
| nargs -= 1; | |
| break; | |
| case 0: | |
| self = ((PyCFunctionObject*)cyfunc)->m_self; | |
| break; | |
| default: | |
| return NULL; | |
| } | |
| return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames); | |
| } | |
| static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) | |
| { | |
| __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; | |
| PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; | |
| PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); | |
| Py_ssize_t nargs = (Py_ssize_t)nargsf; | |
| Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); | |
| PyObject *self; | |
| switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { | |
| case 1: | |
| self = args[0]; | |
| args += 1; | |
| nargs -= 1; | |
| break; | |
| case 0: | |
| self = ((PyCFunctionObject*)cyfunc)->m_self; | |
| break; | |
| default: | |
| return NULL; | |
| } | |
| return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames); | |
| } | |
| static PyType_Slot __pyx_CyFunctionType_slots[] = { | |
| {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, | |
| {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, | |
| {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, | |
| {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, | |
| {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, | |
| {Py_tp_methods, (void *)__pyx_CyFunction_methods}, | |
| {Py_tp_members, (void *)__pyx_CyFunction_members}, | |
| {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, | |
| {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, | |
| {0, 0}, | |
| }; | |
| static PyType_Spec __pyx_CyFunctionType_spec = { | |
| __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", | |
| sizeof(__pyx_CyFunctionObject), | |
| 0, | |
| Py_TPFLAGS_METHOD_DESCRIPTOR | | |
| _Py_TPFLAGS_HAVE_VECTORCALL | | |
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
| __pyx_CyFunctionType_slots | |
| }; | |
| static PyTypeObject __pyx_CyFunctionType_type = { | |
| PyVarObject_HEAD_INIT(0, 0) | |
| __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", /*tp_name*/ | |
| sizeof(__pyx_CyFunctionObject), /*tp_basicsize*/ | |
| 0, /*tp_itemsize*/ | |
| (destructor) __Pyx_CyFunction_dealloc, /*tp_dealloc*/ | |
| 0, /*tp_print*/ | |
| (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall), /*tp_vectorcall_offset backported into tp_print*/ | |
| offsetof(PyCFunctionObject, vectorcall), /*tp_vectorcall_offset*/ | |
| 0, /*tp_getattr*/ | |
| 0, /*tp_setattr*/ | |
| 0, /*tp_compare*/ | |
| 0, /*tp_as_async*/ | |
| (reprfunc) __Pyx_CyFunction_repr, /*tp_repr*/ | |
| 0, /*tp_as_number*/ | |
| 0, /*tp_as_sequence*/ | |
| 0, /*tp_as_mapping*/ | |
| 0, /*tp_hash*/ | |
| __Pyx_CyFunction_CallAsMethod, /*tp_call*/ | |
| 0, /*tp_str*/ | |
| 0, /*tp_getattro*/ | |
| 0, /*tp_setattro*/ | |
| 0, /*tp_as_buffer*/ | |
| Py_TPFLAGS_METHOD_DESCRIPTOR | | |
| _Py_TPFLAGS_HAVE_VECTORCALL | | |
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
| 0, /*tp_doc*/ | |
| (traverseproc) __Pyx_CyFunction_traverse, /*tp_traverse*/ | |
| (inquiry) __Pyx_CyFunction_clear, /*tp_clear*/ | |
| 0, /*tp_richcompare*/ | |
| offsetof(__pyx_CyFunctionObject, func_weakreflist), /*tp_weaklistoffset*/ | |
| offsetof(PyCFunctionObject, m_weakreflist), /*tp_weaklistoffset*/ | |
| 0, /*tp_iter*/ | |
| 0, /*tp_iternext*/ | |
| __pyx_CyFunction_methods, /*tp_methods*/ | |
| __pyx_CyFunction_members, /*tp_members*/ | |
| __pyx_CyFunction_getsets, /*tp_getset*/ | |
| 0, /*tp_base*/ | |
| 0, /*tp_dict*/ | |
| __Pyx_PyMethod_New, /*tp_descr_get*/ | |
| 0, /*tp_descr_set*/ | |
| offsetof(__pyx_CyFunctionObject, func_dict),/*tp_dictoffset*/ | |
| 0, /*tp_init*/ | |
| 0, /*tp_alloc*/ | |
| 0, /*tp_new*/ | |
| 0, /*tp_free*/ | |
| 0, /*tp_is_gc*/ | |
| 0, /*tp_bases*/ | |
| 0, /*tp_mro*/ | |
| 0, /*tp_cache*/ | |
| 0, /*tp_subclasses*/ | |
| 0, /*tp_weaklist*/ | |
| 0, /*tp_del*/ | |
| 0, /*tp_version_tag*/ | |
| 0, /*tp_finalize*/ | |
| 0, /*tp_vectorcall*/ | |
| 0, /*tp_print*/ | |
| 0, /*tp_watched*/ | |
| 0, /*tp_pypy_flags*/ | |
| }; | |
| static int __pyx_CyFunction_init(PyObject *module) { | |
| __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL); | |
| CYTHON_UNUSED_VAR(module); | |
| __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); | |
| if (unlikely(__pyx_CyFunctionType == NULL)) { | |
| return -1; | |
| } | |
| return 0; | |
| } | |
| static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { | |
| __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; | |
| m->defaults = PyObject_Malloc(size); | |
| if (unlikely(!m->defaults)) | |
| return PyErr_NoMemory(); | |
| memset(m->defaults, 0, size); | |
| m->defaults_pyobjects = pyobjects; | |
| m->defaults_size = size; | |
| return m->defaults; | |
| } | |
| static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { | |
| __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; | |
| m->defaults_tuple = tuple; | |
| Py_INCREF(tuple); | |
| } | |
| static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { | |
| __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; | |
| m->defaults_kwdict = dict; | |
| Py_INCREF(dict); | |
| } | |
| static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { | |
| __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; | |
| m->func_annotations = dict; | |
| Py_INCREF(dict); | |
| } | |
| //////////////////// CythonFunction.proto //////////////////// | |
| static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, | |
| int flags, PyObject* qualname, | |
| PyObject *closure, | |
| PyObject *module, PyObject *globals, | |
| PyObject* code); | |
| //////////////////// CythonFunction //////////////////// | |
| //@requires: CythonFunctionShared | |
| static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, | |
| PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { | |
| PyObject *op = __Pyx_CyFunction_Init( | |
| PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType), | |
| ml, flags, qualname, closure, module, globals, code | |
| ); | |
| if (likely(op)) { | |
| PyObject_GC_Track(op); | |
| } | |
| return op; | |
| } | |
| //////////////////// CyFunctionClassCell.proto //////////////////// | |
| static int __Pyx_CyFunction_InitClassCell(PyObject *cyfunctions, PyObject *classobj);/*proto*/ | |
| //////////////////// CyFunctionClassCell //////////////////// | |
| //@requires: CythonFunctionShared | |
| static int __Pyx_CyFunction_InitClassCell(PyObject *cyfunctions, PyObject *classobj) { | |
| Py_ssize_t i, count = PyList_GET_SIZE(cyfunctions); | |
| for (i = 0; i < count; i++) { | |
| __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) | |
| PyList_GET_ITEM(cyfunctions, i); | |
| PySequence_ITEM(cyfunctions, i); | |
| if (unlikely(!m)) | |
| return -1; | |
| __Pyx_CyFunction_SetClassObj(m, classobj); | |
| Py_DECREF((PyObject*)m); | |
| } | |
| return 0; | |
| } | |
| //////////////////// FusedFunction.proto //////////////////// | |
| typedef struct { | |
| __pyx_CyFunctionObject func; | |
| PyObject *__signatures__; | |
| PyObject *self; | |
| } __pyx_FusedFunctionObject; | |
| static PyObject *__pyx_FusedFunction_New(PyMethodDef *ml, int flags, | |
| PyObject *qualname, PyObject *closure, | |
| PyObject *module, PyObject *globals, | |
| PyObject *code); | |
| static int __pyx_FusedFunction_clear(__pyx_FusedFunctionObject *self); | |
| static int __pyx_FusedFunction_init(PyObject *module); | |
| //////////////////// FusedFunction //////////////////// | |
| //@requires: CythonFunctionShared | |
| static PyObject * | |
| __pyx_FusedFunction_New(PyMethodDef *ml, int flags, | |
| PyObject *qualname, PyObject *closure, | |
| PyObject *module, PyObject *globals, | |
| PyObject *code) | |
| { | |
| PyObject *op = __Pyx_CyFunction_Init( | |
| // __pyx_CyFunctionObject is correct below since that's the cast that we want. | |
| PyObject_GC_New(__pyx_CyFunctionObject, __pyx_FusedFunctionType), | |
| ml, flags, qualname, closure, module, globals, code | |
| ); | |
| if (likely(op)) { | |
| __pyx_FusedFunctionObject *fusedfunc = (__pyx_FusedFunctionObject *) op; | |
| fusedfunc->__signatures__ = NULL; | |
| fusedfunc->self = NULL; | |
| PyObject_GC_Track(op); | |
| } | |
| return op; | |
| } | |
| static void | |
| __pyx_FusedFunction_dealloc(__pyx_FusedFunctionObject *self) | |
| { | |
| PyObject_GC_UnTrack(self); | |
| Py_CLEAR(self->self); | |
| Py_CLEAR(self->__signatures__); | |
| __Pyx__CyFunction_dealloc((__pyx_CyFunctionObject *) self); | |
| } | |
| static int | |
| __pyx_FusedFunction_traverse(__pyx_FusedFunctionObject *self, | |
| visitproc visit, | |
| void *arg) | |
| { | |
| Py_VISIT(self->self); | |
| Py_VISIT(self->__signatures__); | |
| return __Pyx_CyFunction_traverse((__pyx_CyFunctionObject *) self, visit, arg); | |
| } | |
| static int | |
| __pyx_FusedFunction_clear(__pyx_FusedFunctionObject *self) | |
| { | |
| Py_CLEAR(self->self); | |
| Py_CLEAR(self->__signatures__); | |
| return __Pyx_CyFunction_clear((__pyx_CyFunctionObject *) self); | |
| } | |
| static PyObject * | |
| __pyx_FusedFunction_descr_get(PyObject *self, PyObject *obj, PyObject *type) | |
| { | |
| __pyx_FusedFunctionObject *func, *meth; | |
| func = (__pyx_FusedFunctionObject *) self; | |
| if (func->self || func->func.flags & __Pyx_CYFUNCTION_STATICMETHOD) { | |
| // Do not allow rebinding and don't do anything for static methods | |
| Py_INCREF(self); | |
| return self; | |
| } | |
| if (obj == Py_None) | |
| obj = NULL; | |
| if (func->func.flags & __Pyx_CYFUNCTION_CLASSMETHOD) | |
| obj = type; | |
| if (obj == NULL) { | |
| // We aren't actually binding to anything, save the effort of rebinding | |
| Py_INCREF(self); | |
| return self; | |
| } | |
| meth = (__pyx_FusedFunctionObject *) __pyx_FusedFunction_New( | |
| ((PyCFunctionObject *) func)->m_ml, | |
| ((__pyx_CyFunctionObject *) func)->flags, | |
| ((__pyx_CyFunctionObject *) func)->func_qualname, | |
| ((__pyx_CyFunctionObject *) func)->func_closure, | |
| ((PyCFunctionObject *) func)->m_module, | |
| ((__pyx_CyFunctionObject *) func)->func_globals, | |
| ((__pyx_CyFunctionObject *) func)->func_code); | |
| if (unlikely(!meth)) | |
| return NULL; | |
| // defaults needs copying fully rather than just copying the pointer | |
| // since otherwise it will be freed on destruction of meth despite | |
| // belonging to func rather than meth | |
| if (func->func.defaults) { | |
| PyObject **pydefaults; | |
| int i; | |
| if (unlikely(!__Pyx_CyFunction_InitDefaults( | |
| (PyObject*)meth, | |
| func->func.defaults_size, | |
| func->func.defaults_pyobjects))) { | |
| Py_XDECREF((PyObject*)meth); | |
| return NULL; | |
| } | |
| memcpy(meth->func.defaults, func->func.defaults, func->func.defaults_size); | |
| pydefaults = __Pyx_CyFunction_Defaults(PyObject *, meth); | |
| for (i = 0; i < meth->func.defaults_pyobjects; i++) | |
| Py_XINCREF(pydefaults[i]); | |
| } | |
| __Pyx_CyFunction_SetClassObj(meth, __Pyx_CyFunction_GetClassObj(func)); | |
| Py_XINCREF(func->__signatures__); | |
| meth->__signatures__ = func->__signatures__; | |
| Py_XINCREF(func->func.defaults_tuple); | |
| meth->func.defaults_tuple = func->func.defaults_tuple; | |
| Py_XINCREF(obj); | |
| meth->self = obj; | |
| return (PyObject *) meth; | |
| } | |
| static PyObject * | |
| _obj_to_string(PyObject *obj) | |
| { | |
| if (PyUnicode_CheckExact(obj)) | |
| return __Pyx_NewRef(obj); | |
| else if (PyString_Check(obj)) | |
| return PyUnicode_FromEncodedObject(obj, NULL, "strict"); | |
| else if (PyType_Check(obj)) | |
| return PyObject_GetAttr(obj, PYIDENT("__name__")); | |
| else | |
| return PyObject_Unicode(obj); | |
| } | |
| static PyObject * | |
| __pyx_FusedFunction_getitem(__pyx_FusedFunctionObject *self, PyObject *idx) | |
| { | |
| PyObject *signature = NULL; | |
| PyObject *unbound_result_func; | |
| PyObject *result_func = NULL; | |
| if (unlikely(self->__signatures__ == NULL)) { | |
| PyErr_SetString(PyExc_TypeError, "Function is not fused"); | |
| return NULL; | |
| } | |
| if (PyTuple_Check(idx)) { | |
| Py_ssize_t n = PyTuple_GET_SIZE(idx); | |
| PyObject *list = PyList_New(n); | |
| int i; | |
| if (unlikely(!list)) | |
| return NULL; | |
| for (i = 0; i < n; i++) { | |
| PyObject *string; | |
| PyObject *item = PyTuple_GET_ITEM(idx, i); | |
| PyObject *item = PySequence_ITEM(idx, i); if (unlikely(!item)) goto __pyx_err; | |
| string = _obj_to_string(item); | |
| Py_DECREF(item); | |
| if (unlikely(!string)) goto __pyx_err; | |
| PyList_SET_ITEM(list, i, string); | |
| } | |
| signature = PyUnicode_Join(PYUNICODE("|"), list); | |
| __pyx_err:; | |
| Py_DECREF(list); | |
| } else { | |
| signature = _obj_to_string(idx); | |
| } | |
| if (unlikely(!signature)) | |
| return NULL; | |
| unbound_result_func = PyObject_GetItem(self->__signatures__, signature); | |
| if (likely(unbound_result_func)) { | |
| if (self->self) { | |
| __pyx_FusedFunctionObject *unbound = (__pyx_FusedFunctionObject *) unbound_result_func; | |
| // TODO: move this to InitClassCell | |
| __Pyx_CyFunction_SetClassObj(unbound, __Pyx_CyFunction_GetClassObj(self)); | |
| result_func = __pyx_FusedFunction_descr_get(unbound_result_func, | |
| self->self, self->self); | |
| } else { | |
| result_func = unbound_result_func; | |
| Py_INCREF(result_func); | |
| } | |
| } | |
| Py_DECREF(signature); | |
| Py_XDECREF(unbound_result_func); | |
| return result_func; | |
| } | |
| static PyObject * | |
| __pyx_FusedFunction_callfunction(PyObject *func, PyObject *args, PyObject *kw) | |
| { | |
| __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; | |
| int static_specialized = (cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD && | |
| !((__pyx_FusedFunctionObject *) func)->__signatures__); | |
| if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !static_specialized) { | |
| return __Pyx_CyFunction_CallAsMethod(func, args, kw); | |
| } else { | |
| return __Pyx_CyFunction_Call(func, args, kw); | |
| } | |
| } | |
| // Note: the 'self' from method binding is passed in in the args tuple, | |
| // whereas PyCFunctionObject's m_self is passed in as the first | |
| // argument to the C function. For extension methods we need | |
| // to pass 'self' as 'm_self' and not as the first element of the | |
| // args tuple. | |
| static PyObject * | |
| __pyx_FusedFunction_call(PyObject *func, PyObject *args, PyObject *kw) | |
| { | |
| __pyx_FusedFunctionObject *binding_func = (__pyx_FusedFunctionObject *) func; | |
| Py_ssize_t argc = PyTuple_GET_SIZE(args); | |
| PyObject *new_args = NULL; | |
| __pyx_FusedFunctionObject *new_func = NULL; | |
| PyObject *result = NULL; | |
| int is_staticmethod = binding_func->func.flags & __Pyx_CYFUNCTION_STATICMETHOD; | |
| if (binding_func->self) { | |
| // Bound method call, put 'self' in the args tuple | |
| PyObject *self; | |
| Py_ssize_t i; | |
| new_args = PyTuple_New(argc + 1); | |
| if (unlikely(!new_args)) | |
| return NULL; | |
| self = binding_func->self; | |
| Py_INCREF(self); | |
| PyTuple_SET_ITEM(new_args, 0, self); | |
| self = NULL; | |
| for (i = 0; i < argc; i++) { | |
| PyObject *item = PyTuple_GET_ITEM(args, i); | |
| Py_INCREF(item); | |
| PyObject *item = PySequence_ITEM(args, i); if (unlikely(!item)) goto bad; | |
| PyTuple_SET_ITEM(new_args, i + 1, item); | |
| } | |
| args = new_args; | |
| } | |
| if (binding_func->__signatures__) { | |
| PyObject *tup; | |
| if (is_staticmethod && binding_func->func.flags & __Pyx_CYFUNCTION_CCLASS) { | |
| // FIXME: this seems wrong, but we must currently pass the signatures dict as 'self' argument | |
| tup = PyTuple_Pack(3, args, | |
| kw == NULL ? Py_None : kw, | |
| binding_func->func.defaults_tuple); | |
| if (unlikely(!tup)) goto bad; | |
| new_func = (__pyx_FusedFunctionObject *) __Pyx_CyFunction_CallMethod( | |
| func, binding_func->__signatures__, tup, NULL); | |
| } else { | |
| tup = PyTuple_Pack(4, binding_func->__signatures__, args, | |
| kw == NULL ? Py_None : kw, | |
| binding_func->func.defaults_tuple); | |
| if (unlikely(!tup)) goto bad; | |
| new_func = (__pyx_FusedFunctionObject *) __pyx_FusedFunction_callfunction(func, tup, NULL); | |
| } | |
| Py_DECREF(tup); | |
| if (unlikely(!new_func)) | |
| goto bad; | |
| __Pyx_CyFunction_SetClassObj(new_func, __Pyx_CyFunction_GetClassObj(binding_func)); | |
| func = (PyObject *) new_func; | |
| } | |
| result = __pyx_FusedFunction_callfunction(func, args, kw); | |
| bad: | |
| Py_XDECREF(new_args); | |
| Py_XDECREF((PyObject *) new_func); | |
| return result; | |
| } | |
| static PyMemberDef __pyx_FusedFunction_members[] = { | |
| {(char *) "__signatures__", | |
| T_OBJECT, | |
| offsetof(__pyx_FusedFunctionObject, __signatures__), | |
| READONLY, | |
| 0}, | |
| {(char *) "__self__", T_OBJECT_EX, offsetof(__pyx_FusedFunctionObject, self), READONLY, 0}, | |
| {0, 0, 0, 0, 0}, | |
| }; | |
| static PyGetSetDef __pyx_FusedFunction_getsets[] = { | |
| // __doc__ is None for the fused function type, but we need it to be | |
| // a descriptor for the instance's __doc__, so rebuild the descriptor in our subclass | |
| // (all other descriptors are inherited) | |
| {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, | |
| {0, 0, 0, 0, 0} | |
| }; | |
| static PyType_Slot __pyx_FusedFunctionType_slots[] = { | |
| {Py_tp_dealloc, (void *)__pyx_FusedFunction_dealloc}, | |
| {Py_tp_call, (void *)__pyx_FusedFunction_call}, | |
| {Py_tp_traverse, (void *)__pyx_FusedFunction_traverse}, | |
| {Py_tp_clear, (void *)__pyx_FusedFunction_clear}, | |
| {Py_tp_members, (void *)__pyx_FusedFunction_members}, | |
| {Py_tp_getset, (void *)__pyx_FusedFunction_getsets}, | |
| {Py_tp_descr_get, (void *)__pyx_FusedFunction_descr_get}, | |
| {Py_mp_subscript, (void *)__pyx_FusedFunction_getitem}, | |
| {0, 0}, | |
| }; | |
| static PyType_Spec __pyx_FusedFunctionType_spec = { | |
| __PYX_TYPE_MODULE_PREFIX "fused_cython_function", | |
| sizeof(__pyx_FusedFunctionObject), | |
| 0, | |
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
| __pyx_FusedFunctionType_slots | |
| }; | |
| static PyMappingMethods __pyx_FusedFunction_mapping_methods = { | |
| 0, | |
| (binaryfunc) __pyx_FusedFunction_getitem, | |
| 0, | |
| }; | |
| static PyTypeObject __pyx_FusedFunctionType_type = { | |
| PyVarObject_HEAD_INIT(0, 0) | |
| __PYX_TYPE_MODULE_PREFIX "fused_cython_function", /*tp_name*/ | |
| sizeof(__pyx_FusedFunctionObject), /*tp_basicsize*/ | |
| 0, /*tp_itemsize*/ | |
| (destructor) __pyx_FusedFunction_dealloc, /*tp_dealloc*/ | |
| 0, /*tp_print*/ | |
| 0, /*tp_getattr*/ | |
| 0, /*tp_setattr*/ | |
| 0, /*tp_compare*/ | |
| 0, /*tp_as_async*/ | |
| 0, /*tp_repr*/ | |
| 0, /*tp_as_number*/ | |
| 0, /*tp_as_sequence*/ | |
| &__pyx_FusedFunction_mapping_methods, /*tp_as_mapping*/ | |
| 0, /*tp_hash*/ | |
| (ternaryfunc) __pyx_FusedFunction_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_BASETYPE, /*tp_flags*/ | |
| 0, /*tp_doc*/ | |
| (traverseproc) __pyx_FusedFunction_traverse, /*tp_traverse*/ | |
| (inquiry) __pyx_FusedFunction_clear,/*tp_clear*/ | |
| 0, /*tp_richcompare*/ | |
| 0, /*tp_weaklistoffset*/ | |
| 0, /*tp_iter*/ | |
| 0, /*tp_iternext*/ | |
| 0, /*tp_methods*/ | |
| __pyx_FusedFunction_members, /*tp_members*/ | |
| __pyx_FusedFunction_getsets, /*tp_getset*/ | |
| // NOTE: tp_base may be changed later during module initialisation when importing CyFunction across modules. | |
| &__pyx_CyFunctionType_type, /*tp_base*/ | |
| 0, /*tp_dict*/ | |
| __pyx_FusedFunction_descr_get, /*tp_descr_get*/ | |
| 0, /*tp_descr_set*/ | |
| 0, /*tp_dictoffset*/ | |
| 0, /*tp_init*/ | |
| 0, /*tp_alloc*/ | |
| 0, /*tp_new*/ | |
| 0, /*tp_free*/ | |
| 0, /*tp_is_gc*/ | |
| 0, /*tp_bases*/ | |
| 0, /*tp_mro*/ | |
| 0, /*tp_cache*/ | |
| 0, /*tp_subclasses*/ | |
| 0, /*tp_weaklist*/ | |
| 0, /*tp_del*/ | |
| 0, /*tp_version_tag*/ | |
| 0, /*tp_finalize*/ | |
| 0, /*tp_vectorcall*/ | |
| 0, /*tp_print*/ | |
| 0, /*tp_watched*/ | |
| 0, /*tp_pypy_flags*/ | |
| }; | |
| static int __pyx_FusedFunction_init(PyObject *module) { | |
| PyObject *bases = PyTuple_Pack(1, __pyx_CyFunctionType); | |
| if (unlikely(!bases)) { | |
| return -1; | |
| } | |
| __pyx_FusedFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_FusedFunctionType_spec, bases); | |
| Py_DECREF(bases); | |
| CYTHON_UNUSED_VAR(module); | |
| // Set base from __Pyx_FetchCommonTypeFromSpec, in case it's different from the local static value. | |
| __pyx_FusedFunctionType_type.tp_base = __pyx_CyFunctionType; | |
| __pyx_FusedFunctionType = __Pyx_FetchCommonType(&__pyx_FusedFunctionType_type); | |
| if (unlikely(__pyx_FusedFunctionType == NULL)) { | |
| return -1; | |
| } | |
| return 0; | |
| } | |
| //////////////////// ClassMethod.proto //////////////////// | |
| CYTHON_UNUSED static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/ | |
| //////////////////// ClassMethod //////////////////// | |
| static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { | |
| if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) { | |
| // cdef classes | |
| return PyClassMethod_New(method); | |
| } | |
| // special C-API function only in PyPy >= 5.9 | |
| if (PyMethodDescr_Check(method)) | |
| // PyMethodDescr_Type is not exposed in the CPython C-API in Py2. | |
| static PyTypeObject *methoddescr_type = NULL; | |
| if (unlikely(methoddescr_type == NULL)) { | |
| PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append"); | |
| if (unlikely(!meth)) return NULL; | |
| methoddescr_type = Py_TYPE(meth); | |
| Py_DECREF(meth); | |
| } | |
| PyTypeObject *methoddescr_type = &PyMethodDescr_Type; | |
| if (__Pyx_TypeCheck(method, methoddescr_type)) | |
| { | |
| // cdef classes | |
| PyMethodDescrObject *descr = (PyMethodDescrObject *)method; | |
| PyTypeObject *d_type = descr->d_type; | |
| PyTypeObject *d_type = descr->d_common.d_type; | |
| return PyDescr_NewClassMethod(d_type, descr->d_method); | |
| } | |
| else if (PyMethod_Check(method)) { | |
| // python classes | |
| return PyClassMethod_New(PyMethod_GET_FUNCTION(method)); | |
| } | |
| else { | |
| return PyClassMethod_New(method); | |
| } | |
| } | |