3 //////////////////// CythonFunction.proto ////////////////////
4 #define __Pyx_CyFunction_USED 1
5 #include <structmember.h>
7 #define __Pyx_CYFUNCTION_STATICMETHOD 0x01
8 #define __Pyx_CYFUNCTION_CLASSMETHOD 0x02
9 #define __Pyx_CYFUNCTION_CCLASS 0x04
11 #define __Pyx_CyFunction_GetClosure(f) \
12 (((__pyx_CyFunctionObject *) (f))->func_closure)
13 #define __Pyx_CyFunction_GetClassObj(f) \
14 (((__pyx_CyFunctionObject *) (f))->func_classobj)
16 #define __Pyx_CyFunction_Defaults(type, f) \
17 ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
18 #define __Pyx_CyFunction_SetDefaultsGetter(f, g) \
19 ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
23 PyCFunctionObject func
;
25 PyObject
*func_weakreflist
;
27 PyObject
*func_qualname
;
29 PyObject
*func_globals
;
31 PyObject
*func_closure
;
32 PyObject
*func_classobj
; /* No-args super() class cell */
34 /* Dynamic default args and annotations */
36 int defaults_pyobjects
;
40 PyObject
*defaults_tuple
; /* Const defaults tuple */
41 PyObject
*defaults_kwdict
; /* Const kwonly defaults dict */
42 PyObject
*(*defaults_getter
)(PyObject
*);
43 PyObject
*func_annotations
; /* function annotations dict */
44 } __pyx_CyFunctionObject
;
46 static PyTypeObject
*__pyx_CyFunctionType
= 0;
48 #define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code) \
49 __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
51 static PyObject
*__Pyx_CyFunction_New(PyTypeObject
*, PyMethodDef
*ml
,
52 int flags
, PyObject
* qualname
,
54 PyObject
*module
, PyObject
*globals
,
57 static CYTHON_INLINE
void *__Pyx_CyFunction_InitDefaults(PyObject
*m
,
60 static CYTHON_INLINE
void __Pyx_CyFunction_SetDefaultsTuple(PyObject
*m
,
62 static CYTHON_INLINE
void __Pyx_CyFunction_SetDefaultsKwDict(PyObject
*m
,
64 static CYTHON_INLINE
void __Pyx_CyFunction_SetAnnotationsDict(PyObject
*m
,
68 static int __Pyx_CyFunction_init(void);
70 //////////////////// CythonFunction ////////////////////
72 //@requires: CommonTypes.c::FetchCommonType
73 ////@requires: ObjectHandling.c::PyObjectGetAttrStr
76 __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject
*op
, CYTHON_UNUSED
void *closure
)
78 if (unlikely(op
->func_doc
== NULL
)) {
79 if (op
->func
.m_ml
->ml_doc
) {
80 #if PY_MAJOR_VERSION >= 3
81 op
->func_doc
= PyUnicode_FromString(op
->func
.m_ml
->ml_doc
);
83 op
->func_doc
= PyString_FromString(op
->func
.m_ml
->ml_doc
);
85 if (unlikely(op
->func_doc
== NULL
))
92 Py_INCREF(op
->func_doc
);
97 __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject
*op
, PyObject
*value
)
99 PyObject
*tmp
= op
->func_doc
;
101 value
= Py_None
; /* Mark as deleted */
103 op
->func_doc
= value
;
109 __Pyx_CyFunction_get_name(__pyx_CyFunctionObject
*op
)
111 if (unlikely(op
->func_name
== NULL
)) {
112 #if PY_MAJOR_VERSION >= 3
113 op
->func_name
= PyUnicode_InternFromString(op
->func
.m_ml
->ml_name
);
115 op
->func_name
= PyString_InternFromString(op
->func
.m_ml
->ml_name
);
117 if (unlikely(op
->func_name
== NULL
))
120 Py_INCREF(op
->func_name
);
121 return op
->func_name
;
125 __Pyx_CyFunction_set_name(__pyx_CyFunctionObject
*op
, PyObject
*value
)
129 #if PY_MAJOR_VERSION >= 3
130 if (unlikely(value
== NULL
|| !PyUnicode_Check(value
))) {
132 if (unlikely(value
== NULL
|| !PyString_Check(value
))) {
134 PyErr_SetString(PyExc_TypeError
,
135 "__name__ must be set to a string object");
140 op
->func_name
= value
;
146 __Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject
*op
)
148 Py_INCREF(op
->func_qualname
);
149 return op
->func_qualname
;
153 __Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject
*op
, PyObject
*value
)
157 #if PY_MAJOR_VERSION >= 3
158 if (unlikely(value
== NULL
|| !PyUnicode_Check(value
))) {
160 if (unlikely(value
== NULL
|| !PyString_Check(value
))) {
162 PyErr_SetString(PyExc_TypeError
,
163 "__qualname__ must be set to a string object");
166 tmp
= op
->func_qualname
;
168 op
->func_qualname
= value
;
174 __Pyx_CyFunction_get_self(__pyx_CyFunctionObject
*m
, CYTHON_UNUSED
void *closure
)
178 self
= m
->func_closure
;
186 __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject
*op
)
188 if (unlikely(op
->func_dict
== NULL
)) {
189 op
->func_dict
= PyDict_New();
190 if (unlikely(op
->func_dict
== NULL
))
193 Py_INCREF(op
->func_dict
);
194 return op
->func_dict
;
198 __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject
*op
, PyObject
*value
)
202 if (unlikely(value
== NULL
)) {
203 PyErr_SetString(PyExc_TypeError
,
204 "function's dictionary may not be deleted");
207 if (unlikely(!PyDict_Check(value
))) {
208 PyErr_SetString(PyExc_TypeError
,
209 "setting function's dictionary to a non-dict");
214 op
->func_dict
= value
;
220 __Pyx_CyFunction_get_globals(__pyx_CyFunctionObject
*op
)
222 Py_INCREF(op
->func_globals
);
223 return op
->func_globals
;
227 __Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject
*op
)
234 __Pyx_CyFunction_get_code(__pyx_CyFunctionObject
*op
)
236 PyObject
* result
= (op
->func_code
) ? op
->func_code
: Py_None
;
242 __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject
*op
) {
243 PyObject
*res
= op
->defaults_getter((PyObject
*) op
);
248 op
->defaults_tuple
= PyTuple_GET_ITEM(res
, 0);
249 Py_INCREF(op
->defaults_tuple
);
250 op
->defaults_kwdict
= PyTuple_GET_ITEM(res
, 1);
251 Py_INCREF(op
->defaults_kwdict
);
257 __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject
*op
, PyObject
* value
) {
260 // del => explicit None to prevent rebuilding
262 } else if (value
!= Py_None
&& !PyTuple_Check(value
)) {
263 PyErr_SetString(PyExc_TypeError
,
264 "__defaults__ must be set to a tuple object");
268 tmp
= op
->defaults_tuple
;
269 op
->defaults_tuple
= value
;
275 __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject
*op
) {
276 PyObject
* result
= op
->defaults_tuple
;
277 if (unlikely(!result
)) {
278 if (op
->defaults_getter
) {
279 if (__Pyx_CyFunction_init_defaults(op
) < 0) return NULL
;
280 result
= op
->defaults_tuple
;
290 __Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject
*op
, PyObject
* value
) {
293 // del => explicit None to prevent rebuilding
295 } else if (value
!= Py_None
&& !PyDict_Check(value
)) {
296 PyErr_SetString(PyExc_TypeError
,
297 "__kwdefaults__ must be set to a dict object");
301 tmp
= op
->defaults_kwdict
;
302 op
->defaults_kwdict
= value
;
308 __Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject
*op
) {
309 PyObject
* result
= op
->defaults_kwdict
;
310 if (unlikely(!result
)) {
311 if (op
->defaults_getter
) {
312 if (__Pyx_CyFunction_init_defaults(op
) < 0) return NULL
;
313 result
= op
->defaults_kwdict
;
323 __Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject
*op
, PyObject
* value
) {
325 if (!value
|| value
== Py_None
) {
327 } else if (!PyDict_Check(value
)) {
328 PyErr_SetString(PyExc_TypeError
,
329 "__annotations__ must be set to a dict object");
333 tmp
= op
->func_annotations
;
334 op
->func_annotations
= value
;
340 __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject
*op
) {
341 PyObject
* result
= op
->func_annotations
;
342 if (unlikely(!result
)) {
343 result
= PyDict_New();
344 if (unlikely(!result
)) return NULL
;
345 op
->func_annotations
= result
;
351 //#if PY_VERSION_HEX >= 0x030400C1
353 //__Pyx_CyFunction_get_signature(__pyx_CyFunctionObject *op) {
354 // PyObject *inspect_module, *signature_class, *signature;
355 // // from inspect import Signature
356 // inspect_module = PyImport_ImportModuleLevelObject(PYIDENT("inspect"), NULL, NULL, NULL, 0);
357 // if (unlikely(!inspect_module))
359 // signature_class = __Pyx_PyObject_GetAttrStr(inspect_module, PYIDENT("Signature"));
360 // Py_DECREF(inspect_module);
361 // if (unlikely(!signature_class))
363 // // return Signature.from_function(op)
364 // signature = PyObject_CallMethodObjArgs(signature_class, PYIDENT("from_function"), op, NULL);
365 // Py_DECREF(signature_class);
366 // if (likely(signature))
369 // // make sure we raise an AttributeError from this property on any errors
370 // if (!PyErr_ExceptionMatches(PyExc_AttributeError))
371 // PyErr_SetString(PyExc_AttributeError, "failed to calculate __signature__");
376 static PyGetSetDef __pyx_CyFunction_getsets
[] = {
377 {(char *) "func_doc", (getter
)__Pyx_CyFunction_get_doc
, (setter
)__Pyx_CyFunction_set_doc
, 0, 0},
378 {(char *) "__doc__", (getter
)__Pyx_CyFunction_get_doc
, (setter
)__Pyx_CyFunction_set_doc
, 0, 0},
379 {(char *) "func_name", (getter
)__Pyx_CyFunction_get_name
, (setter
)__Pyx_CyFunction_set_name
, 0, 0},
380 {(char *) "__name__", (getter
)__Pyx_CyFunction_get_name
, (setter
)__Pyx_CyFunction_set_name
, 0, 0},
381 {(char *) "__qualname__", (getter
)__Pyx_CyFunction_get_qualname
, (setter
)__Pyx_CyFunction_set_qualname
, 0, 0},
382 {(char *) "__self__", (getter
)__Pyx_CyFunction_get_self
, 0, 0, 0},
383 {(char *) "func_dict", (getter
)__Pyx_CyFunction_get_dict
, (setter
)__Pyx_CyFunction_set_dict
, 0, 0},
384 {(char *) "__dict__", (getter
)__Pyx_CyFunction_get_dict
, (setter
)__Pyx_CyFunction_set_dict
, 0, 0},
385 {(char *) "func_globals", (getter
)__Pyx_CyFunction_get_globals
, 0, 0, 0},
386 {(char *) "__globals__", (getter
)__Pyx_CyFunction_get_globals
, 0, 0, 0},
387 {(char *) "func_closure", (getter
)__Pyx_CyFunction_get_closure
, 0, 0, 0},
388 {(char *) "__closure__", (getter
)__Pyx_CyFunction_get_closure
, 0, 0, 0},
389 {(char *) "func_code", (getter
)__Pyx_CyFunction_get_code
, 0, 0, 0},
390 {(char *) "__code__", (getter
)__Pyx_CyFunction_get_code
, 0, 0, 0},
391 {(char *) "func_defaults", (getter
)__Pyx_CyFunction_get_defaults
, (setter
)__Pyx_CyFunction_set_defaults
, 0, 0},
392 {(char *) "__defaults__", (getter
)__Pyx_CyFunction_get_defaults
, (setter
)__Pyx_CyFunction_set_defaults
, 0, 0},
393 {(char *) "__kwdefaults__", (getter
)__Pyx_CyFunction_get_kwdefaults
, (setter
)__Pyx_CyFunction_set_kwdefaults
, 0, 0},
394 {(char *) "__annotations__", (getter
)__Pyx_CyFunction_get_annotations
, (setter
)__Pyx_CyFunction_set_annotations
, 0, 0},
395 //#if PY_VERSION_HEX >= 0x030400C1
396 // {(char *) "__signature__", (getter)__Pyx_CyFunction_get_signature, 0, 0, 0},
401 #ifndef PY_WRITE_RESTRICTED /* < Py2.5 */
402 #define PY_WRITE_RESTRICTED WRITE_RESTRICTED
405 static PyMemberDef __pyx_CyFunction_members
[] = {
406 {(char *) "__module__", T_OBJECT
, offsetof(__pyx_CyFunctionObject
, func
.m_module
), PY_WRITE_RESTRICTED
, 0},
411 __Pyx_CyFunction_reduce(__pyx_CyFunctionObject
*m
, CYTHON_UNUSED PyObject
*args
)
413 #if PY_MAJOR_VERSION >= 3
414 return PyUnicode_FromString(m
->func
.m_ml
->ml_name
);
416 return PyString_FromString(m
->func
.m_ml
->ml_name
);
420 static PyMethodDef __pyx_CyFunction_methods
[] = {
421 {__Pyx_NAMESTR("__reduce__"), (PyCFunction
)__Pyx_CyFunction_reduce
, METH_VARARGS
, 0},
426 static PyObject
*__Pyx_CyFunction_New(PyTypeObject
*type
, PyMethodDef
*ml
, int flags
, PyObject
* qualname
,
427 PyObject
*closure
, PyObject
*module
, PyObject
* globals
, PyObject
* code
) {
428 __pyx_CyFunctionObject
*op
= PyObject_GC_New(__pyx_CyFunctionObject
, type
);
432 op
->func_weakreflist
= NULL
;
434 op
->func
.m_self
= (PyObject
*) op
;
436 op
->func_closure
= closure
;
438 op
->func
.m_module
= module
;
439 op
->func_dict
= NULL
;
440 op
->func_name
= NULL
;
442 op
->func_qualname
= qualname
;
444 op
->func_classobj
= NULL
;
445 op
->func_globals
= globals
;
446 Py_INCREF(op
->func_globals
);
448 op
->func_code
= code
;
449 /* Dynamic Default args */
450 op
->defaults_pyobjects
= 0;
452 op
->defaults_tuple
= NULL
;
453 op
->defaults_kwdict
= NULL
;
454 op
->defaults_getter
= NULL
;
455 op
->func_annotations
= NULL
;
456 PyObject_GC_Track(op
);
457 return (PyObject
*) op
;
461 __Pyx_CyFunction_clear(__pyx_CyFunctionObject
*m
)
463 Py_CLEAR(m
->func_closure
);
464 Py_CLEAR(m
->func
.m_module
);
465 Py_CLEAR(m
->func_dict
);
466 Py_CLEAR(m
->func_name
);
467 Py_CLEAR(m
->func_qualname
);
468 Py_CLEAR(m
->func_doc
);
469 Py_CLEAR(m
->func_globals
);
470 Py_CLEAR(m
->func_code
);
471 Py_CLEAR(m
->func_classobj
);
472 Py_CLEAR(m
->defaults_tuple
);
473 Py_CLEAR(m
->defaults_kwdict
);
474 Py_CLEAR(m
->func_annotations
);
477 PyObject
**pydefaults
= __Pyx_CyFunction_Defaults(PyObject
*, m
);
480 for (i
= 0; i
< m
->defaults_pyobjects
; i
++)
481 Py_XDECREF(pydefaults
[i
]);
483 PyMem_Free(m
->defaults
);
490 static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject
*m
)
492 PyObject_GC_UnTrack(m
);
493 if (m
->func_weakreflist
!= NULL
)
494 PyObject_ClearWeakRefs((PyObject
*) m
);
495 __Pyx_CyFunction_clear(m
);
499 static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject
*m
, visitproc visit
, void *arg
)
501 Py_VISIT(m
->func_closure
);
502 Py_VISIT(m
->func
.m_module
);
503 Py_VISIT(m
->func_dict
);
504 Py_VISIT(m
->func_name
);
505 Py_VISIT(m
->func_qualname
);
506 Py_VISIT(m
->func_doc
);
507 Py_VISIT(m
->func_globals
);
508 Py_VISIT(m
->func_code
);
509 Py_VISIT(m
->func_classobj
);
510 Py_VISIT(m
->defaults_tuple
);
511 Py_VISIT(m
->defaults_kwdict
);
514 PyObject
**pydefaults
= __Pyx_CyFunction_Defaults(PyObject
*, m
);
517 for (i
= 0; i
< m
->defaults_pyobjects
; i
++)
518 Py_VISIT(pydefaults
[i
]);
524 static PyObject
*__Pyx_CyFunction_descr_get(PyObject
*func
, PyObject
*obj
, PyObject
*type
)
526 __pyx_CyFunctionObject
*m
= (__pyx_CyFunctionObject
*) func
;
528 if (m
->flags
& __Pyx_CYFUNCTION_STATICMETHOD
) {
533 if (m
->flags
& __Pyx_CYFUNCTION_CLASSMETHOD
) {
535 type
= (PyObject
*)(Py_TYPE(obj
));
536 return PyMethod_New(func
,
537 type
, (PyObject
*)(Py_TYPE(type
)));
542 return PyMethod_New(func
, obj
, type
);
546 __Pyx_CyFunction_repr(__pyx_CyFunctionObject
*op
)
548 #if PY_MAJOR_VERSION >= 3
549 return PyUnicode_FromFormat("<cyfunction %U at %p>",
550 op
->func_qualname
, (void *)op
);
552 return PyString_FromFormat("<cyfunction %s at %p>",
553 PyString_AsString(op
->func_qualname
), (void *)op
);
557 #if CYTHON_COMPILING_IN_PYPY
558 /* originally copied from PyCFunction_Call() in CPython's Objects/methodobject.c */
559 /* PyPy does not have this function */
560 static PyObject
* __Pyx_CyFunction_Call(PyObject
*func
, PyObject
*arg
, PyObject
*kw
) {
561 PyCFunctionObject
* f
= (PyCFunctionObject
*)func
;
562 PyCFunction meth
= PyCFunction_GET_FUNCTION(func
);
563 PyObject
*self
= PyCFunction_GET_SELF(func
);
566 switch (PyCFunction_GET_FLAGS(func
) & ~(METH_CLASS
| METH_STATIC
| METH_COEXIST
)) {
568 if (likely(kw
== NULL
) || PyDict_Size(kw
) == 0)
569 return (*meth
)(self
, arg
);
571 case METH_VARARGS
| METH_KEYWORDS
:
572 return (*(PyCFunctionWithKeywords
)meth
)(self
, arg
, kw
);
574 if (likely(kw
== NULL
) || PyDict_Size(kw
) == 0) {
575 size
= PyTuple_GET_SIZE(arg
);
577 return (*meth
)(self
, NULL
);
578 PyErr_Format(PyExc_TypeError
,
579 "%.200s() takes no arguments (%zd given)",
580 f
->m_ml
->ml_name
, size
);
585 if (likely(kw
== NULL
) || PyDict_Size(kw
) == 0) {
586 size
= PyTuple_GET_SIZE(arg
);
588 return (*meth
)(self
, PyTuple_GET_ITEM(arg
, 0));
589 PyErr_Format(PyExc_TypeError
,
590 "%.200s() takes exactly one argument (%zd given)",
591 f
->m_ml
->ml_name
, size
);
596 PyErr_SetString(PyExc_SystemError
, "Bad call flags in "
597 "__Pyx_CyFunction_Call. METH_OLDARGS is no "
598 "longer supported!");
602 PyErr_Format(PyExc_TypeError
, "%.200s() takes no keyword arguments",
607 static PyObject
* __Pyx_CyFunction_Call(PyObject
*func
, PyObject
*arg
, PyObject
*kw
) {
608 return PyCFunction_Call(func
, arg
, kw
);
612 static PyTypeObject __pyx_CyFunctionType_type
= {
613 PyVarObject_HEAD_INIT(0, 0)
614 __Pyx_NAMESTR("cython_function_or_method"), /*tp_name*/
615 sizeof(__pyx_CyFunctionObject
), /*tp_basicsize*/
617 (destructor
) __Pyx_CyFunction_dealloc
, /*tp_dealloc*/
621 #if PY_MAJOR_VERSION < 3
626 (reprfunc
) __Pyx_CyFunction_repr
, /*tp_repr*/
628 0, /*tp_as_sequence*/
631 __Pyx_CyFunction_Call
, /*tp_call*/
636 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
, /* tp_flags*/
638 (traverseproc
) __Pyx_CyFunction_traverse
, /*tp_traverse*/
639 (inquiry
) __Pyx_CyFunction_clear
, /*tp_clear*/
640 0, /*tp_richcompare*/
641 offsetof(__pyx_CyFunctionObject
, func_weakreflist
), /* tp_weaklistoffse */
644 __pyx_CyFunction_methods
, /*tp_methods*/
645 __pyx_CyFunction_members
, /*tp_members*/
646 __pyx_CyFunction_getsets
, /*tp_getset*/
649 __Pyx_CyFunction_descr_get
, /*tp_descr_get*/
651 offsetof(__pyx_CyFunctionObject
, func_dict
),/*tp_dictoffset*/
663 #if PY_VERSION_HEX >= 0x02060000
664 0, /*tp_version_tag*/
666 #if PY_VERSION_HEX >= 0x030400a1
672 static int __Pyx_CyFunction_init(void) {
673 #if !CYTHON_COMPILING_IN_PYPY
674 // avoid a useless level of call indirection
675 __pyx_CyFunctionType_type
.tp_call
= PyCFunction_Call
;
677 __pyx_CyFunctionType
= __Pyx_FetchCommonType(&__pyx_CyFunctionType_type
);
678 if (__pyx_CyFunctionType
== NULL
) {
684 static CYTHON_INLINE
void *__Pyx_CyFunction_InitDefaults(PyObject
*func
, size_t size
, int pyobjects
) {
685 __pyx_CyFunctionObject
*m
= (__pyx_CyFunctionObject
*) func
;
687 m
->defaults
= PyMem_Malloc(size
);
689 return PyErr_NoMemory();
690 memset(m
->defaults
, 0, size
);
691 m
->defaults_pyobjects
= pyobjects
;
695 static CYTHON_INLINE
void __Pyx_CyFunction_SetDefaultsTuple(PyObject
*func
, PyObject
*tuple
) {
696 __pyx_CyFunctionObject
*m
= (__pyx_CyFunctionObject
*) func
;
697 m
->defaults_tuple
= tuple
;
701 static CYTHON_INLINE
void __Pyx_CyFunction_SetDefaultsKwDict(PyObject
*func
, PyObject
*dict
) {
702 __pyx_CyFunctionObject
*m
= (__pyx_CyFunctionObject
*) func
;
703 m
->defaults_kwdict
= dict
;
707 static CYTHON_INLINE
void __Pyx_CyFunction_SetAnnotationsDict(PyObject
*func
, PyObject
*dict
) {
708 __pyx_CyFunctionObject
*m
= (__pyx_CyFunctionObject
*) func
;
709 m
->func_annotations
= dict
;
713 //////////////////// CyFunctionClassCell.proto ////////////////////
714 static CYTHON_INLINE
void __Pyx_CyFunction_InitClassCell(PyObject
*cyfunctions
,
717 //////////////////// CyFunctionClassCell ////////////////////
718 //@requires: CythonFunction
720 static CYTHON_INLINE
void __Pyx_CyFunction_InitClassCell(PyObject
*cyfunctions
, PyObject
*classobj
) {
723 for (i
= 0; i
< PyList_GET_SIZE(cyfunctions
); i
++) {
724 __pyx_CyFunctionObject
*m
=
725 (__pyx_CyFunctionObject
*) PyList_GET_ITEM(cyfunctions
, i
);
726 m
->func_classobj
= classobj
;
731 //////////////////// FusedFunction.proto ////////////////////
733 __pyx_CyFunctionObject func
;
734 PyObject
*__signatures__
;
737 } __pyx_FusedFunctionObject
;
739 #define __pyx_FusedFunction_NewEx(ml, flags, qualname, self, module, globals, code) \
740 __pyx_FusedFunction_New(__pyx_FusedFunctionType, ml, flags, qualname, self, module, globals, code)
741 static PyObject
*__pyx_FusedFunction_New(PyTypeObject
*type
,
742 PyMethodDef
*ml
, int flags
,
743 PyObject
*qualname
, PyObject
*self
,
744 PyObject
*module
, PyObject
*globals
,
747 static int __pyx_FusedFunction_clear(__pyx_FusedFunctionObject
*self
);
748 static PyTypeObject
*__pyx_FusedFunctionType
= NULL
;
749 static int __pyx_FusedFunction_init(void);
751 #define __Pyx_FusedFunction_USED
753 //////////////////// FusedFunction ////////////////////
754 //@requires: CythonFunction
757 __pyx_FusedFunction_New(PyTypeObject
*type
, PyMethodDef
*ml
, int flags
,
758 PyObject
*qualname
, PyObject
*self
,
759 PyObject
*module
, PyObject
*globals
,
762 __pyx_FusedFunctionObject
*fusedfunc
=
763 (__pyx_FusedFunctionObject
*) __Pyx_CyFunction_New(type
, ml
, flags
, qualname
,
764 self
, module
, globals
, code
);
768 fusedfunc
->__signatures__
= NULL
;
769 fusedfunc
->type
= NULL
;
770 fusedfunc
->self
= NULL
;
771 return (PyObject
*) fusedfunc
;
774 static void __pyx_FusedFunction_dealloc(__pyx_FusedFunctionObject
*self
) {
775 __pyx_FusedFunction_clear(self
);
776 __pyx_FusedFunctionType
->tp_free((PyObject
*) self
);
780 __pyx_FusedFunction_traverse(__pyx_FusedFunctionObject
*self
,
784 Py_VISIT(self
->self
);
785 Py_VISIT(self
->type
);
786 Py_VISIT(self
->__signatures__
);
787 return __Pyx_CyFunction_traverse((__pyx_CyFunctionObject
*) self
, visit
, arg
);
791 __pyx_FusedFunction_clear(__pyx_FusedFunctionObject
*self
)
793 Py_CLEAR(self
->self
);
794 Py_CLEAR(self
->type
);
795 Py_CLEAR(self
->__signatures__
);
796 return __Pyx_CyFunction_clear((__pyx_CyFunctionObject
*) self
);
801 __pyx_FusedFunction_descr_get(PyObject
*self
, PyObject
*obj
, PyObject
*type
)
803 __pyx_FusedFunctionObject
*func
, *meth
;
805 func
= (__pyx_FusedFunctionObject
*) self
;
807 if (func
->self
|| func
->func
.flags
& __Pyx_CYFUNCTION_STATICMETHOD
) {
808 /* Do not allow rebinding and don't do anything for static methods */
816 meth
= (__pyx_FusedFunctionObject
*) __pyx_FusedFunction_NewEx(
817 ((PyCFunctionObject
*) func
)->m_ml
,
818 ((__pyx_CyFunctionObject
*) func
)->flags
,
819 ((__pyx_CyFunctionObject
*) func
)->func_qualname
,
820 ((__pyx_CyFunctionObject
*) func
)->func_closure
,
821 ((PyCFunctionObject
*) func
)->m_module
,
822 ((__pyx_CyFunctionObject
*) func
)->func_globals
,
823 ((__pyx_CyFunctionObject
*) func
)->func_code
);
827 Py_XINCREF(func
->func
.func_classobj
);
828 meth
->func
.func_classobj
= func
->func
.func_classobj
;
830 Py_XINCREF(func
->__signatures__
);
831 meth
->__signatures__
= func
->__signatures__
;
836 Py_XINCREF(func
->func
.defaults_tuple
);
837 meth
->func
.defaults_tuple
= func
->func
.defaults_tuple
;
839 if (func
->func
.flags
& __Pyx_CYFUNCTION_CLASSMETHOD
)
845 return (PyObject
*) meth
;
849 _obj_to_str(PyObject
*obj
)
851 if (PyType_Check(obj
))
852 return PyObject_GetAttr(obj
, PYIDENT("__name__"));
854 return PyObject_Str(obj
);
858 __pyx_FusedFunction_getitem(__pyx_FusedFunctionObject
*self
, PyObject
*idx
)
860 PyObject
*signature
= NULL
;
861 PyObject
*unbound_result_func
;
862 PyObject
*result_func
= NULL
;
864 if (self
->__signatures__
== NULL
) {
865 PyErr_SetString(PyExc_TypeError
, "Function is not fused");
869 if (PyTuple_Check(idx
)) {
870 PyObject
*list
= PyList_New(0);
871 Py_ssize_t n
= PyTuple_GET_SIZE(idx
);
872 PyObject
*string
= NULL
;
873 PyObject
*sep
= NULL
;
879 for (i
= 0; i
< n
; i
++) {
880 PyObject
*item
= PyTuple_GET_ITEM(idx
, i
);
882 string
= _obj_to_str(item
);
883 if (!string
|| PyList_Append(list
, string
) < 0)
889 sep
= PyUnicode_FromString("|");
891 signature
= PyUnicode_Join(sep
, list
);
897 signature
= _obj_to_str(idx
);
903 unbound_result_func
= PyObject_GetItem(self
->__signatures__
, signature
);
905 if (unbound_result_func
) {
906 if (self
->self
|| self
->type
) {
907 __pyx_FusedFunctionObject
*unbound
= (__pyx_FusedFunctionObject
*) unbound_result_func
;
909 /* Todo: move this to InitClassCell */
910 Py_CLEAR(unbound
->func
.func_classobj
);
911 Py_XINCREF(self
->func
.func_classobj
);
912 unbound
->func
.func_classobj
= self
->func
.func_classobj
;
914 result_func
= __pyx_FusedFunction_descr_get(unbound_result_func
,
915 self
->self
, self
->type
);
917 result_func
= unbound_result_func
;
918 Py_INCREF(result_func
);
922 Py_DECREF(signature
);
923 Py_XDECREF(unbound_result_func
);
929 __pyx_FusedFunction_callfunction(PyObject
*func
, PyObject
*args
, PyObject
*kw
)
931 __pyx_CyFunctionObject
*cyfunc
= (__pyx_CyFunctionObject
*) func
;
933 int static_specialized
= (cyfunc
->flags
& __Pyx_CYFUNCTION_STATICMETHOD
&&
934 !((__pyx_FusedFunctionObject
*) func
)->__signatures__
);
936 if (cyfunc
->flags
& __Pyx_CYFUNCTION_CCLASS
&& !static_specialized
) {
942 argc
= PyTuple_GET_SIZE(args
);
943 new_args
= PyTuple_GetSlice(args
, 1, argc
);
948 self
= PyTuple_GetItem(args
, 0);
953 m_self
= cyfunc
->func
.m_self
;
954 cyfunc
->func
.m_self
= self
;
955 result
= __Pyx_CyFunction_Call(func
, new_args
, kw
);
956 cyfunc
->func
.m_self
= m_self
;
960 result
= __Pyx_CyFunction_Call(func
, args
, kw
);
966 /* Note: the 'self' from method binding is passed in in the args tuple,
967 whereas PyCFunctionObject's m_self is passed in as the first
968 argument to the C function. For extension methods we need
969 to pass 'self' as 'm_self' and not as the first element of the
973 __pyx_FusedFunction_call(PyObject
*func
, PyObject
*args
, PyObject
*kw
)
975 __pyx_FusedFunctionObject
*binding_func
= (__pyx_FusedFunctionObject
*) func
;
976 Py_ssize_t argc
= PyTuple_GET_SIZE(args
);
977 PyObject
*new_args
= NULL
;
978 __pyx_FusedFunctionObject
*new_func
= NULL
;
979 PyObject
*result
= NULL
;
980 PyObject
*self
= NULL
;
981 int is_staticmethod
= binding_func
->func
.flags
& __Pyx_CYFUNCTION_STATICMETHOD
;
982 int is_classmethod
= binding_func
->func
.flags
& __Pyx_CYFUNCTION_CLASSMETHOD
;
984 if (binding_func
->self
) {
985 /* Bound method call, put 'self' in the args tuple */
987 new_args
= PyTuple_New(argc
+ 1);
991 self
= binding_func
->self
;
993 PyTuple_SET_ITEM(new_args
, 0, self
);
995 for (i
= 0; i
< argc
; i
++) {
996 PyObject
*item
= PyTuple_GET_ITEM(args
, i
);
998 PyTuple_SET_ITEM(new_args
, i
+ 1, item
);
1002 } else if (binding_func
->type
) {
1003 /* Unbound method call */
1005 PyErr_SetString(PyExc_TypeError
, "Need at least one argument, 0 given.");
1008 self
= PyTuple_GET_ITEM(args
, 0);
1011 if (self
&& !is_classmethod
&& !is_staticmethod
&&
1012 !PyObject_IsInstance(self
, binding_func
->type
)) {
1013 PyErr_Format(PyExc_TypeError
,
1014 "First argument should be of type %.200s, got %.200s.",
1015 ((PyTypeObject
*) binding_func
->type
)->tp_name
,
1016 self
->ob_type
->tp_name
);
1020 if (binding_func
->__signatures__
) {
1021 PyObject
*tup
= PyTuple_Pack(4, binding_func
->__signatures__
, args
,
1022 kw
== NULL
? Py_None
: kw
,
1023 binding_func
->func
.defaults_tuple
);
1027 new_func
= (__pyx_FusedFunctionObject
*) __pyx_FusedFunction_callfunction(func
, tup
, NULL
);
1033 Py_XINCREF(binding_func
->func
.func_classobj
);
1034 Py_CLEAR(new_func
->func
.func_classobj
);
1035 new_func
->func
.func_classobj
= binding_func
->func
.func_classobj
;
1037 func
= (PyObject
*) new_func
;
1040 result
= __pyx_FusedFunction_callfunction(func
, args
, kw
);
1042 Py_XDECREF(new_args
);
1043 Py_XDECREF((PyObject
*) new_func
);
1047 static PyMemberDef __pyx_FusedFunction_members
[] = {
1048 {(char *) "__signatures__",
1050 offsetof(__pyx_FusedFunctionObject
, __signatures__
),
1056 static PyMappingMethods __pyx_FusedFunction_mapping_methods
= {
1058 (binaryfunc
) __pyx_FusedFunction_getitem
,
1062 static PyTypeObject __pyx_FusedFunctionType_type
= {
1063 PyVarObject_HEAD_INIT(0, 0)
1064 __Pyx_NAMESTR("fused_cython_function"), /*tp_name*/
1065 sizeof(__pyx_FusedFunctionObject
), /*tp_basicsize*/
1067 (destructor
) __pyx_FusedFunction_dealloc
, /*tp_dealloc*/
1071 #if PY_MAJOR_VERSION < 3
1078 0, /*tp_as_sequence*/
1079 &__pyx_FusedFunction_mapping_methods
, /*tp_as_mapping*/
1081 (ternaryfunc
) __pyx_FusedFunction_call
, /*tp_call*/
1086 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
| Py_TPFLAGS_BASETYPE
, /* tp_flags*/
1088 (traverseproc
) __pyx_FusedFunction_traverse
, /*tp_traverse*/
1089 (inquiry
) __pyx_FusedFunction_clear
,/*tp_clear*/
1090 0, /*tp_richcompare*/
1091 0, /*tp_weaklistoffset*/
1095 __pyx_FusedFunction_members
, /*tp_members*/
1096 /* __doc__ is None for the fused function type, but we need it to be */
1097 /* a descriptor for the instance's __doc__, so rebuild descriptors in our subclass */
1098 __pyx_CyFunction_getsets
, /*tp_getset*/
1099 &__pyx_CyFunctionType_type
, /*tp_base*/
1101 __pyx_FusedFunction_descr_get
, /*tp_descr_get*/
1103 0, /*tp_dictoffset*/
1112 0, /*tp_subclasses*/
1115 #if PY_VERSION_HEX >= 0x02060000
1116 0, /*tp_version_tag*/
1118 #if PY_VERSION_HEX >= 0x030400a1
1123 static int __pyx_FusedFunction_init(void) {
1124 __pyx_FusedFunctionType
= __Pyx_FetchCommonType(&__pyx_FusedFunctionType_type
);
1125 if (__pyx_FusedFunctionType
== NULL
) {
1131 //////////////////// ClassMethod.proto ////////////////////
1133 #include "descrobject.h"
1134 static PyObject
* __Pyx_Method_ClassMethod(PyObject
*method
); /*proto*/
1136 //////////////////// ClassMethod ////////////////////
1138 static PyObject
* __Pyx_Method_ClassMethod(PyObject
*method
) {
1139 #if CYTHON_COMPILING_IN_PYPY
1140 if (PyObject_TypeCheck(method
, &PyWrapperDescr_Type
)) { /* cdef classes */
1141 return PyClassMethod_New(method
);
1144 /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
1145 static PyTypeObject
*methoddescr_type
= NULL
;
1146 if (methoddescr_type
== NULL
) {
1147 PyObject
*meth
= __Pyx_GetAttrString((PyObject
*)&PyList_Type
, "append");
1148 if (!meth
) return NULL
;
1149 methoddescr_type
= Py_TYPE(meth
);
1152 if (PyObject_TypeCheck(method
, methoddescr_type
)) { /* cdef classes */
1153 PyMethodDescrObject
*descr
= (PyMethodDescrObject
*)method
;
1154 #if PY_VERSION_HEX < 0x03020000
1155 PyTypeObject
*d_type
= descr
->d_type
;
1157 PyTypeObject
*d_type
= descr
->d_common
.d_type
;
1159 return PyDescr_NewClassMethod(d_type
, descr
->d_method
);
1162 else if (PyMethod_Check(method
)) { /* python classes */
1163 return PyClassMethod_New(PyMethod_GET_FUNCTION(method
));
1165 else if (PyCFunction_Check(method
)) {
1166 return PyClassMethod_New(method
);
1168 #ifdef __Pyx_CyFunction_USED
1169 else if (PyObject_TypeCheck(method
, __pyx_CyFunctionType
)) {
1170 return PyClassMethod_New(method
);
1173 PyErr_SetString(PyExc_TypeError
,
1174 "Class-level classmethod() can only be called on "
1175 "a method_descriptor or instance method.");