Nuitka
The Python compiler
Loading...
Searching...
No Matches
HelpersCallingGenerated.c
1// Copyright 2026, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3/* WARNING, this code is GENERATED. Modify the template CodeTemplateCallsPositional.c.j2 instead! */
4
5/* This file is included from another C file, help IDEs to still parse it on its own. */
6#ifdef __IDE_ONLY__
7#include "nuitka/prelude.h"
8#endif
9
10// We are switching some warnings off for this code, as they are triggered
11// by the generated code constructs in a way that is not useful.
12// spell-checker: ignore Wparentheses GNUC
13#if defined(__clang__)
14#pragma clang diagnostic push
15#pragma clang diagnostic ignored "-Wparentheses-equality"
16#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
17#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
18#pragma GCC diagnostic push
19#endif
20#pragma GCC diagnostic ignored "-Wparentheses"
21#endif
22
23PyObject *CALL_FUNCTION_NO_ARGS(PyThreadState *tstate, PyObject *called) {
24 CHECK_OBJECT(called);
25
26 if (Nuitka_Function_Check(called)) {
27 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
28 return NULL;
29 }
30
31 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
32 PyObject *result;
33
34 if (function->m_args_simple && 0 == function->m_args_positional_count) {
35 result = function->m_c_code(tstate, function, NULL);
36 } else if (function->m_args_simple && 0 + function->m_defaults_given == function->m_args_positional_count) {
37 PyObject **python_pars = &PyTuple_GET_ITEM(function->m_defaults, 0);
38
39 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
40 Py_INCREF(python_pars[i]);
41 }
42
43 result = function->m_c_code(tstate, function, python_pars);
44 } else {
45 result = Nuitka_CallFunctionNoArgs(tstate, function);
46 }
47
48 Py_LeaveRecursiveCall();
49
50 CHECK_OBJECT_X(result);
51
52 return result;
53 } else if (Nuitka_Method_Check(called)) {
54 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
55
56 if (method->m_object == NULL) {
57 PyErr_Format(
58 PyExc_TypeError,
59 "unbound compiled_method %s%s must be called with %s instance as first argument (got nothing instead)",
60 GET_CALLABLE_NAME((PyObject *)method->m_function), GET_CALLABLE_DESC((PyObject *)method->m_function),
61 GET_CLASS_NAME(method->m_class));
62 return NULL;
63 } else {
64 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
65 return NULL;
66 }
67
68 struct Nuitka_FunctionObject *function = method->m_function;
69
70 PyObject *result;
71
72 if (function->m_args_simple && 0 + 1 == function->m_args_positional_count) {
73 PyObject *python_pars[0 + 1];
74
75 python_pars[0] = method->m_object;
76 Py_INCREF(method->m_object);
77
78 result = function->m_c_code(tstate, function, python_pars);
79 } else if (function->m_args_simple &&
80 0 + 1 + function->m_defaults_given == function->m_args_positional_count) {
81 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
82
83 python_pars[0] = method->m_object;
84 Py_INCREF(method->m_object);
85
86 memcpy(python_pars + 1 + 0, &PyTuple_GET_ITEM(function->m_defaults, 0),
87 function->m_defaults_given * sizeof(PyObject *));
88
89 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
90 Py_INCREF(python_pars[i]);
91 }
92
93 result = function->m_c_code(tstate, function, python_pars);
94 } else {
95 result = Nuitka_CallMethodFunctionNoArgs(tstate, function, method->m_object);
96 }
97
98 Py_LeaveRecursiveCall();
99
100 CHECK_OBJECT_X(result);
101
102 return result;
103 }
104#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
105 } else if (PyCFunction_CheckExact(called)) {
106#if PYTHON_VERSION >= 0x380
107#ifdef _NUITKA_FULL_COMPAT
108 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
109 return NULL;
110 }
111#endif
112
113 int flags = PyCFunction_GET_FLAGS(called);
114
115 PyObject *result;
116
117 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
118
119 if (func != NULL) {
120 result = func(called, NULL, 0, NULL);
121
122 CHECK_OBJECT_X(result);
123 } else {
124 PyCFunction method = PyCFunction_GET_FUNCTION(called);
125 PyObject *self = PyCFunction_GET_SELF(called);
126
127 PyObject *pos_args = const_tuple_empty;
128
129 if (flags & METH_KEYWORDS) {
130 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
131 } else {
132 result = (*method)(self, pos_args);
133 }
134 }
135
136#ifdef _NUITKA_FULL_COMPAT
137 Py_LeaveRecursiveCall();
138#endif
139 CHECK_OBJECT_X(result);
140
141 return Nuitka_CheckFunctionResult(tstate, called, result);
142#else
143 // Try to be fast about wrapping the arguments.
144 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
145
146 if (likely(flags & METH_NOARGS)) {
147 // Recursion guard is not strictly necessary, as we already have
148 // one on our way to here.
149#ifdef _NUITKA_FULL_COMPAT
150 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
151 return NULL;
152 }
153#endif
154 PyCFunction method = PyCFunction_GET_FUNCTION(called);
155 PyObject *self = PyCFunction_GET_SELF(called);
156
157 PyObject *result = (*method)(self, NULL);
158
159#ifdef _NUITKA_FULL_COMPAT
160 Py_LeaveRecursiveCall();
161#endif
162 CHECK_OBJECT_X(result);
163
164 return Nuitka_CheckFunctionResult(tstate, called, result);
165 } else if (unlikely(flags & METH_O)) {
166 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (0 given)",
167 ((PyCFunctionObject *)called)->m_ml->ml_name);
168 return NULL;
169 } else if (flags & METH_VARARGS) {
170 // Recursion guard is not strictly necessary, as we already have
171 // one on our way to here.
172#ifdef _NUITKA_FULL_COMPAT
173 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
174 return NULL;
175 }
176#endif
177 PyCFunction method = PyCFunction_GET_FUNCTION(called);
178 PyObject *self = PyCFunction_GET_SELF(called);
179
180 PyObject *result;
181
182#if PYTHON_VERSION < 0x360
183 PyObject *pos_args = const_tuple_empty;
184 if (flags & METH_KEYWORDS) {
185 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
186 } else {
187 result = (*method)(self, pos_args);
188 }
189
190#else
191 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
192 PyObject *pos_args = const_tuple_empty;
193 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
194 } else if (flags == METH_FASTCALL) {
195#if PYTHON_VERSION < 0x370
196 result = (*(_PyCFunctionFast)method)(self, NULL, 0, NULL);
197#else
198 PyObject *pos_args = const_tuple_empty;
199 result = (*(_PyCFunctionFast)method)(self, &pos_args, 0);
200#endif
201 } else {
202 PyObject *pos_args = const_tuple_empty;
203 result = (*method)(self, pos_args);
204 }
205#endif
206
207#ifdef _NUITKA_FULL_COMPAT
208 Py_LeaveRecursiveCall();
209#endif
210
211 CHECK_OBJECT_X(result);
212
213 return Nuitka_CheckFunctionResult(tstate, called, result);
214 }
215#endif
216#endif
217#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
218 } else if (PyFunction_Check(called)) {
219#if PYTHON_VERSION < 0x3b0
220 PyObject *result = callPythonFunctionNoArgs(called);
221#else
222 PyObject *result = _PyFunction_Vectorcall(called, NULL, 0, NULL);
223#endif
224 CHECK_OBJECT_X(result);
225
226 return result;
227#endif
228#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
229 } else if (PyType_Check(called)) {
230 PyTypeObject *type = Py_TYPE(called);
231
232 if (type->tp_call == PyType_Type.tp_call) {
233 PyTypeObject *called_type = (PyTypeObject *)(called);
234
235 if (unlikely(called_type->tp_new == NULL)) {
236 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
237 return NULL;
238 }
239
240 PyObject *pos_args = const_tuple_empty;
241 PyObject *obj;
242
243 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
244 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
245 formatCannotInstantiateAbstractClass(tstate, called_type);
246 return NULL;
247 }
248
249 obj = called_type->tp_alloc(called_type, 0);
250 CHECK_OBJECT(obj);
251 } else {
252 obj = called_type->tp_new(called_type, pos_args, NULL);
253 }
254
255 if (likely(obj != NULL)) {
256 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
257 return obj;
258 }
259
260 // Work on produced type.
261 type = Py_TYPE(obj);
262
263 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
264 if (type->tp_init == default_tp_init_wrapper) {
265
266 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
267
268 // Not really allowed, since we wouldn't have the default wrapper set.
269 assert(init_method != NULL);
270
271 bool is_compiled_function = false;
272 bool init_method_needs_release = false;
273
274 if (likely(init_method != NULL)) {
275 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
276
277 if (func == Nuitka_Function_Type.tp_descr_get) {
278 is_compiled_function = true;
279 } else if (func != NULL) {
280 init_method = func(init_method, obj, (PyObject *)(type));
281 init_method_needs_release = true;
282 }
283 }
284
285 if (unlikely(init_method == NULL)) {
286 if (!HAS_ERROR_OCCURRED(tstate)) {
287 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
288 const_str_plain___init__);
289 }
290
291 return NULL;
292 }
293
294 PyObject *result;
295 if (is_compiled_function) {
296 result = Nuitka_CallMethodFunctionNoArgs(
297 tstate, (struct Nuitka_FunctionObject const *)init_method, obj);
298 } else {
299 result = CALL_FUNCTION_NO_ARGS(tstate, init_method);
300
301 if (init_method_needs_release) {
302 Py_DECREF(init_method);
303 }
304 }
305
306 if (unlikely(result == NULL)) {
307 Py_DECREF(obj);
308 return NULL;
309 }
310
311 Py_DECREF(result);
312
313 if (unlikely(result != Py_None)) {
314 Py_DECREF(obj);
315
316 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
317 return NULL;
318 }
319 } else {
320
321 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
322 Py_DECREF(obj);
323 return NULL;
324 }
325 }
326 }
327 }
328
329 CHECK_OBJECT_X(obj);
330
331 return obj;
332 }
333#endif
334#if PYTHON_VERSION < 0x300
335 } else if (PyClass_Check(called)) {
336 PyObject *obj = PyInstance_NewRaw(called, NULL);
337
338 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
339
340 if ((init_method == NULL)) {
341 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
342 Py_DECREF(obj);
343 return NULL;
344 }
345
346 return obj;
347 }
348
349 bool is_compiled_function = false;
350
351 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
352
353 if (descr_get == NULL) {
354 Py_INCREF(init_method);
355 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
356 is_compiled_function = true;
357 } else if (descr_get != NULL) {
358 PyObject *descr_method = descr_get(init_method, obj, called);
359
360 if (unlikely(descr_method == NULL)) {
361 return NULL;
362 }
363
364 init_method = descr_method;
365 }
366
367 PyObject *result;
368 if (is_compiled_function) {
369 result = Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj);
370 } else {
371 result = CALL_FUNCTION_NO_ARGS(tstate, init_method);
372 Py_DECREF(init_method);
373 }
374 if (unlikely(result == NULL)) {
375 return NULL;
376 }
377
378 Py_DECREF(result);
379
380 if (unlikely(result != Py_None)) {
381 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
382 return NULL;
383 }
384
385 CHECK_OBJECT_X(obj);
386
387 return obj;
388#endif
389#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
390 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
391 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
392
393 if (likely(func != NULL)) {
394 PyObject *result = func(called, NULL, 0, NULL);
395
396 CHECK_OBJECT_X(result);
397
398 return Nuitka_CheckFunctionResult(tstate, called, result);
399 }
400#endif
401 }
402
403#if 0
404 PRINT_NEW_LINE();
405 PRINT_STRING("FALLBACK");
406 PRINT_ITEM(called);
407 PRINT_NEW_LINE();
408#endif
409
410 PyObject *result = CALL_FUNCTION(tstate, called, const_tuple_empty, NULL);
411
412 CHECK_OBJECT_X(result);
413
414 return result;
415}
416PyObject *CALL_FUNCTION_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg) {
417 PyObject *const *args = &arg; // For easier code compatibility.
418 CHECK_OBJECT(called);
419 CHECK_OBJECTS(args, 1);
420
421 if (Nuitka_Function_Check(called)) {
422 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
423 return NULL;
424 }
425
426 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
427 PyObject *result;
428
429 if (function->m_args_simple && 1 == function->m_args_positional_count) {
430 Py_INCREF(args[0]);
431 result = function->m_c_code(tstate, function, (PyObject **)args);
432 } else if (function->m_args_simple && 1 + function->m_defaults_given == function->m_args_positional_count) {
433 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
434
435 memcpy(python_pars, args, 1 * sizeof(PyObject *));
436 memcpy(python_pars + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
437 function->m_defaults_given * sizeof(PyObject *));
438
439 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
440 Py_INCREF(python_pars[i]);
441 }
442
443 result = function->m_c_code(tstate, function, python_pars);
444 } else {
445 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 1);
446 }
447
448 Py_LeaveRecursiveCall();
449
450 CHECK_OBJECT_X(result);
451
452 return result;
453 } else if (Nuitka_Method_Check(called)) {
454 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
455
456 if (method->m_object == NULL) {
457 PyObject *self = args[0];
458
459 int res = PyObject_IsInstance(self, method->m_class);
460
461 if (unlikely(res < 0)) {
462 return NULL;
463 } else if (unlikely(res == 0)) {
464 PyErr_Format(PyExc_TypeError,
465 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
466 "instance instead)",
467 GET_CALLABLE_NAME((PyObject *)method->m_function),
468 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
469 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
470
471 return NULL;
472 }
473
474 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 1);
475
476 CHECK_OBJECT_X(result);
477
478 return result;
479 } else {
480 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
481 return NULL;
482 }
483
484 struct Nuitka_FunctionObject *function = method->m_function;
485
486 PyObject *result;
487
488 if (function->m_args_simple && 1 + 1 == function->m_args_positional_count) {
489 PyObject *python_pars[1 + 1];
490
491 python_pars[0] = method->m_object;
492 Py_INCREF(method->m_object);
493
494 python_pars[1] = args[0];
495 Py_INCREF(args[0]);
496 result = function->m_c_code(tstate, function, python_pars);
497 } else if (function->m_args_simple &&
498 1 + 1 + function->m_defaults_given == function->m_args_positional_count) {
499 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
500
501 python_pars[0] = method->m_object;
502 Py_INCREF(method->m_object);
503
504 memcpy(python_pars + 1, args, 1 * sizeof(PyObject *));
505 memcpy(python_pars + 1 + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
506 function->m_defaults_given * sizeof(PyObject *));
507
508 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
509 Py_INCREF(python_pars[i]);
510 }
511
512 result = function->m_c_code(tstate, function, python_pars);
513 } else {
514 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 1);
515 }
516
517 Py_LeaveRecursiveCall();
518
519 CHECK_OBJECT_X(result);
520
521 return result;
522 }
523#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
524 } else if (PyCFunction_CheckExact(called)) {
525#if PYTHON_VERSION >= 0x380
526#ifdef _NUITKA_FULL_COMPAT
527 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
528 return NULL;
529 }
530#endif
531
532 int flags = PyCFunction_GET_FLAGS(called);
533
534 PyObject *result;
535
536 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
537
538 if (func != NULL) {
539 result = func(called, args, 1, NULL);
540
541 CHECK_OBJECT_X(result);
542 } else {
543 PyCFunction method = PyCFunction_GET_FUNCTION(called);
544 PyObject *self = PyCFunction_GET_SELF(called);
545
546 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
547
548 if (flags & METH_KEYWORDS) {
549 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
550 } else {
551 result = (*method)(self, pos_args);
552 }
553
554 Py_DECREF(pos_args);
555 }
556
557#ifdef _NUITKA_FULL_COMPAT
558 Py_LeaveRecursiveCall();
559#endif
560 CHECK_OBJECT_X(result);
561
562 return Nuitka_CheckFunctionResult(tstate, called, result);
563#else
564 // Try to be fast about wrapping the arguments.
565 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
566
567 if (unlikely(flags & METH_NOARGS)) {
568 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (1 given)",
569 ((PyCFunctionObject *)called)->m_ml->ml_name);
570 return NULL;
571 } else if ((flags & METH_O)) {
572 // Recursion guard is not strictly necessary, as we already have
573 // one on our way to here.
574#ifdef _NUITKA_FULL_COMPAT
575 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
576 return NULL;
577 }
578#endif
579 PyCFunction method = PyCFunction_GET_FUNCTION(called);
580 PyObject *self = PyCFunction_GET_SELF(called);
581
582 PyObject *result = (*method)(self, args[0]);
583
584#ifdef _NUITKA_FULL_COMPAT
585 Py_LeaveRecursiveCall();
586#endif
587
588 CHECK_OBJECT_X(result);
589
590 return Nuitka_CheckFunctionResult(tstate, called, result);
591 } else if (flags & METH_VARARGS) {
592 // Recursion guard is not strictly necessary, as we already have
593 // one on our way to here.
594#ifdef _NUITKA_FULL_COMPAT
595 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
596 return NULL;
597 }
598#endif
599 PyCFunction method = PyCFunction_GET_FUNCTION(called);
600 PyObject *self = PyCFunction_GET_SELF(called);
601
602 PyObject *result;
603
604#if PYTHON_VERSION < 0x360
605 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
606 if (flags & METH_KEYWORDS) {
607 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
608 } else {
609 result = (*method)(self, pos_args);
610 }
611
612 Py_DECREF(pos_args);
613#else
614 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
615 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
616 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
617 Py_DECREF(pos_args);
618 } else if (flags == METH_FASTCALL) {
619#if PYTHON_VERSION < 0x370
620 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 1, NULL);
621#else
622 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
623 result = (*(_PyCFunctionFast)method)(self, &pos_args, 1);
624 Py_DECREF(pos_args);
625#endif
626 } else {
627 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
628 result = (*method)(self, pos_args);
629 Py_DECREF(pos_args);
630 }
631#endif
632
633#ifdef _NUITKA_FULL_COMPAT
634 Py_LeaveRecursiveCall();
635#endif
636
637 CHECK_OBJECT_X(result);
638
639 return Nuitka_CheckFunctionResult(tstate, called, result);
640 }
641#endif
642#endif
643#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
644 } else if (PyFunction_Check(called)) {
645#if PYTHON_VERSION < 0x3b0
646 PyObject *result = callPythonFunction(called, args, 1);
647#else
648 PyObject *result = _PyFunction_Vectorcall(called, args, 1, NULL);
649#endif
650 CHECK_OBJECT_X(result);
651
652 return result;
653#endif
654#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
655 } else if (PyType_Check(called)) {
656 PyTypeObject *type = Py_TYPE(called);
657
658 if (type->tp_call == PyType_Type.tp_call) {
659 PyTypeObject *called_type = (PyTypeObject *)(called);
660
661 if (unlikely(called == (PyObject *)&PyType_Type)) {
662 PyObject *result = (PyObject *)Py_TYPE(args[0]);
663 Py_INCREF(result);
664 return result;
665 }
666
667 if (unlikely(called_type->tp_new == NULL)) {
668 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
669 return NULL;
670 }
671
672 PyObject *pos_args = NULL;
673 PyObject *obj;
674
675 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
676 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
677 formatCannotInstantiateAbstractClass(tstate, called_type);
678 return NULL;
679 }
680
681 obj = called_type->tp_alloc(called_type, 0);
682 CHECK_OBJECT(obj);
683 } else {
684 pos_args = MAKE_TUPLE(tstate, args, 1);
685 obj = called_type->tp_new(called_type, pos_args, NULL);
686 }
687
688 if (likely(obj != NULL)) {
689 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
690 Py_DECREF(pos_args);
691 return obj;
692 }
693
694 // Work on produced type.
695 type = Py_TYPE(obj);
696
697 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
698 if (type->tp_init == default_tp_init_wrapper) {
699 Py_XDECREF(pos_args);
700 pos_args = NULL;
701
702 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
703
704 // Not really allowed, since we wouldn't have the default wrapper set.
705 assert(init_method != NULL);
706
707 bool is_compiled_function = false;
708 bool init_method_needs_release = false;
709
710 if (likely(init_method != NULL)) {
711 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
712
713 if (func == Nuitka_Function_Type.tp_descr_get) {
714 is_compiled_function = true;
715 } else if (func != NULL) {
716 init_method = func(init_method, obj, (PyObject *)(type));
717 init_method_needs_release = true;
718 }
719 }
720
721 if (unlikely(init_method == NULL)) {
722 if (!HAS_ERROR_OCCURRED(tstate)) {
723 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
724 const_str_plain___init__);
725 }
726
727 return NULL;
728 }
729
730 PyObject *result;
731 if (is_compiled_function) {
732 result = Nuitka_CallMethodFunctionPosArgs(
733 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 1);
734 } else {
735 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
736
737 if (init_method_needs_release) {
738 Py_DECREF(init_method);
739 }
740 }
741
742 if (unlikely(result == NULL)) {
743 Py_DECREF(obj);
744 return NULL;
745 }
746
747 Py_DECREF(result);
748
749 if (unlikely(result != Py_None)) {
750 Py_DECREF(obj);
751
752 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
753 return NULL;
754 }
755 } else {
756 if (pos_args == NULL) {
757 pos_args = MAKE_TUPLE(tstate, args, 1);
758 }
759
760 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
761 Py_DECREF(obj);
762 Py_XDECREF(pos_args);
763 return NULL;
764 }
765 }
766 }
767 }
768
769 Py_XDECREF(pos_args);
770
771 CHECK_OBJECT_X(obj);
772
773 return obj;
774 }
775#endif
776#if PYTHON_VERSION < 0x300
777 } else if (PyClass_Check(called)) {
778 PyObject *obj = PyInstance_NewRaw(called, NULL);
779
780 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
781
782 if (unlikely(init_method == NULL)) {
783 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
784 Py_DECREF(obj);
785 return NULL;
786 }
787
788 Py_DECREF(obj);
789
790 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
791 return NULL;
792 }
793
794 bool is_compiled_function = false;
795
796 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
797
798 if (descr_get == NULL) {
799 Py_INCREF(init_method);
800 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
801 is_compiled_function = true;
802 } else if (descr_get != NULL) {
803 PyObject *descr_method = descr_get(init_method, obj, called);
804
805 if (unlikely(descr_method == NULL)) {
806 return NULL;
807 }
808
809 init_method = descr_method;
810 }
811
812 PyObject *result;
813 if (is_compiled_function) {
814 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
815 args, 1);
816 } else {
817 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
818 Py_DECREF(init_method);
819 }
820 if (unlikely(result == NULL)) {
821 return NULL;
822 }
823
824 Py_DECREF(result);
825
826 if (unlikely(result != Py_None)) {
827 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
828 return NULL;
829 }
830
831 CHECK_OBJECT_X(obj);
832
833 return obj;
834#endif
835#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
836 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
837 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
838
839 if (likely(func != NULL)) {
840 PyObject *result = func(called, args, 1, NULL);
841
842 CHECK_OBJECT_X(result);
843
844 return Nuitka_CheckFunctionResult(tstate, called, result);
845 }
846#endif
847 }
848
849#if 0
850 PRINT_NEW_LINE();
851 PRINT_STRING("FALLBACK");
852 PRINT_ITEM(called);
853 PRINT_NEW_LINE();
854#endif
855
856 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
857
858 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
859
860 Py_DECREF(pos_args);
861
862 CHECK_OBJECT_X(result);
863
864 return result;
865}
866PyObject *CALL_FUNCTION_WITH_POS_ARGS1(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
867 assert(PyTuple_CheckExact(pos_args));
868 assert(PyTuple_GET_SIZE(pos_args) == 1);
869 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
870 CHECK_OBJECT(called);
871 CHECK_OBJECTS(args, 1);
872
873 if (Nuitka_Function_Check(called)) {
874 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
875 return NULL;
876 }
877
878 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
879 PyObject *result;
880
881 if (function->m_args_simple && 1 == function->m_args_positional_count) {
882 Py_INCREF(args[0]);
883 result = function->m_c_code(tstate, function, (PyObject **)args);
884 } else if (function->m_args_simple && 1 + function->m_defaults_given == function->m_args_positional_count) {
885 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
886
887 memcpy(python_pars, args, 1 * sizeof(PyObject *));
888 memcpy(python_pars + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
889 function->m_defaults_given * sizeof(PyObject *));
890
891 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
892 Py_INCREF(python_pars[i]);
893 }
894
895 result = function->m_c_code(tstate, function, python_pars);
896 } else {
897 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 1);
898 }
899
900 Py_LeaveRecursiveCall();
901
902 CHECK_OBJECT_X(result);
903
904 return result;
905 } else if (Nuitka_Method_Check(called)) {
906 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
907
908 if (method->m_object == NULL) {
909 PyObject *self = args[0];
910
911 int res = PyObject_IsInstance(self, method->m_class);
912
913 if (unlikely(res < 0)) {
914 return NULL;
915 } else if (unlikely(res == 0)) {
916 PyErr_Format(PyExc_TypeError,
917 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
918 "instance instead)",
919 GET_CALLABLE_NAME((PyObject *)method->m_function),
920 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
921 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
922
923 return NULL;
924 }
925
926 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 1);
927
928 CHECK_OBJECT_X(result);
929
930 return result;
931 } else {
932 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
933 return NULL;
934 }
935
936 struct Nuitka_FunctionObject *function = method->m_function;
937
938 PyObject *result;
939
940 if (function->m_args_simple && 1 + 1 == function->m_args_positional_count) {
941 PyObject *python_pars[1 + 1];
942
943 python_pars[0] = method->m_object;
944 Py_INCREF(method->m_object);
945
946 python_pars[1] = args[0];
947 Py_INCREF(args[0]);
948 result = function->m_c_code(tstate, function, python_pars);
949 } else if (function->m_args_simple &&
950 1 + 1 + function->m_defaults_given == function->m_args_positional_count) {
951 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
952
953 python_pars[0] = method->m_object;
954 Py_INCREF(method->m_object);
955
956 memcpy(python_pars + 1, args, 1 * sizeof(PyObject *));
957 memcpy(python_pars + 1 + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
958 function->m_defaults_given * sizeof(PyObject *));
959
960 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
961 Py_INCREF(python_pars[i]);
962 }
963
964 result = function->m_c_code(tstate, function, python_pars);
965 } else {
966 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 1);
967 }
968
969 Py_LeaveRecursiveCall();
970
971 CHECK_OBJECT_X(result);
972
973 return result;
974 }
975#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
976 } else if (PyCFunction_CheckExact(called)) {
977#if PYTHON_VERSION >= 0x380
978#ifdef _NUITKA_FULL_COMPAT
979 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
980 return NULL;
981 }
982#endif
983
984 int flags = PyCFunction_GET_FLAGS(called);
985
986 PyObject *result;
987
988 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
989
990 if (func != NULL) {
991 result = func(called, args, 1, NULL);
992
993 CHECK_OBJECT_X(result);
994 } else {
995 PyCFunction method = PyCFunction_GET_FUNCTION(called);
996 PyObject *self = PyCFunction_GET_SELF(called);
997
998 if (flags & METH_KEYWORDS) {
999 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1000 } else {
1001 result = (*method)(self, pos_args);
1002 }
1003 }
1004
1005#ifdef _NUITKA_FULL_COMPAT
1006 Py_LeaveRecursiveCall();
1007#endif
1008 CHECK_OBJECT_X(result);
1009
1010 return Nuitka_CheckFunctionResult(tstate, called, result);
1011#else
1012 // Try to be fast about wrapping the arguments.
1013 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1014
1015 if (unlikely(flags & METH_NOARGS)) {
1016 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (1 given)",
1017 ((PyCFunctionObject *)called)->m_ml->ml_name);
1018 return NULL;
1019 } else if ((flags & METH_O)) {
1020 // Recursion guard is not strictly necessary, as we already have
1021 // one on our way to here.
1022#ifdef _NUITKA_FULL_COMPAT
1023 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1024 return NULL;
1025 }
1026#endif
1027 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1028 PyObject *self = PyCFunction_GET_SELF(called);
1029
1030 PyObject *result = (*method)(self, args[0]);
1031
1032#ifdef _NUITKA_FULL_COMPAT
1033 Py_LeaveRecursiveCall();
1034#endif
1035
1036 CHECK_OBJECT_X(result);
1037
1038 return Nuitka_CheckFunctionResult(tstate, called, result);
1039 } else if (flags & METH_VARARGS) {
1040 // Recursion guard is not strictly necessary, as we already have
1041 // one on our way to here.
1042#ifdef _NUITKA_FULL_COMPAT
1043 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1044 return NULL;
1045 }
1046#endif
1047 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1048 PyObject *self = PyCFunction_GET_SELF(called);
1049
1050 PyObject *result;
1051
1052#if PYTHON_VERSION < 0x360
1053 if (flags & METH_KEYWORDS) {
1054 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1055 } else {
1056 result = (*method)(self, pos_args);
1057 }
1058
1059#else
1060 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1061 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1062 } else if (flags == METH_FASTCALL) {
1063#if PYTHON_VERSION < 0x370
1064 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 1, NULL);
1065#else
1066 result = (*(_PyCFunctionFast)method)(self, &pos_args, 1);
1067#endif
1068 } else {
1069 result = (*method)(self, pos_args);
1070 }
1071#endif
1072
1073#ifdef _NUITKA_FULL_COMPAT
1074 Py_LeaveRecursiveCall();
1075#endif
1076
1077 CHECK_OBJECT_X(result);
1078
1079 return Nuitka_CheckFunctionResult(tstate, called, result);
1080 }
1081#endif
1082#endif
1083#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1084 } else if (PyFunction_Check(called)) {
1085#if PYTHON_VERSION < 0x3b0
1086 PyObject *result = callPythonFunction(called, args, 1);
1087#else
1088 PyObject *result = _PyFunction_Vectorcall(called, args, 1, NULL);
1089#endif
1090 CHECK_OBJECT_X(result);
1091
1092 return result;
1093#endif
1094#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1095 } else if (PyType_Check(called)) {
1096 PyTypeObject *type = Py_TYPE(called);
1097
1098 if (type->tp_call == PyType_Type.tp_call) {
1099 PyTypeObject *called_type = (PyTypeObject *)(called);
1100
1101 if (unlikely(called == (PyObject *)&PyType_Type)) {
1102 PyObject *result = (PyObject *)Py_TYPE(args[0]);
1103 Py_INCREF(result);
1104 return result;
1105 }
1106
1107 if (unlikely(called_type->tp_new == NULL)) {
1108 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1109 return NULL;
1110 }
1111
1112 PyObject *obj;
1113
1114 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1115 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1116 formatCannotInstantiateAbstractClass(tstate, called_type);
1117 return NULL;
1118 }
1119
1120 obj = called_type->tp_alloc(called_type, 0);
1121 CHECK_OBJECT(obj);
1122 } else {
1123 obj = called_type->tp_new(called_type, pos_args, NULL);
1124 }
1125
1126 if (likely(obj != NULL)) {
1127 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1128 return obj;
1129 }
1130
1131 // Work on produced type.
1132 type = Py_TYPE(obj);
1133
1134 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1135 if (type->tp_init == default_tp_init_wrapper) {
1136
1137 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1138
1139 // Not really allowed, since we wouldn't have the default wrapper set.
1140 assert(init_method != NULL);
1141
1142 bool is_compiled_function = false;
1143 bool init_method_needs_release = false;
1144
1145 if (likely(init_method != NULL)) {
1146 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1147
1148 if (func == Nuitka_Function_Type.tp_descr_get) {
1149 is_compiled_function = true;
1150 } else if (func != NULL) {
1151 init_method = func(init_method, obj, (PyObject *)(type));
1152 init_method_needs_release = true;
1153 }
1154 }
1155
1156 if (unlikely(init_method == NULL)) {
1157 if (!HAS_ERROR_OCCURRED(tstate)) {
1158 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1159 const_str_plain___init__);
1160 }
1161
1162 return NULL;
1163 }
1164
1165 PyObject *result;
1166 if (is_compiled_function) {
1167 result = Nuitka_CallMethodFunctionPosArgs(
1168 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 1);
1169 } else {
1170 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
1171
1172 if (init_method_needs_release) {
1173 Py_DECREF(init_method);
1174 }
1175 }
1176
1177 if (unlikely(result == NULL)) {
1178 Py_DECREF(obj);
1179 return NULL;
1180 }
1181
1182 Py_DECREF(result);
1183
1184 if (unlikely(result != Py_None)) {
1185 Py_DECREF(obj);
1186
1187 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1188 return NULL;
1189 }
1190 } else {
1191
1192 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
1193 Py_DECREF(obj);
1194 return NULL;
1195 }
1196 }
1197 }
1198 }
1199
1200 CHECK_OBJECT_X(obj);
1201
1202 return obj;
1203 }
1204#endif
1205#if PYTHON_VERSION < 0x300
1206 } else if (PyClass_Check(called)) {
1207 PyObject *obj = PyInstance_NewRaw(called, NULL);
1208
1209 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
1210
1211 if (unlikely(init_method == NULL)) {
1212 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
1213 Py_DECREF(obj);
1214 return NULL;
1215 }
1216
1217 Py_DECREF(obj);
1218
1219 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
1220 return NULL;
1221 }
1222
1223 bool is_compiled_function = false;
1224
1225 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
1226
1227 if (descr_get == NULL) {
1228 Py_INCREF(init_method);
1229 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
1230 is_compiled_function = true;
1231 } else if (descr_get != NULL) {
1232 PyObject *descr_method = descr_get(init_method, obj, called);
1233
1234 if (unlikely(descr_method == NULL)) {
1235 return NULL;
1236 }
1237
1238 init_method = descr_method;
1239 }
1240
1241 PyObject *result;
1242 if (is_compiled_function) {
1243 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
1244 args, 1);
1245 } else {
1246 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
1247 Py_DECREF(init_method);
1248 }
1249 if (unlikely(result == NULL)) {
1250 return NULL;
1251 }
1252
1253 Py_DECREF(result);
1254
1255 if (unlikely(result != Py_None)) {
1256 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1257 return NULL;
1258 }
1259
1260 CHECK_OBJECT_X(obj);
1261
1262 return obj;
1263#endif
1264#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
1265 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
1266 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1267
1268 if (likely(func != NULL)) {
1269 PyObject *result = func(called, args, 1, NULL);
1270
1271 CHECK_OBJECT_X(result);
1272
1273 return Nuitka_CheckFunctionResult(tstate, called, result);
1274 }
1275#endif
1276 }
1277
1278#if 0
1279 PRINT_NEW_LINE();
1280 PRINT_STRING("FALLBACK");
1281 PRINT_ITEM(called);
1282 PRINT_NEW_LINE();
1283#endif
1284
1285 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
1286
1287 CHECK_OBJECT_X(result);
1288
1289 return result;
1290}
1291PyObject *CALL_FUNCTION_WITH_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
1292 CHECK_OBJECT(called);
1293 CHECK_OBJECTS(args, 2);
1294
1295 if (Nuitka_Function_Check(called)) {
1296 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1297 return NULL;
1298 }
1299
1300 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
1301 PyObject *result;
1302
1303 if (function->m_args_simple && 2 == function->m_args_positional_count) {
1304 for (Py_ssize_t i = 0; i < 2; i++) {
1305 Py_INCREF(args[i]);
1306 }
1307 result = function->m_c_code(tstate, function, (PyObject **)args);
1308 } else if (function->m_args_simple && 2 + function->m_defaults_given == function->m_args_positional_count) {
1309 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1310
1311 memcpy(python_pars, args, 2 * sizeof(PyObject *));
1312 memcpy(python_pars + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1313 function->m_defaults_given * sizeof(PyObject *));
1314
1315 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
1316 Py_INCREF(python_pars[i]);
1317 }
1318
1319 result = function->m_c_code(tstate, function, python_pars);
1320 } else {
1321 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 2);
1322 }
1323
1324 Py_LeaveRecursiveCall();
1325
1326 CHECK_OBJECT_X(result);
1327
1328 return result;
1329 } else if (Nuitka_Method_Check(called)) {
1330 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
1331
1332 if (method->m_object == NULL) {
1333 PyObject *self = args[0];
1334
1335 int res = PyObject_IsInstance(self, method->m_class);
1336
1337 if (unlikely(res < 0)) {
1338 return NULL;
1339 } else if (unlikely(res == 0)) {
1340 PyErr_Format(PyExc_TypeError,
1341 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
1342 "instance instead)",
1343 GET_CALLABLE_NAME((PyObject *)method->m_function),
1344 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
1345 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
1346
1347 return NULL;
1348 }
1349
1350 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 2);
1351
1352 CHECK_OBJECT_X(result);
1353
1354 return result;
1355 } else {
1356 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1357 return NULL;
1358 }
1359
1360 struct Nuitka_FunctionObject *function = method->m_function;
1361
1362 PyObject *result;
1363
1364 if (function->m_args_simple && 2 + 1 == function->m_args_positional_count) {
1365 PyObject *python_pars[2 + 1];
1366
1367 python_pars[0] = method->m_object;
1368 Py_INCREF(method->m_object);
1369
1370 for (Py_ssize_t i = 0; i < 2; i++) {
1371 python_pars[i + 1] = args[i];
1372 Py_INCREF(args[i]);
1373 }
1374 result = function->m_c_code(tstate, function, python_pars);
1375 } else if (function->m_args_simple &&
1376 2 + 1 + function->m_defaults_given == function->m_args_positional_count) {
1377 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1378
1379 python_pars[0] = method->m_object;
1380 Py_INCREF(method->m_object);
1381
1382 memcpy(python_pars + 1, args, 2 * sizeof(PyObject *));
1383 memcpy(python_pars + 1 + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1384 function->m_defaults_given * sizeof(PyObject *));
1385
1386 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
1387 Py_INCREF(python_pars[i]);
1388 }
1389
1390 result = function->m_c_code(tstate, function, python_pars);
1391 } else {
1392 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 2);
1393 }
1394
1395 Py_LeaveRecursiveCall();
1396
1397 CHECK_OBJECT_X(result);
1398
1399 return result;
1400 }
1401#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
1402 } else if (PyCFunction_CheckExact(called)) {
1403#if PYTHON_VERSION >= 0x380
1404#ifdef _NUITKA_FULL_COMPAT
1405 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1406 return NULL;
1407 }
1408#endif
1409
1410 int flags = PyCFunction_GET_FLAGS(called);
1411
1412 PyObject *result;
1413
1414 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1415
1416 if (func != NULL) {
1417 result = func(called, args, 2, NULL);
1418
1419 CHECK_OBJECT_X(result);
1420 } else {
1421 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1422 PyObject *self = PyCFunction_GET_SELF(called);
1423
1424 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1425
1426 if (flags & METH_KEYWORDS) {
1427 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1428 } else {
1429 result = (*method)(self, pos_args);
1430 }
1431
1432 Py_DECREF(pos_args);
1433 }
1434
1435#ifdef _NUITKA_FULL_COMPAT
1436 Py_LeaveRecursiveCall();
1437#endif
1438 CHECK_OBJECT_X(result);
1439
1440 return Nuitka_CheckFunctionResult(tstate, called, result);
1441#else
1442 // Try to be fast about wrapping the arguments.
1443 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1444
1445 if (unlikely(flags & METH_NOARGS)) {
1446 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (2 given)",
1447 ((PyCFunctionObject *)called)->m_ml->ml_name);
1448 return NULL;
1449 } else if (unlikely(flags & METH_O)) {
1450 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (2 given)",
1451 ((PyCFunctionObject *)called)->m_ml->ml_name);
1452 return NULL;
1453 } else if (flags & METH_VARARGS) {
1454 // Recursion guard is not strictly necessary, as we already have
1455 // one on our way to here.
1456#ifdef _NUITKA_FULL_COMPAT
1457 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1458 return NULL;
1459 }
1460#endif
1461 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1462 PyObject *self = PyCFunction_GET_SELF(called);
1463
1464 PyObject *result;
1465
1466#if PYTHON_VERSION < 0x360
1467 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1468 if (flags & METH_KEYWORDS) {
1469 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1470 } else {
1471 result = (*method)(self, pos_args);
1472 }
1473
1474 Py_DECREF(pos_args);
1475#else
1476 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1477 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1478 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1479 Py_DECREF(pos_args);
1480 } else if (flags == METH_FASTCALL) {
1481#if PYTHON_VERSION < 0x370
1482 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 2, NULL);
1483#else
1484 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1485 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
1486 Py_DECREF(pos_args);
1487#endif
1488 } else {
1489 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1490 result = (*method)(self, pos_args);
1491 Py_DECREF(pos_args);
1492 }
1493#endif
1494
1495#ifdef _NUITKA_FULL_COMPAT
1496 Py_LeaveRecursiveCall();
1497#endif
1498
1499 CHECK_OBJECT_X(result);
1500
1501 return Nuitka_CheckFunctionResult(tstate, called, result);
1502 }
1503#endif
1504#endif
1505#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1506 } else if (PyFunction_Check(called)) {
1507#if PYTHON_VERSION < 0x3b0
1508 PyObject *result = callPythonFunction(called, args, 2);
1509#else
1510 PyObject *result = _PyFunction_Vectorcall(called, args, 2, NULL);
1511#endif
1512 CHECK_OBJECT_X(result);
1513
1514 return result;
1515#endif
1516#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1517 } else if (PyType_Check(called)) {
1518 PyTypeObject *type = Py_TYPE(called);
1519
1520 if (type->tp_call == PyType_Type.tp_call) {
1521 PyTypeObject *called_type = (PyTypeObject *)(called);
1522
1523 if (unlikely(called_type->tp_new == NULL)) {
1524 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1525 return NULL;
1526 }
1527
1528 PyObject *pos_args = NULL;
1529 PyObject *obj;
1530
1531 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1532 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1533 formatCannotInstantiateAbstractClass(tstate, called_type);
1534 return NULL;
1535 }
1536
1537 obj = called_type->tp_alloc(called_type, 0);
1538 CHECK_OBJECT(obj);
1539 } else {
1540 pos_args = MAKE_TUPLE(tstate, args, 2);
1541 obj = called_type->tp_new(called_type, pos_args, NULL);
1542 }
1543
1544 if (likely(obj != NULL)) {
1545 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1546 Py_DECREF(pos_args);
1547 return obj;
1548 }
1549
1550 // Work on produced type.
1551 type = Py_TYPE(obj);
1552
1553 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1554 if (type->tp_init == default_tp_init_wrapper) {
1555 Py_XDECREF(pos_args);
1556 pos_args = NULL;
1557
1558 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1559
1560 // Not really allowed, since we wouldn't have the default wrapper set.
1561 assert(init_method != NULL);
1562
1563 bool is_compiled_function = false;
1564 bool init_method_needs_release = false;
1565
1566 if (likely(init_method != NULL)) {
1567 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1568
1569 if (func == Nuitka_Function_Type.tp_descr_get) {
1570 is_compiled_function = true;
1571 } else if (func != NULL) {
1572 init_method = func(init_method, obj, (PyObject *)(type));
1573 init_method_needs_release = true;
1574 }
1575 }
1576
1577 if (unlikely(init_method == NULL)) {
1578 if (!HAS_ERROR_OCCURRED(tstate)) {
1579 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1580 const_str_plain___init__);
1581 }
1582
1583 return NULL;
1584 }
1585
1586 PyObject *result;
1587 if (is_compiled_function) {
1588 result = Nuitka_CallMethodFunctionPosArgs(
1589 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 2);
1590 } else {
1591 result = CALL_FUNCTION_WITH_ARGS2(tstate, init_method, args);
1592 if (init_method_needs_release) {
1593 Py_DECREF(init_method);
1594 }
1595 }
1596
1597 if (unlikely(result == NULL)) {
1598 Py_DECREF(obj);
1599 return NULL;
1600 }
1601
1602 Py_DECREF(result);
1603
1604 if (unlikely(result != Py_None)) {
1605 Py_DECREF(obj);
1606
1607 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1608 return NULL;
1609 }
1610 } else {
1611 if (pos_args == NULL) {
1612 pos_args = MAKE_TUPLE(tstate, args, 2);
1613 }
1614
1615 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
1616 Py_DECREF(obj);
1617 Py_XDECREF(pos_args);
1618 return NULL;
1619 }
1620 }
1621 }
1622 }
1623
1624 Py_XDECREF(pos_args);
1625
1626 CHECK_OBJECT_X(obj);
1627
1628 return obj;
1629 }
1630#endif
1631#if PYTHON_VERSION < 0x300
1632 } else if (PyClass_Check(called)) {
1633 PyObject *obj = PyInstance_NewRaw(called, NULL);
1634
1635 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
1636
1637 if (unlikely(init_method == NULL)) {
1638 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
1639 Py_DECREF(obj);
1640 return NULL;
1641 }
1642
1643 Py_DECREF(obj);
1644
1645 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
1646 return NULL;
1647 }
1648
1649 bool is_compiled_function = false;
1650
1651 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
1652
1653 if (descr_get == NULL) {
1654 Py_INCREF(init_method);
1655 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
1656 is_compiled_function = true;
1657 } else if (descr_get != NULL) {
1658 PyObject *descr_method = descr_get(init_method, obj, called);
1659
1660 if (unlikely(descr_method == NULL)) {
1661 return NULL;
1662 }
1663
1664 init_method = descr_method;
1665 }
1666
1667 PyObject *result;
1668 if (is_compiled_function) {
1669 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
1670 args, 2);
1671 } else {
1672 result = CALL_FUNCTION_WITH_ARGS2(tstate, init_method, args);
1673 Py_DECREF(init_method);
1674 }
1675 if (unlikely(result == NULL)) {
1676 return NULL;
1677 }
1678
1679 Py_DECREF(result);
1680
1681 if (unlikely(result != Py_None)) {
1682 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1683 return NULL;
1684 }
1685
1686 CHECK_OBJECT_X(obj);
1687
1688 return obj;
1689#endif
1690#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
1691 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
1692 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1693
1694 if (likely(func != NULL)) {
1695 PyObject *result = func(called, args, 2, NULL);
1696
1697 CHECK_OBJECT_X(result);
1698
1699 return Nuitka_CheckFunctionResult(tstate, called, result);
1700 }
1701#endif
1702 }
1703
1704#if 0
1705 PRINT_NEW_LINE();
1706 PRINT_STRING("FALLBACK");
1707 PRINT_ITEM(called);
1708 PRINT_NEW_LINE();
1709#endif
1710
1711 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1712
1713 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
1714
1715 Py_DECREF(pos_args);
1716
1717 CHECK_OBJECT_X(result);
1718
1719 return result;
1720}
1721PyObject *CALL_FUNCTION_WITH_POS_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
1722 assert(PyTuple_CheckExact(pos_args));
1723 assert(PyTuple_GET_SIZE(pos_args) == 2);
1724 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
1725 CHECK_OBJECT(called);
1726 CHECK_OBJECTS(args, 2);
1727
1728 if (Nuitka_Function_Check(called)) {
1729 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1730 return NULL;
1731 }
1732
1733 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
1734 PyObject *result;
1735
1736 if (function->m_args_simple && 2 == function->m_args_positional_count) {
1737 for (Py_ssize_t i = 0; i < 2; i++) {
1738 Py_INCREF(args[i]);
1739 }
1740 result = function->m_c_code(tstate, function, (PyObject **)args);
1741 } else if (function->m_args_simple && 2 + function->m_defaults_given == function->m_args_positional_count) {
1742 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1743
1744 memcpy(python_pars, args, 2 * sizeof(PyObject *));
1745 memcpy(python_pars + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1746 function->m_defaults_given * sizeof(PyObject *));
1747
1748 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
1749 Py_INCREF(python_pars[i]);
1750 }
1751
1752 result = function->m_c_code(tstate, function, python_pars);
1753 } else {
1754 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 2);
1755 }
1756
1757 Py_LeaveRecursiveCall();
1758
1759 CHECK_OBJECT_X(result);
1760
1761 return result;
1762 } else if (Nuitka_Method_Check(called)) {
1763 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
1764
1765 if (method->m_object == NULL) {
1766 PyObject *self = args[0];
1767
1768 int res = PyObject_IsInstance(self, method->m_class);
1769
1770 if (unlikely(res < 0)) {
1771 return NULL;
1772 } else if (unlikely(res == 0)) {
1773 PyErr_Format(PyExc_TypeError,
1774 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
1775 "instance instead)",
1776 GET_CALLABLE_NAME((PyObject *)method->m_function),
1777 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
1778 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
1779
1780 return NULL;
1781 }
1782
1783 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 2);
1784
1785 CHECK_OBJECT_X(result);
1786
1787 return result;
1788 } else {
1789 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1790 return NULL;
1791 }
1792
1793 struct Nuitka_FunctionObject *function = method->m_function;
1794
1795 PyObject *result;
1796
1797 if (function->m_args_simple && 2 + 1 == function->m_args_positional_count) {
1798 PyObject *python_pars[2 + 1];
1799
1800 python_pars[0] = method->m_object;
1801 Py_INCREF(method->m_object);
1802
1803 for (Py_ssize_t i = 0; i < 2; i++) {
1804 python_pars[i + 1] = args[i];
1805 Py_INCREF(args[i]);
1806 }
1807 result = function->m_c_code(tstate, function, python_pars);
1808 } else if (function->m_args_simple &&
1809 2 + 1 + function->m_defaults_given == function->m_args_positional_count) {
1810 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1811
1812 python_pars[0] = method->m_object;
1813 Py_INCREF(method->m_object);
1814
1815 memcpy(python_pars + 1, args, 2 * sizeof(PyObject *));
1816 memcpy(python_pars + 1 + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1817 function->m_defaults_given * sizeof(PyObject *));
1818
1819 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
1820 Py_INCREF(python_pars[i]);
1821 }
1822
1823 result = function->m_c_code(tstate, function, python_pars);
1824 } else {
1825 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 2);
1826 }
1827
1828 Py_LeaveRecursiveCall();
1829
1830 CHECK_OBJECT_X(result);
1831
1832 return result;
1833 }
1834#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
1835 } else if (PyCFunction_CheckExact(called)) {
1836#if PYTHON_VERSION >= 0x380
1837#ifdef _NUITKA_FULL_COMPAT
1838 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1839 return NULL;
1840 }
1841#endif
1842
1843 int flags = PyCFunction_GET_FLAGS(called);
1844
1845 PyObject *result;
1846
1847 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1848
1849 if (func != NULL) {
1850 result = func(called, args, 2, NULL);
1851
1852 CHECK_OBJECT_X(result);
1853 } else {
1854 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1855 PyObject *self = PyCFunction_GET_SELF(called);
1856
1857 if (flags & METH_KEYWORDS) {
1858 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1859 } else {
1860 result = (*method)(self, pos_args);
1861 }
1862 }
1863
1864#ifdef _NUITKA_FULL_COMPAT
1865 Py_LeaveRecursiveCall();
1866#endif
1867 CHECK_OBJECT_X(result);
1868
1869 return Nuitka_CheckFunctionResult(tstate, called, result);
1870#else
1871 // Try to be fast about wrapping the arguments.
1872 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1873
1874 if (unlikely(flags & METH_NOARGS)) {
1875 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (2 given)",
1876 ((PyCFunctionObject *)called)->m_ml->ml_name);
1877 return NULL;
1878 } else if (unlikely(flags & METH_O)) {
1879 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (2 given)",
1880 ((PyCFunctionObject *)called)->m_ml->ml_name);
1881 return NULL;
1882 } else if (flags & METH_VARARGS) {
1883 // Recursion guard is not strictly necessary, as we already have
1884 // one on our way to here.
1885#ifdef _NUITKA_FULL_COMPAT
1886 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1887 return NULL;
1888 }
1889#endif
1890 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1891 PyObject *self = PyCFunction_GET_SELF(called);
1892
1893 PyObject *result;
1894
1895#if PYTHON_VERSION < 0x360
1896 if (flags & METH_KEYWORDS) {
1897 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1898 } else {
1899 result = (*method)(self, pos_args);
1900 }
1901
1902#else
1903 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1904 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1905 } else if (flags == METH_FASTCALL) {
1906#if PYTHON_VERSION < 0x370
1907 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 2, NULL);
1908#else
1909 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
1910#endif
1911 } else {
1912 result = (*method)(self, pos_args);
1913 }
1914#endif
1915
1916#ifdef _NUITKA_FULL_COMPAT
1917 Py_LeaveRecursiveCall();
1918#endif
1919
1920 CHECK_OBJECT_X(result);
1921
1922 return Nuitka_CheckFunctionResult(tstate, called, result);
1923 }
1924#endif
1925#endif
1926#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1927 } else if (PyFunction_Check(called)) {
1928#if PYTHON_VERSION < 0x3b0
1929 PyObject *result = callPythonFunction(called, args, 2);
1930#else
1931 PyObject *result = _PyFunction_Vectorcall(called, args, 2, NULL);
1932#endif
1933 CHECK_OBJECT_X(result);
1934
1935 return result;
1936#endif
1937#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1938 } else if (PyType_Check(called)) {
1939 PyTypeObject *type = Py_TYPE(called);
1940
1941 if (type->tp_call == PyType_Type.tp_call) {
1942 PyTypeObject *called_type = (PyTypeObject *)(called);
1943
1944 if (unlikely(called_type->tp_new == NULL)) {
1945 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1946 return NULL;
1947 }
1948
1949 PyObject *obj;
1950
1951 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1952 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1953 formatCannotInstantiateAbstractClass(tstate, called_type);
1954 return NULL;
1955 }
1956
1957 obj = called_type->tp_alloc(called_type, 0);
1958 CHECK_OBJECT(obj);
1959 } else {
1960 obj = called_type->tp_new(called_type, pos_args, NULL);
1961 }
1962
1963 if (likely(obj != NULL)) {
1964 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1965 return obj;
1966 }
1967
1968 // Work on produced type.
1969 type = Py_TYPE(obj);
1970
1971 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1972 if (type->tp_init == default_tp_init_wrapper) {
1973
1974 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1975
1976 // Not really allowed, since we wouldn't have the default wrapper set.
1977 assert(init_method != NULL);
1978
1979 bool is_compiled_function = false;
1980 bool init_method_needs_release = false;
1981
1982 if (likely(init_method != NULL)) {
1983 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1984
1985 if (func == Nuitka_Function_Type.tp_descr_get) {
1986 is_compiled_function = true;
1987 } else if (func != NULL) {
1988 init_method = func(init_method, obj, (PyObject *)(type));
1989 init_method_needs_release = true;
1990 }
1991 }
1992
1993 if (unlikely(init_method == NULL)) {
1994 if (!HAS_ERROR_OCCURRED(tstate)) {
1995 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1996 const_str_plain___init__);
1997 }
1998
1999 return NULL;
2000 }
2001
2002 PyObject *result;
2003 if (is_compiled_function) {
2004 result = Nuitka_CallMethodFunctionPosArgs(
2005 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 2);
2006 } else {
2007 result = CALL_FUNCTION_WITH_POS_ARGS2(tstate, init_method, pos_args);
2008 if (init_method_needs_release) {
2009 Py_DECREF(init_method);
2010 }
2011 }
2012
2013 if (unlikely(result == NULL)) {
2014 Py_DECREF(obj);
2015 return NULL;
2016 }
2017
2018 Py_DECREF(result);
2019
2020 if (unlikely(result != Py_None)) {
2021 Py_DECREF(obj);
2022
2023 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2024 return NULL;
2025 }
2026 } else {
2027
2028 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2029 Py_DECREF(obj);
2030 return NULL;
2031 }
2032 }
2033 }
2034 }
2035
2036 CHECK_OBJECT_X(obj);
2037
2038 return obj;
2039 }
2040#endif
2041#if PYTHON_VERSION < 0x300
2042 } else if (PyClass_Check(called)) {
2043 PyObject *obj = PyInstance_NewRaw(called, NULL);
2044
2045 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2046
2047 if (unlikely(init_method == NULL)) {
2048 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2049 Py_DECREF(obj);
2050 return NULL;
2051 }
2052
2053 Py_DECREF(obj);
2054
2055 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2056 return NULL;
2057 }
2058
2059 bool is_compiled_function = false;
2060
2061 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2062
2063 if (descr_get == NULL) {
2064 Py_INCREF(init_method);
2065 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2066 is_compiled_function = true;
2067 } else if (descr_get != NULL) {
2068 PyObject *descr_method = descr_get(init_method, obj, called);
2069
2070 if (unlikely(descr_method == NULL)) {
2071 return NULL;
2072 }
2073
2074 init_method = descr_method;
2075 }
2076
2077 PyObject *result;
2078 if (is_compiled_function) {
2079 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2080 args, 2);
2081 } else {
2082 result = CALL_FUNCTION_WITH_POS_ARGS2(tstate, init_method, pos_args);
2083 Py_DECREF(init_method);
2084 }
2085 if (unlikely(result == NULL)) {
2086 return NULL;
2087 }
2088
2089 Py_DECREF(result);
2090
2091 if (unlikely(result != Py_None)) {
2092 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2093 return NULL;
2094 }
2095
2096 CHECK_OBJECT_X(obj);
2097
2098 return obj;
2099#endif
2100#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2101 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2102 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2103
2104 if (likely(func != NULL)) {
2105 PyObject *result = func(called, args, 2, NULL);
2106
2107 CHECK_OBJECT_X(result);
2108
2109 return Nuitka_CheckFunctionResult(tstate, called, result);
2110 }
2111#endif
2112 }
2113
2114#if 0
2115 PRINT_NEW_LINE();
2116 PRINT_STRING("FALLBACK");
2117 PRINT_ITEM(called);
2118 PRINT_NEW_LINE();
2119#endif
2120
2121 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2122
2123 CHECK_OBJECT_X(result);
2124
2125 return result;
2126}
2127PyObject *CALL_FUNCTION_WITH_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
2128 CHECK_OBJECT(called);
2129 CHECK_OBJECTS(args, 3);
2130
2131 if (Nuitka_Function_Check(called)) {
2132 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2133 return NULL;
2134 }
2135
2136 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2137 PyObject *result;
2138
2139 if (function->m_args_simple && 3 == function->m_args_positional_count) {
2140 for (Py_ssize_t i = 0; i < 3; i++) {
2141 Py_INCREF(args[i]);
2142 }
2143 result = function->m_c_code(tstate, function, (PyObject **)args);
2144 } else if (function->m_args_simple && 3 + function->m_defaults_given == function->m_args_positional_count) {
2145 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2146
2147 memcpy(python_pars, args, 3 * sizeof(PyObject *));
2148 memcpy(python_pars + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2149 function->m_defaults_given * sizeof(PyObject *));
2150
2151 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2152 Py_INCREF(python_pars[i]);
2153 }
2154
2155 result = function->m_c_code(tstate, function, python_pars);
2156 } else {
2157 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 3);
2158 }
2159
2160 Py_LeaveRecursiveCall();
2161
2162 CHECK_OBJECT_X(result);
2163
2164 return result;
2165 } else if (Nuitka_Method_Check(called)) {
2166 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
2167
2168 if (method->m_object == NULL) {
2169 PyObject *self = args[0];
2170
2171 int res = PyObject_IsInstance(self, method->m_class);
2172
2173 if (unlikely(res < 0)) {
2174 return NULL;
2175 } else if (unlikely(res == 0)) {
2176 PyErr_Format(PyExc_TypeError,
2177 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
2178 "instance instead)",
2179 GET_CALLABLE_NAME((PyObject *)method->m_function),
2180 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
2181 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
2182
2183 return NULL;
2184 }
2185
2186 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 3);
2187
2188 CHECK_OBJECT_X(result);
2189
2190 return result;
2191 } else {
2192 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2193 return NULL;
2194 }
2195
2196 struct Nuitka_FunctionObject *function = method->m_function;
2197
2198 PyObject *result;
2199
2200 if (function->m_args_simple && 3 + 1 == function->m_args_positional_count) {
2201 PyObject *python_pars[3 + 1];
2202
2203 python_pars[0] = method->m_object;
2204 Py_INCREF(method->m_object);
2205
2206 for (Py_ssize_t i = 0; i < 3; i++) {
2207 python_pars[i + 1] = args[i];
2208 Py_INCREF(args[i]);
2209 }
2210 result = function->m_c_code(tstate, function, python_pars);
2211 } else if (function->m_args_simple &&
2212 3 + 1 + function->m_defaults_given == function->m_args_positional_count) {
2213 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2214
2215 python_pars[0] = method->m_object;
2216 Py_INCREF(method->m_object);
2217
2218 memcpy(python_pars + 1, args, 3 * sizeof(PyObject *));
2219 memcpy(python_pars + 1 + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2220 function->m_defaults_given * sizeof(PyObject *));
2221
2222 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
2223 Py_INCREF(python_pars[i]);
2224 }
2225
2226 result = function->m_c_code(tstate, function, python_pars);
2227 } else {
2228 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 3);
2229 }
2230
2231 Py_LeaveRecursiveCall();
2232
2233 CHECK_OBJECT_X(result);
2234
2235 return result;
2236 }
2237#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
2238 } else if (PyCFunction_CheckExact(called)) {
2239#if PYTHON_VERSION >= 0x380
2240#ifdef _NUITKA_FULL_COMPAT
2241 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2242 return NULL;
2243 }
2244#endif
2245
2246 int flags = PyCFunction_GET_FLAGS(called);
2247
2248 PyObject *result;
2249
2250 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2251
2252 if (func != NULL) {
2253 result = func(called, args, 3, NULL);
2254
2255 CHECK_OBJECT_X(result);
2256 } else {
2257 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2258 PyObject *self = PyCFunction_GET_SELF(called);
2259
2260 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2261
2262 if (flags & METH_KEYWORDS) {
2263 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
2264 } else {
2265 result = (*method)(self, pos_args);
2266 }
2267
2268 Py_DECREF(pos_args);
2269 }
2270
2271#ifdef _NUITKA_FULL_COMPAT
2272 Py_LeaveRecursiveCall();
2273#endif
2274 CHECK_OBJECT_X(result);
2275
2276 return Nuitka_CheckFunctionResult(tstate, called, result);
2277#else
2278 // Try to be fast about wrapping the arguments.
2279 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
2280
2281 if (unlikely(flags & METH_NOARGS)) {
2282 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (3 given)",
2283 ((PyCFunctionObject *)called)->m_ml->ml_name);
2284 return NULL;
2285 } else if (unlikely(flags & METH_O)) {
2286 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
2287 ((PyCFunctionObject *)called)->m_ml->ml_name);
2288 return NULL;
2289 } else if (flags & METH_VARARGS) {
2290 // Recursion guard is not strictly necessary, as we already have
2291 // one on our way to here.
2292#ifdef _NUITKA_FULL_COMPAT
2293 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2294 return NULL;
2295 }
2296#endif
2297 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2298 PyObject *self = PyCFunction_GET_SELF(called);
2299
2300 PyObject *result;
2301
2302#if PYTHON_VERSION < 0x360
2303 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2304 if (flags & METH_KEYWORDS) {
2305 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2306 } else {
2307 result = (*method)(self, pos_args);
2308 }
2309
2310 Py_DECREF(pos_args);
2311#else
2312 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
2313 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2314 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2315 Py_DECREF(pos_args);
2316 } else if (flags == METH_FASTCALL) {
2317#if PYTHON_VERSION < 0x370
2318 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 3, NULL);
2319#else
2320 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2321 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
2322 Py_DECREF(pos_args);
2323#endif
2324 } else {
2325 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2326 result = (*method)(self, pos_args);
2327 Py_DECREF(pos_args);
2328 }
2329#endif
2330
2331#ifdef _NUITKA_FULL_COMPAT
2332 Py_LeaveRecursiveCall();
2333#endif
2334
2335 CHECK_OBJECT_X(result);
2336
2337 return Nuitka_CheckFunctionResult(tstate, called, result);
2338 }
2339#endif
2340#endif
2341#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
2342 } else if (PyFunction_Check(called)) {
2343#if PYTHON_VERSION < 0x3b0
2344 PyObject *result = callPythonFunction(called, args, 3);
2345#else
2346 PyObject *result = _PyFunction_Vectorcall(called, args, 3, NULL);
2347#endif
2348 CHECK_OBJECT_X(result);
2349
2350 return result;
2351#endif
2352#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
2353 } else if (PyType_Check(called)) {
2354 PyTypeObject *type = Py_TYPE(called);
2355
2356 if (type->tp_call == PyType_Type.tp_call) {
2357 PyTypeObject *called_type = (PyTypeObject *)(called);
2358
2359 if (unlikely(called_type->tp_new == NULL)) {
2360 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
2361 return NULL;
2362 }
2363
2364 PyObject *pos_args = NULL;
2365 PyObject *obj;
2366
2367 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
2368 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
2369 formatCannotInstantiateAbstractClass(tstate, called_type);
2370 return NULL;
2371 }
2372
2373 obj = called_type->tp_alloc(called_type, 0);
2374 CHECK_OBJECT(obj);
2375 } else {
2376 pos_args = MAKE_TUPLE(tstate, args, 3);
2377 obj = called_type->tp_new(called_type, pos_args, NULL);
2378 }
2379
2380 if (likely(obj != NULL)) {
2381 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
2382 Py_DECREF(pos_args);
2383 return obj;
2384 }
2385
2386 // Work on produced type.
2387 type = Py_TYPE(obj);
2388
2389 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
2390 if (type->tp_init == default_tp_init_wrapper) {
2391 Py_XDECREF(pos_args);
2392 pos_args = NULL;
2393
2394 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
2395
2396 // Not really allowed, since we wouldn't have the default wrapper set.
2397 assert(init_method != NULL);
2398
2399 bool is_compiled_function = false;
2400 bool init_method_needs_release = false;
2401
2402 if (likely(init_method != NULL)) {
2403 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
2404
2405 if (func == Nuitka_Function_Type.tp_descr_get) {
2406 is_compiled_function = true;
2407 } else if (func != NULL) {
2408 init_method = func(init_method, obj, (PyObject *)(type));
2409 init_method_needs_release = true;
2410 }
2411 }
2412
2413 if (unlikely(init_method == NULL)) {
2414 if (!HAS_ERROR_OCCURRED(tstate)) {
2415 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2416 const_str_plain___init__);
2417 }
2418
2419 return NULL;
2420 }
2421
2422 PyObject *result;
2423 if (is_compiled_function) {
2424 result = Nuitka_CallMethodFunctionPosArgs(
2425 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 3);
2426 } else {
2427 result = CALL_FUNCTION_WITH_ARGS3(tstate, init_method, args);
2428 if (init_method_needs_release) {
2429 Py_DECREF(init_method);
2430 }
2431 }
2432
2433 if (unlikely(result == NULL)) {
2434 Py_DECREF(obj);
2435 return NULL;
2436 }
2437
2438 Py_DECREF(result);
2439
2440 if (unlikely(result != Py_None)) {
2441 Py_DECREF(obj);
2442
2443 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2444 return NULL;
2445 }
2446 } else {
2447 if (pos_args == NULL) {
2448 pos_args = MAKE_TUPLE(tstate, args, 3);
2449 }
2450
2451 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2452 Py_DECREF(obj);
2453 Py_XDECREF(pos_args);
2454 return NULL;
2455 }
2456 }
2457 }
2458 }
2459
2460 Py_XDECREF(pos_args);
2461
2462 CHECK_OBJECT_X(obj);
2463
2464 return obj;
2465 }
2466#endif
2467#if PYTHON_VERSION < 0x300
2468 } else if (PyClass_Check(called)) {
2469 PyObject *obj = PyInstance_NewRaw(called, NULL);
2470
2471 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2472
2473 if (unlikely(init_method == NULL)) {
2474 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2475 Py_DECREF(obj);
2476 return NULL;
2477 }
2478
2479 Py_DECREF(obj);
2480
2481 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2482 return NULL;
2483 }
2484
2485 bool is_compiled_function = false;
2486
2487 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2488
2489 if (descr_get == NULL) {
2490 Py_INCREF(init_method);
2491 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2492 is_compiled_function = true;
2493 } else if (descr_get != NULL) {
2494 PyObject *descr_method = descr_get(init_method, obj, called);
2495
2496 if (unlikely(descr_method == NULL)) {
2497 return NULL;
2498 }
2499
2500 init_method = descr_method;
2501 }
2502
2503 PyObject *result;
2504 if (is_compiled_function) {
2505 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2506 args, 3);
2507 } else {
2508 result = CALL_FUNCTION_WITH_ARGS3(tstate, init_method, args);
2509 Py_DECREF(init_method);
2510 }
2511 if (unlikely(result == NULL)) {
2512 return NULL;
2513 }
2514
2515 Py_DECREF(result);
2516
2517 if (unlikely(result != Py_None)) {
2518 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2519 return NULL;
2520 }
2521
2522 CHECK_OBJECT_X(obj);
2523
2524 return obj;
2525#endif
2526#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2527 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2528 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2529
2530 if (likely(func != NULL)) {
2531 PyObject *result = func(called, args, 3, NULL);
2532
2533 CHECK_OBJECT_X(result);
2534
2535 return Nuitka_CheckFunctionResult(tstate, called, result);
2536 }
2537#endif
2538 }
2539
2540#if 0
2541 PRINT_NEW_LINE();
2542 PRINT_STRING("FALLBACK");
2543 PRINT_ITEM(called);
2544 PRINT_NEW_LINE();
2545#endif
2546
2547 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2548
2549 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2550
2551 Py_DECREF(pos_args);
2552
2553 CHECK_OBJECT_X(result);
2554
2555 return result;
2556}
2557PyObject *CALL_FUNCTION_WITH_POS_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
2558 assert(PyTuple_CheckExact(pos_args));
2559 assert(PyTuple_GET_SIZE(pos_args) == 3);
2560 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
2561 CHECK_OBJECT(called);
2562 CHECK_OBJECTS(args, 3);
2563
2564 if (Nuitka_Function_Check(called)) {
2565 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2566 return NULL;
2567 }
2568
2569 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2570 PyObject *result;
2571
2572 if (function->m_args_simple && 3 == function->m_args_positional_count) {
2573 for (Py_ssize_t i = 0; i < 3; i++) {
2574 Py_INCREF(args[i]);
2575 }
2576 result = function->m_c_code(tstate, function, (PyObject **)args);
2577 } else if (function->m_args_simple && 3 + function->m_defaults_given == function->m_args_positional_count) {
2578 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2579
2580 memcpy(python_pars, args, 3 * sizeof(PyObject *));
2581 memcpy(python_pars + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2582 function->m_defaults_given * sizeof(PyObject *));
2583
2584 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2585 Py_INCREF(python_pars[i]);
2586 }
2587
2588 result = function->m_c_code(tstate, function, python_pars);
2589 } else {
2590 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 3);
2591 }
2592
2593 Py_LeaveRecursiveCall();
2594
2595 CHECK_OBJECT_X(result);
2596
2597 return result;
2598 } else if (Nuitka_Method_Check(called)) {
2599 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
2600
2601 if (method->m_object == NULL) {
2602 PyObject *self = args[0];
2603
2604 int res = PyObject_IsInstance(self, method->m_class);
2605
2606 if (unlikely(res < 0)) {
2607 return NULL;
2608 } else if (unlikely(res == 0)) {
2609 PyErr_Format(PyExc_TypeError,
2610 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
2611 "instance instead)",
2612 GET_CALLABLE_NAME((PyObject *)method->m_function),
2613 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
2614 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
2615
2616 return NULL;
2617 }
2618
2619 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 3);
2620
2621 CHECK_OBJECT_X(result);
2622
2623 return result;
2624 } else {
2625 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2626 return NULL;
2627 }
2628
2629 struct Nuitka_FunctionObject *function = method->m_function;
2630
2631 PyObject *result;
2632
2633 if (function->m_args_simple && 3 + 1 == function->m_args_positional_count) {
2634 PyObject *python_pars[3 + 1];
2635
2636 python_pars[0] = method->m_object;
2637 Py_INCREF(method->m_object);
2638
2639 for (Py_ssize_t i = 0; i < 3; i++) {
2640 python_pars[i + 1] = args[i];
2641 Py_INCREF(args[i]);
2642 }
2643 result = function->m_c_code(tstate, function, python_pars);
2644 } else if (function->m_args_simple &&
2645 3 + 1 + function->m_defaults_given == function->m_args_positional_count) {
2646 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2647
2648 python_pars[0] = method->m_object;
2649 Py_INCREF(method->m_object);
2650
2651 memcpy(python_pars + 1, args, 3 * sizeof(PyObject *));
2652 memcpy(python_pars + 1 + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2653 function->m_defaults_given * sizeof(PyObject *));
2654
2655 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
2656 Py_INCREF(python_pars[i]);
2657 }
2658
2659 result = function->m_c_code(tstate, function, python_pars);
2660 } else {
2661 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 3);
2662 }
2663
2664 Py_LeaveRecursiveCall();
2665
2666 CHECK_OBJECT_X(result);
2667
2668 return result;
2669 }
2670#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
2671 } else if (PyCFunction_CheckExact(called)) {
2672#if PYTHON_VERSION >= 0x380
2673#ifdef _NUITKA_FULL_COMPAT
2674 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2675 return NULL;
2676 }
2677#endif
2678
2679 int flags = PyCFunction_GET_FLAGS(called);
2680
2681 PyObject *result;
2682
2683 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2684
2685 if (func != NULL) {
2686 result = func(called, args, 3, NULL);
2687
2688 CHECK_OBJECT_X(result);
2689 } else {
2690 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2691 PyObject *self = PyCFunction_GET_SELF(called);
2692
2693 if (flags & METH_KEYWORDS) {
2694 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
2695 } else {
2696 result = (*method)(self, pos_args);
2697 }
2698 }
2699
2700#ifdef _NUITKA_FULL_COMPAT
2701 Py_LeaveRecursiveCall();
2702#endif
2703 CHECK_OBJECT_X(result);
2704
2705 return Nuitka_CheckFunctionResult(tstate, called, result);
2706#else
2707 // Try to be fast about wrapping the arguments.
2708 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
2709
2710 if (unlikely(flags & METH_NOARGS)) {
2711 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (3 given)",
2712 ((PyCFunctionObject *)called)->m_ml->ml_name);
2713 return NULL;
2714 } else if (unlikely(flags & METH_O)) {
2715 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
2716 ((PyCFunctionObject *)called)->m_ml->ml_name);
2717 return NULL;
2718 } else if (flags & METH_VARARGS) {
2719 // Recursion guard is not strictly necessary, as we already have
2720 // one on our way to here.
2721#ifdef _NUITKA_FULL_COMPAT
2722 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2723 return NULL;
2724 }
2725#endif
2726 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2727 PyObject *self = PyCFunction_GET_SELF(called);
2728
2729 PyObject *result;
2730
2731#if PYTHON_VERSION < 0x360
2732 if (flags & METH_KEYWORDS) {
2733 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2734 } else {
2735 result = (*method)(self, pos_args);
2736 }
2737
2738#else
2739 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
2740 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2741 } else if (flags == METH_FASTCALL) {
2742#if PYTHON_VERSION < 0x370
2743 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 3, NULL);
2744#else
2745 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
2746#endif
2747 } else {
2748 result = (*method)(self, pos_args);
2749 }
2750#endif
2751
2752#ifdef _NUITKA_FULL_COMPAT
2753 Py_LeaveRecursiveCall();
2754#endif
2755
2756 CHECK_OBJECT_X(result);
2757
2758 return Nuitka_CheckFunctionResult(tstate, called, result);
2759 }
2760#endif
2761#endif
2762#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
2763 } else if (PyFunction_Check(called)) {
2764#if PYTHON_VERSION < 0x3b0
2765 PyObject *result = callPythonFunction(called, args, 3);
2766#else
2767 PyObject *result = _PyFunction_Vectorcall(called, args, 3, NULL);
2768#endif
2769 CHECK_OBJECT_X(result);
2770
2771 return result;
2772#endif
2773#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
2774 } else if (PyType_Check(called)) {
2775 PyTypeObject *type = Py_TYPE(called);
2776
2777 if (type->tp_call == PyType_Type.tp_call) {
2778 PyTypeObject *called_type = (PyTypeObject *)(called);
2779
2780 if (unlikely(called_type->tp_new == NULL)) {
2781 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
2782 return NULL;
2783 }
2784
2785 PyObject *obj;
2786
2787 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
2788 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
2789 formatCannotInstantiateAbstractClass(tstate, called_type);
2790 return NULL;
2791 }
2792
2793 obj = called_type->tp_alloc(called_type, 0);
2794 CHECK_OBJECT(obj);
2795 } else {
2796 obj = called_type->tp_new(called_type, pos_args, NULL);
2797 }
2798
2799 if (likely(obj != NULL)) {
2800 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
2801 return obj;
2802 }
2803
2804 // Work on produced type.
2805 type = Py_TYPE(obj);
2806
2807 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
2808 if (type->tp_init == default_tp_init_wrapper) {
2809
2810 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
2811
2812 // Not really allowed, since we wouldn't have the default wrapper set.
2813 assert(init_method != NULL);
2814
2815 bool is_compiled_function = false;
2816 bool init_method_needs_release = false;
2817
2818 if (likely(init_method != NULL)) {
2819 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
2820
2821 if (func == Nuitka_Function_Type.tp_descr_get) {
2822 is_compiled_function = true;
2823 } else if (func != NULL) {
2824 init_method = func(init_method, obj, (PyObject *)(type));
2825 init_method_needs_release = true;
2826 }
2827 }
2828
2829 if (unlikely(init_method == NULL)) {
2830 if (!HAS_ERROR_OCCURRED(tstate)) {
2831 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2832 const_str_plain___init__);
2833 }
2834
2835 return NULL;
2836 }
2837
2838 PyObject *result;
2839 if (is_compiled_function) {
2840 result = Nuitka_CallMethodFunctionPosArgs(
2841 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 3);
2842 } else {
2843 result = CALL_FUNCTION_WITH_POS_ARGS3(tstate, init_method, pos_args);
2844 if (init_method_needs_release) {
2845 Py_DECREF(init_method);
2846 }
2847 }
2848
2849 if (unlikely(result == NULL)) {
2850 Py_DECREF(obj);
2851 return NULL;
2852 }
2853
2854 Py_DECREF(result);
2855
2856 if (unlikely(result != Py_None)) {
2857 Py_DECREF(obj);
2858
2859 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2860 return NULL;
2861 }
2862 } else {
2863
2864 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2865 Py_DECREF(obj);
2866 return NULL;
2867 }
2868 }
2869 }
2870 }
2871
2872 CHECK_OBJECT_X(obj);
2873
2874 return obj;
2875 }
2876#endif
2877#if PYTHON_VERSION < 0x300
2878 } else if (PyClass_Check(called)) {
2879 PyObject *obj = PyInstance_NewRaw(called, NULL);
2880
2881 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2882
2883 if (unlikely(init_method == NULL)) {
2884 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2885 Py_DECREF(obj);
2886 return NULL;
2887 }
2888
2889 Py_DECREF(obj);
2890
2891 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2892 return NULL;
2893 }
2894
2895 bool is_compiled_function = false;
2896
2897 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2898
2899 if (descr_get == NULL) {
2900 Py_INCREF(init_method);
2901 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2902 is_compiled_function = true;
2903 } else if (descr_get != NULL) {
2904 PyObject *descr_method = descr_get(init_method, obj, called);
2905
2906 if (unlikely(descr_method == NULL)) {
2907 return NULL;
2908 }
2909
2910 init_method = descr_method;
2911 }
2912
2913 PyObject *result;
2914 if (is_compiled_function) {
2915 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2916 args, 3);
2917 } else {
2918 result = CALL_FUNCTION_WITH_POS_ARGS3(tstate, init_method, pos_args);
2919 Py_DECREF(init_method);
2920 }
2921 if (unlikely(result == NULL)) {
2922 return NULL;
2923 }
2924
2925 Py_DECREF(result);
2926
2927 if (unlikely(result != Py_None)) {
2928 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2929 return NULL;
2930 }
2931
2932 CHECK_OBJECT_X(obj);
2933
2934 return obj;
2935#endif
2936#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2937 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2938 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2939
2940 if (likely(func != NULL)) {
2941 PyObject *result = func(called, args, 3, NULL);
2942
2943 CHECK_OBJECT_X(result);
2944
2945 return Nuitka_CheckFunctionResult(tstate, called, result);
2946 }
2947#endif
2948 }
2949
2950#if 0
2951 PRINT_NEW_LINE();
2952 PRINT_STRING("FALLBACK");
2953 PRINT_ITEM(called);
2954 PRINT_NEW_LINE();
2955#endif
2956
2957 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2958
2959 CHECK_OBJECT_X(result);
2960
2961 return result;
2962}
2963PyObject *CALL_FUNCTION_WITH_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
2964 CHECK_OBJECT(called);
2965 CHECK_OBJECTS(args, 4);
2966
2967 if (Nuitka_Function_Check(called)) {
2968 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2969 return NULL;
2970 }
2971
2972 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2973 PyObject *result;
2974
2975 if (function->m_args_simple && 4 == function->m_args_positional_count) {
2976 for (Py_ssize_t i = 0; i < 4; i++) {
2977 Py_INCREF(args[i]);
2978 }
2979 result = function->m_c_code(tstate, function, (PyObject **)args);
2980 } else if (function->m_args_simple && 4 + function->m_defaults_given == function->m_args_positional_count) {
2981 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2982
2983 memcpy(python_pars, args, 4 * sizeof(PyObject *));
2984 memcpy(python_pars + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
2985 function->m_defaults_given * sizeof(PyObject *));
2986
2987 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2988 Py_INCREF(python_pars[i]);
2989 }
2990
2991 result = function->m_c_code(tstate, function, python_pars);
2992 } else {
2993 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 4);
2994 }
2995
2996 Py_LeaveRecursiveCall();
2997
2998 CHECK_OBJECT_X(result);
2999
3000 return result;
3001 } else if (Nuitka_Method_Check(called)) {
3002 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3003
3004 if (method->m_object == NULL) {
3005 PyObject *self = args[0];
3006
3007 int res = PyObject_IsInstance(self, method->m_class);
3008
3009 if (unlikely(res < 0)) {
3010 return NULL;
3011 } else if (unlikely(res == 0)) {
3012 PyErr_Format(PyExc_TypeError,
3013 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3014 "instance instead)",
3015 GET_CALLABLE_NAME((PyObject *)method->m_function),
3016 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3017 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3018
3019 return NULL;
3020 }
3021
3022 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 4);
3023
3024 CHECK_OBJECT_X(result);
3025
3026 return result;
3027 } else {
3028 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3029 return NULL;
3030 }
3031
3032 struct Nuitka_FunctionObject *function = method->m_function;
3033
3034 PyObject *result;
3035
3036 if (function->m_args_simple && 4 + 1 == function->m_args_positional_count) {
3037 PyObject *python_pars[4 + 1];
3038
3039 python_pars[0] = method->m_object;
3040 Py_INCREF(method->m_object);
3041
3042 for (Py_ssize_t i = 0; i < 4; i++) {
3043 python_pars[i + 1] = args[i];
3044 Py_INCREF(args[i]);
3045 }
3046 result = function->m_c_code(tstate, function, python_pars);
3047 } else if (function->m_args_simple &&
3048 4 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3049 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3050
3051 python_pars[0] = method->m_object;
3052 Py_INCREF(method->m_object);
3053
3054 memcpy(python_pars + 1, args, 4 * sizeof(PyObject *));
3055 memcpy(python_pars + 1 + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3056 function->m_defaults_given * sizeof(PyObject *));
3057
3058 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3059 Py_INCREF(python_pars[i]);
3060 }
3061
3062 result = function->m_c_code(tstate, function, python_pars);
3063 } else {
3064 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 4);
3065 }
3066
3067 Py_LeaveRecursiveCall();
3068
3069 CHECK_OBJECT_X(result);
3070
3071 return result;
3072 }
3073#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3074 } else if (PyCFunction_CheckExact(called)) {
3075#if PYTHON_VERSION >= 0x380
3076#ifdef _NUITKA_FULL_COMPAT
3077 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3078 return NULL;
3079 }
3080#endif
3081
3082 int flags = PyCFunction_GET_FLAGS(called);
3083
3084 PyObject *result;
3085
3086 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3087
3088 if (func != NULL) {
3089 result = func(called, args, 4, NULL);
3090
3091 CHECK_OBJECT_X(result);
3092 } else {
3093 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3094 PyObject *self = PyCFunction_GET_SELF(called);
3095
3096 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3097
3098 if (flags & METH_KEYWORDS) {
3099 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3100 } else {
3101 result = (*method)(self, pos_args);
3102 }
3103
3104 Py_DECREF(pos_args);
3105 }
3106
3107#ifdef _NUITKA_FULL_COMPAT
3108 Py_LeaveRecursiveCall();
3109#endif
3110 CHECK_OBJECT_X(result);
3111
3112 return Nuitka_CheckFunctionResult(tstate, called, result);
3113#else
3114 // Try to be fast about wrapping the arguments.
3115 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3116
3117 if (unlikely(flags & METH_NOARGS)) {
3118 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (4 given)",
3119 ((PyCFunctionObject *)called)->m_ml->ml_name);
3120 return NULL;
3121 } else if (unlikely(flags & METH_O)) {
3122 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
3123 ((PyCFunctionObject *)called)->m_ml->ml_name);
3124 return NULL;
3125 } else if (flags & METH_VARARGS) {
3126 // Recursion guard is not strictly necessary, as we already have
3127 // one on our way to here.
3128#ifdef _NUITKA_FULL_COMPAT
3129 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3130 return NULL;
3131 }
3132#endif
3133 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3134 PyObject *self = PyCFunction_GET_SELF(called);
3135
3136 PyObject *result;
3137
3138#if PYTHON_VERSION < 0x360
3139 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3140 if (flags & METH_KEYWORDS) {
3141 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3142 } else {
3143 result = (*method)(self, pos_args);
3144 }
3145
3146 Py_DECREF(pos_args);
3147#else
3148 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3149 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3150 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3151 Py_DECREF(pos_args);
3152 } else if (flags == METH_FASTCALL) {
3153#if PYTHON_VERSION < 0x370
3154 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 4, NULL);
3155#else
3156 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3157 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
3158 Py_DECREF(pos_args);
3159#endif
3160 } else {
3161 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3162 result = (*method)(self, pos_args);
3163 Py_DECREF(pos_args);
3164 }
3165#endif
3166
3167#ifdef _NUITKA_FULL_COMPAT
3168 Py_LeaveRecursiveCall();
3169#endif
3170
3171 CHECK_OBJECT_X(result);
3172
3173 return Nuitka_CheckFunctionResult(tstate, called, result);
3174 }
3175#endif
3176#endif
3177#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
3178 } else if (PyFunction_Check(called)) {
3179#if PYTHON_VERSION < 0x3b0
3180 PyObject *result = callPythonFunction(called, args, 4);
3181#else
3182 PyObject *result = _PyFunction_Vectorcall(called, args, 4, NULL);
3183#endif
3184 CHECK_OBJECT_X(result);
3185
3186 return result;
3187#endif
3188#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
3189 } else if (PyType_Check(called)) {
3190 PyTypeObject *type = Py_TYPE(called);
3191
3192 if (type->tp_call == PyType_Type.tp_call) {
3193 PyTypeObject *called_type = (PyTypeObject *)(called);
3194
3195 if (unlikely(called_type->tp_new == NULL)) {
3196 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
3197 return NULL;
3198 }
3199
3200 PyObject *pos_args = NULL;
3201 PyObject *obj;
3202
3203 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
3204 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
3205 formatCannotInstantiateAbstractClass(tstate, called_type);
3206 return NULL;
3207 }
3208
3209 obj = called_type->tp_alloc(called_type, 0);
3210 CHECK_OBJECT(obj);
3211 } else {
3212 pos_args = MAKE_TUPLE(tstate, args, 4);
3213 obj = called_type->tp_new(called_type, pos_args, NULL);
3214 }
3215
3216 if (likely(obj != NULL)) {
3217 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
3218 Py_DECREF(pos_args);
3219 return obj;
3220 }
3221
3222 // Work on produced type.
3223 type = Py_TYPE(obj);
3224
3225 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
3226 if (type->tp_init == default_tp_init_wrapper) {
3227 Py_XDECREF(pos_args);
3228 pos_args = NULL;
3229
3230 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
3231
3232 // Not really allowed, since we wouldn't have the default wrapper set.
3233 assert(init_method != NULL);
3234
3235 bool is_compiled_function = false;
3236 bool init_method_needs_release = false;
3237
3238 if (likely(init_method != NULL)) {
3239 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
3240
3241 if (func == Nuitka_Function_Type.tp_descr_get) {
3242 is_compiled_function = true;
3243 } else if (func != NULL) {
3244 init_method = func(init_method, obj, (PyObject *)(type));
3245 init_method_needs_release = true;
3246 }
3247 }
3248
3249 if (unlikely(init_method == NULL)) {
3250 if (!HAS_ERROR_OCCURRED(tstate)) {
3251 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
3252 const_str_plain___init__);
3253 }
3254
3255 return NULL;
3256 }
3257
3258 PyObject *result;
3259 if (is_compiled_function) {
3260 result = Nuitka_CallMethodFunctionPosArgs(
3261 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 4);
3262 } else {
3263 result = CALL_FUNCTION_WITH_ARGS4(tstate, init_method, args);
3264 if (init_method_needs_release) {
3265 Py_DECREF(init_method);
3266 }
3267 }
3268
3269 if (unlikely(result == NULL)) {
3270 Py_DECREF(obj);
3271 return NULL;
3272 }
3273
3274 Py_DECREF(result);
3275
3276 if (unlikely(result != Py_None)) {
3277 Py_DECREF(obj);
3278
3279 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3280 return NULL;
3281 }
3282 } else {
3283 if (pos_args == NULL) {
3284 pos_args = MAKE_TUPLE(tstate, args, 4);
3285 }
3286
3287 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
3288 Py_DECREF(obj);
3289 Py_XDECREF(pos_args);
3290 return NULL;
3291 }
3292 }
3293 }
3294 }
3295
3296 Py_XDECREF(pos_args);
3297
3298 CHECK_OBJECT_X(obj);
3299
3300 return obj;
3301 }
3302#endif
3303#if PYTHON_VERSION < 0x300
3304 } else if (PyClass_Check(called)) {
3305 PyObject *obj = PyInstance_NewRaw(called, NULL);
3306
3307 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
3308
3309 if (unlikely(init_method == NULL)) {
3310 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
3311 Py_DECREF(obj);
3312 return NULL;
3313 }
3314
3315 Py_DECREF(obj);
3316
3317 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
3318 return NULL;
3319 }
3320
3321 bool is_compiled_function = false;
3322
3323 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
3324
3325 if (descr_get == NULL) {
3326 Py_INCREF(init_method);
3327 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
3328 is_compiled_function = true;
3329 } else if (descr_get != NULL) {
3330 PyObject *descr_method = descr_get(init_method, obj, called);
3331
3332 if (unlikely(descr_method == NULL)) {
3333 return NULL;
3334 }
3335
3336 init_method = descr_method;
3337 }
3338
3339 PyObject *result;
3340 if (is_compiled_function) {
3341 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
3342 args, 4);
3343 } else {
3344 result = CALL_FUNCTION_WITH_ARGS4(tstate, init_method, args);
3345 Py_DECREF(init_method);
3346 }
3347 if (unlikely(result == NULL)) {
3348 return NULL;
3349 }
3350
3351 Py_DECREF(result);
3352
3353 if (unlikely(result != Py_None)) {
3354 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3355 return NULL;
3356 }
3357
3358 CHECK_OBJECT_X(obj);
3359
3360 return obj;
3361#endif
3362#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
3363 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
3364 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3365
3366 if (likely(func != NULL)) {
3367 PyObject *result = func(called, args, 4, NULL);
3368
3369 CHECK_OBJECT_X(result);
3370
3371 return Nuitka_CheckFunctionResult(tstate, called, result);
3372 }
3373#endif
3374 }
3375
3376#if 0
3377 PRINT_NEW_LINE();
3378 PRINT_STRING("FALLBACK");
3379 PRINT_ITEM(called);
3380 PRINT_NEW_LINE();
3381#endif
3382
3383 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3384
3385 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
3386
3387 Py_DECREF(pos_args);
3388
3389 CHECK_OBJECT_X(result);
3390
3391 return result;
3392}
3393PyObject *CALL_FUNCTION_WITH_POS_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
3394 assert(PyTuple_CheckExact(pos_args));
3395 assert(PyTuple_GET_SIZE(pos_args) == 4);
3396 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
3397 CHECK_OBJECT(called);
3398 CHECK_OBJECTS(args, 4);
3399
3400 if (Nuitka_Function_Check(called)) {
3401 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3402 return NULL;
3403 }
3404
3405 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
3406 PyObject *result;
3407
3408 if (function->m_args_simple && 4 == function->m_args_positional_count) {
3409 for (Py_ssize_t i = 0; i < 4; i++) {
3410 Py_INCREF(args[i]);
3411 }
3412 result = function->m_c_code(tstate, function, (PyObject **)args);
3413 } else if (function->m_args_simple && 4 + function->m_defaults_given == function->m_args_positional_count) {
3414 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3415
3416 memcpy(python_pars, args, 4 * sizeof(PyObject *));
3417 memcpy(python_pars + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3418 function->m_defaults_given * sizeof(PyObject *));
3419
3420 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
3421 Py_INCREF(python_pars[i]);
3422 }
3423
3424 result = function->m_c_code(tstate, function, python_pars);
3425 } else {
3426 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 4);
3427 }
3428
3429 Py_LeaveRecursiveCall();
3430
3431 CHECK_OBJECT_X(result);
3432
3433 return result;
3434 } else if (Nuitka_Method_Check(called)) {
3435 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3436
3437 if (method->m_object == NULL) {
3438 PyObject *self = args[0];
3439
3440 int res = PyObject_IsInstance(self, method->m_class);
3441
3442 if (unlikely(res < 0)) {
3443 return NULL;
3444 } else if (unlikely(res == 0)) {
3445 PyErr_Format(PyExc_TypeError,
3446 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3447 "instance instead)",
3448 GET_CALLABLE_NAME((PyObject *)method->m_function),
3449 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3450 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3451
3452 return NULL;
3453 }
3454
3455 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 4);
3456
3457 CHECK_OBJECT_X(result);
3458
3459 return result;
3460 } else {
3461 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3462 return NULL;
3463 }
3464
3465 struct Nuitka_FunctionObject *function = method->m_function;
3466
3467 PyObject *result;
3468
3469 if (function->m_args_simple && 4 + 1 == function->m_args_positional_count) {
3470 PyObject *python_pars[4 + 1];
3471
3472 python_pars[0] = method->m_object;
3473 Py_INCREF(method->m_object);
3474
3475 for (Py_ssize_t i = 0; i < 4; i++) {
3476 python_pars[i + 1] = args[i];
3477 Py_INCREF(args[i]);
3478 }
3479 result = function->m_c_code(tstate, function, python_pars);
3480 } else if (function->m_args_simple &&
3481 4 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3482 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3483
3484 python_pars[0] = method->m_object;
3485 Py_INCREF(method->m_object);
3486
3487 memcpy(python_pars + 1, args, 4 * sizeof(PyObject *));
3488 memcpy(python_pars + 1 + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3489 function->m_defaults_given * sizeof(PyObject *));
3490
3491 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3492 Py_INCREF(python_pars[i]);
3493 }
3494
3495 result = function->m_c_code(tstate, function, python_pars);
3496 } else {
3497 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 4);
3498 }
3499
3500 Py_LeaveRecursiveCall();
3501
3502 CHECK_OBJECT_X(result);
3503
3504 return result;
3505 }
3506#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3507 } else if (PyCFunction_CheckExact(called)) {
3508#if PYTHON_VERSION >= 0x380
3509#ifdef _NUITKA_FULL_COMPAT
3510 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3511 return NULL;
3512 }
3513#endif
3514
3515 int flags = PyCFunction_GET_FLAGS(called);
3516
3517 PyObject *result;
3518
3519 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3520
3521 if (func != NULL) {
3522 result = func(called, args, 4, NULL);
3523
3524 CHECK_OBJECT_X(result);
3525 } else {
3526 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3527 PyObject *self = PyCFunction_GET_SELF(called);
3528
3529 if (flags & METH_KEYWORDS) {
3530 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3531 } else {
3532 result = (*method)(self, pos_args);
3533 }
3534 }
3535
3536#ifdef _NUITKA_FULL_COMPAT
3537 Py_LeaveRecursiveCall();
3538#endif
3539 CHECK_OBJECT_X(result);
3540
3541 return Nuitka_CheckFunctionResult(tstate, called, result);
3542#else
3543 // Try to be fast about wrapping the arguments.
3544 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3545
3546 if (unlikely(flags & METH_NOARGS)) {
3547 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (4 given)",
3548 ((PyCFunctionObject *)called)->m_ml->ml_name);
3549 return NULL;
3550 } else if (unlikely(flags & METH_O)) {
3551 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
3552 ((PyCFunctionObject *)called)->m_ml->ml_name);
3553 return NULL;
3554 } else if (flags & METH_VARARGS) {
3555 // Recursion guard is not strictly necessary, as we already have
3556 // one on our way to here.
3557#ifdef _NUITKA_FULL_COMPAT
3558 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3559 return NULL;
3560 }
3561#endif
3562 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3563 PyObject *self = PyCFunction_GET_SELF(called);
3564
3565 PyObject *result;
3566
3567#if PYTHON_VERSION < 0x360
3568 if (flags & METH_KEYWORDS) {
3569 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3570 } else {
3571 result = (*method)(self, pos_args);
3572 }
3573
3574#else
3575 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3576 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3577 } else if (flags == METH_FASTCALL) {
3578#if PYTHON_VERSION < 0x370
3579 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 4, NULL);
3580#else
3581 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
3582#endif
3583 } else {
3584 result = (*method)(self, pos_args);
3585 }
3586#endif
3587
3588#ifdef _NUITKA_FULL_COMPAT
3589 Py_LeaveRecursiveCall();
3590#endif
3591
3592 CHECK_OBJECT_X(result);
3593
3594 return Nuitka_CheckFunctionResult(tstate, called, result);
3595 }
3596#endif
3597#endif
3598#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
3599 } else if (PyFunction_Check(called)) {
3600#if PYTHON_VERSION < 0x3b0
3601 PyObject *result = callPythonFunction(called, args, 4);
3602#else
3603 PyObject *result = _PyFunction_Vectorcall(called, args, 4, NULL);
3604#endif
3605 CHECK_OBJECT_X(result);
3606
3607 return result;
3608#endif
3609#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
3610 } else if (PyType_Check(called)) {
3611 PyTypeObject *type = Py_TYPE(called);
3612
3613 if (type->tp_call == PyType_Type.tp_call) {
3614 PyTypeObject *called_type = (PyTypeObject *)(called);
3615
3616 if (unlikely(called_type->tp_new == NULL)) {
3617 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
3618 return NULL;
3619 }
3620
3621 PyObject *obj;
3622
3623 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
3624 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
3625 formatCannotInstantiateAbstractClass(tstate, called_type);
3626 return NULL;
3627 }
3628
3629 obj = called_type->tp_alloc(called_type, 0);
3630 CHECK_OBJECT(obj);
3631 } else {
3632 obj = called_type->tp_new(called_type, pos_args, NULL);
3633 }
3634
3635 if (likely(obj != NULL)) {
3636 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
3637 return obj;
3638 }
3639
3640 // Work on produced type.
3641 type = Py_TYPE(obj);
3642
3643 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
3644 if (type->tp_init == default_tp_init_wrapper) {
3645
3646 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
3647
3648 // Not really allowed, since we wouldn't have the default wrapper set.
3649 assert(init_method != NULL);
3650
3651 bool is_compiled_function = false;
3652 bool init_method_needs_release = false;
3653
3654 if (likely(init_method != NULL)) {
3655 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
3656
3657 if (func == Nuitka_Function_Type.tp_descr_get) {
3658 is_compiled_function = true;
3659 } else if (func != NULL) {
3660 init_method = func(init_method, obj, (PyObject *)(type));
3661 init_method_needs_release = true;
3662 }
3663 }
3664
3665 if (unlikely(init_method == NULL)) {
3666 if (!HAS_ERROR_OCCURRED(tstate)) {
3667 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
3668 const_str_plain___init__);
3669 }
3670
3671 return NULL;
3672 }
3673
3674 PyObject *result;
3675 if (is_compiled_function) {
3676 result = Nuitka_CallMethodFunctionPosArgs(
3677 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 4);
3678 } else {
3679 result = CALL_FUNCTION_WITH_POS_ARGS4(tstate, init_method, pos_args);
3680 if (init_method_needs_release) {
3681 Py_DECREF(init_method);
3682 }
3683 }
3684
3685 if (unlikely(result == NULL)) {
3686 Py_DECREF(obj);
3687 return NULL;
3688 }
3689
3690 Py_DECREF(result);
3691
3692 if (unlikely(result != Py_None)) {
3693 Py_DECREF(obj);
3694
3695 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3696 return NULL;
3697 }
3698 } else {
3699
3700 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
3701 Py_DECREF(obj);
3702 return NULL;
3703 }
3704 }
3705 }
3706 }
3707
3708 CHECK_OBJECT_X(obj);
3709
3710 return obj;
3711 }
3712#endif
3713#if PYTHON_VERSION < 0x300
3714 } else if (PyClass_Check(called)) {
3715 PyObject *obj = PyInstance_NewRaw(called, NULL);
3716
3717 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
3718
3719 if (unlikely(init_method == NULL)) {
3720 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
3721 Py_DECREF(obj);
3722 return NULL;
3723 }
3724
3725 Py_DECREF(obj);
3726
3727 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
3728 return NULL;
3729 }
3730
3731 bool is_compiled_function = false;
3732
3733 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
3734
3735 if (descr_get == NULL) {
3736 Py_INCREF(init_method);
3737 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
3738 is_compiled_function = true;
3739 } else if (descr_get != NULL) {
3740 PyObject *descr_method = descr_get(init_method, obj, called);
3741
3742 if (unlikely(descr_method == NULL)) {
3743 return NULL;
3744 }
3745
3746 init_method = descr_method;
3747 }
3748
3749 PyObject *result;
3750 if (is_compiled_function) {
3751 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
3752 args, 4);
3753 } else {
3754 result = CALL_FUNCTION_WITH_POS_ARGS4(tstate, init_method, pos_args);
3755 Py_DECREF(init_method);
3756 }
3757 if (unlikely(result == NULL)) {
3758 return NULL;
3759 }
3760
3761 Py_DECREF(result);
3762
3763 if (unlikely(result != Py_None)) {
3764 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3765 return NULL;
3766 }
3767
3768 CHECK_OBJECT_X(obj);
3769
3770 return obj;
3771#endif
3772#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
3773 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
3774 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3775
3776 if (likely(func != NULL)) {
3777 PyObject *result = func(called, args, 4, NULL);
3778
3779 CHECK_OBJECT_X(result);
3780
3781 return Nuitka_CheckFunctionResult(tstate, called, result);
3782 }
3783#endif
3784 }
3785
3786#if 0
3787 PRINT_NEW_LINE();
3788 PRINT_STRING("FALLBACK");
3789 PRINT_ITEM(called);
3790 PRINT_NEW_LINE();
3791#endif
3792
3793 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
3794
3795 CHECK_OBJECT_X(result);
3796
3797 return result;
3798}
3799PyObject *CALL_FUNCTION_WITH_ARGS5(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
3800 CHECK_OBJECT(called);
3801 CHECK_OBJECTS(args, 5);
3802
3803 if (Nuitka_Function_Check(called)) {
3804 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3805 return NULL;
3806 }
3807
3808 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
3809 PyObject *result;
3810
3811 if (function->m_args_simple && 5 == function->m_args_positional_count) {
3812 for (Py_ssize_t i = 0; i < 5; i++) {
3813 Py_INCREF(args[i]);
3814 }
3815 result = function->m_c_code(tstate, function, (PyObject **)args);
3816 } else if (function->m_args_simple && 5 + function->m_defaults_given == function->m_args_positional_count) {
3817 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3818
3819 memcpy(python_pars, args, 5 * sizeof(PyObject *));
3820 memcpy(python_pars + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
3821 function->m_defaults_given * sizeof(PyObject *));
3822
3823 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
3824 Py_INCREF(python_pars[i]);
3825 }
3826
3827 result = function->m_c_code(tstate, function, python_pars);
3828 } else {
3829 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 5);
3830 }
3831
3832 Py_LeaveRecursiveCall();
3833
3834 CHECK_OBJECT_X(result);
3835
3836 return result;
3837 } else if (Nuitka_Method_Check(called)) {
3838 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3839
3840 if (method->m_object == NULL) {
3841 PyObject *self = args[0];
3842
3843 int res = PyObject_IsInstance(self, method->m_class);
3844
3845 if (unlikely(res < 0)) {
3846 return NULL;
3847 } else if (unlikely(res == 0)) {
3848 PyErr_Format(PyExc_TypeError,
3849 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3850 "instance instead)",
3851 GET_CALLABLE_NAME((PyObject *)method->m_function),
3852 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3853 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3854
3855 return NULL;
3856 }
3857
3858 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 5);
3859
3860 CHECK_OBJECT_X(result);
3861
3862 return result;
3863 } else {
3864 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3865 return NULL;
3866 }
3867
3868 struct Nuitka_FunctionObject *function = method->m_function;
3869
3870 PyObject *result;
3871
3872 if (function->m_args_simple && 5 + 1 == function->m_args_positional_count) {
3873 PyObject *python_pars[5 + 1];
3874
3875 python_pars[0] = method->m_object;
3876 Py_INCREF(method->m_object);
3877
3878 for (Py_ssize_t i = 0; i < 5; i++) {
3879 python_pars[i + 1] = args[i];
3880 Py_INCREF(args[i]);
3881 }
3882 result = function->m_c_code(tstate, function, python_pars);
3883 } else if (function->m_args_simple &&
3884 5 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3885 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3886
3887 python_pars[0] = method->m_object;
3888 Py_INCREF(method->m_object);
3889
3890 memcpy(python_pars + 1, args, 5 * sizeof(PyObject *));
3891 memcpy(python_pars + 1 + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
3892 function->m_defaults_given * sizeof(PyObject *));
3893
3894 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3895 Py_INCREF(python_pars[i]);
3896 }
3897
3898 result = function->m_c_code(tstate, function, python_pars);
3899 } else {
3900 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 5);
3901 }
3902
3903 Py_LeaveRecursiveCall();
3904
3905 CHECK_OBJECT_X(result);
3906
3907 return result;
3908 }
3909#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3910 } else if (PyCFunction_CheckExact(called)) {
3911#if PYTHON_VERSION >= 0x380
3912#ifdef _NUITKA_FULL_COMPAT
3913 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3914 return NULL;
3915 }
3916#endif
3917
3918 int flags = PyCFunction_GET_FLAGS(called);
3919
3920 PyObject *result;
3921
3922 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3923
3924 if (func != NULL) {
3925 result = func(called, args, 5, NULL);
3926
3927 CHECK_OBJECT_X(result);
3928 } else {
3929 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3930 PyObject *self = PyCFunction_GET_SELF(called);
3931
3932 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3933
3934 if (flags & METH_KEYWORDS) {
3935 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3936 } else {
3937 result = (*method)(self, pos_args);
3938 }
3939
3940 Py_DECREF(pos_args);
3941 }
3942
3943#ifdef _NUITKA_FULL_COMPAT
3944 Py_LeaveRecursiveCall();
3945#endif
3946 CHECK_OBJECT_X(result);
3947
3948 return Nuitka_CheckFunctionResult(tstate, called, result);
3949#else
3950 // Try to be fast about wrapping the arguments.
3951 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3952
3953 if (unlikely(flags & METH_NOARGS)) {
3954 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (5 given)",
3955 ((PyCFunctionObject *)called)->m_ml->ml_name);
3956 return NULL;
3957 } else if (unlikely(flags & METH_O)) {
3958 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (5 given)",
3959 ((PyCFunctionObject *)called)->m_ml->ml_name);
3960 return NULL;
3961 } else if (flags & METH_VARARGS) {
3962 // Recursion guard is not strictly necessary, as we already have
3963 // one on our way to here.
3964#ifdef _NUITKA_FULL_COMPAT
3965 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3966 return NULL;
3967 }
3968#endif
3969 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3970 PyObject *self = PyCFunction_GET_SELF(called);
3971
3972 PyObject *result;
3973
3974#if PYTHON_VERSION < 0x360
3975 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3976 if (flags & METH_KEYWORDS) {
3977 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3978 } else {
3979 result = (*method)(self, pos_args);
3980 }
3981
3982 Py_DECREF(pos_args);
3983#else
3984 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3985 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3986 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3987 Py_DECREF(pos_args);
3988 } else if (flags == METH_FASTCALL) {
3989#if PYTHON_VERSION < 0x370
3990 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 5, NULL);
3991#else
3992 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3993 result = (*(_PyCFunctionFast)method)(self, &pos_args, 5);
3994 Py_DECREF(pos_args);
3995#endif
3996 } else {
3997 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3998 result = (*method)(self, pos_args);
3999 Py_DECREF(pos_args);
4000 }
4001#endif
4002
4003#ifdef _NUITKA_FULL_COMPAT
4004 Py_LeaveRecursiveCall();
4005#endif
4006
4007 CHECK_OBJECT_X(result);
4008
4009 return Nuitka_CheckFunctionResult(tstate, called, result);
4010 }
4011#endif
4012#endif
4013#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4014 } else if (PyFunction_Check(called)) {
4015#if PYTHON_VERSION < 0x3b0
4016 PyObject *result = callPythonFunction(called, args, 5);
4017#else
4018 PyObject *result = _PyFunction_Vectorcall(called, args, 5, NULL);
4019#endif
4020 CHECK_OBJECT_X(result);
4021
4022 return result;
4023#endif
4024#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4025 } else if (PyType_Check(called)) {
4026 PyTypeObject *type = Py_TYPE(called);
4027
4028 if (type->tp_call == PyType_Type.tp_call) {
4029 PyTypeObject *called_type = (PyTypeObject *)(called);
4030
4031 if (unlikely(called_type->tp_new == NULL)) {
4032 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4033 return NULL;
4034 }
4035
4036 PyObject *pos_args = NULL;
4037 PyObject *obj;
4038
4039 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4040 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4041 formatCannotInstantiateAbstractClass(tstate, called_type);
4042 return NULL;
4043 }
4044
4045 obj = called_type->tp_alloc(called_type, 0);
4046 CHECK_OBJECT(obj);
4047 } else {
4048 pos_args = MAKE_TUPLE(tstate, args, 5);
4049 obj = called_type->tp_new(called_type, pos_args, NULL);
4050 }
4051
4052 if (likely(obj != NULL)) {
4053 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4054 Py_DECREF(pos_args);
4055 return obj;
4056 }
4057
4058 // Work on produced type.
4059 type = Py_TYPE(obj);
4060
4061 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4062 if (type->tp_init == default_tp_init_wrapper) {
4063 Py_XDECREF(pos_args);
4064 pos_args = NULL;
4065
4066 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4067
4068 // Not really allowed, since we wouldn't have the default wrapper set.
4069 assert(init_method != NULL);
4070
4071 bool is_compiled_function = false;
4072 bool init_method_needs_release = false;
4073
4074 if (likely(init_method != NULL)) {
4075 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4076
4077 if (func == Nuitka_Function_Type.tp_descr_get) {
4078 is_compiled_function = true;
4079 } else if (func != NULL) {
4080 init_method = func(init_method, obj, (PyObject *)(type));
4081 init_method_needs_release = true;
4082 }
4083 }
4084
4085 if (unlikely(init_method == NULL)) {
4086 if (!HAS_ERROR_OCCURRED(tstate)) {
4087 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4088 const_str_plain___init__);
4089 }
4090
4091 return NULL;
4092 }
4093
4094 PyObject *result;
4095 if (is_compiled_function) {
4096 result = Nuitka_CallMethodFunctionPosArgs(
4097 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 5);
4098 } else {
4099 result = CALL_FUNCTION_WITH_ARGS5(tstate, init_method, args);
4100 if (init_method_needs_release) {
4101 Py_DECREF(init_method);
4102 }
4103 }
4104
4105 if (unlikely(result == NULL)) {
4106 Py_DECREF(obj);
4107 return NULL;
4108 }
4109
4110 Py_DECREF(result);
4111
4112 if (unlikely(result != Py_None)) {
4113 Py_DECREF(obj);
4114
4115 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4116 return NULL;
4117 }
4118 } else {
4119 if (pos_args == NULL) {
4120 pos_args = MAKE_TUPLE(tstate, args, 5);
4121 }
4122
4123 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4124 Py_DECREF(obj);
4125 Py_XDECREF(pos_args);
4126 return NULL;
4127 }
4128 }
4129 }
4130 }
4131
4132 Py_XDECREF(pos_args);
4133
4134 CHECK_OBJECT_X(obj);
4135
4136 return obj;
4137 }
4138#endif
4139#if PYTHON_VERSION < 0x300
4140 } else if (PyClass_Check(called)) {
4141 PyObject *obj = PyInstance_NewRaw(called, NULL);
4142
4143 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4144
4145 if (unlikely(init_method == NULL)) {
4146 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4147 Py_DECREF(obj);
4148 return NULL;
4149 }
4150
4151 Py_DECREF(obj);
4152
4153 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4154 return NULL;
4155 }
4156
4157 bool is_compiled_function = false;
4158
4159 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4160
4161 if (descr_get == NULL) {
4162 Py_INCREF(init_method);
4163 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
4164 is_compiled_function = true;
4165 } else if (descr_get != NULL) {
4166 PyObject *descr_method = descr_get(init_method, obj, called);
4167
4168 if (unlikely(descr_method == NULL)) {
4169 return NULL;
4170 }
4171
4172 init_method = descr_method;
4173 }
4174
4175 PyObject *result;
4176 if (is_compiled_function) {
4177 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
4178 args, 5);
4179 } else {
4180 result = CALL_FUNCTION_WITH_ARGS5(tstate, init_method, args);
4181 Py_DECREF(init_method);
4182 }
4183 if (unlikely(result == NULL)) {
4184 return NULL;
4185 }
4186
4187 Py_DECREF(result);
4188
4189 if (unlikely(result != Py_None)) {
4190 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4191 return NULL;
4192 }
4193
4194 CHECK_OBJECT_X(obj);
4195
4196 return obj;
4197#endif
4198#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
4199 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
4200 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4201
4202 if (likely(func != NULL)) {
4203 PyObject *result = func(called, args, 5, NULL);
4204
4205 CHECK_OBJECT_X(result);
4206
4207 return Nuitka_CheckFunctionResult(tstate, called, result);
4208 }
4209#endif
4210 }
4211
4212#if 0
4213 PRINT_NEW_LINE();
4214 PRINT_STRING("FALLBACK");
4215 PRINT_ITEM(called);
4216 PRINT_NEW_LINE();
4217#endif
4218
4219 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4220
4221 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
4222
4223 Py_DECREF(pos_args);
4224
4225 CHECK_OBJECT_X(result);
4226
4227 return result;
4228}
4229PyObject *CALL_FUNCTION_WITH_POS_ARGS5(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
4230 assert(PyTuple_CheckExact(pos_args));
4231 assert(PyTuple_GET_SIZE(pos_args) == 5);
4232 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
4233 CHECK_OBJECT(called);
4234 CHECK_OBJECTS(args, 5);
4235
4236 if (Nuitka_Function_Check(called)) {
4237 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4238 return NULL;
4239 }
4240
4241 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
4242 PyObject *result;
4243
4244 if (function->m_args_simple && 5 == function->m_args_positional_count) {
4245 for (Py_ssize_t i = 0; i < 5; i++) {
4246 Py_INCREF(args[i]);
4247 }
4248 result = function->m_c_code(tstate, function, (PyObject **)args);
4249 } else if (function->m_args_simple && 5 + function->m_defaults_given == function->m_args_positional_count) {
4250 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4251
4252 memcpy(python_pars, args, 5 * sizeof(PyObject *));
4253 memcpy(python_pars + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
4254 function->m_defaults_given * sizeof(PyObject *));
4255
4256 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
4257 Py_INCREF(python_pars[i]);
4258 }
4259
4260 result = function->m_c_code(tstate, function, python_pars);
4261 } else {
4262 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 5);
4263 }
4264
4265 Py_LeaveRecursiveCall();
4266
4267 CHECK_OBJECT_X(result);
4268
4269 return result;
4270 } else if (Nuitka_Method_Check(called)) {
4271 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
4272
4273 if (method->m_object == NULL) {
4274 PyObject *self = args[0];
4275
4276 int res = PyObject_IsInstance(self, method->m_class);
4277
4278 if (unlikely(res < 0)) {
4279 return NULL;
4280 } else if (unlikely(res == 0)) {
4281 PyErr_Format(PyExc_TypeError,
4282 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
4283 "instance instead)",
4284 GET_CALLABLE_NAME((PyObject *)method->m_function),
4285 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
4286 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
4287
4288 return NULL;
4289 }
4290
4291 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 5);
4292
4293 CHECK_OBJECT_X(result);
4294
4295 return result;
4296 } else {
4297 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4298 return NULL;
4299 }
4300
4301 struct Nuitka_FunctionObject *function = method->m_function;
4302
4303 PyObject *result;
4304
4305 if (function->m_args_simple && 5 + 1 == function->m_args_positional_count) {
4306 PyObject *python_pars[5 + 1];
4307
4308 python_pars[0] = method->m_object;
4309 Py_INCREF(method->m_object);
4310
4311 for (Py_ssize_t i = 0; i < 5; i++) {
4312 python_pars[i + 1] = args[i];
4313 Py_INCREF(args[i]);
4314 }
4315 result = function->m_c_code(tstate, function, python_pars);
4316 } else if (function->m_args_simple &&
4317 5 + 1 + function->m_defaults_given == function->m_args_positional_count) {
4318 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4319
4320 python_pars[0] = method->m_object;
4321 Py_INCREF(method->m_object);
4322
4323 memcpy(python_pars + 1, args, 5 * sizeof(PyObject *));
4324 memcpy(python_pars + 1 + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
4325 function->m_defaults_given * sizeof(PyObject *));
4326
4327 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
4328 Py_INCREF(python_pars[i]);
4329 }
4330
4331 result = function->m_c_code(tstate, function, python_pars);
4332 } else {
4333 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 5);
4334 }
4335
4336 Py_LeaveRecursiveCall();
4337
4338 CHECK_OBJECT_X(result);
4339
4340 return result;
4341 }
4342#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
4343 } else if (PyCFunction_CheckExact(called)) {
4344#if PYTHON_VERSION >= 0x380
4345#ifdef _NUITKA_FULL_COMPAT
4346 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4347 return NULL;
4348 }
4349#endif
4350
4351 int flags = PyCFunction_GET_FLAGS(called);
4352
4353 PyObject *result;
4354
4355 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4356
4357 if (func != NULL) {
4358 result = func(called, args, 5, NULL);
4359
4360 CHECK_OBJECT_X(result);
4361 } else {
4362 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4363 PyObject *self = PyCFunction_GET_SELF(called);
4364
4365 if (flags & METH_KEYWORDS) {
4366 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
4367 } else {
4368 result = (*method)(self, pos_args);
4369 }
4370 }
4371
4372#ifdef _NUITKA_FULL_COMPAT
4373 Py_LeaveRecursiveCall();
4374#endif
4375 CHECK_OBJECT_X(result);
4376
4377 return Nuitka_CheckFunctionResult(tstate, called, result);
4378#else
4379 // Try to be fast about wrapping the arguments.
4380 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
4381
4382 if (unlikely(flags & METH_NOARGS)) {
4383 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (5 given)",
4384 ((PyCFunctionObject *)called)->m_ml->ml_name);
4385 return NULL;
4386 } else if (unlikely(flags & METH_O)) {
4387 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (5 given)",
4388 ((PyCFunctionObject *)called)->m_ml->ml_name);
4389 return NULL;
4390 } else if (flags & METH_VARARGS) {
4391 // Recursion guard is not strictly necessary, as we already have
4392 // one on our way to here.
4393#ifdef _NUITKA_FULL_COMPAT
4394 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4395 return NULL;
4396 }
4397#endif
4398 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4399 PyObject *self = PyCFunction_GET_SELF(called);
4400
4401 PyObject *result;
4402
4403#if PYTHON_VERSION < 0x360
4404 if (flags & METH_KEYWORDS) {
4405 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4406 } else {
4407 result = (*method)(self, pos_args);
4408 }
4409
4410#else
4411 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
4412 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4413 } else if (flags == METH_FASTCALL) {
4414#if PYTHON_VERSION < 0x370
4415 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 5, NULL);
4416#else
4417 result = (*(_PyCFunctionFast)method)(self, &pos_args, 5);
4418#endif
4419 } else {
4420 result = (*method)(self, pos_args);
4421 }
4422#endif
4423
4424#ifdef _NUITKA_FULL_COMPAT
4425 Py_LeaveRecursiveCall();
4426#endif
4427
4428 CHECK_OBJECT_X(result);
4429
4430 return Nuitka_CheckFunctionResult(tstate, called, result);
4431 }
4432#endif
4433#endif
4434#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4435 } else if (PyFunction_Check(called)) {
4436#if PYTHON_VERSION < 0x3b0
4437 PyObject *result = callPythonFunction(called, args, 5);
4438#else
4439 PyObject *result = _PyFunction_Vectorcall(called, args, 5, NULL);
4440#endif
4441 CHECK_OBJECT_X(result);
4442
4443 return result;
4444#endif
4445#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4446 } else if (PyType_Check(called)) {
4447 PyTypeObject *type = Py_TYPE(called);
4448
4449 if (type->tp_call == PyType_Type.tp_call) {
4450 PyTypeObject *called_type = (PyTypeObject *)(called);
4451
4452 if (unlikely(called_type->tp_new == NULL)) {
4453 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4454 return NULL;
4455 }
4456
4457 PyObject *obj;
4458
4459 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4460 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4461 formatCannotInstantiateAbstractClass(tstate, called_type);
4462 return NULL;
4463 }
4464
4465 obj = called_type->tp_alloc(called_type, 0);
4466 CHECK_OBJECT(obj);
4467 } else {
4468 obj = called_type->tp_new(called_type, pos_args, NULL);
4469 }
4470
4471 if (likely(obj != NULL)) {
4472 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4473 return obj;
4474 }
4475
4476 // Work on produced type.
4477 type = Py_TYPE(obj);
4478
4479 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4480 if (type->tp_init == default_tp_init_wrapper) {
4481
4482 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4483
4484 // Not really allowed, since we wouldn't have the default wrapper set.
4485 assert(init_method != NULL);
4486
4487 bool is_compiled_function = false;
4488 bool init_method_needs_release = false;
4489
4490 if (likely(init_method != NULL)) {
4491 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4492
4493 if (func == Nuitka_Function_Type.tp_descr_get) {
4494 is_compiled_function = true;
4495 } else if (func != NULL) {
4496 init_method = func(init_method, obj, (PyObject *)(type));
4497 init_method_needs_release = true;
4498 }
4499 }
4500
4501 if (unlikely(init_method == NULL)) {
4502 if (!HAS_ERROR_OCCURRED(tstate)) {
4503 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4504 const_str_plain___init__);
4505 }
4506
4507 return NULL;
4508 }
4509
4510 PyObject *result;
4511 if (is_compiled_function) {
4512 result = Nuitka_CallMethodFunctionPosArgs(
4513 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 5);
4514 } else {
4515 result = CALL_FUNCTION_WITH_POS_ARGS5(tstate, init_method, pos_args);
4516 if (init_method_needs_release) {
4517 Py_DECREF(init_method);
4518 }
4519 }
4520
4521 if (unlikely(result == NULL)) {
4522 Py_DECREF(obj);
4523 return NULL;
4524 }
4525
4526 Py_DECREF(result);
4527
4528 if (unlikely(result != Py_None)) {
4529 Py_DECREF(obj);
4530
4531 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4532 return NULL;
4533 }
4534 } else {
4535
4536 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4537 Py_DECREF(obj);
4538 return NULL;
4539 }
4540 }
4541 }
4542 }
4543
4544 CHECK_OBJECT_X(obj);
4545
4546 return obj;
4547 }
4548#endif
4549#if PYTHON_VERSION < 0x300
4550 } else if (PyClass_Check(called)) {
4551 PyObject *obj = PyInstance_NewRaw(called, NULL);
4552
4553 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4554
4555 if (unlikely(init_method == NULL)) {
4556 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4557 Py_DECREF(obj);
4558 return NULL;
4559 }
4560
4561 Py_DECREF(obj);
4562
4563 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4564 return NULL;
4565 }
4566
4567 bool is_compiled_function = false;
4568
4569 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4570
4571 if (descr_get == NULL) {
4572 Py_INCREF(init_method);
4573 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
4574 is_compiled_function = true;
4575 } else if (descr_get != NULL) {
4576 PyObject *descr_method = descr_get(init_method, obj, called);
4577
4578 if (unlikely(descr_method == NULL)) {
4579 return NULL;
4580 }
4581
4582 init_method = descr_method;
4583 }
4584
4585 PyObject *result;
4586 if (is_compiled_function) {
4587 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
4588 args, 5);
4589 } else {
4590 result = CALL_FUNCTION_WITH_POS_ARGS5(tstate, init_method, pos_args);
4591 Py_DECREF(init_method);
4592 }
4593 if (unlikely(result == NULL)) {
4594 return NULL;
4595 }
4596
4597 Py_DECREF(result);
4598
4599 if (unlikely(result != Py_None)) {
4600 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4601 return NULL;
4602 }
4603
4604 CHECK_OBJECT_X(obj);
4605
4606 return obj;
4607#endif
4608#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
4609 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
4610 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4611
4612 if (likely(func != NULL)) {
4613 PyObject *result = func(called, args, 5, NULL);
4614
4615 CHECK_OBJECT_X(result);
4616
4617 return Nuitka_CheckFunctionResult(tstate, called, result);
4618 }
4619#endif
4620 }
4621
4622#if 0
4623 PRINT_NEW_LINE();
4624 PRINT_STRING("FALLBACK");
4625 PRINT_ITEM(called);
4626 PRINT_NEW_LINE();
4627#endif
4628
4629 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
4630
4631 CHECK_OBJECT_X(result);
4632
4633 return result;
4634}
4635PyObject *CALL_FUNCTION_WITH_ARGS6(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
4636 CHECK_OBJECT(called);
4637 CHECK_OBJECTS(args, 6);
4638
4639 if (Nuitka_Function_Check(called)) {
4640 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4641 return NULL;
4642 }
4643
4644 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
4645 PyObject *result;
4646
4647 if (function->m_args_simple && 6 == function->m_args_positional_count) {
4648 for (Py_ssize_t i = 0; i < 6; i++) {
4649 Py_INCREF(args[i]);
4650 }
4651 result = function->m_c_code(tstate, function, (PyObject **)args);
4652 } else if (function->m_args_simple && 6 + function->m_defaults_given == function->m_args_positional_count) {
4653 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4654
4655 memcpy(python_pars, args, 6 * sizeof(PyObject *));
4656 memcpy(python_pars + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
4657 function->m_defaults_given * sizeof(PyObject *));
4658
4659 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
4660 Py_INCREF(python_pars[i]);
4661 }
4662
4663 result = function->m_c_code(tstate, function, python_pars);
4664 } else {
4665 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 6);
4666 }
4667
4668 Py_LeaveRecursiveCall();
4669
4670 CHECK_OBJECT_X(result);
4671
4672 return result;
4673 } else if (Nuitka_Method_Check(called)) {
4674 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
4675
4676 if (method->m_object == NULL) {
4677 PyObject *self = args[0];
4678
4679 int res = PyObject_IsInstance(self, method->m_class);
4680
4681 if (unlikely(res < 0)) {
4682 return NULL;
4683 } else if (unlikely(res == 0)) {
4684 PyErr_Format(PyExc_TypeError,
4685 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
4686 "instance instead)",
4687 GET_CALLABLE_NAME((PyObject *)method->m_function),
4688 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
4689 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
4690
4691 return NULL;
4692 }
4693
4694 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 6);
4695
4696 CHECK_OBJECT_X(result);
4697
4698 return result;
4699 } else {
4700 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4701 return NULL;
4702 }
4703
4704 struct Nuitka_FunctionObject *function = method->m_function;
4705
4706 PyObject *result;
4707
4708 if (function->m_args_simple && 6 + 1 == function->m_args_positional_count) {
4709 PyObject *python_pars[6 + 1];
4710
4711 python_pars[0] = method->m_object;
4712 Py_INCREF(method->m_object);
4713
4714 for (Py_ssize_t i = 0; i < 6; i++) {
4715 python_pars[i + 1] = args[i];
4716 Py_INCREF(args[i]);
4717 }
4718 result = function->m_c_code(tstate, function, python_pars);
4719 } else if (function->m_args_simple &&
4720 6 + 1 + function->m_defaults_given == function->m_args_positional_count) {
4721 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4722
4723 python_pars[0] = method->m_object;
4724 Py_INCREF(method->m_object);
4725
4726 memcpy(python_pars + 1, args, 6 * sizeof(PyObject *));
4727 memcpy(python_pars + 1 + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
4728 function->m_defaults_given * sizeof(PyObject *));
4729
4730 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
4731 Py_INCREF(python_pars[i]);
4732 }
4733
4734 result = function->m_c_code(tstate, function, python_pars);
4735 } else {
4736 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 6);
4737 }
4738
4739 Py_LeaveRecursiveCall();
4740
4741 CHECK_OBJECT_X(result);
4742
4743 return result;
4744 }
4745#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
4746 } else if (PyCFunction_CheckExact(called)) {
4747#if PYTHON_VERSION >= 0x380
4748#ifdef _NUITKA_FULL_COMPAT
4749 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4750 return NULL;
4751 }
4752#endif
4753
4754 int flags = PyCFunction_GET_FLAGS(called);
4755
4756 PyObject *result;
4757
4758 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4759
4760 if (func != NULL) {
4761 result = func(called, args, 6, NULL);
4762
4763 CHECK_OBJECT_X(result);
4764 } else {
4765 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4766 PyObject *self = PyCFunction_GET_SELF(called);
4767
4768 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4769
4770 if (flags & METH_KEYWORDS) {
4771 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
4772 } else {
4773 result = (*method)(self, pos_args);
4774 }
4775
4776 Py_DECREF(pos_args);
4777 }
4778
4779#ifdef _NUITKA_FULL_COMPAT
4780 Py_LeaveRecursiveCall();
4781#endif
4782 CHECK_OBJECT_X(result);
4783
4784 return Nuitka_CheckFunctionResult(tstate, called, result);
4785#else
4786 // Try to be fast about wrapping the arguments.
4787 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
4788
4789 if (unlikely(flags & METH_NOARGS)) {
4790 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (6 given)",
4791 ((PyCFunctionObject *)called)->m_ml->ml_name);
4792 return NULL;
4793 } else if (unlikely(flags & METH_O)) {
4794 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (6 given)",
4795 ((PyCFunctionObject *)called)->m_ml->ml_name);
4796 return NULL;
4797 } else if (flags & METH_VARARGS) {
4798 // Recursion guard is not strictly necessary, as we already have
4799 // one on our way to here.
4800#ifdef _NUITKA_FULL_COMPAT
4801 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4802 return NULL;
4803 }
4804#endif
4805 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4806 PyObject *self = PyCFunction_GET_SELF(called);
4807
4808 PyObject *result;
4809
4810#if PYTHON_VERSION < 0x360
4811 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4812 if (flags & METH_KEYWORDS) {
4813 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4814 } else {
4815 result = (*method)(self, pos_args);
4816 }
4817
4818 Py_DECREF(pos_args);
4819#else
4820 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
4821 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4822 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4823 Py_DECREF(pos_args);
4824 } else if (flags == METH_FASTCALL) {
4825#if PYTHON_VERSION < 0x370
4826 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 6, NULL);
4827#else
4828 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4829 result = (*(_PyCFunctionFast)method)(self, &pos_args, 6);
4830 Py_DECREF(pos_args);
4831#endif
4832 } else {
4833 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4834 result = (*method)(self, pos_args);
4835 Py_DECREF(pos_args);
4836 }
4837#endif
4838
4839#ifdef _NUITKA_FULL_COMPAT
4840 Py_LeaveRecursiveCall();
4841#endif
4842
4843 CHECK_OBJECT_X(result);
4844
4845 return Nuitka_CheckFunctionResult(tstate, called, result);
4846 }
4847#endif
4848#endif
4849#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4850 } else if (PyFunction_Check(called)) {
4851#if PYTHON_VERSION < 0x3b0
4852 PyObject *result = callPythonFunction(called, args, 6);
4853#else
4854 PyObject *result = _PyFunction_Vectorcall(called, args, 6, NULL);
4855#endif
4856 CHECK_OBJECT_X(result);
4857
4858 return result;
4859#endif
4860#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4861 } else if (PyType_Check(called)) {
4862 PyTypeObject *type = Py_TYPE(called);
4863
4864 if (type->tp_call == PyType_Type.tp_call) {
4865 PyTypeObject *called_type = (PyTypeObject *)(called);
4866
4867 if (unlikely(called_type->tp_new == NULL)) {
4868 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4869 return NULL;
4870 }
4871
4872 PyObject *pos_args = NULL;
4873 PyObject *obj;
4874
4875 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4876 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4877 formatCannotInstantiateAbstractClass(tstate, called_type);
4878 return NULL;
4879 }
4880
4881 obj = called_type->tp_alloc(called_type, 0);
4882 CHECK_OBJECT(obj);
4883 } else {
4884 pos_args = MAKE_TUPLE(tstate, args, 6);
4885 obj = called_type->tp_new(called_type, pos_args, NULL);
4886 }
4887
4888 if (likely(obj != NULL)) {
4889 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4890 Py_DECREF(pos_args);
4891 return obj;
4892 }
4893
4894 // Work on produced type.
4895 type = Py_TYPE(obj);
4896
4897 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4898 if (type->tp_init == default_tp_init_wrapper) {
4899 Py_XDECREF(pos_args);
4900 pos_args = NULL;
4901
4902 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4903
4904 // Not really allowed, since we wouldn't have the default wrapper set.
4905 assert(init_method != NULL);
4906
4907 bool is_compiled_function = false;
4908 bool init_method_needs_release = false;
4909
4910 if (likely(init_method != NULL)) {
4911 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4912
4913 if (func == Nuitka_Function_Type.tp_descr_get) {
4914 is_compiled_function = true;
4915 } else if (func != NULL) {
4916 init_method = func(init_method, obj, (PyObject *)(type));
4917 init_method_needs_release = true;
4918 }
4919 }
4920
4921 if (unlikely(init_method == NULL)) {
4922 if (!HAS_ERROR_OCCURRED(tstate)) {
4923 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4924 const_str_plain___init__);
4925 }
4926
4927 return NULL;
4928 }
4929
4930 PyObject *result;
4931 if (is_compiled_function) {
4932 result = Nuitka_CallMethodFunctionPosArgs(
4933 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 6);
4934 } else {
4935 result = CALL_FUNCTION_WITH_ARGS6(tstate, init_method, args);
4936 if (init_method_needs_release) {
4937 Py_DECREF(init_method);
4938 }
4939 }
4940
4941 if (unlikely(result == NULL)) {
4942 Py_DECREF(obj);
4943 return NULL;
4944 }
4945
4946 Py_DECREF(result);
4947
4948 if (unlikely(result != Py_None)) {
4949 Py_DECREF(obj);
4950
4951 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4952 return NULL;
4953 }
4954 } else {
4955 if (pos_args == NULL) {
4956 pos_args = MAKE_TUPLE(tstate, args, 6);
4957 }
4958
4959 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4960 Py_DECREF(obj);
4961 Py_XDECREF(pos_args);
4962 return NULL;
4963 }
4964 }
4965 }
4966 }
4967
4968 Py_XDECREF(pos_args);
4969
4970 CHECK_OBJECT_X(obj);
4971
4972 return obj;
4973 }
4974#endif
4975#if PYTHON_VERSION < 0x300
4976 } else if (PyClass_Check(called)) {
4977 PyObject *obj = PyInstance_NewRaw(called, NULL);
4978
4979 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4980
4981 if (unlikely(init_method == NULL)) {
4982 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4983 Py_DECREF(obj);
4984 return NULL;
4985 }
4986
4987 Py_DECREF(obj);
4988
4989 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4990 return NULL;
4991 }
4992
4993 bool is_compiled_function = false;
4994
4995 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4996
4997 if (descr_get == NULL) {
4998 Py_INCREF(init_method);
4999 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5000 is_compiled_function = true;
5001 } else if (descr_get != NULL) {
5002 PyObject *descr_method = descr_get(init_method, obj, called);
5003
5004 if (unlikely(descr_method == NULL)) {
5005 return NULL;
5006 }
5007
5008 init_method = descr_method;
5009 }
5010
5011 PyObject *result;
5012 if (is_compiled_function) {
5013 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5014 args, 6);
5015 } else {
5016 result = CALL_FUNCTION_WITH_ARGS6(tstate, init_method, args);
5017 Py_DECREF(init_method);
5018 }
5019 if (unlikely(result == NULL)) {
5020 return NULL;
5021 }
5022
5023 Py_DECREF(result);
5024
5025 if (unlikely(result != Py_None)) {
5026 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5027 return NULL;
5028 }
5029
5030 CHECK_OBJECT_X(obj);
5031
5032 return obj;
5033#endif
5034#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5035 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5036 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5037
5038 if (likely(func != NULL)) {
5039 PyObject *result = func(called, args, 6, NULL);
5040
5041 CHECK_OBJECT_X(result);
5042
5043 return Nuitka_CheckFunctionResult(tstate, called, result);
5044 }
5045#endif
5046 }
5047
5048#if 0
5049 PRINT_NEW_LINE();
5050 PRINT_STRING("FALLBACK");
5051 PRINT_ITEM(called);
5052 PRINT_NEW_LINE();
5053#endif
5054
5055 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
5056
5057 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5058
5059 Py_DECREF(pos_args);
5060
5061 CHECK_OBJECT_X(result);
5062
5063 return result;
5064}
5065PyObject *CALL_FUNCTION_WITH_POS_ARGS6(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
5066 assert(PyTuple_CheckExact(pos_args));
5067 assert(PyTuple_GET_SIZE(pos_args) == 6);
5068 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
5069 CHECK_OBJECT(called);
5070 CHECK_OBJECTS(args, 6);
5071
5072 if (Nuitka_Function_Check(called)) {
5073 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5074 return NULL;
5075 }
5076
5077 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5078 PyObject *result;
5079
5080 if (function->m_args_simple && 6 == function->m_args_positional_count) {
5081 for (Py_ssize_t i = 0; i < 6; i++) {
5082 Py_INCREF(args[i]);
5083 }
5084 result = function->m_c_code(tstate, function, (PyObject **)args);
5085 } else if (function->m_args_simple && 6 + function->m_defaults_given == function->m_args_positional_count) {
5086 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5087
5088 memcpy(python_pars, args, 6 * sizeof(PyObject *));
5089 memcpy(python_pars + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
5090 function->m_defaults_given * sizeof(PyObject *));
5091
5092 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5093 Py_INCREF(python_pars[i]);
5094 }
5095
5096 result = function->m_c_code(tstate, function, python_pars);
5097 } else {
5098 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 6);
5099 }
5100
5101 Py_LeaveRecursiveCall();
5102
5103 CHECK_OBJECT_X(result);
5104
5105 return result;
5106 } else if (Nuitka_Method_Check(called)) {
5107 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5108
5109 if (method->m_object == NULL) {
5110 PyObject *self = args[0];
5111
5112 int res = PyObject_IsInstance(self, method->m_class);
5113
5114 if (unlikely(res < 0)) {
5115 return NULL;
5116 } else if (unlikely(res == 0)) {
5117 PyErr_Format(PyExc_TypeError,
5118 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5119 "instance instead)",
5120 GET_CALLABLE_NAME((PyObject *)method->m_function),
5121 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5122 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5123
5124 return NULL;
5125 }
5126
5127 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 6);
5128
5129 CHECK_OBJECT_X(result);
5130
5131 return result;
5132 } else {
5133 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5134 return NULL;
5135 }
5136
5137 struct Nuitka_FunctionObject *function = method->m_function;
5138
5139 PyObject *result;
5140
5141 if (function->m_args_simple && 6 + 1 == function->m_args_positional_count) {
5142 PyObject *python_pars[6 + 1];
5143
5144 python_pars[0] = method->m_object;
5145 Py_INCREF(method->m_object);
5146
5147 for (Py_ssize_t i = 0; i < 6; i++) {
5148 python_pars[i + 1] = args[i];
5149 Py_INCREF(args[i]);
5150 }
5151 result = function->m_c_code(tstate, function, python_pars);
5152 } else if (function->m_args_simple &&
5153 6 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5154 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5155
5156 python_pars[0] = method->m_object;
5157 Py_INCREF(method->m_object);
5158
5159 memcpy(python_pars + 1, args, 6 * sizeof(PyObject *));
5160 memcpy(python_pars + 1 + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
5161 function->m_defaults_given * sizeof(PyObject *));
5162
5163 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
5164 Py_INCREF(python_pars[i]);
5165 }
5166
5167 result = function->m_c_code(tstate, function, python_pars);
5168 } else {
5169 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 6);
5170 }
5171
5172 Py_LeaveRecursiveCall();
5173
5174 CHECK_OBJECT_X(result);
5175
5176 return result;
5177 }
5178#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
5179 } else if (PyCFunction_CheckExact(called)) {
5180#if PYTHON_VERSION >= 0x380
5181#ifdef _NUITKA_FULL_COMPAT
5182 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5183 return NULL;
5184 }
5185#endif
5186
5187 int flags = PyCFunction_GET_FLAGS(called);
5188
5189 PyObject *result;
5190
5191 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5192
5193 if (func != NULL) {
5194 result = func(called, args, 6, NULL);
5195
5196 CHECK_OBJECT_X(result);
5197 } else {
5198 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5199 PyObject *self = PyCFunction_GET_SELF(called);
5200
5201 if (flags & METH_KEYWORDS) {
5202 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
5203 } else {
5204 result = (*method)(self, pos_args);
5205 }
5206 }
5207
5208#ifdef _NUITKA_FULL_COMPAT
5209 Py_LeaveRecursiveCall();
5210#endif
5211 CHECK_OBJECT_X(result);
5212
5213 return Nuitka_CheckFunctionResult(tstate, called, result);
5214#else
5215 // Try to be fast about wrapping the arguments.
5216 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
5217
5218 if (unlikely(flags & METH_NOARGS)) {
5219 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (6 given)",
5220 ((PyCFunctionObject *)called)->m_ml->ml_name);
5221 return NULL;
5222 } else if (unlikely(flags & METH_O)) {
5223 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (6 given)",
5224 ((PyCFunctionObject *)called)->m_ml->ml_name);
5225 return NULL;
5226 } else if (flags & METH_VARARGS) {
5227 // Recursion guard is not strictly necessary, as we already have
5228 // one on our way to here.
5229#ifdef _NUITKA_FULL_COMPAT
5230 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5231 return NULL;
5232 }
5233#endif
5234 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5235 PyObject *self = PyCFunction_GET_SELF(called);
5236
5237 PyObject *result;
5238
5239#if PYTHON_VERSION < 0x360
5240 if (flags & METH_KEYWORDS) {
5241 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5242 } else {
5243 result = (*method)(self, pos_args);
5244 }
5245
5246#else
5247 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
5248 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5249 } else if (flags == METH_FASTCALL) {
5250#if PYTHON_VERSION < 0x370
5251 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 6, NULL);
5252#else
5253 result = (*(_PyCFunctionFast)method)(self, &pos_args, 6);
5254#endif
5255 } else {
5256 result = (*method)(self, pos_args);
5257 }
5258#endif
5259
5260#ifdef _NUITKA_FULL_COMPAT
5261 Py_LeaveRecursiveCall();
5262#endif
5263
5264 CHECK_OBJECT_X(result);
5265
5266 return Nuitka_CheckFunctionResult(tstate, called, result);
5267 }
5268#endif
5269#endif
5270#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
5271 } else if (PyFunction_Check(called)) {
5272#if PYTHON_VERSION < 0x3b0
5273 PyObject *result = callPythonFunction(called, args, 6);
5274#else
5275 PyObject *result = _PyFunction_Vectorcall(called, args, 6, NULL);
5276#endif
5277 CHECK_OBJECT_X(result);
5278
5279 return result;
5280#endif
5281#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
5282 } else if (PyType_Check(called)) {
5283 PyTypeObject *type = Py_TYPE(called);
5284
5285 if (type->tp_call == PyType_Type.tp_call) {
5286 PyTypeObject *called_type = (PyTypeObject *)(called);
5287
5288 if (unlikely(called_type->tp_new == NULL)) {
5289 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
5290 return NULL;
5291 }
5292
5293 PyObject *obj;
5294
5295 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
5296 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
5297 formatCannotInstantiateAbstractClass(tstate, called_type);
5298 return NULL;
5299 }
5300
5301 obj = called_type->tp_alloc(called_type, 0);
5302 CHECK_OBJECT(obj);
5303 } else {
5304 obj = called_type->tp_new(called_type, pos_args, NULL);
5305 }
5306
5307 if (likely(obj != NULL)) {
5308 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
5309 return obj;
5310 }
5311
5312 // Work on produced type.
5313 type = Py_TYPE(obj);
5314
5315 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
5316 if (type->tp_init == default_tp_init_wrapper) {
5317
5318 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
5319
5320 // Not really allowed, since we wouldn't have the default wrapper set.
5321 assert(init_method != NULL);
5322
5323 bool is_compiled_function = false;
5324 bool init_method_needs_release = false;
5325
5326 if (likely(init_method != NULL)) {
5327 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
5328
5329 if (func == Nuitka_Function_Type.tp_descr_get) {
5330 is_compiled_function = true;
5331 } else if (func != NULL) {
5332 init_method = func(init_method, obj, (PyObject *)(type));
5333 init_method_needs_release = true;
5334 }
5335 }
5336
5337 if (unlikely(init_method == NULL)) {
5338 if (!HAS_ERROR_OCCURRED(tstate)) {
5339 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
5340 const_str_plain___init__);
5341 }
5342
5343 return NULL;
5344 }
5345
5346 PyObject *result;
5347 if (is_compiled_function) {
5348 result = Nuitka_CallMethodFunctionPosArgs(
5349 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 6);
5350 } else {
5351 result = CALL_FUNCTION_WITH_POS_ARGS6(tstate, init_method, pos_args);
5352 if (init_method_needs_release) {
5353 Py_DECREF(init_method);
5354 }
5355 }
5356
5357 if (unlikely(result == NULL)) {
5358 Py_DECREF(obj);
5359 return NULL;
5360 }
5361
5362 Py_DECREF(result);
5363
5364 if (unlikely(result != Py_None)) {
5365 Py_DECREF(obj);
5366
5367 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5368 return NULL;
5369 }
5370 } else {
5371
5372 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
5373 Py_DECREF(obj);
5374 return NULL;
5375 }
5376 }
5377 }
5378 }
5379
5380 CHECK_OBJECT_X(obj);
5381
5382 return obj;
5383 }
5384#endif
5385#if PYTHON_VERSION < 0x300
5386 } else if (PyClass_Check(called)) {
5387 PyObject *obj = PyInstance_NewRaw(called, NULL);
5388
5389 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
5390
5391 if (unlikely(init_method == NULL)) {
5392 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
5393 Py_DECREF(obj);
5394 return NULL;
5395 }
5396
5397 Py_DECREF(obj);
5398
5399 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5400 return NULL;
5401 }
5402
5403 bool is_compiled_function = false;
5404
5405 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5406
5407 if (descr_get == NULL) {
5408 Py_INCREF(init_method);
5409 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5410 is_compiled_function = true;
5411 } else if (descr_get != NULL) {
5412 PyObject *descr_method = descr_get(init_method, obj, called);
5413
5414 if (unlikely(descr_method == NULL)) {
5415 return NULL;
5416 }
5417
5418 init_method = descr_method;
5419 }
5420
5421 PyObject *result;
5422 if (is_compiled_function) {
5423 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5424 args, 6);
5425 } else {
5426 result = CALL_FUNCTION_WITH_POS_ARGS6(tstate, init_method, pos_args);
5427 Py_DECREF(init_method);
5428 }
5429 if (unlikely(result == NULL)) {
5430 return NULL;
5431 }
5432
5433 Py_DECREF(result);
5434
5435 if (unlikely(result != Py_None)) {
5436 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5437 return NULL;
5438 }
5439
5440 CHECK_OBJECT_X(obj);
5441
5442 return obj;
5443#endif
5444#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5445 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5446 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5447
5448 if (likely(func != NULL)) {
5449 PyObject *result = func(called, args, 6, NULL);
5450
5451 CHECK_OBJECT_X(result);
5452
5453 return Nuitka_CheckFunctionResult(tstate, called, result);
5454 }
5455#endif
5456 }
5457
5458#if 0
5459 PRINT_NEW_LINE();
5460 PRINT_STRING("FALLBACK");
5461 PRINT_ITEM(called);
5462 PRINT_NEW_LINE();
5463#endif
5464
5465 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5466
5467 CHECK_OBJECT_X(result);
5468
5469 return result;
5470}
5471PyObject *CALL_FUNCTION_WITH_ARGS7(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
5472 CHECK_OBJECT(called);
5473 CHECK_OBJECTS(args, 7);
5474
5475 if (Nuitka_Function_Check(called)) {
5476 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5477 return NULL;
5478 }
5479
5480 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5481 PyObject *result;
5482
5483 if (function->m_args_simple && 7 == function->m_args_positional_count) {
5484 for (Py_ssize_t i = 0; i < 7; i++) {
5485 Py_INCREF(args[i]);
5486 }
5487 result = function->m_c_code(tstate, function, (PyObject **)args);
5488 } else if (function->m_args_simple && 7 + function->m_defaults_given == function->m_args_positional_count) {
5489 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5490
5491 memcpy(python_pars, args, 7 * sizeof(PyObject *));
5492 memcpy(python_pars + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5493 function->m_defaults_given * sizeof(PyObject *));
5494
5495 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5496 Py_INCREF(python_pars[i]);
5497 }
5498
5499 result = function->m_c_code(tstate, function, python_pars);
5500 } else {
5501 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 7);
5502 }
5503
5504 Py_LeaveRecursiveCall();
5505
5506 CHECK_OBJECT_X(result);
5507
5508 return result;
5509 } else if (Nuitka_Method_Check(called)) {
5510 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5511
5512 if (method->m_object == NULL) {
5513 PyObject *self = args[0];
5514
5515 int res = PyObject_IsInstance(self, method->m_class);
5516
5517 if (unlikely(res < 0)) {
5518 return NULL;
5519 } else if (unlikely(res == 0)) {
5520 PyErr_Format(PyExc_TypeError,
5521 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5522 "instance instead)",
5523 GET_CALLABLE_NAME((PyObject *)method->m_function),
5524 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5525 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5526
5527 return NULL;
5528 }
5529
5530 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 7);
5531
5532 CHECK_OBJECT_X(result);
5533
5534 return result;
5535 } else {
5536 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5537 return NULL;
5538 }
5539
5540 struct Nuitka_FunctionObject *function = method->m_function;
5541
5542 PyObject *result;
5543
5544 if (function->m_args_simple && 7 + 1 == function->m_args_positional_count) {
5545 PyObject *python_pars[7 + 1];
5546
5547 python_pars[0] = method->m_object;
5548 Py_INCREF(method->m_object);
5549
5550 for (Py_ssize_t i = 0; i < 7; i++) {
5551 python_pars[i + 1] = args[i];
5552 Py_INCREF(args[i]);
5553 }
5554 result = function->m_c_code(tstate, function, python_pars);
5555 } else if (function->m_args_simple &&
5556 7 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5557 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5558
5559 python_pars[0] = method->m_object;
5560 Py_INCREF(method->m_object);
5561
5562 memcpy(python_pars + 1, args, 7 * sizeof(PyObject *));
5563 memcpy(python_pars + 1 + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5564 function->m_defaults_given * sizeof(PyObject *));
5565
5566 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
5567 Py_INCREF(python_pars[i]);
5568 }
5569
5570 result = function->m_c_code(tstate, function, python_pars);
5571 } else {
5572 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 7);
5573 }
5574
5575 Py_LeaveRecursiveCall();
5576
5577 CHECK_OBJECT_X(result);
5578
5579 return result;
5580 }
5581#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
5582 } else if (PyCFunction_CheckExact(called)) {
5583#if PYTHON_VERSION >= 0x380
5584#ifdef _NUITKA_FULL_COMPAT
5585 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5586 return NULL;
5587 }
5588#endif
5589
5590 int flags = PyCFunction_GET_FLAGS(called);
5591
5592 PyObject *result;
5593
5594 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5595
5596 if (func != NULL) {
5597 result = func(called, args, 7, NULL);
5598
5599 CHECK_OBJECT_X(result);
5600 } else {
5601 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5602 PyObject *self = PyCFunction_GET_SELF(called);
5603
5604 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5605
5606 if (flags & METH_KEYWORDS) {
5607 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
5608 } else {
5609 result = (*method)(self, pos_args);
5610 }
5611
5612 Py_DECREF(pos_args);
5613 }
5614
5615#ifdef _NUITKA_FULL_COMPAT
5616 Py_LeaveRecursiveCall();
5617#endif
5618 CHECK_OBJECT_X(result);
5619
5620 return Nuitka_CheckFunctionResult(tstate, called, result);
5621#else
5622 // Try to be fast about wrapping the arguments.
5623 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
5624
5625 if (unlikely(flags & METH_NOARGS)) {
5626 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (7 given)",
5627 ((PyCFunctionObject *)called)->m_ml->ml_name);
5628 return NULL;
5629 } else if (unlikely(flags & METH_O)) {
5630 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (7 given)",
5631 ((PyCFunctionObject *)called)->m_ml->ml_name);
5632 return NULL;
5633 } else if (flags & METH_VARARGS) {
5634 // Recursion guard is not strictly necessary, as we already have
5635 // one on our way to here.
5636#ifdef _NUITKA_FULL_COMPAT
5637 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5638 return NULL;
5639 }
5640#endif
5641 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5642 PyObject *self = PyCFunction_GET_SELF(called);
5643
5644 PyObject *result;
5645
5646#if PYTHON_VERSION < 0x360
5647 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5648 if (flags & METH_KEYWORDS) {
5649 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5650 } else {
5651 result = (*method)(self, pos_args);
5652 }
5653
5654 Py_DECREF(pos_args);
5655#else
5656 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
5657 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5658 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5659 Py_DECREF(pos_args);
5660 } else if (flags == METH_FASTCALL) {
5661#if PYTHON_VERSION < 0x370
5662 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 7, NULL);
5663#else
5664 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5665 result = (*(_PyCFunctionFast)method)(self, &pos_args, 7);
5666 Py_DECREF(pos_args);
5667#endif
5668 } else {
5669 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5670 result = (*method)(self, pos_args);
5671 Py_DECREF(pos_args);
5672 }
5673#endif
5674
5675#ifdef _NUITKA_FULL_COMPAT
5676 Py_LeaveRecursiveCall();
5677#endif
5678
5679 CHECK_OBJECT_X(result);
5680
5681 return Nuitka_CheckFunctionResult(tstate, called, result);
5682 }
5683#endif
5684#endif
5685#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
5686 } else if (PyFunction_Check(called)) {
5687#if PYTHON_VERSION < 0x3b0
5688 PyObject *result = callPythonFunction(called, args, 7);
5689#else
5690 PyObject *result = _PyFunction_Vectorcall(called, args, 7, NULL);
5691#endif
5692 CHECK_OBJECT_X(result);
5693
5694 return result;
5695#endif
5696#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
5697 } else if (PyType_Check(called)) {
5698 PyTypeObject *type = Py_TYPE(called);
5699
5700 if (type->tp_call == PyType_Type.tp_call) {
5701 PyTypeObject *called_type = (PyTypeObject *)(called);
5702
5703 if (unlikely(called_type->tp_new == NULL)) {
5704 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
5705 return NULL;
5706 }
5707
5708 PyObject *pos_args = NULL;
5709 PyObject *obj;
5710
5711 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
5712 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
5713 formatCannotInstantiateAbstractClass(tstate, called_type);
5714 return NULL;
5715 }
5716
5717 obj = called_type->tp_alloc(called_type, 0);
5718 CHECK_OBJECT(obj);
5719 } else {
5720 pos_args = MAKE_TUPLE(tstate, args, 7);
5721 obj = called_type->tp_new(called_type, pos_args, NULL);
5722 }
5723
5724 if (likely(obj != NULL)) {
5725 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
5726 Py_DECREF(pos_args);
5727 return obj;
5728 }
5729
5730 // Work on produced type.
5731 type = Py_TYPE(obj);
5732
5733 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
5734 if (type->tp_init == default_tp_init_wrapper) {
5735 Py_XDECREF(pos_args);
5736 pos_args = NULL;
5737
5738 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
5739
5740 // Not really allowed, since we wouldn't have the default wrapper set.
5741 assert(init_method != NULL);
5742
5743 bool is_compiled_function = false;
5744 bool init_method_needs_release = false;
5745
5746 if (likely(init_method != NULL)) {
5747 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
5748
5749 if (func == Nuitka_Function_Type.tp_descr_get) {
5750 is_compiled_function = true;
5751 } else if (func != NULL) {
5752 init_method = func(init_method, obj, (PyObject *)(type));
5753 init_method_needs_release = true;
5754 }
5755 }
5756
5757 if (unlikely(init_method == NULL)) {
5758 if (!HAS_ERROR_OCCURRED(tstate)) {
5759 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
5760 const_str_plain___init__);
5761 }
5762
5763 return NULL;
5764 }
5765
5766 PyObject *result;
5767 if (is_compiled_function) {
5768 result = Nuitka_CallMethodFunctionPosArgs(
5769 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 7);
5770 } else {
5771 result = CALL_FUNCTION_WITH_ARGS7(tstate, init_method, args);
5772 if (init_method_needs_release) {
5773 Py_DECREF(init_method);
5774 }
5775 }
5776
5777 if (unlikely(result == NULL)) {
5778 Py_DECREF(obj);
5779 return NULL;
5780 }
5781
5782 Py_DECREF(result);
5783
5784 if (unlikely(result != Py_None)) {
5785 Py_DECREF(obj);
5786
5787 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5788 return NULL;
5789 }
5790 } else {
5791 if (pos_args == NULL) {
5792 pos_args = MAKE_TUPLE(tstate, args, 7);
5793 }
5794
5795 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
5796 Py_DECREF(obj);
5797 Py_XDECREF(pos_args);
5798 return NULL;
5799 }
5800 }
5801 }
5802 }
5803
5804 Py_XDECREF(pos_args);
5805
5806 CHECK_OBJECT_X(obj);
5807
5808 return obj;
5809 }
5810#endif
5811#if PYTHON_VERSION < 0x300
5812 } else if (PyClass_Check(called)) {
5813 PyObject *obj = PyInstance_NewRaw(called, NULL);
5814
5815 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
5816
5817 if (unlikely(init_method == NULL)) {
5818 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
5819 Py_DECREF(obj);
5820 return NULL;
5821 }
5822
5823 Py_DECREF(obj);
5824
5825 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5826 return NULL;
5827 }
5828
5829 bool is_compiled_function = false;
5830
5831 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5832
5833 if (descr_get == NULL) {
5834 Py_INCREF(init_method);
5835 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5836 is_compiled_function = true;
5837 } else if (descr_get != NULL) {
5838 PyObject *descr_method = descr_get(init_method, obj, called);
5839
5840 if (unlikely(descr_method == NULL)) {
5841 return NULL;
5842 }
5843
5844 init_method = descr_method;
5845 }
5846
5847 PyObject *result;
5848 if (is_compiled_function) {
5849 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5850 args, 7);
5851 } else {
5852 result = CALL_FUNCTION_WITH_ARGS7(tstate, init_method, args);
5853 Py_DECREF(init_method);
5854 }
5855 if (unlikely(result == NULL)) {
5856 return NULL;
5857 }
5858
5859 Py_DECREF(result);
5860
5861 if (unlikely(result != Py_None)) {
5862 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5863 return NULL;
5864 }
5865
5866 CHECK_OBJECT_X(obj);
5867
5868 return obj;
5869#endif
5870#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5871 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5872 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5873
5874 if (likely(func != NULL)) {
5875 PyObject *result = func(called, args, 7, NULL);
5876
5877 CHECK_OBJECT_X(result);
5878
5879 return Nuitka_CheckFunctionResult(tstate, called, result);
5880 }
5881#endif
5882 }
5883
5884#if 0
5885 PRINT_NEW_LINE();
5886 PRINT_STRING("FALLBACK");
5887 PRINT_ITEM(called);
5888 PRINT_NEW_LINE();
5889#endif
5890
5891 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5892
5893 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5894
5895 Py_DECREF(pos_args);
5896
5897 CHECK_OBJECT_X(result);
5898
5899 return result;
5900}
5901PyObject *CALL_FUNCTION_WITH_POS_ARGS7(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
5902 assert(PyTuple_CheckExact(pos_args));
5903 assert(PyTuple_GET_SIZE(pos_args) == 7);
5904 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
5905 CHECK_OBJECT(called);
5906 CHECK_OBJECTS(args, 7);
5907
5908 if (Nuitka_Function_Check(called)) {
5909 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5910 return NULL;
5911 }
5912
5913 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5914 PyObject *result;
5915
5916 if (function->m_args_simple && 7 == function->m_args_positional_count) {
5917 for (Py_ssize_t i = 0; i < 7; i++) {
5918 Py_INCREF(args[i]);
5919 }
5920 result = function->m_c_code(tstate, function, (PyObject **)args);
5921 } else if (function->m_args_simple && 7 + function->m_defaults_given == function->m_args_positional_count) {
5922 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5923
5924 memcpy(python_pars, args, 7 * sizeof(PyObject *));
5925 memcpy(python_pars + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5926 function->m_defaults_given * sizeof(PyObject *));
5927
5928 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5929 Py_INCREF(python_pars[i]);
5930 }
5931
5932 result = function->m_c_code(tstate, function, python_pars);
5933 } else {
5934 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 7);
5935 }
5936
5937 Py_LeaveRecursiveCall();
5938
5939 CHECK_OBJECT_X(result);
5940
5941 return result;
5942 } else if (Nuitka_Method_Check(called)) {
5943 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5944
5945 if (method->m_object == NULL) {
5946 PyObject *self = args[0];
5947
5948 int res = PyObject_IsInstance(self, method->m_class);
5949
5950 if (unlikely(res < 0)) {
5951 return NULL;
5952 } else if (unlikely(res == 0)) {
5953 PyErr_Format(PyExc_TypeError,
5954 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5955 "instance instead)",
5956 GET_CALLABLE_NAME((PyObject *)method->m_function),
5957 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5958 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5959
5960 return NULL;
5961 }
5962
5963 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 7);
5964
5965 CHECK_OBJECT_X(result);
5966
5967 return result;
5968 } else {
5969 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5970 return NULL;
5971 }
5972
5973 struct Nuitka_FunctionObject *function = method->m_function;
5974
5975 PyObject *result;
5976
5977 if (function->m_args_simple && 7 + 1 == function->m_args_positional_count) {
5978 PyObject *python_pars[7 + 1];
5979
5980 python_pars[0] = method->m_object;
5981 Py_INCREF(method->m_object);
5982
5983 for (Py_ssize_t i = 0; i < 7; i++) {
5984 python_pars[i + 1] = args[i];
5985 Py_INCREF(args[i]);
5986 }
5987 result = function->m_c_code(tstate, function, python_pars);
5988 } else if (function->m_args_simple &&
5989 7 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5990 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5991
5992 python_pars[0] = method->m_object;
5993 Py_INCREF(method->m_object);
5994
5995 memcpy(python_pars + 1, args, 7 * sizeof(PyObject *));
5996 memcpy(python_pars + 1 + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5997 function->m_defaults_given * sizeof(PyObject *));
5998
5999 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6000 Py_INCREF(python_pars[i]);
6001 }
6002
6003 result = function->m_c_code(tstate, function, python_pars);
6004 } else {
6005 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 7);
6006 }
6007
6008 Py_LeaveRecursiveCall();
6009
6010 CHECK_OBJECT_X(result);
6011
6012 return result;
6013 }
6014#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6015 } else if (PyCFunction_CheckExact(called)) {
6016#if PYTHON_VERSION >= 0x380
6017#ifdef _NUITKA_FULL_COMPAT
6018 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6019 return NULL;
6020 }
6021#endif
6022
6023 int flags = PyCFunction_GET_FLAGS(called);
6024
6025 PyObject *result;
6026
6027 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6028
6029 if (func != NULL) {
6030 result = func(called, args, 7, NULL);
6031
6032 CHECK_OBJECT_X(result);
6033 } else {
6034 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6035 PyObject *self = PyCFunction_GET_SELF(called);
6036
6037 if (flags & METH_KEYWORDS) {
6038 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6039 } else {
6040 result = (*method)(self, pos_args);
6041 }
6042 }
6043
6044#ifdef _NUITKA_FULL_COMPAT
6045 Py_LeaveRecursiveCall();
6046#endif
6047 CHECK_OBJECT_X(result);
6048
6049 return Nuitka_CheckFunctionResult(tstate, called, result);
6050#else
6051 // Try to be fast about wrapping the arguments.
6052 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6053
6054 if (unlikely(flags & METH_NOARGS)) {
6055 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (7 given)",
6056 ((PyCFunctionObject *)called)->m_ml->ml_name);
6057 return NULL;
6058 } else if (unlikely(flags & METH_O)) {
6059 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (7 given)",
6060 ((PyCFunctionObject *)called)->m_ml->ml_name);
6061 return NULL;
6062 } else if (flags & METH_VARARGS) {
6063 // Recursion guard is not strictly necessary, as we already have
6064 // one on our way to here.
6065#ifdef _NUITKA_FULL_COMPAT
6066 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6067 return NULL;
6068 }
6069#endif
6070 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6071 PyObject *self = PyCFunction_GET_SELF(called);
6072
6073 PyObject *result;
6074
6075#if PYTHON_VERSION < 0x360
6076 if (flags & METH_KEYWORDS) {
6077 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6078 } else {
6079 result = (*method)(self, pos_args);
6080 }
6081
6082#else
6083 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6084 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6085 } else if (flags == METH_FASTCALL) {
6086#if PYTHON_VERSION < 0x370
6087 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 7, NULL);
6088#else
6089 result = (*(_PyCFunctionFast)method)(self, &pos_args, 7);
6090#endif
6091 } else {
6092 result = (*method)(self, pos_args);
6093 }
6094#endif
6095
6096#ifdef _NUITKA_FULL_COMPAT
6097 Py_LeaveRecursiveCall();
6098#endif
6099
6100 CHECK_OBJECT_X(result);
6101
6102 return Nuitka_CheckFunctionResult(tstate, called, result);
6103 }
6104#endif
6105#endif
6106#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6107 } else if (PyFunction_Check(called)) {
6108#if PYTHON_VERSION < 0x3b0
6109 PyObject *result = callPythonFunction(called, args, 7);
6110#else
6111 PyObject *result = _PyFunction_Vectorcall(called, args, 7, NULL);
6112#endif
6113 CHECK_OBJECT_X(result);
6114
6115 return result;
6116#endif
6117#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6118 } else if (PyType_Check(called)) {
6119 PyTypeObject *type = Py_TYPE(called);
6120
6121 if (type->tp_call == PyType_Type.tp_call) {
6122 PyTypeObject *called_type = (PyTypeObject *)(called);
6123
6124 if (unlikely(called_type->tp_new == NULL)) {
6125 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6126 return NULL;
6127 }
6128
6129 PyObject *obj;
6130
6131 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6132 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6133 formatCannotInstantiateAbstractClass(tstate, called_type);
6134 return NULL;
6135 }
6136
6137 obj = called_type->tp_alloc(called_type, 0);
6138 CHECK_OBJECT(obj);
6139 } else {
6140 obj = called_type->tp_new(called_type, pos_args, NULL);
6141 }
6142
6143 if (likely(obj != NULL)) {
6144 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6145 return obj;
6146 }
6147
6148 // Work on produced type.
6149 type = Py_TYPE(obj);
6150
6151 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6152 if (type->tp_init == default_tp_init_wrapper) {
6153
6154 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6155
6156 // Not really allowed, since we wouldn't have the default wrapper set.
6157 assert(init_method != NULL);
6158
6159 bool is_compiled_function = false;
6160 bool init_method_needs_release = false;
6161
6162 if (likely(init_method != NULL)) {
6163 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
6164
6165 if (func == Nuitka_Function_Type.tp_descr_get) {
6166 is_compiled_function = true;
6167 } else if (func != NULL) {
6168 init_method = func(init_method, obj, (PyObject *)(type));
6169 init_method_needs_release = true;
6170 }
6171 }
6172
6173 if (unlikely(init_method == NULL)) {
6174 if (!HAS_ERROR_OCCURRED(tstate)) {
6175 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
6176 const_str_plain___init__);
6177 }
6178
6179 return NULL;
6180 }
6181
6182 PyObject *result;
6183 if (is_compiled_function) {
6184 result = Nuitka_CallMethodFunctionPosArgs(
6185 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 7);
6186 } else {
6187 result = CALL_FUNCTION_WITH_POS_ARGS7(tstate, init_method, pos_args);
6188 if (init_method_needs_release) {
6189 Py_DECREF(init_method);
6190 }
6191 }
6192
6193 if (unlikely(result == NULL)) {
6194 Py_DECREF(obj);
6195 return NULL;
6196 }
6197
6198 Py_DECREF(result);
6199
6200 if (unlikely(result != Py_None)) {
6201 Py_DECREF(obj);
6202
6203 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6204 return NULL;
6205 }
6206 } else {
6207
6208 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
6209 Py_DECREF(obj);
6210 return NULL;
6211 }
6212 }
6213 }
6214 }
6215
6216 CHECK_OBJECT_X(obj);
6217
6218 return obj;
6219 }
6220#endif
6221#if PYTHON_VERSION < 0x300
6222 } else if (PyClass_Check(called)) {
6223 PyObject *obj = PyInstance_NewRaw(called, NULL);
6224
6225 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
6226
6227 if (unlikely(init_method == NULL)) {
6228 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
6229 Py_DECREF(obj);
6230 return NULL;
6231 }
6232
6233 Py_DECREF(obj);
6234
6235 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
6236 return NULL;
6237 }
6238
6239 bool is_compiled_function = false;
6240
6241 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
6242
6243 if (descr_get == NULL) {
6244 Py_INCREF(init_method);
6245 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
6246 is_compiled_function = true;
6247 } else if (descr_get != NULL) {
6248 PyObject *descr_method = descr_get(init_method, obj, called);
6249
6250 if (unlikely(descr_method == NULL)) {
6251 return NULL;
6252 }
6253
6254 init_method = descr_method;
6255 }
6256
6257 PyObject *result;
6258 if (is_compiled_function) {
6259 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
6260 args, 7);
6261 } else {
6262 result = CALL_FUNCTION_WITH_POS_ARGS7(tstate, init_method, pos_args);
6263 Py_DECREF(init_method);
6264 }
6265 if (unlikely(result == NULL)) {
6266 return NULL;
6267 }
6268
6269 Py_DECREF(result);
6270
6271 if (unlikely(result != Py_None)) {
6272 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6273 return NULL;
6274 }
6275
6276 CHECK_OBJECT_X(obj);
6277
6278 return obj;
6279#endif
6280#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
6281 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
6282 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6283
6284 if (likely(func != NULL)) {
6285 PyObject *result = func(called, args, 7, NULL);
6286
6287 CHECK_OBJECT_X(result);
6288
6289 return Nuitka_CheckFunctionResult(tstate, called, result);
6290 }
6291#endif
6292 }
6293
6294#if 0
6295 PRINT_NEW_LINE();
6296 PRINT_STRING("FALLBACK");
6297 PRINT_ITEM(called);
6298 PRINT_NEW_LINE();
6299#endif
6300
6301 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
6302
6303 CHECK_OBJECT_X(result);
6304
6305 return result;
6306}
6307PyObject *CALL_FUNCTION_WITH_ARGS8(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
6308 CHECK_OBJECT(called);
6309 CHECK_OBJECTS(args, 8);
6310
6311 if (Nuitka_Function_Check(called)) {
6312 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6313 return NULL;
6314 }
6315
6316 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
6317 PyObject *result;
6318
6319 if (function->m_args_simple && 8 == function->m_args_positional_count) {
6320 for (Py_ssize_t i = 0; i < 8; i++) {
6321 Py_INCREF(args[i]);
6322 }
6323 result = function->m_c_code(tstate, function, (PyObject **)args);
6324 } else if (function->m_args_simple && 8 + function->m_defaults_given == function->m_args_positional_count) {
6325 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6326
6327 memcpy(python_pars, args, 8 * sizeof(PyObject *));
6328 memcpy(python_pars + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6329 function->m_defaults_given * sizeof(PyObject *));
6330
6331 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
6332 Py_INCREF(python_pars[i]);
6333 }
6334
6335 result = function->m_c_code(tstate, function, python_pars);
6336 } else {
6337 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 8);
6338 }
6339
6340 Py_LeaveRecursiveCall();
6341
6342 CHECK_OBJECT_X(result);
6343
6344 return result;
6345 } else if (Nuitka_Method_Check(called)) {
6346 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
6347
6348 if (method->m_object == NULL) {
6349 PyObject *self = args[0];
6350
6351 int res = PyObject_IsInstance(self, method->m_class);
6352
6353 if (unlikely(res < 0)) {
6354 return NULL;
6355 } else if (unlikely(res == 0)) {
6356 PyErr_Format(PyExc_TypeError,
6357 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
6358 "instance instead)",
6359 GET_CALLABLE_NAME((PyObject *)method->m_function),
6360 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
6361 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
6362
6363 return NULL;
6364 }
6365
6366 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 8);
6367
6368 CHECK_OBJECT_X(result);
6369
6370 return result;
6371 } else {
6372 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6373 return NULL;
6374 }
6375
6376 struct Nuitka_FunctionObject *function = method->m_function;
6377
6378 PyObject *result;
6379
6380 if (function->m_args_simple && 8 + 1 == function->m_args_positional_count) {
6381 PyObject *python_pars[8 + 1];
6382
6383 python_pars[0] = method->m_object;
6384 Py_INCREF(method->m_object);
6385
6386 for (Py_ssize_t i = 0; i < 8; i++) {
6387 python_pars[i + 1] = args[i];
6388 Py_INCREF(args[i]);
6389 }
6390 result = function->m_c_code(tstate, function, python_pars);
6391 } else if (function->m_args_simple &&
6392 8 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6393 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6394
6395 python_pars[0] = method->m_object;
6396 Py_INCREF(method->m_object);
6397
6398 memcpy(python_pars + 1, args, 8 * sizeof(PyObject *));
6399 memcpy(python_pars + 1 + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6400 function->m_defaults_given * sizeof(PyObject *));
6401
6402 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6403 Py_INCREF(python_pars[i]);
6404 }
6405
6406 result = function->m_c_code(tstate, function, python_pars);
6407 } else {
6408 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 8);
6409 }
6410
6411 Py_LeaveRecursiveCall();
6412
6413 CHECK_OBJECT_X(result);
6414
6415 return result;
6416 }
6417#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6418 } else if (PyCFunction_CheckExact(called)) {
6419#if PYTHON_VERSION >= 0x380
6420#ifdef _NUITKA_FULL_COMPAT
6421 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6422 return NULL;
6423 }
6424#endif
6425
6426 int flags = PyCFunction_GET_FLAGS(called);
6427
6428 PyObject *result;
6429
6430 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6431
6432 if (func != NULL) {
6433 result = func(called, args, 8, NULL);
6434
6435 CHECK_OBJECT_X(result);
6436 } else {
6437 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6438 PyObject *self = PyCFunction_GET_SELF(called);
6439
6440 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6441
6442 if (flags & METH_KEYWORDS) {
6443 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6444 } else {
6445 result = (*method)(self, pos_args);
6446 }
6447
6448 Py_DECREF(pos_args);
6449 }
6450
6451#ifdef _NUITKA_FULL_COMPAT
6452 Py_LeaveRecursiveCall();
6453#endif
6454 CHECK_OBJECT_X(result);
6455
6456 return Nuitka_CheckFunctionResult(tstate, called, result);
6457#else
6458 // Try to be fast about wrapping the arguments.
6459 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6460
6461 if (unlikely(flags & METH_NOARGS)) {
6462 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (8 given)",
6463 ((PyCFunctionObject *)called)->m_ml->ml_name);
6464 return NULL;
6465 } else if (unlikely(flags & METH_O)) {
6466 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (8 given)",
6467 ((PyCFunctionObject *)called)->m_ml->ml_name);
6468 return NULL;
6469 } else if (flags & METH_VARARGS) {
6470 // Recursion guard is not strictly necessary, as we already have
6471 // one on our way to here.
6472#ifdef _NUITKA_FULL_COMPAT
6473 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6474 return NULL;
6475 }
6476#endif
6477 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6478 PyObject *self = PyCFunction_GET_SELF(called);
6479
6480 PyObject *result;
6481
6482#if PYTHON_VERSION < 0x360
6483 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6484 if (flags & METH_KEYWORDS) {
6485 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6486 } else {
6487 result = (*method)(self, pos_args);
6488 }
6489
6490 Py_DECREF(pos_args);
6491#else
6492 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6493 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6494 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6495 Py_DECREF(pos_args);
6496 } else if (flags == METH_FASTCALL) {
6497#if PYTHON_VERSION < 0x370
6498 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 8, NULL);
6499#else
6500 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6501 result = (*(_PyCFunctionFast)method)(self, &pos_args, 8);
6502 Py_DECREF(pos_args);
6503#endif
6504 } else {
6505 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6506 result = (*method)(self, pos_args);
6507 Py_DECREF(pos_args);
6508 }
6509#endif
6510
6511#ifdef _NUITKA_FULL_COMPAT
6512 Py_LeaveRecursiveCall();
6513#endif
6514
6515 CHECK_OBJECT_X(result);
6516
6517 return Nuitka_CheckFunctionResult(tstate, called, result);
6518 }
6519#endif
6520#endif
6521#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6522 } else if (PyFunction_Check(called)) {
6523#if PYTHON_VERSION < 0x3b0
6524 PyObject *result = callPythonFunction(called, args, 8);
6525#else
6526 PyObject *result = _PyFunction_Vectorcall(called, args, 8, NULL);
6527#endif
6528 CHECK_OBJECT_X(result);
6529
6530 return result;
6531#endif
6532#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6533 } else if (PyType_Check(called)) {
6534 PyTypeObject *type = Py_TYPE(called);
6535
6536 if (type->tp_call == PyType_Type.tp_call) {
6537 PyTypeObject *called_type = (PyTypeObject *)(called);
6538
6539 if (unlikely(called_type->tp_new == NULL)) {
6540 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6541 return NULL;
6542 }
6543
6544 PyObject *pos_args = NULL;
6545 PyObject *obj;
6546
6547 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6548 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6549 formatCannotInstantiateAbstractClass(tstate, called_type);
6550 return NULL;
6551 }
6552
6553 obj = called_type->tp_alloc(called_type, 0);
6554 CHECK_OBJECT(obj);
6555 } else {
6556 pos_args = MAKE_TUPLE(tstate, args, 8);
6557 obj = called_type->tp_new(called_type, pos_args, NULL);
6558 }
6559
6560 if (likely(obj != NULL)) {
6561 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6562 Py_DECREF(pos_args);
6563 return obj;
6564 }
6565
6566 // Work on produced type.
6567 type = Py_TYPE(obj);
6568
6569 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6570 if (type->tp_init == default_tp_init_wrapper) {
6571 Py_XDECREF(pos_args);
6572 pos_args = NULL;
6573
6574 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6575
6576 // Not really allowed, since we wouldn't have the default wrapper set.
6577 assert(init_method != NULL);
6578
6579 bool is_compiled_function = false;
6580 bool init_method_needs_release = false;
6581
6582 if (likely(init_method != NULL)) {
6583 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
6584
6585 if (func == Nuitka_Function_Type.tp_descr_get) {
6586 is_compiled_function = true;
6587 } else if (func != NULL) {
6588 init_method = func(init_method, obj, (PyObject *)(type));
6589 init_method_needs_release = true;
6590 }
6591 }
6592
6593 if (unlikely(init_method == NULL)) {
6594 if (!HAS_ERROR_OCCURRED(tstate)) {
6595 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
6596 const_str_plain___init__);
6597 }
6598
6599 return NULL;
6600 }
6601
6602 PyObject *result;
6603 if (is_compiled_function) {
6604 result = Nuitka_CallMethodFunctionPosArgs(
6605 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 8);
6606 } else {
6607 result = CALL_FUNCTION_WITH_ARGS8(tstate, init_method, args);
6608 if (init_method_needs_release) {
6609 Py_DECREF(init_method);
6610 }
6611 }
6612
6613 if (unlikely(result == NULL)) {
6614 Py_DECREF(obj);
6615 return NULL;
6616 }
6617
6618 Py_DECREF(result);
6619
6620 if (unlikely(result != Py_None)) {
6621 Py_DECREF(obj);
6622
6623 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6624 return NULL;
6625 }
6626 } else {
6627 if (pos_args == NULL) {
6628 pos_args = MAKE_TUPLE(tstate, args, 8);
6629 }
6630
6631 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
6632 Py_DECREF(obj);
6633 Py_XDECREF(pos_args);
6634 return NULL;
6635 }
6636 }
6637 }
6638 }
6639
6640 Py_XDECREF(pos_args);
6641
6642 CHECK_OBJECT_X(obj);
6643
6644 return obj;
6645 }
6646#endif
6647#if PYTHON_VERSION < 0x300
6648 } else if (PyClass_Check(called)) {
6649 PyObject *obj = PyInstance_NewRaw(called, NULL);
6650
6651 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
6652
6653 if (unlikely(init_method == NULL)) {
6654 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
6655 Py_DECREF(obj);
6656 return NULL;
6657 }
6658
6659 Py_DECREF(obj);
6660
6661 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
6662 return NULL;
6663 }
6664
6665 bool is_compiled_function = false;
6666
6667 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
6668
6669 if (descr_get == NULL) {
6670 Py_INCREF(init_method);
6671 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
6672 is_compiled_function = true;
6673 } else if (descr_get != NULL) {
6674 PyObject *descr_method = descr_get(init_method, obj, called);
6675
6676 if (unlikely(descr_method == NULL)) {
6677 return NULL;
6678 }
6679
6680 init_method = descr_method;
6681 }
6682
6683 PyObject *result;
6684 if (is_compiled_function) {
6685 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
6686 args, 8);
6687 } else {
6688 result = CALL_FUNCTION_WITH_ARGS8(tstate, init_method, args);
6689 Py_DECREF(init_method);
6690 }
6691 if (unlikely(result == NULL)) {
6692 return NULL;
6693 }
6694
6695 Py_DECREF(result);
6696
6697 if (unlikely(result != Py_None)) {
6698 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6699 return NULL;
6700 }
6701
6702 CHECK_OBJECT_X(obj);
6703
6704 return obj;
6705#endif
6706#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
6707 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
6708 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6709
6710 if (likely(func != NULL)) {
6711 PyObject *result = func(called, args, 8, NULL);
6712
6713 CHECK_OBJECT_X(result);
6714
6715 return Nuitka_CheckFunctionResult(tstate, called, result);
6716 }
6717#endif
6718 }
6719
6720#if 0
6721 PRINT_NEW_LINE();
6722 PRINT_STRING("FALLBACK");
6723 PRINT_ITEM(called);
6724 PRINT_NEW_LINE();
6725#endif
6726
6727 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6728
6729 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
6730
6731 Py_DECREF(pos_args);
6732
6733 CHECK_OBJECT_X(result);
6734
6735 return result;
6736}
6737PyObject *CALL_FUNCTION_WITH_POS_ARGS8(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
6738 assert(PyTuple_CheckExact(pos_args));
6739 assert(PyTuple_GET_SIZE(pos_args) == 8);
6740 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
6741 CHECK_OBJECT(called);
6742 CHECK_OBJECTS(args, 8);
6743
6744 if (Nuitka_Function_Check(called)) {
6745 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6746 return NULL;
6747 }
6748
6749 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
6750 PyObject *result;
6751
6752 if (function->m_args_simple && 8 == function->m_args_positional_count) {
6753 for (Py_ssize_t i = 0; i < 8; i++) {
6754 Py_INCREF(args[i]);
6755 }
6756 result = function->m_c_code(tstate, function, (PyObject **)args);
6757 } else if (function->m_args_simple && 8 + function->m_defaults_given == function->m_args_positional_count) {
6758 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6759
6760 memcpy(python_pars, args, 8 * sizeof(PyObject *));
6761 memcpy(python_pars + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6762 function->m_defaults_given * sizeof(PyObject *));
6763
6764 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
6765 Py_INCREF(python_pars[i]);
6766 }
6767
6768 result = function->m_c_code(tstate, function, python_pars);
6769 } else {
6770 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 8);
6771 }
6772
6773 Py_LeaveRecursiveCall();
6774
6775 CHECK_OBJECT_X(result);
6776
6777 return result;
6778 } else if (Nuitka_Method_Check(called)) {
6779 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
6780
6781 if (method->m_object == NULL) {
6782 PyObject *self = args[0];
6783
6784 int res = PyObject_IsInstance(self, method->m_class);
6785
6786 if (unlikely(res < 0)) {
6787 return NULL;
6788 } else if (unlikely(res == 0)) {
6789 PyErr_Format(PyExc_TypeError,
6790 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
6791 "instance instead)",
6792 GET_CALLABLE_NAME((PyObject *)method->m_function),
6793 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
6794 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
6795
6796 return NULL;
6797 }
6798
6799 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 8);
6800
6801 CHECK_OBJECT_X(result);
6802
6803 return result;
6804 } else {
6805 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6806 return NULL;
6807 }
6808
6809 struct Nuitka_FunctionObject *function = method->m_function;
6810
6811 PyObject *result;
6812
6813 if (function->m_args_simple && 8 + 1 == function->m_args_positional_count) {
6814 PyObject *python_pars[8 + 1];
6815
6816 python_pars[0] = method->m_object;
6817 Py_INCREF(method->m_object);
6818
6819 for (Py_ssize_t i = 0; i < 8; i++) {
6820 python_pars[i + 1] = args[i];
6821 Py_INCREF(args[i]);
6822 }
6823 result = function->m_c_code(tstate, function, python_pars);
6824 } else if (function->m_args_simple &&
6825 8 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6826 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6827
6828 python_pars[0] = method->m_object;
6829 Py_INCREF(method->m_object);
6830
6831 memcpy(python_pars + 1, args, 8 * sizeof(PyObject *));
6832 memcpy(python_pars + 1 + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6833 function->m_defaults_given * sizeof(PyObject *));
6834
6835 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6836 Py_INCREF(python_pars[i]);
6837 }
6838
6839 result = function->m_c_code(tstate, function, python_pars);
6840 } else {
6841 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 8);
6842 }
6843
6844 Py_LeaveRecursiveCall();
6845
6846 CHECK_OBJECT_X(result);
6847
6848 return result;
6849 }
6850#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6851 } else if (PyCFunction_CheckExact(called)) {
6852#if PYTHON_VERSION >= 0x380
6853#ifdef _NUITKA_FULL_COMPAT
6854 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6855 return NULL;
6856 }
6857#endif
6858
6859 int flags = PyCFunction_GET_FLAGS(called);
6860
6861 PyObject *result;
6862
6863 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6864
6865 if (func != NULL) {
6866 result = func(called, args, 8, NULL);
6867
6868 CHECK_OBJECT_X(result);
6869 } else {
6870 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6871 PyObject *self = PyCFunction_GET_SELF(called);
6872
6873 if (flags & METH_KEYWORDS) {
6874 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6875 } else {
6876 result = (*method)(self, pos_args);
6877 }
6878 }
6879
6880#ifdef _NUITKA_FULL_COMPAT
6881 Py_LeaveRecursiveCall();
6882#endif
6883 CHECK_OBJECT_X(result);
6884
6885 return Nuitka_CheckFunctionResult(tstate, called, result);
6886#else
6887 // Try to be fast about wrapping the arguments.
6888 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6889
6890 if (unlikely(flags & METH_NOARGS)) {
6891 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (8 given)",
6892 ((PyCFunctionObject *)called)->m_ml->ml_name);
6893 return NULL;
6894 } else if (unlikely(flags & METH_O)) {
6895 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (8 given)",
6896 ((PyCFunctionObject *)called)->m_ml->ml_name);
6897 return NULL;
6898 } else if (flags & METH_VARARGS) {
6899 // Recursion guard is not strictly necessary, as we already have
6900 // one on our way to here.
6901#ifdef _NUITKA_FULL_COMPAT
6902 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6903 return NULL;
6904 }
6905#endif
6906 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6907 PyObject *self = PyCFunction_GET_SELF(called);
6908
6909 PyObject *result;
6910
6911#if PYTHON_VERSION < 0x360
6912 if (flags & METH_KEYWORDS) {
6913 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6914 } else {
6915 result = (*method)(self, pos_args);
6916 }
6917
6918#else
6919 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6920 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6921 } else if (flags == METH_FASTCALL) {
6922#if PYTHON_VERSION < 0x370
6923 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 8, NULL);
6924#else
6925 result = (*(_PyCFunctionFast)method)(self, &pos_args, 8);
6926#endif
6927 } else {
6928 result = (*method)(self, pos_args);
6929 }
6930#endif
6931
6932#ifdef _NUITKA_FULL_COMPAT
6933 Py_LeaveRecursiveCall();
6934#endif
6935
6936 CHECK_OBJECT_X(result);
6937
6938 return Nuitka_CheckFunctionResult(tstate, called, result);
6939 }
6940#endif
6941#endif
6942#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6943 } else if (PyFunction_Check(called)) {
6944#if PYTHON_VERSION < 0x3b0
6945 PyObject *result = callPythonFunction(called, args, 8);
6946#else
6947 PyObject *result = _PyFunction_Vectorcall(called, args, 8, NULL);
6948#endif
6949 CHECK_OBJECT_X(result);
6950
6951 return result;
6952#endif
6953#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6954 } else if (PyType_Check(called)) {
6955 PyTypeObject *type = Py_TYPE(called);
6956
6957 if (type->tp_call == PyType_Type.tp_call) {
6958 PyTypeObject *called_type = (PyTypeObject *)(called);
6959
6960 if (unlikely(called_type->tp_new == NULL)) {
6961 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6962 return NULL;
6963 }
6964
6965 PyObject *obj;
6966
6967 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6968 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6969 formatCannotInstantiateAbstractClass(tstate, called_type);
6970 return NULL;
6971 }
6972
6973 obj = called_type->tp_alloc(called_type, 0);
6974 CHECK_OBJECT(obj);
6975 } else {
6976 obj = called_type->tp_new(called_type, pos_args, NULL);
6977 }
6978
6979 if (likely(obj != NULL)) {
6980 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6981 return obj;
6982 }
6983
6984 // Work on produced type.
6985 type = Py_TYPE(obj);
6986
6987 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6988 if (type->tp_init == default_tp_init_wrapper) {
6989
6990 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6991
6992 // Not really allowed, since we wouldn't have the default wrapper set.
6993 assert(init_method != NULL);
6994
6995 bool is_compiled_function = false;
6996 bool init_method_needs_release = false;
6997
6998 if (likely(init_method != NULL)) {
6999 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7000
7001 if (func == Nuitka_Function_Type.tp_descr_get) {
7002 is_compiled_function = true;
7003 } else if (func != NULL) {
7004 init_method = func(init_method, obj, (PyObject *)(type));
7005 init_method_needs_release = true;
7006 }
7007 }
7008
7009 if (unlikely(init_method == NULL)) {
7010 if (!HAS_ERROR_OCCURRED(tstate)) {
7011 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7012 const_str_plain___init__);
7013 }
7014
7015 return NULL;
7016 }
7017
7018 PyObject *result;
7019 if (is_compiled_function) {
7020 result = Nuitka_CallMethodFunctionPosArgs(
7021 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 8);
7022 } else {
7023 result = CALL_FUNCTION_WITH_POS_ARGS8(tstate, init_method, pos_args);
7024 if (init_method_needs_release) {
7025 Py_DECREF(init_method);
7026 }
7027 }
7028
7029 if (unlikely(result == NULL)) {
7030 Py_DECREF(obj);
7031 return NULL;
7032 }
7033
7034 Py_DECREF(result);
7035
7036 if (unlikely(result != Py_None)) {
7037 Py_DECREF(obj);
7038
7039 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7040 return NULL;
7041 }
7042 } else {
7043
7044 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7045 Py_DECREF(obj);
7046 return NULL;
7047 }
7048 }
7049 }
7050 }
7051
7052 CHECK_OBJECT_X(obj);
7053
7054 return obj;
7055 }
7056#endif
7057#if PYTHON_VERSION < 0x300
7058 } else if (PyClass_Check(called)) {
7059 PyObject *obj = PyInstance_NewRaw(called, NULL);
7060
7061 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7062
7063 if (unlikely(init_method == NULL)) {
7064 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7065 Py_DECREF(obj);
7066 return NULL;
7067 }
7068
7069 Py_DECREF(obj);
7070
7071 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7072 return NULL;
7073 }
7074
7075 bool is_compiled_function = false;
7076
7077 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7078
7079 if (descr_get == NULL) {
7080 Py_INCREF(init_method);
7081 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7082 is_compiled_function = true;
7083 } else if (descr_get != NULL) {
7084 PyObject *descr_method = descr_get(init_method, obj, called);
7085
7086 if (unlikely(descr_method == NULL)) {
7087 return NULL;
7088 }
7089
7090 init_method = descr_method;
7091 }
7092
7093 PyObject *result;
7094 if (is_compiled_function) {
7095 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7096 args, 8);
7097 } else {
7098 result = CALL_FUNCTION_WITH_POS_ARGS8(tstate, init_method, pos_args);
7099 Py_DECREF(init_method);
7100 }
7101 if (unlikely(result == NULL)) {
7102 return NULL;
7103 }
7104
7105 Py_DECREF(result);
7106
7107 if (unlikely(result != Py_None)) {
7108 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7109 return NULL;
7110 }
7111
7112 CHECK_OBJECT_X(obj);
7113
7114 return obj;
7115#endif
7116#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7117 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7118 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7119
7120 if (likely(func != NULL)) {
7121 PyObject *result = func(called, args, 8, NULL);
7122
7123 CHECK_OBJECT_X(result);
7124
7125 return Nuitka_CheckFunctionResult(tstate, called, result);
7126 }
7127#endif
7128 }
7129
7130#if 0
7131 PRINT_NEW_LINE();
7132 PRINT_STRING("FALLBACK");
7133 PRINT_ITEM(called);
7134 PRINT_NEW_LINE();
7135#endif
7136
7137 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7138
7139 CHECK_OBJECT_X(result);
7140
7141 return result;
7142}
7143PyObject *CALL_FUNCTION_WITH_ARGS9(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
7144 CHECK_OBJECT(called);
7145 CHECK_OBJECTS(args, 9);
7146
7147 if (Nuitka_Function_Check(called)) {
7148 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7149 return NULL;
7150 }
7151
7152 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7153 PyObject *result;
7154
7155 if (function->m_args_simple && 9 == function->m_args_positional_count) {
7156 for (Py_ssize_t i = 0; i < 9; i++) {
7157 Py_INCREF(args[i]);
7158 }
7159 result = function->m_c_code(tstate, function, (PyObject **)args);
7160 } else if (function->m_args_simple && 9 + function->m_defaults_given == function->m_args_positional_count) {
7161 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7162
7163 memcpy(python_pars, args, 9 * sizeof(PyObject *));
7164 memcpy(python_pars + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7165 function->m_defaults_given * sizeof(PyObject *));
7166
7167 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
7168 Py_INCREF(python_pars[i]);
7169 }
7170
7171 result = function->m_c_code(tstate, function, python_pars);
7172 } else {
7173 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 9);
7174 }
7175
7176 Py_LeaveRecursiveCall();
7177
7178 CHECK_OBJECT_X(result);
7179
7180 return result;
7181 } else if (Nuitka_Method_Check(called)) {
7182 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
7183
7184 if (method->m_object == NULL) {
7185 PyObject *self = args[0];
7186
7187 int res = PyObject_IsInstance(self, method->m_class);
7188
7189 if (unlikely(res < 0)) {
7190 return NULL;
7191 } else if (unlikely(res == 0)) {
7192 PyErr_Format(PyExc_TypeError,
7193 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
7194 "instance instead)",
7195 GET_CALLABLE_NAME((PyObject *)method->m_function),
7196 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
7197 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
7198
7199 return NULL;
7200 }
7201
7202 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 9);
7203
7204 CHECK_OBJECT_X(result);
7205
7206 return result;
7207 } else {
7208 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7209 return NULL;
7210 }
7211
7212 struct Nuitka_FunctionObject *function = method->m_function;
7213
7214 PyObject *result;
7215
7216 if (function->m_args_simple && 9 + 1 == function->m_args_positional_count) {
7217 PyObject *python_pars[9 + 1];
7218
7219 python_pars[0] = method->m_object;
7220 Py_INCREF(method->m_object);
7221
7222 for (Py_ssize_t i = 0; i < 9; i++) {
7223 python_pars[i + 1] = args[i];
7224 Py_INCREF(args[i]);
7225 }
7226 result = function->m_c_code(tstate, function, python_pars);
7227 } else if (function->m_args_simple &&
7228 9 + 1 + function->m_defaults_given == function->m_args_positional_count) {
7229 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7230
7231 python_pars[0] = method->m_object;
7232 Py_INCREF(method->m_object);
7233
7234 memcpy(python_pars + 1, args, 9 * sizeof(PyObject *));
7235 memcpy(python_pars + 1 + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7236 function->m_defaults_given * sizeof(PyObject *));
7237
7238 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
7239 Py_INCREF(python_pars[i]);
7240 }
7241
7242 result = function->m_c_code(tstate, function, python_pars);
7243 } else {
7244 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 9);
7245 }
7246
7247 Py_LeaveRecursiveCall();
7248
7249 CHECK_OBJECT_X(result);
7250
7251 return result;
7252 }
7253#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
7254 } else if (PyCFunction_CheckExact(called)) {
7255#if PYTHON_VERSION >= 0x380
7256#ifdef _NUITKA_FULL_COMPAT
7257 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7258 return NULL;
7259 }
7260#endif
7261
7262 int flags = PyCFunction_GET_FLAGS(called);
7263
7264 PyObject *result;
7265
7266 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7267
7268 if (func != NULL) {
7269 result = func(called, args, 9, NULL);
7270
7271 CHECK_OBJECT_X(result);
7272 } else {
7273 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7274 PyObject *self = PyCFunction_GET_SELF(called);
7275
7276 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7277
7278 if (flags & METH_KEYWORDS) {
7279 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
7280 } else {
7281 result = (*method)(self, pos_args);
7282 }
7283
7284 Py_DECREF(pos_args);
7285 }
7286
7287#ifdef _NUITKA_FULL_COMPAT
7288 Py_LeaveRecursiveCall();
7289#endif
7290 CHECK_OBJECT_X(result);
7291
7292 return Nuitka_CheckFunctionResult(tstate, called, result);
7293#else
7294 // Try to be fast about wrapping the arguments.
7295 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
7296
7297 if (unlikely(flags & METH_NOARGS)) {
7298 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (9 given)",
7299 ((PyCFunctionObject *)called)->m_ml->ml_name);
7300 return NULL;
7301 } else if (unlikely(flags & METH_O)) {
7302 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (9 given)",
7303 ((PyCFunctionObject *)called)->m_ml->ml_name);
7304 return NULL;
7305 } else if (flags & METH_VARARGS) {
7306 // Recursion guard is not strictly necessary, as we already have
7307 // one on our way to here.
7308#ifdef _NUITKA_FULL_COMPAT
7309 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7310 return NULL;
7311 }
7312#endif
7313 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7314 PyObject *self = PyCFunction_GET_SELF(called);
7315
7316 PyObject *result;
7317
7318#if PYTHON_VERSION < 0x360
7319 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7320 if (flags & METH_KEYWORDS) {
7321 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7322 } else {
7323 result = (*method)(self, pos_args);
7324 }
7325
7326 Py_DECREF(pos_args);
7327#else
7328 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
7329 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7330 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7331 Py_DECREF(pos_args);
7332 } else if (flags == METH_FASTCALL) {
7333#if PYTHON_VERSION < 0x370
7334 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 9, NULL);
7335#else
7336 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7337 result = (*(_PyCFunctionFast)method)(self, &pos_args, 9);
7338 Py_DECREF(pos_args);
7339#endif
7340 } else {
7341 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7342 result = (*method)(self, pos_args);
7343 Py_DECREF(pos_args);
7344 }
7345#endif
7346
7347#ifdef _NUITKA_FULL_COMPAT
7348 Py_LeaveRecursiveCall();
7349#endif
7350
7351 CHECK_OBJECT_X(result);
7352
7353 return Nuitka_CheckFunctionResult(tstate, called, result);
7354 }
7355#endif
7356#endif
7357#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
7358 } else if (PyFunction_Check(called)) {
7359#if PYTHON_VERSION < 0x3b0
7360 PyObject *result = callPythonFunction(called, args, 9);
7361#else
7362 PyObject *result = _PyFunction_Vectorcall(called, args, 9, NULL);
7363#endif
7364 CHECK_OBJECT_X(result);
7365
7366 return result;
7367#endif
7368#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
7369 } else if (PyType_Check(called)) {
7370 PyTypeObject *type = Py_TYPE(called);
7371
7372 if (type->tp_call == PyType_Type.tp_call) {
7373 PyTypeObject *called_type = (PyTypeObject *)(called);
7374
7375 if (unlikely(called_type->tp_new == NULL)) {
7376 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
7377 return NULL;
7378 }
7379
7380 PyObject *pos_args = NULL;
7381 PyObject *obj;
7382
7383 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
7384 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
7385 formatCannotInstantiateAbstractClass(tstate, called_type);
7386 return NULL;
7387 }
7388
7389 obj = called_type->tp_alloc(called_type, 0);
7390 CHECK_OBJECT(obj);
7391 } else {
7392 pos_args = MAKE_TUPLE(tstate, args, 9);
7393 obj = called_type->tp_new(called_type, pos_args, NULL);
7394 }
7395
7396 if (likely(obj != NULL)) {
7397 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
7398 Py_DECREF(pos_args);
7399 return obj;
7400 }
7401
7402 // Work on produced type.
7403 type = Py_TYPE(obj);
7404
7405 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7406 if (type->tp_init == default_tp_init_wrapper) {
7407 Py_XDECREF(pos_args);
7408 pos_args = NULL;
7409
7410 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7411
7412 // Not really allowed, since we wouldn't have the default wrapper set.
7413 assert(init_method != NULL);
7414
7415 bool is_compiled_function = false;
7416 bool init_method_needs_release = false;
7417
7418 if (likely(init_method != NULL)) {
7419 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7420
7421 if (func == Nuitka_Function_Type.tp_descr_get) {
7422 is_compiled_function = true;
7423 } else if (func != NULL) {
7424 init_method = func(init_method, obj, (PyObject *)(type));
7425 init_method_needs_release = true;
7426 }
7427 }
7428
7429 if (unlikely(init_method == NULL)) {
7430 if (!HAS_ERROR_OCCURRED(tstate)) {
7431 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7432 const_str_plain___init__);
7433 }
7434
7435 return NULL;
7436 }
7437
7438 PyObject *result;
7439 if (is_compiled_function) {
7440 result = Nuitka_CallMethodFunctionPosArgs(
7441 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 9);
7442 } else {
7443 result = CALL_FUNCTION_WITH_ARGS9(tstate, init_method, args);
7444 if (init_method_needs_release) {
7445 Py_DECREF(init_method);
7446 }
7447 }
7448
7449 if (unlikely(result == NULL)) {
7450 Py_DECREF(obj);
7451 return NULL;
7452 }
7453
7454 Py_DECREF(result);
7455
7456 if (unlikely(result != Py_None)) {
7457 Py_DECREF(obj);
7458
7459 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7460 return NULL;
7461 }
7462 } else {
7463 if (pos_args == NULL) {
7464 pos_args = MAKE_TUPLE(tstate, args, 9);
7465 }
7466
7467 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7468 Py_DECREF(obj);
7469 Py_XDECREF(pos_args);
7470 return NULL;
7471 }
7472 }
7473 }
7474 }
7475
7476 Py_XDECREF(pos_args);
7477
7478 CHECK_OBJECT_X(obj);
7479
7480 return obj;
7481 }
7482#endif
7483#if PYTHON_VERSION < 0x300
7484 } else if (PyClass_Check(called)) {
7485 PyObject *obj = PyInstance_NewRaw(called, NULL);
7486
7487 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7488
7489 if (unlikely(init_method == NULL)) {
7490 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7491 Py_DECREF(obj);
7492 return NULL;
7493 }
7494
7495 Py_DECREF(obj);
7496
7497 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7498 return NULL;
7499 }
7500
7501 bool is_compiled_function = false;
7502
7503 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7504
7505 if (descr_get == NULL) {
7506 Py_INCREF(init_method);
7507 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7508 is_compiled_function = true;
7509 } else if (descr_get != NULL) {
7510 PyObject *descr_method = descr_get(init_method, obj, called);
7511
7512 if (unlikely(descr_method == NULL)) {
7513 return NULL;
7514 }
7515
7516 init_method = descr_method;
7517 }
7518
7519 PyObject *result;
7520 if (is_compiled_function) {
7521 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7522 args, 9);
7523 } else {
7524 result = CALL_FUNCTION_WITH_ARGS9(tstate, init_method, args);
7525 Py_DECREF(init_method);
7526 }
7527 if (unlikely(result == NULL)) {
7528 return NULL;
7529 }
7530
7531 Py_DECREF(result);
7532
7533 if (unlikely(result != Py_None)) {
7534 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7535 return NULL;
7536 }
7537
7538 CHECK_OBJECT_X(obj);
7539
7540 return obj;
7541#endif
7542#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7543 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7544 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7545
7546 if (likely(func != NULL)) {
7547 PyObject *result = func(called, args, 9, NULL);
7548
7549 CHECK_OBJECT_X(result);
7550
7551 return Nuitka_CheckFunctionResult(tstate, called, result);
7552 }
7553#endif
7554 }
7555
7556#if 0
7557 PRINT_NEW_LINE();
7558 PRINT_STRING("FALLBACK");
7559 PRINT_ITEM(called);
7560 PRINT_NEW_LINE();
7561#endif
7562
7563 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7564
7565 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7566
7567 Py_DECREF(pos_args);
7568
7569 CHECK_OBJECT_X(result);
7570
7571 return result;
7572}
7573PyObject *CALL_FUNCTION_WITH_POS_ARGS9(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
7574 assert(PyTuple_CheckExact(pos_args));
7575 assert(PyTuple_GET_SIZE(pos_args) == 9);
7576 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
7577 CHECK_OBJECT(called);
7578 CHECK_OBJECTS(args, 9);
7579
7580 if (Nuitka_Function_Check(called)) {
7581 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7582 return NULL;
7583 }
7584
7585 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7586 PyObject *result;
7587
7588 if (function->m_args_simple && 9 == function->m_args_positional_count) {
7589 for (Py_ssize_t i = 0; i < 9; i++) {
7590 Py_INCREF(args[i]);
7591 }
7592 result = function->m_c_code(tstate, function, (PyObject **)args);
7593 } else if (function->m_args_simple && 9 + function->m_defaults_given == function->m_args_positional_count) {
7594 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7595
7596 memcpy(python_pars, args, 9 * sizeof(PyObject *));
7597 memcpy(python_pars + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7598 function->m_defaults_given * sizeof(PyObject *));
7599
7600 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
7601 Py_INCREF(python_pars[i]);
7602 }
7603
7604 result = function->m_c_code(tstate, function, python_pars);
7605 } else {
7606 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 9);
7607 }
7608
7609 Py_LeaveRecursiveCall();
7610
7611 CHECK_OBJECT_X(result);
7612
7613 return result;
7614 } else if (Nuitka_Method_Check(called)) {
7615 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
7616
7617 if (method->m_object == NULL) {
7618 PyObject *self = args[0];
7619
7620 int res = PyObject_IsInstance(self, method->m_class);
7621
7622 if (unlikely(res < 0)) {
7623 return NULL;
7624 } else if (unlikely(res == 0)) {
7625 PyErr_Format(PyExc_TypeError,
7626 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
7627 "instance instead)",
7628 GET_CALLABLE_NAME((PyObject *)method->m_function),
7629 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
7630 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
7631
7632 return NULL;
7633 }
7634
7635 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 9);
7636
7637 CHECK_OBJECT_X(result);
7638
7639 return result;
7640 } else {
7641 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7642 return NULL;
7643 }
7644
7645 struct Nuitka_FunctionObject *function = method->m_function;
7646
7647 PyObject *result;
7648
7649 if (function->m_args_simple && 9 + 1 == function->m_args_positional_count) {
7650 PyObject *python_pars[9 + 1];
7651
7652 python_pars[0] = method->m_object;
7653 Py_INCREF(method->m_object);
7654
7655 for (Py_ssize_t i = 0; i < 9; i++) {
7656 python_pars[i + 1] = args[i];
7657 Py_INCREF(args[i]);
7658 }
7659 result = function->m_c_code(tstate, function, python_pars);
7660 } else if (function->m_args_simple &&
7661 9 + 1 + function->m_defaults_given == function->m_args_positional_count) {
7662 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7663
7664 python_pars[0] = method->m_object;
7665 Py_INCREF(method->m_object);
7666
7667 memcpy(python_pars + 1, args, 9 * sizeof(PyObject *));
7668 memcpy(python_pars + 1 + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7669 function->m_defaults_given * sizeof(PyObject *));
7670
7671 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
7672 Py_INCREF(python_pars[i]);
7673 }
7674
7675 result = function->m_c_code(tstate, function, python_pars);
7676 } else {
7677 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 9);
7678 }
7679
7680 Py_LeaveRecursiveCall();
7681
7682 CHECK_OBJECT_X(result);
7683
7684 return result;
7685 }
7686#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
7687 } else if (PyCFunction_CheckExact(called)) {
7688#if PYTHON_VERSION >= 0x380
7689#ifdef _NUITKA_FULL_COMPAT
7690 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7691 return NULL;
7692 }
7693#endif
7694
7695 int flags = PyCFunction_GET_FLAGS(called);
7696
7697 PyObject *result;
7698
7699 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7700
7701 if (func != NULL) {
7702 result = func(called, args, 9, NULL);
7703
7704 CHECK_OBJECT_X(result);
7705 } else {
7706 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7707 PyObject *self = PyCFunction_GET_SELF(called);
7708
7709 if (flags & METH_KEYWORDS) {
7710 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
7711 } else {
7712 result = (*method)(self, pos_args);
7713 }
7714 }
7715
7716#ifdef _NUITKA_FULL_COMPAT
7717 Py_LeaveRecursiveCall();
7718#endif
7719 CHECK_OBJECT_X(result);
7720
7721 return Nuitka_CheckFunctionResult(tstate, called, result);
7722#else
7723 // Try to be fast about wrapping the arguments.
7724 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
7725
7726 if (unlikely(flags & METH_NOARGS)) {
7727 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (9 given)",
7728 ((PyCFunctionObject *)called)->m_ml->ml_name);
7729 return NULL;
7730 } else if (unlikely(flags & METH_O)) {
7731 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (9 given)",
7732 ((PyCFunctionObject *)called)->m_ml->ml_name);
7733 return NULL;
7734 } else if (flags & METH_VARARGS) {
7735 // Recursion guard is not strictly necessary, as we already have
7736 // one on our way to here.
7737#ifdef _NUITKA_FULL_COMPAT
7738 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7739 return NULL;
7740 }
7741#endif
7742 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7743 PyObject *self = PyCFunction_GET_SELF(called);
7744
7745 PyObject *result;
7746
7747#if PYTHON_VERSION < 0x360
7748 if (flags & METH_KEYWORDS) {
7749 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7750 } else {
7751 result = (*method)(self, pos_args);
7752 }
7753
7754#else
7755 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
7756 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7757 } else if (flags == METH_FASTCALL) {
7758#if PYTHON_VERSION < 0x370
7759 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 9, NULL);
7760#else
7761 result = (*(_PyCFunctionFast)method)(self, &pos_args, 9);
7762#endif
7763 } else {
7764 result = (*method)(self, pos_args);
7765 }
7766#endif
7767
7768#ifdef _NUITKA_FULL_COMPAT
7769 Py_LeaveRecursiveCall();
7770#endif
7771
7772 CHECK_OBJECT_X(result);
7773
7774 return Nuitka_CheckFunctionResult(tstate, called, result);
7775 }
7776#endif
7777#endif
7778#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
7779 } else if (PyFunction_Check(called)) {
7780#if PYTHON_VERSION < 0x3b0
7781 PyObject *result = callPythonFunction(called, args, 9);
7782#else
7783 PyObject *result = _PyFunction_Vectorcall(called, args, 9, NULL);
7784#endif
7785 CHECK_OBJECT_X(result);
7786
7787 return result;
7788#endif
7789#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
7790 } else if (PyType_Check(called)) {
7791 PyTypeObject *type = Py_TYPE(called);
7792
7793 if (type->tp_call == PyType_Type.tp_call) {
7794 PyTypeObject *called_type = (PyTypeObject *)(called);
7795
7796 if (unlikely(called_type->tp_new == NULL)) {
7797 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
7798 return NULL;
7799 }
7800
7801 PyObject *obj;
7802
7803 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
7804 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
7805 formatCannotInstantiateAbstractClass(tstate, called_type);
7806 return NULL;
7807 }
7808
7809 obj = called_type->tp_alloc(called_type, 0);
7810 CHECK_OBJECT(obj);
7811 } else {
7812 obj = called_type->tp_new(called_type, pos_args, NULL);
7813 }
7814
7815 if (likely(obj != NULL)) {
7816 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
7817 return obj;
7818 }
7819
7820 // Work on produced type.
7821 type = Py_TYPE(obj);
7822
7823 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7824 if (type->tp_init == default_tp_init_wrapper) {
7825
7826 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7827
7828 // Not really allowed, since we wouldn't have the default wrapper set.
7829 assert(init_method != NULL);
7830
7831 bool is_compiled_function = false;
7832 bool init_method_needs_release = false;
7833
7834 if (likely(init_method != NULL)) {
7835 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7836
7837 if (func == Nuitka_Function_Type.tp_descr_get) {
7838 is_compiled_function = true;
7839 } else if (func != NULL) {
7840 init_method = func(init_method, obj, (PyObject *)(type));
7841 init_method_needs_release = true;
7842 }
7843 }
7844
7845 if (unlikely(init_method == NULL)) {
7846 if (!HAS_ERROR_OCCURRED(tstate)) {
7847 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7848 const_str_plain___init__);
7849 }
7850
7851 return NULL;
7852 }
7853
7854 PyObject *result;
7855 if (is_compiled_function) {
7856 result = Nuitka_CallMethodFunctionPosArgs(
7857 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 9);
7858 } else {
7859 result = CALL_FUNCTION_WITH_POS_ARGS9(tstate, init_method, pos_args);
7860 if (init_method_needs_release) {
7861 Py_DECREF(init_method);
7862 }
7863 }
7864
7865 if (unlikely(result == NULL)) {
7866 Py_DECREF(obj);
7867 return NULL;
7868 }
7869
7870 Py_DECREF(result);
7871
7872 if (unlikely(result != Py_None)) {
7873 Py_DECREF(obj);
7874
7875 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7876 return NULL;
7877 }
7878 } else {
7879
7880 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7881 Py_DECREF(obj);
7882 return NULL;
7883 }
7884 }
7885 }
7886 }
7887
7888 CHECK_OBJECT_X(obj);
7889
7890 return obj;
7891 }
7892#endif
7893#if PYTHON_VERSION < 0x300
7894 } else if (PyClass_Check(called)) {
7895 PyObject *obj = PyInstance_NewRaw(called, NULL);
7896
7897 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7898
7899 if (unlikely(init_method == NULL)) {
7900 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7901 Py_DECREF(obj);
7902 return NULL;
7903 }
7904
7905 Py_DECREF(obj);
7906
7907 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7908 return NULL;
7909 }
7910
7911 bool is_compiled_function = false;
7912
7913 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7914
7915 if (descr_get == NULL) {
7916 Py_INCREF(init_method);
7917 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7918 is_compiled_function = true;
7919 } else if (descr_get != NULL) {
7920 PyObject *descr_method = descr_get(init_method, obj, called);
7921
7922 if (unlikely(descr_method == NULL)) {
7923 return NULL;
7924 }
7925
7926 init_method = descr_method;
7927 }
7928
7929 PyObject *result;
7930 if (is_compiled_function) {
7931 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7932 args, 9);
7933 } else {
7934 result = CALL_FUNCTION_WITH_POS_ARGS9(tstate, init_method, pos_args);
7935 Py_DECREF(init_method);
7936 }
7937 if (unlikely(result == NULL)) {
7938 return NULL;
7939 }
7940
7941 Py_DECREF(result);
7942
7943 if (unlikely(result != Py_None)) {
7944 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7945 return NULL;
7946 }
7947
7948 CHECK_OBJECT_X(obj);
7949
7950 return obj;
7951#endif
7952#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7953 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7954 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7955
7956 if (likely(func != NULL)) {
7957 PyObject *result = func(called, args, 9, NULL);
7958
7959 CHECK_OBJECT_X(result);
7960
7961 return Nuitka_CheckFunctionResult(tstate, called, result);
7962 }
7963#endif
7964 }
7965
7966#if 0
7967 PRINT_NEW_LINE();
7968 PRINT_STRING("FALLBACK");
7969 PRINT_ITEM(called);
7970 PRINT_NEW_LINE();
7971#endif
7972
7973 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7974
7975 CHECK_OBJECT_X(result);
7976
7977 return result;
7978}
7979PyObject *CALL_FUNCTION_WITH_ARGS10(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
7980 CHECK_OBJECT(called);
7981 CHECK_OBJECTS(args, 10);
7982
7983 if (Nuitka_Function_Check(called)) {
7984 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7985 return NULL;
7986 }
7987
7988 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7989 PyObject *result;
7990
7991 if (function->m_args_simple && 10 == function->m_args_positional_count) {
7992 for (Py_ssize_t i = 0; i < 10; i++) {
7993 Py_INCREF(args[i]);
7994 }
7995 result = function->m_c_code(tstate, function, (PyObject **)args);
7996 } else if (function->m_args_simple && 10 + function->m_defaults_given == function->m_args_positional_count) {
7997 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7998
7999 memcpy(python_pars, args, 10 * sizeof(PyObject *));
8000 memcpy(python_pars + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8001 function->m_defaults_given * sizeof(PyObject *));
8002
8003 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
8004 Py_INCREF(python_pars[i]);
8005 }
8006
8007 result = function->m_c_code(tstate, function, python_pars);
8008 } else {
8009 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 10);
8010 }
8011
8012 Py_LeaveRecursiveCall();
8013
8014 CHECK_OBJECT_X(result);
8015
8016 return result;
8017 } else if (Nuitka_Method_Check(called)) {
8018 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
8019
8020 if (method->m_object == NULL) {
8021 PyObject *self = args[0];
8022
8023 int res = PyObject_IsInstance(self, method->m_class);
8024
8025 if (unlikely(res < 0)) {
8026 return NULL;
8027 } else if (unlikely(res == 0)) {
8028 PyErr_Format(PyExc_TypeError,
8029 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
8030 "instance instead)",
8031 GET_CALLABLE_NAME((PyObject *)method->m_function),
8032 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
8033 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
8034
8035 return NULL;
8036 }
8037
8038 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 10);
8039
8040 CHECK_OBJECT_X(result);
8041
8042 return result;
8043 } else {
8044 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8045 return NULL;
8046 }
8047
8048 struct Nuitka_FunctionObject *function = method->m_function;
8049
8050 PyObject *result;
8051
8052 if (function->m_args_simple && 10 + 1 == function->m_args_positional_count) {
8053 PyObject *python_pars[10 + 1];
8054
8055 python_pars[0] = method->m_object;
8056 Py_INCREF(method->m_object);
8057
8058 for (Py_ssize_t i = 0; i < 10; i++) {
8059 python_pars[i + 1] = args[i];
8060 Py_INCREF(args[i]);
8061 }
8062 result = function->m_c_code(tstate, function, python_pars);
8063 } else if (function->m_args_simple &&
8064 10 + 1 + function->m_defaults_given == function->m_args_positional_count) {
8065 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8066
8067 python_pars[0] = method->m_object;
8068 Py_INCREF(method->m_object);
8069
8070 memcpy(python_pars + 1, args, 10 * sizeof(PyObject *));
8071 memcpy(python_pars + 1 + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8072 function->m_defaults_given * sizeof(PyObject *));
8073
8074 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
8075 Py_INCREF(python_pars[i]);
8076 }
8077
8078 result = function->m_c_code(tstate, function, python_pars);
8079 } else {
8080 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 10);
8081 }
8082
8083 Py_LeaveRecursiveCall();
8084
8085 CHECK_OBJECT_X(result);
8086
8087 return result;
8088 }
8089#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
8090 } else if (PyCFunction_CheckExact(called)) {
8091#if PYTHON_VERSION >= 0x380
8092#ifdef _NUITKA_FULL_COMPAT
8093 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8094 return NULL;
8095 }
8096#endif
8097
8098 int flags = PyCFunction_GET_FLAGS(called);
8099
8100 PyObject *result;
8101
8102 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8103
8104 if (func != NULL) {
8105 result = func(called, args, 10, NULL);
8106
8107 CHECK_OBJECT_X(result);
8108 } else {
8109 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8110 PyObject *self = PyCFunction_GET_SELF(called);
8111
8112 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8113
8114 if (flags & METH_KEYWORDS) {
8115 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
8116 } else {
8117 result = (*method)(self, pos_args);
8118 }
8119
8120 Py_DECREF(pos_args);
8121 }
8122
8123#ifdef _NUITKA_FULL_COMPAT
8124 Py_LeaveRecursiveCall();
8125#endif
8126 CHECK_OBJECT_X(result);
8127
8128 return Nuitka_CheckFunctionResult(tstate, called, result);
8129#else
8130 // Try to be fast about wrapping the arguments.
8131 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
8132
8133 if (unlikely(flags & METH_NOARGS)) {
8134 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (10 given)",
8135 ((PyCFunctionObject *)called)->m_ml->ml_name);
8136 return NULL;
8137 } else if (unlikely(flags & METH_O)) {
8138 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (10 given)",
8139 ((PyCFunctionObject *)called)->m_ml->ml_name);
8140 return NULL;
8141 } else if (flags & METH_VARARGS) {
8142 // Recursion guard is not strictly necessary, as we already have
8143 // one on our way to here.
8144#ifdef _NUITKA_FULL_COMPAT
8145 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8146 return NULL;
8147 }
8148#endif
8149 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8150 PyObject *self = PyCFunction_GET_SELF(called);
8151
8152 PyObject *result;
8153
8154#if PYTHON_VERSION < 0x360
8155 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8156 if (flags & METH_KEYWORDS) {
8157 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8158 } else {
8159 result = (*method)(self, pos_args);
8160 }
8161
8162 Py_DECREF(pos_args);
8163#else
8164 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
8165 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8166 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8167 Py_DECREF(pos_args);
8168 } else if (flags == METH_FASTCALL) {
8169#if PYTHON_VERSION < 0x370
8170 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 10, NULL);
8171#else
8172 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8173 result = (*(_PyCFunctionFast)method)(self, &pos_args, 10);
8174 Py_DECREF(pos_args);
8175#endif
8176 } else {
8177 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8178 result = (*method)(self, pos_args);
8179 Py_DECREF(pos_args);
8180 }
8181#endif
8182
8183#ifdef _NUITKA_FULL_COMPAT
8184 Py_LeaveRecursiveCall();
8185#endif
8186
8187 CHECK_OBJECT_X(result);
8188
8189 return Nuitka_CheckFunctionResult(tstate, called, result);
8190 }
8191#endif
8192#endif
8193#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
8194 } else if (PyFunction_Check(called)) {
8195#if PYTHON_VERSION < 0x3b0
8196 PyObject *result = callPythonFunction(called, args, 10);
8197#else
8198 PyObject *result = _PyFunction_Vectorcall(called, args, 10, NULL);
8199#endif
8200 CHECK_OBJECT_X(result);
8201
8202 return result;
8203#endif
8204#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
8205 } else if (PyType_Check(called)) {
8206 PyTypeObject *type = Py_TYPE(called);
8207
8208 if (type->tp_call == PyType_Type.tp_call) {
8209 PyTypeObject *called_type = (PyTypeObject *)(called);
8210
8211 if (unlikely(called_type->tp_new == NULL)) {
8212 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
8213 return NULL;
8214 }
8215
8216 PyObject *pos_args = NULL;
8217 PyObject *obj;
8218
8219 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
8220 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
8221 formatCannotInstantiateAbstractClass(tstate, called_type);
8222 return NULL;
8223 }
8224
8225 obj = called_type->tp_alloc(called_type, 0);
8226 CHECK_OBJECT(obj);
8227 } else {
8228 pos_args = MAKE_TUPLE(tstate, args, 10);
8229 obj = called_type->tp_new(called_type, pos_args, NULL);
8230 }
8231
8232 if (likely(obj != NULL)) {
8233 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
8234 Py_DECREF(pos_args);
8235 return obj;
8236 }
8237
8238 // Work on produced type.
8239 type = Py_TYPE(obj);
8240
8241 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
8242 if (type->tp_init == default_tp_init_wrapper) {
8243 Py_XDECREF(pos_args);
8244 pos_args = NULL;
8245
8246 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
8247
8248 // Not really allowed, since we wouldn't have the default wrapper set.
8249 assert(init_method != NULL);
8250
8251 bool is_compiled_function = false;
8252 bool init_method_needs_release = false;
8253
8254 if (likely(init_method != NULL)) {
8255 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
8256
8257 if (func == Nuitka_Function_Type.tp_descr_get) {
8258 is_compiled_function = true;
8259 } else if (func != NULL) {
8260 init_method = func(init_method, obj, (PyObject *)(type));
8261 init_method_needs_release = true;
8262 }
8263 }
8264
8265 if (unlikely(init_method == NULL)) {
8266 if (!HAS_ERROR_OCCURRED(tstate)) {
8267 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
8268 const_str_plain___init__);
8269 }
8270
8271 return NULL;
8272 }
8273
8274 PyObject *result;
8275 if (is_compiled_function) {
8276 result = Nuitka_CallMethodFunctionPosArgs(
8277 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 10);
8278 } else {
8279 result = CALL_FUNCTION_WITH_ARGS10(tstate, init_method, args);
8280 if (init_method_needs_release) {
8281 Py_DECREF(init_method);
8282 }
8283 }
8284
8285 if (unlikely(result == NULL)) {
8286 Py_DECREF(obj);
8287 return NULL;
8288 }
8289
8290 Py_DECREF(result);
8291
8292 if (unlikely(result != Py_None)) {
8293 Py_DECREF(obj);
8294
8295 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8296 return NULL;
8297 }
8298 } else {
8299 if (pos_args == NULL) {
8300 pos_args = MAKE_TUPLE(tstate, args, 10);
8301 }
8302
8303 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
8304 Py_DECREF(obj);
8305 Py_XDECREF(pos_args);
8306 return NULL;
8307 }
8308 }
8309 }
8310 }
8311
8312 Py_XDECREF(pos_args);
8313
8314 CHECK_OBJECT_X(obj);
8315
8316 return obj;
8317 }
8318#endif
8319#if PYTHON_VERSION < 0x300
8320 } else if (PyClass_Check(called)) {
8321 PyObject *obj = PyInstance_NewRaw(called, NULL);
8322
8323 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
8324
8325 if (unlikely(init_method == NULL)) {
8326 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
8327 Py_DECREF(obj);
8328 return NULL;
8329 }
8330
8331 Py_DECREF(obj);
8332
8333 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
8334 return NULL;
8335 }
8336
8337 bool is_compiled_function = false;
8338
8339 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
8340
8341 if (descr_get == NULL) {
8342 Py_INCREF(init_method);
8343 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
8344 is_compiled_function = true;
8345 } else if (descr_get != NULL) {
8346 PyObject *descr_method = descr_get(init_method, obj, called);
8347
8348 if (unlikely(descr_method == NULL)) {
8349 return NULL;
8350 }
8351
8352 init_method = descr_method;
8353 }
8354
8355 PyObject *result;
8356 if (is_compiled_function) {
8357 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
8358 args, 10);
8359 } else {
8360 result = CALL_FUNCTION_WITH_ARGS10(tstate, init_method, args);
8361 Py_DECREF(init_method);
8362 }
8363 if (unlikely(result == NULL)) {
8364 return NULL;
8365 }
8366
8367 Py_DECREF(result);
8368
8369 if (unlikely(result != Py_None)) {
8370 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8371 return NULL;
8372 }
8373
8374 CHECK_OBJECT_X(obj);
8375
8376 return obj;
8377#endif
8378#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8379 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8380 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8381
8382 if (likely(func != NULL)) {
8383 PyObject *result = func(called, args, 10, NULL);
8384
8385 CHECK_OBJECT_X(result);
8386
8387 return Nuitka_CheckFunctionResult(tstate, called, result);
8388 }
8389#endif
8390 }
8391
8392#if 0
8393 PRINT_NEW_LINE();
8394 PRINT_STRING("FALLBACK");
8395 PRINT_ITEM(called);
8396 PRINT_NEW_LINE();
8397#endif
8398
8399 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8400
8401 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
8402
8403 Py_DECREF(pos_args);
8404
8405 CHECK_OBJECT_X(result);
8406
8407 return result;
8408}
8409PyObject *CALL_FUNCTION_WITH_POS_ARGS10(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
8410 assert(PyTuple_CheckExact(pos_args));
8411 assert(PyTuple_GET_SIZE(pos_args) == 10);
8412 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
8413 CHECK_OBJECT(called);
8414 CHECK_OBJECTS(args, 10);
8415
8416 if (Nuitka_Function_Check(called)) {
8417 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8418 return NULL;
8419 }
8420
8421 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8422 PyObject *result;
8423
8424 if (function->m_args_simple && 10 == function->m_args_positional_count) {
8425 for (Py_ssize_t i = 0; i < 10; i++) {
8426 Py_INCREF(args[i]);
8427 }
8428 result = function->m_c_code(tstate, function, (PyObject **)args);
8429 } else if (function->m_args_simple && 10 + function->m_defaults_given == function->m_args_positional_count) {
8430 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8431
8432 memcpy(python_pars, args, 10 * sizeof(PyObject *));
8433 memcpy(python_pars + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8434 function->m_defaults_given * sizeof(PyObject *));
8435
8436 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
8437 Py_INCREF(python_pars[i]);
8438 }
8439
8440 result = function->m_c_code(tstate, function, python_pars);
8441 } else {
8442 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 10);
8443 }
8444
8445 Py_LeaveRecursiveCall();
8446
8447 CHECK_OBJECT_X(result);
8448
8449 return result;
8450 } else if (Nuitka_Method_Check(called)) {
8451 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
8452
8453 if (method->m_object == NULL) {
8454 PyObject *self = args[0];
8455
8456 int res = PyObject_IsInstance(self, method->m_class);
8457
8458 if (unlikely(res < 0)) {
8459 return NULL;
8460 } else if (unlikely(res == 0)) {
8461 PyErr_Format(PyExc_TypeError,
8462 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
8463 "instance instead)",
8464 GET_CALLABLE_NAME((PyObject *)method->m_function),
8465 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
8466 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
8467
8468 return NULL;
8469 }
8470
8471 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 10);
8472
8473 CHECK_OBJECT_X(result);
8474
8475 return result;
8476 } else {
8477 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8478 return NULL;
8479 }
8480
8481 struct Nuitka_FunctionObject *function = method->m_function;
8482
8483 PyObject *result;
8484
8485 if (function->m_args_simple && 10 + 1 == function->m_args_positional_count) {
8486 PyObject *python_pars[10 + 1];
8487
8488 python_pars[0] = method->m_object;
8489 Py_INCREF(method->m_object);
8490
8491 for (Py_ssize_t i = 0; i < 10; i++) {
8492 python_pars[i + 1] = args[i];
8493 Py_INCREF(args[i]);
8494 }
8495 result = function->m_c_code(tstate, function, python_pars);
8496 } else if (function->m_args_simple &&
8497 10 + 1 + function->m_defaults_given == function->m_args_positional_count) {
8498 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8499
8500 python_pars[0] = method->m_object;
8501 Py_INCREF(method->m_object);
8502
8503 memcpy(python_pars + 1, args, 10 * sizeof(PyObject *));
8504 memcpy(python_pars + 1 + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8505 function->m_defaults_given * sizeof(PyObject *));
8506
8507 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
8508 Py_INCREF(python_pars[i]);
8509 }
8510
8511 result = function->m_c_code(tstate, function, python_pars);
8512 } else {
8513 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 10);
8514 }
8515
8516 Py_LeaveRecursiveCall();
8517
8518 CHECK_OBJECT_X(result);
8519
8520 return result;
8521 }
8522#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
8523 } else if (PyCFunction_CheckExact(called)) {
8524#if PYTHON_VERSION >= 0x380
8525#ifdef _NUITKA_FULL_COMPAT
8526 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8527 return NULL;
8528 }
8529#endif
8530
8531 int flags = PyCFunction_GET_FLAGS(called);
8532
8533 PyObject *result;
8534
8535 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8536
8537 if (func != NULL) {
8538 result = func(called, args, 10, NULL);
8539
8540 CHECK_OBJECT_X(result);
8541 } else {
8542 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8543 PyObject *self = PyCFunction_GET_SELF(called);
8544
8545 if (flags & METH_KEYWORDS) {
8546 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
8547 } else {
8548 result = (*method)(self, pos_args);
8549 }
8550 }
8551
8552#ifdef _NUITKA_FULL_COMPAT
8553 Py_LeaveRecursiveCall();
8554#endif
8555 CHECK_OBJECT_X(result);
8556
8557 return Nuitka_CheckFunctionResult(tstate, called, result);
8558#else
8559 // Try to be fast about wrapping the arguments.
8560 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
8561
8562 if (unlikely(flags & METH_NOARGS)) {
8563 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (10 given)",
8564 ((PyCFunctionObject *)called)->m_ml->ml_name);
8565 return NULL;
8566 } else if (unlikely(flags & METH_O)) {
8567 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (10 given)",
8568 ((PyCFunctionObject *)called)->m_ml->ml_name);
8569 return NULL;
8570 } else if (flags & METH_VARARGS) {
8571 // Recursion guard is not strictly necessary, as we already have
8572 // one on our way to here.
8573#ifdef _NUITKA_FULL_COMPAT
8574 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8575 return NULL;
8576 }
8577#endif
8578 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8579 PyObject *self = PyCFunction_GET_SELF(called);
8580
8581 PyObject *result;
8582
8583#if PYTHON_VERSION < 0x360
8584 if (flags & METH_KEYWORDS) {
8585 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8586 } else {
8587 result = (*method)(self, pos_args);
8588 }
8589
8590#else
8591 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
8592 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8593 } else if (flags == METH_FASTCALL) {
8594#if PYTHON_VERSION < 0x370
8595 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 10, NULL);
8596#else
8597 result = (*(_PyCFunctionFast)method)(self, &pos_args, 10);
8598#endif
8599 } else {
8600 result = (*method)(self, pos_args);
8601 }
8602#endif
8603
8604#ifdef _NUITKA_FULL_COMPAT
8605 Py_LeaveRecursiveCall();
8606#endif
8607
8608 CHECK_OBJECT_X(result);
8609
8610 return Nuitka_CheckFunctionResult(tstate, called, result);
8611 }
8612#endif
8613#endif
8614#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
8615 } else if (PyFunction_Check(called)) {
8616#if PYTHON_VERSION < 0x3b0
8617 PyObject *result = callPythonFunction(called, args, 10);
8618#else
8619 PyObject *result = _PyFunction_Vectorcall(called, args, 10, NULL);
8620#endif
8621 CHECK_OBJECT_X(result);
8622
8623 return result;
8624#endif
8625#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
8626 } else if (PyType_Check(called)) {
8627 PyTypeObject *type = Py_TYPE(called);
8628
8629 if (type->tp_call == PyType_Type.tp_call) {
8630 PyTypeObject *called_type = (PyTypeObject *)(called);
8631
8632 if (unlikely(called_type->tp_new == NULL)) {
8633 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
8634 return NULL;
8635 }
8636
8637 PyObject *obj;
8638
8639 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
8640 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
8641 formatCannotInstantiateAbstractClass(tstate, called_type);
8642 return NULL;
8643 }
8644
8645 obj = called_type->tp_alloc(called_type, 0);
8646 CHECK_OBJECT(obj);
8647 } else {
8648 obj = called_type->tp_new(called_type, pos_args, NULL);
8649 }
8650
8651 if (likely(obj != NULL)) {
8652 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
8653 return obj;
8654 }
8655
8656 // Work on produced type.
8657 type = Py_TYPE(obj);
8658
8659 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
8660 if (type->tp_init == default_tp_init_wrapper) {
8661
8662 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
8663
8664 // Not really allowed, since we wouldn't have the default wrapper set.
8665 assert(init_method != NULL);
8666
8667 bool is_compiled_function = false;
8668 bool init_method_needs_release = false;
8669
8670 if (likely(init_method != NULL)) {
8671 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
8672
8673 if (func == Nuitka_Function_Type.tp_descr_get) {
8674 is_compiled_function = true;
8675 } else if (func != NULL) {
8676 init_method = func(init_method, obj, (PyObject *)(type));
8677 init_method_needs_release = true;
8678 }
8679 }
8680
8681 if (unlikely(init_method == NULL)) {
8682 if (!HAS_ERROR_OCCURRED(tstate)) {
8683 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
8684 const_str_plain___init__);
8685 }
8686
8687 return NULL;
8688 }
8689
8690 PyObject *result;
8691 if (is_compiled_function) {
8692 result = Nuitka_CallMethodFunctionPosArgs(
8693 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 10);
8694 } else {
8695 result = CALL_FUNCTION_WITH_POS_ARGS10(tstate, init_method, pos_args);
8696 if (init_method_needs_release) {
8697 Py_DECREF(init_method);
8698 }
8699 }
8700
8701 if (unlikely(result == NULL)) {
8702 Py_DECREF(obj);
8703 return NULL;
8704 }
8705
8706 Py_DECREF(result);
8707
8708 if (unlikely(result != Py_None)) {
8709 Py_DECREF(obj);
8710
8711 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8712 return NULL;
8713 }
8714 } else {
8715
8716 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
8717 Py_DECREF(obj);
8718 return NULL;
8719 }
8720 }
8721 }
8722 }
8723
8724 CHECK_OBJECT_X(obj);
8725
8726 return obj;
8727 }
8728#endif
8729#if PYTHON_VERSION < 0x300
8730 } else if (PyClass_Check(called)) {
8731 PyObject *obj = PyInstance_NewRaw(called, NULL);
8732
8733 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
8734
8735 if (unlikely(init_method == NULL)) {
8736 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
8737 Py_DECREF(obj);
8738 return NULL;
8739 }
8740
8741 Py_DECREF(obj);
8742
8743 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
8744 return NULL;
8745 }
8746
8747 bool is_compiled_function = false;
8748
8749 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
8750
8751 if (descr_get == NULL) {
8752 Py_INCREF(init_method);
8753 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
8754 is_compiled_function = true;
8755 } else if (descr_get != NULL) {
8756 PyObject *descr_method = descr_get(init_method, obj, called);
8757
8758 if (unlikely(descr_method == NULL)) {
8759 return NULL;
8760 }
8761
8762 init_method = descr_method;
8763 }
8764
8765 PyObject *result;
8766 if (is_compiled_function) {
8767 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
8768 args, 10);
8769 } else {
8770 result = CALL_FUNCTION_WITH_POS_ARGS10(tstate, init_method, pos_args);
8771 Py_DECREF(init_method);
8772 }
8773 if (unlikely(result == NULL)) {
8774 return NULL;
8775 }
8776
8777 Py_DECREF(result);
8778
8779 if (unlikely(result != Py_None)) {
8780 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8781 return NULL;
8782 }
8783
8784 CHECK_OBJECT_X(obj);
8785
8786 return obj;
8787#endif
8788#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8789 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8790 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8791
8792 if (likely(func != NULL)) {
8793 PyObject *result = func(called, args, 10, NULL);
8794
8795 CHECK_OBJECT_X(result);
8796
8797 return Nuitka_CheckFunctionResult(tstate, called, result);
8798 }
8799#endif
8800 }
8801
8802#if 0
8803 PRINT_NEW_LINE();
8804 PRINT_STRING("FALLBACK");
8805 PRINT_ITEM(called);
8806 PRINT_NEW_LINE();
8807#endif
8808
8809 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
8810
8811 CHECK_OBJECT_X(result);
8812
8813 return result;
8814}
8815PyObject *CALL_FUNCTION_WITH_NO_ARGS_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *kw_values,
8816 PyObject *kw_names) {
8817
8818 CHECK_OBJECT(kw_names);
8819 assert(PyTuple_CheckExact(kw_names));
8820 CHECK_OBJECT(called);
8821
8822 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
8823
8824 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
8825
8826 if (Nuitka_Function_Check(called)) {
8827 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8828 return NULL;
8829 }
8830
8831 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8832
8833 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, NULL, 0, kw_values, kw_names);
8834
8835 Py_LeaveRecursiveCall();
8836
8837 CHECK_OBJECT_X(result);
8838
8839 return result;
8840#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8841 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8842 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8843
8844 if (likely(func != NULL)) {
8845 PyObject *result = func(called, kw_values, 0, kw_names);
8846
8847 CHECK_OBJECT_X(result);
8848
8849 return Nuitka_CheckFunctionResult(tstate, called, result);
8850 }
8851#endif
8852 }
8853
8854#if 0
8855 PRINT_STRING("FALLBACK");
8856 PRINT_ITEM(called);
8857 PRINT_NEW_LINE();
8858#endif
8859
8860 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
8861
8862 if (unlikely(call_slot == NULL)) {
8863 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
8864
8865 return NULL;
8866 }
8867
8868 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8869 return NULL;
8870 }
8871
8872 PyObject *pos_args = const_tuple_empty;
8873
8874 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
8875
8876 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
8877 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
8878
8879 PyObject *value = kw_values[i];
8880
8881 CHECK_OBJECT(key);
8882 CHECK_OBJECT(value);
8883
8884 DICT_SET_ITEM(named_args, key, value);
8885 }
8886
8887 PyObject *result = (*call_slot)(called, pos_args, named_args);
8888
8889 Py_DECREF(named_args);
8890
8891 Py_LeaveRecursiveCall();
8892
8893 CHECK_OBJECT_X(result);
8894
8895 return Nuitka_CheckFunctionResult(tstate, called, result);
8896}
8897PyObject *CALL_FUNCTION_WITH_ARGS1_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
8898 PyObject *kw_names) {
8899 CHECK_OBJECTS(args, 1);
8900 CHECK_OBJECT(kw_names);
8901 assert(PyTuple_CheckExact(kw_names));
8902 CHECK_OBJECT(called);
8903
8904 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
8905
8906 CHECK_OBJECTS(&args[1], kwargs_count);
8907
8908 if (Nuitka_Function_Check(called)) {
8909 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8910 return NULL;
8911 }
8912
8913 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8914
8915 PyObject *result =
8916 Nuitka_CallFunctionVectorcall(tstate, function, args, 1, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
8917
8918 Py_LeaveRecursiveCall();
8919
8920 CHECK_OBJECT_X(result);
8921
8922 return result;
8923#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8924 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8925 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8926
8927 if (likely(func != NULL)) {
8928 PyObject *result = func(called, args, 1, kw_names);
8929
8930 CHECK_OBJECT_X(result);
8931
8932 return Nuitka_CheckFunctionResult(tstate, called, result);
8933 }
8934#endif
8935 }
8936
8937#if 0
8938 PRINT_STRING("FALLBACK");
8939 PRINT_ITEM(called);
8940 PRINT_NEW_LINE();
8941#endif
8942
8943 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
8944
8945 if (unlikely(call_slot == NULL)) {
8946 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
8947
8948 return NULL;
8949 }
8950
8951 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8952 return NULL;
8953 }
8954
8955 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
8956
8957 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
8958
8959 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
8960 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
8961
8962 PyObject *value = args[1 + i];
8963
8964 CHECK_OBJECT(key);
8965 CHECK_OBJECT(value);
8966
8967 DICT_SET_ITEM(named_args, key, value);
8968 }
8969
8970 PyObject *result = (*call_slot)(called, pos_args, named_args);
8971
8972 Py_DECREF(pos_args);
8973 Py_DECREF(named_args);
8974
8975 Py_LeaveRecursiveCall();
8976
8977 CHECK_OBJECT_X(result);
8978
8979 return Nuitka_CheckFunctionResult(tstate, called, result);
8980}
8981PyObject *CALL_FUNCTION_WITH_ARGS1_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
8982 PyObject *const *kw_values, PyObject *kw_names) {
8983 CHECK_OBJECTS(args, 1);
8984 CHECK_OBJECT(kw_names);
8985 assert(PyTuple_CheckExact(kw_names));
8986 CHECK_OBJECT(called);
8987
8988 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
8989
8990 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
8991
8992 if (Nuitka_Function_Check(called)) {
8993 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8994 return NULL;
8995 }
8996
8997 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8998
8999 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 1, kw_values, kw_names);
9000
9001 Py_LeaveRecursiveCall();
9002
9003 CHECK_OBJECT_X(result);
9004
9005 return result;
9006#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9007 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9008 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9009
9010 if (likely(func != NULL)) {
9011 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 1 + kwargs_count);
9012
9013 memcpy(vectorcall_args, args, 1 * sizeof(PyObject *));
9014 memcpy(&vectorcall_args[1], kw_values, kwargs_count * sizeof(PyObject *));
9015
9016 PyObject *result = func(called, vectorcall_args, 1, kw_names);
9017
9018 CHECK_OBJECT_X(result);
9019
9020 return Nuitka_CheckFunctionResult(tstate, called, result);
9021 }
9022#endif
9023 }
9024
9025#if 0
9026 PRINT_STRING("FALLBACK");
9027 PRINT_ITEM(called);
9028 PRINT_NEW_LINE();
9029#endif
9030
9031 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9032
9033 if (unlikely(call_slot == NULL)) {
9034 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9035
9036 return NULL;
9037 }
9038
9039 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9040 return NULL;
9041 }
9042
9043 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
9044
9045 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9046
9047 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9048 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9049
9050 PyObject *value = kw_values[i];
9051
9052 CHECK_OBJECT(key);
9053 CHECK_OBJECT(value);
9054
9055 DICT_SET_ITEM(named_args, key, value);
9056 }
9057
9058 PyObject *result = (*call_slot)(called, pos_args, named_args);
9059
9060 Py_DECREF(pos_args);
9061 Py_DECREF(named_args);
9062
9063 Py_LeaveRecursiveCall();
9064
9065 CHECK_OBJECT_X(result);
9066
9067 return Nuitka_CheckFunctionResult(tstate, called, result);
9068}
9069PyObject *CALL_FUNCTION_WITH_POS_ARGS1_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9070 PyObject *const *kw_values, PyObject *kw_names) {
9071 assert(PyTuple_CheckExact(pos_args));
9072 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9073 CHECK_OBJECTS(args, 1);
9074 CHECK_OBJECT(kw_names);
9075 assert(PyTuple_CheckExact(kw_names));
9076 CHECK_OBJECT(called);
9077
9078 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9079
9080 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9081
9082 if (Nuitka_Function_Check(called)) {
9083 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9084 return NULL;
9085 }
9086
9087 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9088
9089 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 1, kw_values, kw_names);
9090
9091 Py_LeaveRecursiveCall();
9092
9093 CHECK_OBJECT_X(result);
9094
9095 return result;
9096#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9097 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9098 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9099
9100 if (likely(func != NULL)) {
9101 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 1 + kwargs_count);
9102
9103 memcpy(vectorcall_args, args, 1 * sizeof(PyObject *));
9104 memcpy(&vectorcall_args[1], kw_values, kwargs_count * sizeof(PyObject *));
9105
9106 PyObject *result = func(called, vectorcall_args, 1, kw_names);
9107
9108 CHECK_OBJECT_X(result);
9109
9110 return Nuitka_CheckFunctionResult(tstate, called, result);
9111 }
9112#endif
9113 }
9114
9115#if 0
9116 PRINT_STRING("FALLBACK");
9117 PRINT_ITEM(called);
9118 PRINT_NEW_LINE();
9119#endif
9120
9121 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9122
9123 if (unlikely(call_slot == NULL)) {
9124 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9125
9126 return NULL;
9127 }
9128
9129 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9130 return NULL;
9131 }
9132
9133 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9134
9135 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9136 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9137
9138 PyObject *value = kw_values[i];
9139
9140 CHECK_OBJECT(key);
9141 CHECK_OBJECT(value);
9142
9143 DICT_SET_ITEM(named_args, key, value);
9144 }
9145
9146 PyObject *result = (*call_slot)(called, pos_args, named_args);
9147
9148 Py_DECREF(named_args);
9149
9150 Py_LeaveRecursiveCall();
9151
9152 CHECK_OBJECT_X(result);
9153
9154 return Nuitka_CheckFunctionResult(tstate, called, result);
9155}
9156PyObject *CALL_FUNCTION_WITH_ARGS2_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9157 PyObject *kw_names) {
9158 CHECK_OBJECTS(args, 2);
9159 CHECK_OBJECT(kw_names);
9160 assert(PyTuple_CheckExact(kw_names));
9161 CHECK_OBJECT(called);
9162
9163 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9164
9165 CHECK_OBJECTS(&args[2], kwargs_count);
9166
9167 if (Nuitka_Function_Check(called)) {
9168 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9169 return NULL;
9170 }
9171
9172 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9173
9174 PyObject *result =
9175 Nuitka_CallFunctionVectorcall(tstate, function, args, 2, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
9176
9177 Py_LeaveRecursiveCall();
9178
9179 CHECK_OBJECT_X(result);
9180
9181 return result;
9182#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9183 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9184 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9185
9186 if (likely(func != NULL)) {
9187 PyObject *result = func(called, args, 2, kw_names);
9188
9189 CHECK_OBJECT_X(result);
9190
9191 return Nuitka_CheckFunctionResult(tstate, called, result);
9192 }
9193#endif
9194 }
9195
9196#if 0
9197 PRINT_STRING("FALLBACK");
9198 PRINT_ITEM(called);
9199 PRINT_NEW_LINE();
9200#endif
9201
9202 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9203
9204 if (unlikely(call_slot == NULL)) {
9205 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9206
9207 return NULL;
9208 }
9209
9210 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9211 return NULL;
9212 }
9213
9214 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
9215
9216 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9217
9218 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9219 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9220
9221 PyObject *value = args[2 + i];
9222
9223 CHECK_OBJECT(key);
9224 CHECK_OBJECT(value);
9225
9226 DICT_SET_ITEM(named_args, key, value);
9227 }
9228
9229 PyObject *result = (*call_slot)(called, pos_args, named_args);
9230
9231 Py_DECREF(pos_args);
9232 Py_DECREF(named_args);
9233
9234 Py_LeaveRecursiveCall();
9235
9236 CHECK_OBJECT_X(result);
9237
9238 return Nuitka_CheckFunctionResult(tstate, called, result);
9239}
9240PyObject *CALL_FUNCTION_WITH_ARGS2_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9241 PyObject *const *kw_values, PyObject *kw_names) {
9242 CHECK_OBJECTS(args, 2);
9243 CHECK_OBJECT(kw_names);
9244 assert(PyTuple_CheckExact(kw_names));
9245 CHECK_OBJECT(called);
9246
9247 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9248
9249 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9250
9251 if (Nuitka_Function_Check(called)) {
9252 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9253 return NULL;
9254 }
9255
9256 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9257
9258 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 2, kw_values, kw_names);
9259
9260 Py_LeaveRecursiveCall();
9261
9262 CHECK_OBJECT_X(result);
9263
9264 return result;
9265#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9266 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9267 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9268
9269 if (likely(func != NULL)) {
9270 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 2 + kwargs_count);
9271
9272 memcpy(vectorcall_args, args, 2 * sizeof(PyObject *));
9273 memcpy(&vectorcall_args[2], kw_values, kwargs_count * sizeof(PyObject *));
9274
9275 PyObject *result = func(called, vectorcall_args, 2, kw_names);
9276
9277 CHECK_OBJECT_X(result);
9278
9279 return Nuitka_CheckFunctionResult(tstate, called, result);
9280 }
9281#endif
9282 }
9283
9284#if 0
9285 PRINT_STRING("FALLBACK");
9286 PRINT_ITEM(called);
9287 PRINT_NEW_LINE();
9288#endif
9289
9290 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9291
9292 if (unlikely(call_slot == NULL)) {
9293 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9294
9295 return NULL;
9296 }
9297
9298 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9299 return NULL;
9300 }
9301
9302 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
9303
9304 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9305
9306 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9307 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9308
9309 PyObject *value = kw_values[i];
9310
9311 CHECK_OBJECT(key);
9312 CHECK_OBJECT(value);
9313
9314 DICT_SET_ITEM(named_args, key, value);
9315 }
9316
9317 PyObject *result = (*call_slot)(called, pos_args, named_args);
9318
9319 Py_DECREF(pos_args);
9320 Py_DECREF(named_args);
9321
9322 Py_LeaveRecursiveCall();
9323
9324 CHECK_OBJECT_X(result);
9325
9326 return Nuitka_CheckFunctionResult(tstate, called, result);
9327}
9328PyObject *CALL_FUNCTION_WITH_POS_ARGS2_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9329 PyObject *const *kw_values, PyObject *kw_names) {
9330 assert(PyTuple_CheckExact(pos_args));
9331 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9332 CHECK_OBJECTS(args, 2);
9333 CHECK_OBJECT(kw_names);
9334 assert(PyTuple_CheckExact(kw_names));
9335 CHECK_OBJECT(called);
9336
9337 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9338
9339 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9340
9341 if (Nuitka_Function_Check(called)) {
9342 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9343 return NULL;
9344 }
9345
9346 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9347
9348 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 2, kw_values, kw_names);
9349
9350 Py_LeaveRecursiveCall();
9351
9352 CHECK_OBJECT_X(result);
9353
9354 return result;
9355#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9356 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9357 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9358
9359 if (likely(func != NULL)) {
9360 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 2 + kwargs_count);
9361
9362 memcpy(vectorcall_args, args, 2 * sizeof(PyObject *));
9363 memcpy(&vectorcall_args[2], kw_values, kwargs_count * sizeof(PyObject *));
9364
9365 PyObject *result = func(called, vectorcall_args, 2, kw_names);
9366
9367 CHECK_OBJECT_X(result);
9368
9369 return Nuitka_CheckFunctionResult(tstate, called, result);
9370 }
9371#endif
9372 }
9373
9374#if 0
9375 PRINT_STRING("FALLBACK");
9376 PRINT_ITEM(called);
9377 PRINT_NEW_LINE();
9378#endif
9379
9380 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9381
9382 if (unlikely(call_slot == NULL)) {
9383 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9384
9385 return NULL;
9386 }
9387
9388 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9389 return NULL;
9390 }
9391
9392 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9393
9394 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9395 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9396
9397 PyObject *value = kw_values[i];
9398
9399 CHECK_OBJECT(key);
9400 CHECK_OBJECT(value);
9401
9402 DICT_SET_ITEM(named_args, key, value);
9403 }
9404
9405 PyObject *result = (*call_slot)(called, pos_args, named_args);
9406
9407 Py_DECREF(named_args);
9408
9409 Py_LeaveRecursiveCall();
9410
9411 CHECK_OBJECT_X(result);
9412
9413 return Nuitka_CheckFunctionResult(tstate, called, result);
9414}
9415PyObject *CALL_FUNCTION_WITH_ARGS3_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9416 PyObject *kw_names) {
9417 CHECK_OBJECTS(args, 3);
9418 CHECK_OBJECT(kw_names);
9419 assert(PyTuple_CheckExact(kw_names));
9420 CHECK_OBJECT(called);
9421
9422 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9423
9424 CHECK_OBJECTS(&args[3], kwargs_count);
9425
9426 if (Nuitka_Function_Check(called)) {
9427 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9428 return NULL;
9429 }
9430
9431 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9432
9433 PyObject *result =
9434 Nuitka_CallFunctionVectorcall(tstate, function, args, 3, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
9435
9436 Py_LeaveRecursiveCall();
9437
9438 CHECK_OBJECT_X(result);
9439
9440 return result;
9441#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9442 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9443 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9444
9445 if (likely(func != NULL)) {
9446 PyObject *result = func(called, args, 3, kw_names);
9447
9448 CHECK_OBJECT_X(result);
9449
9450 return Nuitka_CheckFunctionResult(tstate, called, result);
9451 }
9452#endif
9453 }
9454
9455#if 0
9456 PRINT_STRING("FALLBACK");
9457 PRINT_ITEM(called);
9458 PRINT_NEW_LINE();
9459#endif
9460
9461 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9462
9463 if (unlikely(call_slot == NULL)) {
9464 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9465
9466 return NULL;
9467 }
9468
9469 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9470 return NULL;
9471 }
9472
9473 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
9474
9475 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9476
9477 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9478 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9479
9480 PyObject *value = args[3 + i];
9481
9482 CHECK_OBJECT(key);
9483 CHECK_OBJECT(value);
9484
9485 DICT_SET_ITEM(named_args, key, value);
9486 }
9487
9488 PyObject *result = (*call_slot)(called, pos_args, named_args);
9489
9490 Py_DECREF(pos_args);
9491 Py_DECREF(named_args);
9492
9493 Py_LeaveRecursiveCall();
9494
9495 CHECK_OBJECT_X(result);
9496
9497 return Nuitka_CheckFunctionResult(tstate, called, result);
9498}
9499PyObject *CALL_FUNCTION_WITH_ARGS3_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9500 PyObject *const *kw_values, PyObject *kw_names) {
9501 CHECK_OBJECTS(args, 3);
9502 CHECK_OBJECT(kw_names);
9503 assert(PyTuple_CheckExact(kw_names));
9504 CHECK_OBJECT(called);
9505
9506 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9507
9508 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9509
9510 if (Nuitka_Function_Check(called)) {
9511 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9512 return NULL;
9513 }
9514
9515 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9516
9517 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 3, kw_values, kw_names);
9518
9519 Py_LeaveRecursiveCall();
9520
9521 CHECK_OBJECT_X(result);
9522
9523 return result;
9524#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9525 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9526 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9527
9528 if (likely(func != NULL)) {
9529 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 3 + kwargs_count);
9530
9531 memcpy(vectorcall_args, args, 3 * sizeof(PyObject *));
9532 memcpy(&vectorcall_args[3], kw_values, kwargs_count * sizeof(PyObject *));
9533
9534 PyObject *result = func(called, vectorcall_args, 3, kw_names);
9535
9536 CHECK_OBJECT_X(result);
9537
9538 return Nuitka_CheckFunctionResult(tstate, called, result);
9539 }
9540#endif
9541 }
9542
9543#if 0
9544 PRINT_STRING("FALLBACK");
9545 PRINT_ITEM(called);
9546 PRINT_NEW_LINE();
9547#endif
9548
9549 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9550
9551 if (unlikely(call_slot == NULL)) {
9552 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9553
9554 return NULL;
9555 }
9556
9557 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9558 return NULL;
9559 }
9560
9561 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
9562
9563 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9564
9565 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9566 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9567
9568 PyObject *value = kw_values[i];
9569
9570 CHECK_OBJECT(key);
9571 CHECK_OBJECT(value);
9572
9573 DICT_SET_ITEM(named_args, key, value);
9574 }
9575
9576 PyObject *result = (*call_slot)(called, pos_args, named_args);
9577
9578 Py_DECREF(pos_args);
9579 Py_DECREF(named_args);
9580
9581 Py_LeaveRecursiveCall();
9582
9583 CHECK_OBJECT_X(result);
9584
9585 return Nuitka_CheckFunctionResult(tstate, called, result);
9586}
9587PyObject *CALL_FUNCTION_WITH_POS_ARGS3_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9588 PyObject *const *kw_values, PyObject *kw_names) {
9589 assert(PyTuple_CheckExact(pos_args));
9590 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9591 CHECK_OBJECTS(args, 3);
9592 CHECK_OBJECT(kw_names);
9593 assert(PyTuple_CheckExact(kw_names));
9594 CHECK_OBJECT(called);
9595
9596 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9597
9598 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9599
9600 if (Nuitka_Function_Check(called)) {
9601 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9602 return NULL;
9603 }
9604
9605 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9606
9607 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 3, kw_values, kw_names);
9608
9609 Py_LeaveRecursiveCall();
9610
9611 CHECK_OBJECT_X(result);
9612
9613 return result;
9614#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9615 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9616 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9617
9618 if (likely(func != NULL)) {
9619 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 3 + kwargs_count);
9620
9621 memcpy(vectorcall_args, args, 3 * sizeof(PyObject *));
9622 memcpy(&vectorcall_args[3], kw_values, kwargs_count * sizeof(PyObject *));
9623
9624 PyObject *result = func(called, vectorcall_args, 3, kw_names);
9625
9626 CHECK_OBJECT_X(result);
9627
9628 return Nuitka_CheckFunctionResult(tstate, called, result);
9629 }
9630#endif
9631 }
9632
9633#if 0
9634 PRINT_STRING("FALLBACK");
9635 PRINT_ITEM(called);
9636 PRINT_NEW_LINE();
9637#endif
9638
9639 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9640
9641 if (unlikely(call_slot == NULL)) {
9642 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9643
9644 return NULL;
9645 }
9646
9647 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9648 return NULL;
9649 }
9650
9651 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9652
9653 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9654 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9655
9656 PyObject *value = kw_values[i];
9657
9658 CHECK_OBJECT(key);
9659 CHECK_OBJECT(value);
9660
9661 DICT_SET_ITEM(named_args, key, value);
9662 }
9663
9664 PyObject *result = (*call_slot)(called, pos_args, named_args);
9665
9666 Py_DECREF(named_args);
9667
9668 Py_LeaveRecursiveCall();
9669
9670 CHECK_OBJECT_X(result);
9671
9672 return Nuitka_CheckFunctionResult(tstate, called, result);
9673}
9674PyObject *CALL_FUNCTION_WITH_ARGS4_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9675 PyObject *kw_names) {
9676 CHECK_OBJECTS(args, 4);
9677 CHECK_OBJECT(kw_names);
9678 assert(PyTuple_CheckExact(kw_names));
9679 CHECK_OBJECT(called);
9680
9681 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9682
9683 CHECK_OBJECTS(&args[4], kwargs_count);
9684
9685 if (Nuitka_Function_Check(called)) {
9686 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9687 return NULL;
9688 }
9689
9690 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9691
9692 PyObject *result =
9693 Nuitka_CallFunctionVectorcall(tstate, function, args, 4, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
9694
9695 Py_LeaveRecursiveCall();
9696
9697 CHECK_OBJECT_X(result);
9698
9699 return result;
9700#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9701 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9702 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9703
9704 if (likely(func != NULL)) {
9705 PyObject *result = func(called, args, 4, kw_names);
9706
9707 CHECK_OBJECT_X(result);
9708
9709 return Nuitka_CheckFunctionResult(tstate, called, result);
9710 }
9711#endif
9712 }
9713
9714#if 0
9715 PRINT_STRING("FALLBACK");
9716 PRINT_ITEM(called);
9717 PRINT_NEW_LINE();
9718#endif
9719
9720 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9721
9722 if (unlikely(call_slot == NULL)) {
9723 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9724
9725 return NULL;
9726 }
9727
9728 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9729 return NULL;
9730 }
9731
9732 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
9733
9734 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9735
9736 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9737 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9738
9739 PyObject *value = args[4 + i];
9740
9741 CHECK_OBJECT(key);
9742 CHECK_OBJECT(value);
9743
9744 DICT_SET_ITEM(named_args, key, value);
9745 }
9746
9747 PyObject *result = (*call_slot)(called, pos_args, named_args);
9748
9749 Py_DECREF(pos_args);
9750 Py_DECREF(named_args);
9751
9752 Py_LeaveRecursiveCall();
9753
9754 CHECK_OBJECT_X(result);
9755
9756 return Nuitka_CheckFunctionResult(tstate, called, result);
9757}
9758PyObject *CALL_FUNCTION_WITH_ARGS4_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9759 PyObject *const *kw_values, PyObject *kw_names) {
9760 CHECK_OBJECTS(args, 4);
9761 CHECK_OBJECT(kw_names);
9762 assert(PyTuple_CheckExact(kw_names));
9763 CHECK_OBJECT(called);
9764
9765 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9766
9767 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9768
9769 if (Nuitka_Function_Check(called)) {
9770 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9771 return NULL;
9772 }
9773
9774 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9775
9776 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 4, kw_values, kw_names);
9777
9778 Py_LeaveRecursiveCall();
9779
9780 CHECK_OBJECT_X(result);
9781
9782 return result;
9783#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9784 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9785 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9786
9787 if (likely(func != NULL)) {
9788 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 4 + kwargs_count);
9789
9790 memcpy(vectorcall_args, args, 4 * sizeof(PyObject *));
9791 memcpy(&vectorcall_args[4], kw_values, kwargs_count * sizeof(PyObject *));
9792
9793 PyObject *result = func(called, vectorcall_args, 4, kw_names);
9794
9795 CHECK_OBJECT_X(result);
9796
9797 return Nuitka_CheckFunctionResult(tstate, called, result);
9798 }
9799#endif
9800 }
9801
9802#if 0
9803 PRINT_STRING("FALLBACK");
9804 PRINT_ITEM(called);
9805 PRINT_NEW_LINE();
9806#endif
9807
9808 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9809
9810 if (unlikely(call_slot == NULL)) {
9811 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9812
9813 return NULL;
9814 }
9815
9816 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9817 return NULL;
9818 }
9819
9820 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
9821
9822 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9823
9824 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9825 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9826
9827 PyObject *value = kw_values[i];
9828
9829 CHECK_OBJECT(key);
9830 CHECK_OBJECT(value);
9831
9832 DICT_SET_ITEM(named_args, key, value);
9833 }
9834
9835 PyObject *result = (*call_slot)(called, pos_args, named_args);
9836
9837 Py_DECREF(pos_args);
9838 Py_DECREF(named_args);
9839
9840 Py_LeaveRecursiveCall();
9841
9842 CHECK_OBJECT_X(result);
9843
9844 return Nuitka_CheckFunctionResult(tstate, called, result);
9845}
9846PyObject *CALL_FUNCTION_WITH_POS_ARGS4_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9847 PyObject *const *kw_values, PyObject *kw_names) {
9848 assert(PyTuple_CheckExact(pos_args));
9849 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9850 CHECK_OBJECTS(args, 4);
9851 CHECK_OBJECT(kw_names);
9852 assert(PyTuple_CheckExact(kw_names));
9853 CHECK_OBJECT(called);
9854
9855 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9856
9857 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9858
9859 if (Nuitka_Function_Check(called)) {
9860 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9861 return NULL;
9862 }
9863
9864 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9865
9866 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 4, kw_values, kw_names);
9867
9868 Py_LeaveRecursiveCall();
9869
9870 CHECK_OBJECT_X(result);
9871
9872 return result;
9873#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9874 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9875 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9876
9877 if (likely(func != NULL)) {
9878 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 4 + kwargs_count);
9879
9880 memcpy(vectorcall_args, args, 4 * sizeof(PyObject *));
9881 memcpy(&vectorcall_args[4], kw_values, kwargs_count * sizeof(PyObject *));
9882
9883 PyObject *result = func(called, vectorcall_args, 4, kw_names);
9884
9885 CHECK_OBJECT_X(result);
9886
9887 return Nuitka_CheckFunctionResult(tstate, called, result);
9888 }
9889#endif
9890 }
9891
9892#if 0
9893 PRINT_STRING("FALLBACK");
9894 PRINT_ITEM(called);
9895 PRINT_NEW_LINE();
9896#endif
9897
9898 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9899
9900 if (unlikely(call_slot == NULL)) {
9901 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9902
9903 return NULL;
9904 }
9905
9906 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9907 return NULL;
9908 }
9909
9910 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9911
9912 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9913 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9914
9915 PyObject *value = kw_values[i];
9916
9917 CHECK_OBJECT(key);
9918 CHECK_OBJECT(value);
9919
9920 DICT_SET_ITEM(named_args, key, value);
9921 }
9922
9923 PyObject *result = (*call_slot)(called, pos_args, named_args);
9924
9925 Py_DECREF(named_args);
9926
9927 Py_LeaveRecursiveCall();
9928
9929 CHECK_OBJECT_X(result);
9930
9931 return Nuitka_CheckFunctionResult(tstate, called, result);
9932}
9933PyObject *CALL_FUNCTION_WITH_ARGS5_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9934 PyObject *kw_names) {
9935 CHECK_OBJECTS(args, 5);
9936 CHECK_OBJECT(kw_names);
9937 assert(PyTuple_CheckExact(kw_names));
9938 CHECK_OBJECT(called);
9939
9940 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
9941
9942 CHECK_OBJECTS(&args[5], kwargs_count);
9943
9944 if (Nuitka_Function_Check(called)) {
9945 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9946 return NULL;
9947 }
9948
9949 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9950
9951 PyObject *result =
9952 Nuitka_CallFunctionVectorcall(tstate, function, args, 5, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
9953
9954 Py_LeaveRecursiveCall();
9955
9956 CHECK_OBJECT_X(result);
9957
9958 return result;
9959#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9960 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9961 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9962
9963 if (likely(func != NULL)) {
9964 PyObject *result = func(called, args, 5, kw_names);
9965
9966 CHECK_OBJECT_X(result);
9967
9968 return Nuitka_CheckFunctionResult(tstate, called, result);
9969 }
9970#endif
9971 }
9972
9973#if 0
9974 PRINT_STRING("FALLBACK");
9975 PRINT_ITEM(called);
9976 PRINT_NEW_LINE();
9977#endif
9978
9979 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9980
9981 if (unlikely(call_slot == NULL)) {
9982 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9983
9984 return NULL;
9985 }
9986
9987 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9988 return NULL;
9989 }
9990
9991 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
9992
9993 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
9994
9995 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
9996 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9997
9998 PyObject *value = args[5 + i];
9999
10000 CHECK_OBJECT(key);
10001 CHECK_OBJECT(value);
10002
10003 DICT_SET_ITEM(named_args, key, value);
10004 }
10005
10006 PyObject *result = (*call_slot)(called, pos_args, named_args);
10007
10008 Py_DECREF(pos_args);
10009 Py_DECREF(named_args);
10010
10011 Py_LeaveRecursiveCall();
10012
10013 CHECK_OBJECT_X(result);
10014
10015 return Nuitka_CheckFunctionResult(tstate, called, result);
10016}
10017PyObject *CALL_FUNCTION_WITH_ARGS5_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10018 PyObject *const *kw_values, PyObject *kw_names) {
10019 CHECK_OBJECTS(args, 5);
10020 CHECK_OBJECT(kw_names);
10021 assert(PyTuple_CheckExact(kw_names));
10022 CHECK_OBJECT(called);
10023
10024 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10025
10026 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10027
10028 if (Nuitka_Function_Check(called)) {
10029 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10030 return NULL;
10031 }
10032
10033 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10034
10035 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 5, kw_values, kw_names);
10036
10037 Py_LeaveRecursiveCall();
10038
10039 CHECK_OBJECT_X(result);
10040
10041 return result;
10042#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10043 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10044 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10045
10046 if (likely(func != NULL)) {
10047 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 5 + kwargs_count);
10048
10049 memcpy(vectorcall_args, args, 5 * sizeof(PyObject *));
10050 memcpy(&vectorcall_args[5], kw_values, kwargs_count * sizeof(PyObject *));
10051
10052 PyObject *result = func(called, vectorcall_args, 5, kw_names);
10053
10054 CHECK_OBJECT_X(result);
10055
10056 return Nuitka_CheckFunctionResult(tstate, called, result);
10057 }
10058#endif
10059 }
10060
10061#if 0
10062 PRINT_STRING("FALLBACK");
10063 PRINT_ITEM(called);
10064 PRINT_NEW_LINE();
10065#endif
10066
10067 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10068
10069 if (unlikely(call_slot == NULL)) {
10070 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10071
10072 return NULL;
10073 }
10074
10075 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10076 return NULL;
10077 }
10078
10079 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
10080
10081 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10082
10083 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10084 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10085
10086 PyObject *value = kw_values[i];
10087
10088 CHECK_OBJECT(key);
10089 CHECK_OBJECT(value);
10090
10091 DICT_SET_ITEM(named_args, key, value);
10092 }
10093
10094 PyObject *result = (*call_slot)(called, pos_args, named_args);
10095
10096 Py_DECREF(pos_args);
10097 Py_DECREF(named_args);
10098
10099 Py_LeaveRecursiveCall();
10100
10101 CHECK_OBJECT_X(result);
10102
10103 return Nuitka_CheckFunctionResult(tstate, called, result);
10104}
10105PyObject *CALL_FUNCTION_WITH_POS_ARGS5_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10106 PyObject *const *kw_values, PyObject *kw_names) {
10107 assert(PyTuple_CheckExact(pos_args));
10108 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10109 CHECK_OBJECTS(args, 5);
10110 CHECK_OBJECT(kw_names);
10111 assert(PyTuple_CheckExact(kw_names));
10112 CHECK_OBJECT(called);
10113
10114 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10115
10116 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10117
10118 if (Nuitka_Function_Check(called)) {
10119 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10120 return NULL;
10121 }
10122
10123 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10124
10125 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 5, kw_values, kw_names);
10126
10127 Py_LeaveRecursiveCall();
10128
10129 CHECK_OBJECT_X(result);
10130
10131 return result;
10132#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10133 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10134 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10135
10136 if (likely(func != NULL)) {
10137 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 5 + kwargs_count);
10138
10139 memcpy(vectorcall_args, args, 5 * sizeof(PyObject *));
10140 memcpy(&vectorcall_args[5], kw_values, kwargs_count * sizeof(PyObject *));
10141
10142 PyObject *result = func(called, vectorcall_args, 5, kw_names);
10143
10144 CHECK_OBJECT_X(result);
10145
10146 return Nuitka_CheckFunctionResult(tstate, called, result);
10147 }
10148#endif
10149 }
10150
10151#if 0
10152 PRINT_STRING("FALLBACK");
10153 PRINT_ITEM(called);
10154 PRINT_NEW_LINE();
10155#endif
10156
10157 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10158
10159 if (unlikely(call_slot == NULL)) {
10160 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10161
10162 return NULL;
10163 }
10164
10165 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10166 return NULL;
10167 }
10168
10169 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10170
10171 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10172 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10173
10174 PyObject *value = kw_values[i];
10175
10176 CHECK_OBJECT(key);
10177 CHECK_OBJECT(value);
10178
10179 DICT_SET_ITEM(named_args, key, value);
10180 }
10181
10182 PyObject *result = (*call_slot)(called, pos_args, named_args);
10183
10184 Py_DECREF(named_args);
10185
10186 Py_LeaveRecursiveCall();
10187
10188 CHECK_OBJECT_X(result);
10189
10190 return Nuitka_CheckFunctionResult(tstate, called, result);
10191}
10192PyObject *CALL_FUNCTION_WITH_ARGS6_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10193 PyObject *kw_names) {
10194 CHECK_OBJECTS(args, 6);
10195 CHECK_OBJECT(kw_names);
10196 assert(PyTuple_CheckExact(kw_names));
10197 CHECK_OBJECT(called);
10198
10199 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10200
10201 CHECK_OBJECTS(&args[6], kwargs_count);
10202
10203 if (Nuitka_Function_Check(called)) {
10204 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10205 return NULL;
10206 }
10207
10208 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10209
10210 PyObject *result =
10211 Nuitka_CallFunctionVectorcall(tstate, function, args, 6, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
10212
10213 Py_LeaveRecursiveCall();
10214
10215 CHECK_OBJECT_X(result);
10216
10217 return result;
10218#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10219 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10220 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10221
10222 if (likely(func != NULL)) {
10223 PyObject *result = func(called, args, 6, kw_names);
10224
10225 CHECK_OBJECT_X(result);
10226
10227 return Nuitka_CheckFunctionResult(tstate, called, result);
10228 }
10229#endif
10230 }
10231
10232#if 0
10233 PRINT_STRING("FALLBACK");
10234 PRINT_ITEM(called);
10235 PRINT_NEW_LINE();
10236#endif
10237
10238 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10239
10240 if (unlikely(call_slot == NULL)) {
10241 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10242
10243 return NULL;
10244 }
10245
10246 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10247 return NULL;
10248 }
10249
10250 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
10251
10252 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10253
10254 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10255 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10256
10257 PyObject *value = args[6 + i];
10258
10259 CHECK_OBJECT(key);
10260 CHECK_OBJECT(value);
10261
10262 DICT_SET_ITEM(named_args, key, value);
10263 }
10264
10265 PyObject *result = (*call_slot)(called, pos_args, named_args);
10266
10267 Py_DECREF(pos_args);
10268 Py_DECREF(named_args);
10269
10270 Py_LeaveRecursiveCall();
10271
10272 CHECK_OBJECT_X(result);
10273
10274 return Nuitka_CheckFunctionResult(tstate, called, result);
10275}
10276PyObject *CALL_FUNCTION_WITH_ARGS6_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10277 PyObject *const *kw_values, PyObject *kw_names) {
10278 CHECK_OBJECTS(args, 6);
10279 CHECK_OBJECT(kw_names);
10280 assert(PyTuple_CheckExact(kw_names));
10281 CHECK_OBJECT(called);
10282
10283 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10284
10285 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10286
10287 if (Nuitka_Function_Check(called)) {
10288 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10289 return NULL;
10290 }
10291
10292 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10293
10294 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 6, kw_values, kw_names);
10295
10296 Py_LeaveRecursiveCall();
10297
10298 CHECK_OBJECT_X(result);
10299
10300 return result;
10301#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10302 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10303 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10304
10305 if (likely(func != NULL)) {
10306 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 6 + kwargs_count);
10307
10308 memcpy(vectorcall_args, args, 6 * sizeof(PyObject *));
10309 memcpy(&vectorcall_args[6], kw_values, kwargs_count * sizeof(PyObject *));
10310
10311 PyObject *result = func(called, vectorcall_args, 6, kw_names);
10312
10313 CHECK_OBJECT_X(result);
10314
10315 return Nuitka_CheckFunctionResult(tstate, called, result);
10316 }
10317#endif
10318 }
10319
10320#if 0
10321 PRINT_STRING("FALLBACK");
10322 PRINT_ITEM(called);
10323 PRINT_NEW_LINE();
10324#endif
10325
10326 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10327
10328 if (unlikely(call_slot == NULL)) {
10329 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10330
10331 return NULL;
10332 }
10333
10334 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10335 return NULL;
10336 }
10337
10338 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
10339
10340 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10341
10342 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10343 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10344
10345 PyObject *value = kw_values[i];
10346
10347 CHECK_OBJECT(key);
10348 CHECK_OBJECT(value);
10349
10350 DICT_SET_ITEM(named_args, key, value);
10351 }
10352
10353 PyObject *result = (*call_slot)(called, pos_args, named_args);
10354
10355 Py_DECREF(pos_args);
10356 Py_DECREF(named_args);
10357
10358 Py_LeaveRecursiveCall();
10359
10360 CHECK_OBJECT_X(result);
10361
10362 return Nuitka_CheckFunctionResult(tstate, called, result);
10363}
10364PyObject *CALL_FUNCTION_WITH_POS_ARGS6_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10365 PyObject *const *kw_values, PyObject *kw_names) {
10366 assert(PyTuple_CheckExact(pos_args));
10367 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10368 CHECK_OBJECTS(args, 6);
10369 CHECK_OBJECT(kw_names);
10370 assert(PyTuple_CheckExact(kw_names));
10371 CHECK_OBJECT(called);
10372
10373 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10374
10375 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10376
10377 if (Nuitka_Function_Check(called)) {
10378 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10379 return NULL;
10380 }
10381
10382 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10383
10384 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 6, kw_values, kw_names);
10385
10386 Py_LeaveRecursiveCall();
10387
10388 CHECK_OBJECT_X(result);
10389
10390 return result;
10391#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10392 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10393 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10394
10395 if (likely(func != NULL)) {
10396 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 6 + kwargs_count);
10397
10398 memcpy(vectorcall_args, args, 6 * sizeof(PyObject *));
10399 memcpy(&vectorcall_args[6], kw_values, kwargs_count * sizeof(PyObject *));
10400
10401 PyObject *result = func(called, vectorcall_args, 6, kw_names);
10402
10403 CHECK_OBJECT_X(result);
10404
10405 return Nuitka_CheckFunctionResult(tstate, called, result);
10406 }
10407#endif
10408 }
10409
10410#if 0
10411 PRINT_STRING("FALLBACK");
10412 PRINT_ITEM(called);
10413 PRINT_NEW_LINE();
10414#endif
10415
10416 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10417
10418 if (unlikely(call_slot == NULL)) {
10419 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10420
10421 return NULL;
10422 }
10423
10424 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10425 return NULL;
10426 }
10427
10428 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10429
10430 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10431 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10432
10433 PyObject *value = kw_values[i];
10434
10435 CHECK_OBJECT(key);
10436 CHECK_OBJECT(value);
10437
10438 DICT_SET_ITEM(named_args, key, value);
10439 }
10440
10441 PyObject *result = (*call_slot)(called, pos_args, named_args);
10442
10443 Py_DECREF(named_args);
10444
10445 Py_LeaveRecursiveCall();
10446
10447 CHECK_OBJECT_X(result);
10448
10449 return Nuitka_CheckFunctionResult(tstate, called, result);
10450}
10451PyObject *CALL_FUNCTION_WITH_ARGS7_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10452 PyObject *kw_names) {
10453 CHECK_OBJECTS(args, 7);
10454 CHECK_OBJECT(kw_names);
10455 assert(PyTuple_CheckExact(kw_names));
10456 CHECK_OBJECT(called);
10457
10458 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10459
10460 CHECK_OBJECTS(&args[7], kwargs_count);
10461
10462 if (Nuitka_Function_Check(called)) {
10463 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10464 return NULL;
10465 }
10466
10467 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10468
10469 PyObject *result =
10470 Nuitka_CallFunctionVectorcall(tstate, function, args, 7, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
10471
10472 Py_LeaveRecursiveCall();
10473
10474 CHECK_OBJECT_X(result);
10475
10476 return result;
10477#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10478 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10479 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10480
10481 if (likely(func != NULL)) {
10482 PyObject *result = func(called, args, 7, kw_names);
10483
10484 CHECK_OBJECT_X(result);
10485
10486 return Nuitka_CheckFunctionResult(tstate, called, result);
10487 }
10488#endif
10489 }
10490
10491#if 0
10492 PRINT_STRING("FALLBACK");
10493 PRINT_ITEM(called);
10494 PRINT_NEW_LINE();
10495#endif
10496
10497 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10498
10499 if (unlikely(call_slot == NULL)) {
10500 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10501
10502 return NULL;
10503 }
10504
10505 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10506 return NULL;
10507 }
10508
10509 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
10510
10511 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10512
10513 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10514 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10515
10516 PyObject *value = args[7 + i];
10517
10518 CHECK_OBJECT(key);
10519 CHECK_OBJECT(value);
10520
10521 DICT_SET_ITEM(named_args, key, value);
10522 }
10523
10524 PyObject *result = (*call_slot)(called, pos_args, named_args);
10525
10526 Py_DECREF(pos_args);
10527 Py_DECREF(named_args);
10528
10529 Py_LeaveRecursiveCall();
10530
10531 CHECK_OBJECT_X(result);
10532
10533 return Nuitka_CheckFunctionResult(tstate, called, result);
10534}
10535PyObject *CALL_FUNCTION_WITH_ARGS7_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10536 PyObject *const *kw_values, PyObject *kw_names) {
10537 CHECK_OBJECTS(args, 7);
10538 CHECK_OBJECT(kw_names);
10539 assert(PyTuple_CheckExact(kw_names));
10540 CHECK_OBJECT(called);
10541
10542 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10543
10544 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10545
10546 if (Nuitka_Function_Check(called)) {
10547 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10548 return NULL;
10549 }
10550
10551 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10552
10553 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 7, kw_values, kw_names);
10554
10555 Py_LeaveRecursiveCall();
10556
10557 CHECK_OBJECT_X(result);
10558
10559 return result;
10560#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10561 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10562 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10563
10564 if (likely(func != NULL)) {
10565 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 7 + kwargs_count);
10566
10567 memcpy(vectorcall_args, args, 7 * sizeof(PyObject *));
10568 memcpy(&vectorcall_args[7], kw_values, kwargs_count * sizeof(PyObject *));
10569
10570 PyObject *result = func(called, vectorcall_args, 7, kw_names);
10571
10572 CHECK_OBJECT_X(result);
10573
10574 return Nuitka_CheckFunctionResult(tstate, called, result);
10575 }
10576#endif
10577 }
10578
10579#if 0
10580 PRINT_STRING("FALLBACK");
10581 PRINT_ITEM(called);
10582 PRINT_NEW_LINE();
10583#endif
10584
10585 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10586
10587 if (unlikely(call_slot == NULL)) {
10588 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10589
10590 return NULL;
10591 }
10592
10593 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10594 return NULL;
10595 }
10596
10597 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
10598
10599 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10600
10601 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10602 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10603
10604 PyObject *value = kw_values[i];
10605
10606 CHECK_OBJECT(key);
10607 CHECK_OBJECT(value);
10608
10609 DICT_SET_ITEM(named_args, key, value);
10610 }
10611
10612 PyObject *result = (*call_slot)(called, pos_args, named_args);
10613
10614 Py_DECREF(pos_args);
10615 Py_DECREF(named_args);
10616
10617 Py_LeaveRecursiveCall();
10618
10619 CHECK_OBJECT_X(result);
10620
10621 return Nuitka_CheckFunctionResult(tstate, called, result);
10622}
10623PyObject *CALL_FUNCTION_WITH_POS_ARGS7_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10624 PyObject *const *kw_values, PyObject *kw_names) {
10625 assert(PyTuple_CheckExact(pos_args));
10626 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10627 CHECK_OBJECTS(args, 7);
10628 CHECK_OBJECT(kw_names);
10629 assert(PyTuple_CheckExact(kw_names));
10630 CHECK_OBJECT(called);
10631
10632 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10633
10634 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10635
10636 if (Nuitka_Function_Check(called)) {
10637 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10638 return NULL;
10639 }
10640
10641 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10642
10643 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 7, kw_values, kw_names);
10644
10645 Py_LeaveRecursiveCall();
10646
10647 CHECK_OBJECT_X(result);
10648
10649 return result;
10650#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10651 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10652 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10653
10654 if (likely(func != NULL)) {
10655 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 7 + kwargs_count);
10656
10657 memcpy(vectorcall_args, args, 7 * sizeof(PyObject *));
10658 memcpy(&vectorcall_args[7], kw_values, kwargs_count * sizeof(PyObject *));
10659
10660 PyObject *result = func(called, vectorcall_args, 7, kw_names);
10661
10662 CHECK_OBJECT_X(result);
10663
10664 return Nuitka_CheckFunctionResult(tstate, called, result);
10665 }
10666#endif
10667 }
10668
10669#if 0
10670 PRINT_STRING("FALLBACK");
10671 PRINT_ITEM(called);
10672 PRINT_NEW_LINE();
10673#endif
10674
10675 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10676
10677 if (unlikely(call_slot == NULL)) {
10678 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10679
10680 return NULL;
10681 }
10682
10683 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10684 return NULL;
10685 }
10686
10687 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10688
10689 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10690 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10691
10692 PyObject *value = kw_values[i];
10693
10694 CHECK_OBJECT(key);
10695 CHECK_OBJECT(value);
10696
10697 DICT_SET_ITEM(named_args, key, value);
10698 }
10699
10700 PyObject *result = (*call_slot)(called, pos_args, named_args);
10701
10702 Py_DECREF(named_args);
10703
10704 Py_LeaveRecursiveCall();
10705
10706 CHECK_OBJECT_X(result);
10707
10708 return Nuitka_CheckFunctionResult(tstate, called, result);
10709}
10710PyObject *CALL_FUNCTION_WITH_ARGS8_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10711 PyObject *kw_names) {
10712 CHECK_OBJECTS(args, 8);
10713 CHECK_OBJECT(kw_names);
10714 assert(PyTuple_CheckExact(kw_names));
10715 CHECK_OBJECT(called);
10716
10717 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10718
10719 CHECK_OBJECTS(&args[8], kwargs_count);
10720
10721 if (Nuitka_Function_Check(called)) {
10722 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10723 return NULL;
10724 }
10725
10726 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10727
10728 PyObject *result =
10729 Nuitka_CallFunctionVectorcall(tstate, function, args, 8, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
10730
10731 Py_LeaveRecursiveCall();
10732
10733 CHECK_OBJECT_X(result);
10734
10735 return result;
10736#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10737 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10738 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10739
10740 if (likely(func != NULL)) {
10741 PyObject *result = func(called, args, 8, kw_names);
10742
10743 CHECK_OBJECT_X(result);
10744
10745 return Nuitka_CheckFunctionResult(tstate, called, result);
10746 }
10747#endif
10748 }
10749
10750#if 0
10751 PRINT_STRING("FALLBACK");
10752 PRINT_ITEM(called);
10753 PRINT_NEW_LINE();
10754#endif
10755
10756 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10757
10758 if (unlikely(call_slot == NULL)) {
10759 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10760
10761 return NULL;
10762 }
10763
10764 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10765 return NULL;
10766 }
10767
10768 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
10769
10770 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10771
10772 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10773 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10774
10775 PyObject *value = args[8 + i];
10776
10777 CHECK_OBJECT(key);
10778 CHECK_OBJECT(value);
10779
10780 DICT_SET_ITEM(named_args, key, value);
10781 }
10782
10783 PyObject *result = (*call_slot)(called, pos_args, named_args);
10784
10785 Py_DECREF(pos_args);
10786 Py_DECREF(named_args);
10787
10788 Py_LeaveRecursiveCall();
10789
10790 CHECK_OBJECT_X(result);
10791
10792 return Nuitka_CheckFunctionResult(tstate, called, result);
10793}
10794PyObject *CALL_FUNCTION_WITH_ARGS8_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10795 PyObject *const *kw_values, PyObject *kw_names) {
10796 CHECK_OBJECTS(args, 8);
10797 CHECK_OBJECT(kw_names);
10798 assert(PyTuple_CheckExact(kw_names));
10799 CHECK_OBJECT(called);
10800
10801 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10802
10803 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10804
10805 if (Nuitka_Function_Check(called)) {
10806 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10807 return NULL;
10808 }
10809
10810 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10811
10812 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 8, kw_values, kw_names);
10813
10814 Py_LeaveRecursiveCall();
10815
10816 CHECK_OBJECT_X(result);
10817
10818 return result;
10819#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10820 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10821 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10822
10823 if (likely(func != NULL)) {
10824 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 8 + kwargs_count);
10825
10826 memcpy(vectorcall_args, args, 8 * sizeof(PyObject *));
10827 memcpy(&vectorcall_args[8], kw_values, kwargs_count * sizeof(PyObject *));
10828
10829 PyObject *result = func(called, vectorcall_args, 8, kw_names);
10830
10831 CHECK_OBJECT_X(result);
10832
10833 return Nuitka_CheckFunctionResult(tstate, called, result);
10834 }
10835#endif
10836 }
10837
10838#if 0
10839 PRINT_STRING("FALLBACK");
10840 PRINT_ITEM(called);
10841 PRINT_NEW_LINE();
10842#endif
10843
10844 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10845
10846 if (unlikely(call_slot == NULL)) {
10847 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10848
10849 return NULL;
10850 }
10851
10852 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10853 return NULL;
10854 }
10855
10856 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
10857
10858 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10859
10860 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10861 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10862
10863 PyObject *value = kw_values[i];
10864
10865 CHECK_OBJECT(key);
10866 CHECK_OBJECT(value);
10867
10868 DICT_SET_ITEM(named_args, key, value);
10869 }
10870
10871 PyObject *result = (*call_slot)(called, pos_args, named_args);
10872
10873 Py_DECREF(pos_args);
10874 Py_DECREF(named_args);
10875
10876 Py_LeaveRecursiveCall();
10877
10878 CHECK_OBJECT_X(result);
10879
10880 return Nuitka_CheckFunctionResult(tstate, called, result);
10881}
10882PyObject *CALL_FUNCTION_WITH_POS_ARGS8_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10883 PyObject *const *kw_values, PyObject *kw_names) {
10884 assert(PyTuple_CheckExact(pos_args));
10885 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10886 CHECK_OBJECTS(args, 8);
10887 CHECK_OBJECT(kw_names);
10888 assert(PyTuple_CheckExact(kw_names));
10889 CHECK_OBJECT(called);
10890
10891 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10892
10893 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10894
10895 if (Nuitka_Function_Check(called)) {
10896 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10897 return NULL;
10898 }
10899
10900 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10901
10902 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 8, kw_values, kw_names);
10903
10904 Py_LeaveRecursiveCall();
10905
10906 CHECK_OBJECT_X(result);
10907
10908 return result;
10909#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10910 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10911 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10912
10913 if (likely(func != NULL)) {
10914 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 8 + kwargs_count);
10915
10916 memcpy(vectorcall_args, args, 8 * sizeof(PyObject *));
10917 memcpy(&vectorcall_args[8], kw_values, kwargs_count * sizeof(PyObject *));
10918
10919 PyObject *result = func(called, vectorcall_args, 8, kw_names);
10920
10921 CHECK_OBJECT_X(result);
10922
10923 return Nuitka_CheckFunctionResult(tstate, called, result);
10924 }
10925#endif
10926 }
10927
10928#if 0
10929 PRINT_STRING("FALLBACK");
10930 PRINT_ITEM(called);
10931 PRINT_NEW_LINE();
10932#endif
10933
10934 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10935
10936 if (unlikely(call_slot == NULL)) {
10937 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10938
10939 return NULL;
10940 }
10941
10942 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10943 return NULL;
10944 }
10945
10946 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
10947
10948 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
10949 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10950
10951 PyObject *value = kw_values[i];
10952
10953 CHECK_OBJECT(key);
10954 CHECK_OBJECT(value);
10955
10956 DICT_SET_ITEM(named_args, key, value);
10957 }
10958
10959 PyObject *result = (*call_slot)(called, pos_args, named_args);
10960
10961 Py_DECREF(named_args);
10962
10963 Py_LeaveRecursiveCall();
10964
10965 CHECK_OBJECT_X(result);
10966
10967 return Nuitka_CheckFunctionResult(tstate, called, result);
10968}
10969PyObject *CALL_FUNCTION_WITH_ARGS9_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10970 PyObject *kw_names) {
10971 CHECK_OBJECTS(args, 9);
10972 CHECK_OBJECT(kw_names);
10973 assert(PyTuple_CheckExact(kw_names));
10974 CHECK_OBJECT(called);
10975
10976 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
10977
10978 CHECK_OBJECTS(&args[9], kwargs_count);
10979
10980 if (Nuitka_Function_Check(called)) {
10981 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10982 return NULL;
10983 }
10984
10985 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10986
10987 PyObject *result =
10988 Nuitka_CallFunctionVectorcall(tstate, function, args, 9, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
10989
10990 Py_LeaveRecursiveCall();
10991
10992 CHECK_OBJECT_X(result);
10993
10994 return result;
10995#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10996 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10997 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10998
10999 if (likely(func != NULL)) {
11000 PyObject *result = func(called, args, 9, kw_names);
11001
11002 CHECK_OBJECT_X(result);
11003
11004 return Nuitka_CheckFunctionResult(tstate, called, result);
11005 }
11006#endif
11007 }
11008
11009#if 0
11010 PRINT_STRING("FALLBACK");
11011 PRINT_ITEM(called);
11012 PRINT_NEW_LINE();
11013#endif
11014
11015 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11016
11017 if (unlikely(call_slot == NULL)) {
11018 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11019
11020 return NULL;
11021 }
11022
11023 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11024 return NULL;
11025 }
11026
11027 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
11028
11029 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
11030
11031 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
11032 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11033
11034 PyObject *value = args[9 + i];
11035
11036 CHECK_OBJECT(key);
11037 CHECK_OBJECT(value);
11038
11039 DICT_SET_ITEM(named_args, key, value);
11040 }
11041
11042 PyObject *result = (*call_slot)(called, pos_args, named_args);
11043
11044 Py_DECREF(pos_args);
11045 Py_DECREF(named_args);
11046
11047 Py_LeaveRecursiveCall();
11048
11049 CHECK_OBJECT_X(result);
11050
11051 return Nuitka_CheckFunctionResult(tstate, called, result);
11052}
11053PyObject *CALL_FUNCTION_WITH_ARGS9_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11054 PyObject *const *kw_values, PyObject *kw_names) {
11055 CHECK_OBJECTS(args, 9);
11056 CHECK_OBJECT(kw_names);
11057 assert(PyTuple_CheckExact(kw_names));
11058 CHECK_OBJECT(called);
11059
11060 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
11061
11062 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11063
11064 if (Nuitka_Function_Check(called)) {
11065 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11066 return NULL;
11067 }
11068
11069 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11070
11071 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 9, kw_values, kw_names);
11072
11073 Py_LeaveRecursiveCall();
11074
11075 CHECK_OBJECT_X(result);
11076
11077 return result;
11078#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11079 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11080 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11081
11082 if (likely(func != NULL)) {
11083 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 9 + kwargs_count);
11084
11085 memcpy(vectorcall_args, args, 9 * sizeof(PyObject *));
11086 memcpy(&vectorcall_args[9], kw_values, kwargs_count * sizeof(PyObject *));
11087
11088 PyObject *result = func(called, vectorcall_args, 9, kw_names);
11089
11090 CHECK_OBJECT_X(result);
11091
11092 return Nuitka_CheckFunctionResult(tstate, called, result);
11093 }
11094#endif
11095 }
11096
11097#if 0
11098 PRINT_STRING("FALLBACK");
11099 PRINT_ITEM(called);
11100 PRINT_NEW_LINE();
11101#endif
11102
11103 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11104
11105 if (unlikely(call_slot == NULL)) {
11106 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11107
11108 return NULL;
11109 }
11110
11111 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11112 return NULL;
11113 }
11114
11115 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
11116
11117 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
11118
11119 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
11120 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11121
11122 PyObject *value = kw_values[i];
11123
11124 CHECK_OBJECT(key);
11125 CHECK_OBJECT(value);
11126
11127 DICT_SET_ITEM(named_args, key, value);
11128 }
11129
11130 PyObject *result = (*call_slot)(called, pos_args, named_args);
11131
11132 Py_DECREF(pos_args);
11133 Py_DECREF(named_args);
11134
11135 Py_LeaveRecursiveCall();
11136
11137 CHECK_OBJECT_X(result);
11138
11139 return Nuitka_CheckFunctionResult(tstate, called, result);
11140}
11141PyObject *CALL_FUNCTION_WITH_POS_ARGS9_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
11142 PyObject *const *kw_values, PyObject *kw_names) {
11143 assert(PyTuple_CheckExact(pos_args));
11144 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
11145 CHECK_OBJECTS(args, 9);
11146 CHECK_OBJECT(kw_names);
11147 assert(PyTuple_CheckExact(kw_names));
11148 CHECK_OBJECT(called);
11149
11150 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
11151
11152 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11153
11154 if (Nuitka_Function_Check(called)) {
11155 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11156 return NULL;
11157 }
11158
11159 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11160
11161 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 9, kw_values, kw_names);
11162
11163 Py_LeaveRecursiveCall();
11164
11165 CHECK_OBJECT_X(result);
11166
11167 return result;
11168#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11169 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11170 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11171
11172 if (likely(func != NULL)) {
11173 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 9 + kwargs_count);
11174
11175 memcpy(vectorcall_args, args, 9 * sizeof(PyObject *));
11176 memcpy(&vectorcall_args[9], kw_values, kwargs_count * sizeof(PyObject *));
11177
11178 PyObject *result = func(called, vectorcall_args, 9, kw_names);
11179
11180 CHECK_OBJECT_X(result);
11181
11182 return Nuitka_CheckFunctionResult(tstate, called, result);
11183 }
11184#endif
11185 }
11186
11187#if 0
11188 PRINT_STRING("FALLBACK");
11189 PRINT_ITEM(called);
11190 PRINT_NEW_LINE();
11191#endif
11192
11193 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11194
11195 if (unlikely(call_slot == NULL)) {
11196 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11197
11198 return NULL;
11199 }
11200
11201 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11202 return NULL;
11203 }
11204
11205 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
11206
11207 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
11208 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11209
11210 PyObject *value = kw_values[i];
11211
11212 CHECK_OBJECT(key);
11213 CHECK_OBJECT(value);
11214
11215 DICT_SET_ITEM(named_args, key, value);
11216 }
11217
11218 PyObject *result = (*call_slot)(called, pos_args, named_args);
11219
11220 Py_DECREF(named_args);
11221
11222 Py_LeaveRecursiveCall();
11223
11224 CHECK_OBJECT_X(result);
11225
11226 return Nuitka_CheckFunctionResult(tstate, called, result);
11227}
11228PyObject *CALL_FUNCTION_WITH_ARGS10_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11229 PyObject *kw_names) {
11230 CHECK_OBJECTS(args, 10);
11231 CHECK_OBJECT(kw_names);
11232 assert(PyTuple_CheckExact(kw_names));
11233 CHECK_OBJECT(called);
11234
11235 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
11236
11237 CHECK_OBJECTS(&args[10], kwargs_count);
11238
11239 if (Nuitka_Function_Check(called)) {
11240 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11241 return NULL;
11242 }
11243
11244 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11245
11246 PyObject *result =
11247 Nuitka_CallFunctionVectorcall(tstate, function, args, 10, &PyTuple_GET_ITEM(kw_names, 0), kwargs_count);
11248
11249 Py_LeaveRecursiveCall();
11250
11251 CHECK_OBJECT_X(result);
11252
11253 return result;
11254#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11255 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11256 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11257
11258 if (likely(func != NULL)) {
11259 PyObject *result = func(called, args, 10, kw_names);
11260
11261 CHECK_OBJECT_X(result);
11262
11263 return Nuitka_CheckFunctionResult(tstate, called, result);
11264 }
11265#endif
11266 }
11267
11268#if 0
11269 PRINT_STRING("FALLBACK");
11270 PRINT_ITEM(called);
11271 PRINT_NEW_LINE();
11272#endif
11273
11274 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11275
11276 if (unlikely(call_slot == NULL)) {
11277 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11278
11279 return NULL;
11280 }
11281
11282 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11283 return NULL;
11284 }
11285
11286 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
11287
11288 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
11289
11290 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
11291 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11292
11293 PyObject *value = args[10 + i];
11294
11295 CHECK_OBJECT(key);
11296 CHECK_OBJECT(value);
11297
11298 DICT_SET_ITEM(named_args, key, value);
11299 }
11300
11301 PyObject *result = (*call_slot)(called, pos_args, named_args);
11302
11303 Py_DECREF(pos_args);
11304 Py_DECREF(named_args);
11305
11306 Py_LeaveRecursiveCall();
11307
11308 CHECK_OBJECT_X(result);
11309
11310 return Nuitka_CheckFunctionResult(tstate, called, result);
11311}
11312PyObject *CALL_FUNCTION_WITH_ARGS10_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11313 PyObject *const *kw_values, PyObject *kw_names) {
11314 CHECK_OBJECTS(args, 10);
11315 CHECK_OBJECT(kw_names);
11316 assert(PyTuple_CheckExact(kw_names));
11317 CHECK_OBJECT(called);
11318
11319 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
11320
11321 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11322
11323 if (Nuitka_Function_Check(called)) {
11324 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11325 return NULL;
11326 }
11327
11328 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11329
11330 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 10, kw_values, kw_names);
11331
11332 Py_LeaveRecursiveCall();
11333
11334 CHECK_OBJECT_X(result);
11335
11336 return result;
11337#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11338 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11339 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11340
11341 if (likely(func != NULL)) {
11342 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 10 + kwargs_count);
11343
11344 memcpy(vectorcall_args, args, 10 * sizeof(PyObject *));
11345 memcpy(&vectorcall_args[10], kw_values, kwargs_count * sizeof(PyObject *));
11346
11347 PyObject *result = func(called, vectorcall_args, 10, kw_names);
11348
11349 CHECK_OBJECT_X(result);
11350
11351 return Nuitka_CheckFunctionResult(tstate, called, result);
11352 }
11353#endif
11354 }
11355
11356#if 0
11357 PRINT_STRING("FALLBACK");
11358 PRINT_ITEM(called);
11359 PRINT_NEW_LINE();
11360#endif
11361
11362 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11363
11364 if (unlikely(call_slot == NULL)) {
11365 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11366
11367 return NULL;
11368 }
11369
11370 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11371 return NULL;
11372 }
11373
11374 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
11375
11376 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
11377
11378 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
11379 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11380
11381 PyObject *value = kw_values[i];
11382
11383 CHECK_OBJECT(key);
11384 CHECK_OBJECT(value);
11385
11386 DICT_SET_ITEM(named_args, key, value);
11387 }
11388
11389 PyObject *result = (*call_slot)(called, pos_args, named_args);
11390
11391 Py_DECREF(pos_args);
11392 Py_DECREF(named_args);
11393
11394 Py_LeaveRecursiveCall();
11395
11396 CHECK_OBJECT_X(result);
11397
11398 return Nuitka_CheckFunctionResult(tstate, called, result);
11399}
11400PyObject *CALL_FUNCTION_WITH_POS_ARGS10_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
11401 PyObject *const *kw_values, PyObject *kw_names) {
11402 assert(PyTuple_CheckExact(pos_args));
11403 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
11404 CHECK_OBJECTS(args, 10);
11405 CHECK_OBJECT(kw_names);
11406 assert(PyTuple_CheckExact(kw_names));
11407 CHECK_OBJECT(called);
11408
11409 Py_ssize_t kwargs_count = PyTuple_GET_SIZE(kw_names);
11410
11411 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11412
11413 if (Nuitka_Function_Check(called)) {
11414 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11415 return NULL;
11416 }
11417
11418 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11419
11420 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 10, kw_values, kw_names);
11421
11422 Py_LeaveRecursiveCall();
11423
11424 CHECK_OBJECT_X(result);
11425
11426 return result;
11427#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11428 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11429 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11430
11431 if (likely(func != NULL)) {
11432 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 10 + kwargs_count);
11433
11434 memcpy(vectorcall_args, args, 10 * sizeof(PyObject *));
11435 memcpy(&vectorcall_args[10], kw_values, kwargs_count * sizeof(PyObject *));
11436
11437 PyObject *result = func(called, vectorcall_args, 10, kw_names);
11438
11439 CHECK_OBJECT_X(result);
11440
11441 return Nuitka_CheckFunctionResult(tstate, called, result);
11442 }
11443#endif
11444 }
11445
11446#if 0
11447 PRINT_STRING("FALLBACK");
11448 PRINT_ITEM(called);
11449 PRINT_NEW_LINE();
11450#endif
11451
11452 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11453
11454 if (unlikely(call_slot == NULL)) {
11455 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11456
11457 return NULL;
11458 }
11459
11460 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11461 return NULL;
11462 }
11463
11464 PyObject *named_args = _PyDict_NewPresized(kwargs_count);
11465
11466 for (Py_ssize_t i = 0; i < kwargs_count; i++) {
11467 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11468
11469 PyObject *value = kw_values[i];
11470
11471 CHECK_OBJECT(key);
11472 CHECK_OBJECT(value);
11473
11474 DICT_SET_ITEM(named_args, key, value);
11475 }
11476
11477 PyObject *result = (*call_slot)(called, pos_args, named_args);
11478
11479 Py_DECREF(named_args);
11480
11481 Py_LeaveRecursiveCall();
11482
11483 CHECK_OBJECT_X(result);
11484
11485 return Nuitka_CheckFunctionResult(tstate, called, result);
11486}
11487PyObject *CALL_METHODDESCR_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg) {
11488 PyObject *const *args = &arg; // For easier code compatibility.
11489 CHECK_OBJECT(called);
11490 CHECK_OBJECTS(args, 1);
11491
11492#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11493 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11494 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11495 assert(func != NULL);
11496 PyObject *result = func(called, args, 1, NULL);
11497
11498#ifndef __NUITKA_NO_ASSERT__
11499 return Nuitka_CheckFunctionResult(tstate, called, result);
11500#else
11501 return result;
11502#endif
11503#else
11504 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11505 PyMethodDef *method_def = called_descr->d_method;
11506
11507 // Try to be fast about wrapping the arguments.
11508 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11509
11510 if (likely(flags & METH_NOARGS)) {
11511 PyCFunction method = method_def->ml_meth;
11512 PyObject *self = args[0];
11513
11514 PyObject *result = (*method)(self, NULL);
11515
11516#ifndef __NUITKA_NO_ASSERT__
11517 return Nuitka_CheckFunctionResult(tstate, called, result);
11518#else
11519 return result;
11520#endif
11521 } else if ((flags & METH_O)) {
11522 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (1 given)",
11523 method_def->ml_name);
11524 return NULL;
11525 } else if (flags & METH_VARARGS) {
11526 PyCFunction method = method_def->ml_meth;
11527 PyObject *self = args[0];
11528
11529 PyObject *result;
11530
11531#if PYTHON_VERSION < 0x360
11532 if (flags & METH_KEYWORDS) {
11533 result = (*(PyCFunctionWithKeywords)method)(self, const_tuple_empty, NULL);
11534 } else {
11535 result = (*method)(self, const_tuple_empty);
11536 }
11537#else
11538 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11539 result = (*(PyCFunctionWithKeywords)method)(self, const_tuple_empty, NULL);
11540 } else if (flags == METH_FASTCALL) {
11541#if PYTHON_VERSION < 0x370
11542 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 0, NULL);
11543#else
11544 result = (*(_PyCFunctionFast)method)(self, &const_tuple_empty, 1);
11545#endif
11546 } else {
11547 result = (*method)(self, const_tuple_empty);
11548 }
11549#endif
11550#ifndef __NUITKA_NO_ASSERT__
11551 return Nuitka_CheckFunctionResult(tstate, called, result);
11552#else
11553 return result;
11554#endif
11555 }
11556
11557#if 0
11558 PRINT_NEW_LINE();
11559 PRINT_STRING("FALLBACK");
11560 PRINT_ITEM(called);
11561 PRINT_NEW_LINE();
11562#endif
11563
11564 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
11565
11566 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11567
11568 Py_DECREF(pos_args);
11569
11570 return result;
11571#endif
11572}
11573PyObject *CALL_METHODDESCR_WITH_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11574 CHECK_OBJECT(called);
11575 CHECK_OBJECTS(args, 2);
11576
11577#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11578 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11579 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11580 assert(func != NULL);
11581 PyObject *result = func(called, args, 2, NULL);
11582
11583#ifndef __NUITKA_NO_ASSERT__
11584 return Nuitka_CheckFunctionResult(tstate, called, result);
11585#else
11586 return result;
11587#endif
11588#else
11589 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11590 PyMethodDef *method_def = called_descr->d_method;
11591
11592 // Try to be fast about wrapping the arguments.
11593 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11594
11595 if (unlikely(flags & METH_NOARGS)) {
11596 PyCFunction method = method_def->ml_meth;
11597 PyObject *self = args[0];
11598
11599 PyObject *result = (*method)(self, NULL);
11600
11601#ifndef __NUITKA_NO_ASSERT__
11602 return Nuitka_CheckFunctionResult(tstate, called, result);
11603#else
11604 return result;
11605#endif
11606 } else if (unlikely(flags & METH_O)) {
11607 PyCFunction method = method_def->ml_meth;
11608 PyObject *self = args[0];
11609
11610 PyObject *result = (*method)(self, args[1]);
11611
11612#ifndef __NUITKA_NO_ASSERT__
11613 return Nuitka_CheckFunctionResult(tstate, called, result);
11614#else
11615 return result;
11616#endif
11617 } else if (flags & METH_VARARGS) {
11618 PyCFunction method = method_def->ml_meth;
11619 PyObject *self = args[0];
11620
11621 PyObject *result;
11622
11623#if PYTHON_VERSION < 0x360
11624 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11625
11626 if (flags & METH_KEYWORDS) {
11627 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11628 } else {
11629 result = (*method)(self, pos_args);
11630 }
11631
11632 Py_DECREF(pos_args);
11633#else
11634 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11635 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11636 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11637 Py_DECREF(pos_args);
11638 } else if (flags == METH_FASTCALL) {
11639#if PYTHON_VERSION < 0x370
11640 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 1, NULL);
11641#else
11642 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11643 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
11644 Py_DECREF(pos_args);
11645#endif
11646 } else {
11647 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11648 result = (*method)(self, pos_args);
11649 Py_DECREF(pos_args);
11650 }
11651#endif
11652#ifndef __NUITKA_NO_ASSERT__
11653 return Nuitka_CheckFunctionResult(tstate, called, result);
11654#else
11655 return result;
11656#endif
11657 }
11658
11659#if 0
11660 PRINT_NEW_LINE();
11661 PRINT_STRING("FALLBACK");
11662 PRINT_ITEM(called);
11663 PRINT_NEW_LINE();
11664#endif
11665
11666 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
11667
11668 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11669
11670 Py_DECREF(pos_args);
11671
11672 return result;
11673#endif
11674}
11675PyObject *CALL_METHODDESCR_WITH_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11676 CHECK_OBJECT(called);
11677 CHECK_OBJECTS(args, 3);
11678
11679#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11680 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11681 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11682 assert(func != NULL);
11683 PyObject *result = func(called, args, 3, NULL);
11684
11685#ifndef __NUITKA_NO_ASSERT__
11686 return Nuitka_CheckFunctionResult(tstate, called, result);
11687#else
11688 return result;
11689#endif
11690#else
11691 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11692 PyMethodDef *method_def = called_descr->d_method;
11693
11694 // Try to be fast about wrapping the arguments.
11695 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11696
11697 if (unlikely(flags & METH_NOARGS)) {
11698 PyCFunction method = method_def->ml_meth;
11699 PyObject *self = args[0];
11700
11701 PyObject *result = (*method)(self, NULL);
11702
11703#ifndef __NUITKA_NO_ASSERT__
11704 return Nuitka_CheckFunctionResult(tstate, called, result);
11705#else
11706 return result;
11707#endif
11708 } else if (unlikely(flags & METH_O)) {
11709 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
11710 method_def->ml_name);
11711 return NULL;
11712 } else if (flags & METH_VARARGS) {
11713 PyCFunction method = method_def->ml_meth;
11714 PyObject *self = args[0];
11715
11716 PyObject *result;
11717
11718#if PYTHON_VERSION < 0x360
11719 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11720
11721 if (flags & METH_KEYWORDS) {
11722 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11723 } else {
11724 result = (*method)(self, pos_args);
11725 }
11726
11727 Py_DECREF(pos_args);
11728#else
11729 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11730 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11731 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11732 Py_DECREF(pos_args);
11733 } else if (flags == METH_FASTCALL) {
11734#if PYTHON_VERSION < 0x370
11735 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 2, NULL);
11736#else
11737 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11738 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
11739 Py_DECREF(pos_args);
11740#endif
11741 } else {
11742 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11743 result = (*method)(self, pos_args);
11744 Py_DECREF(pos_args);
11745 }
11746#endif
11747#ifndef __NUITKA_NO_ASSERT__
11748 return Nuitka_CheckFunctionResult(tstate, called, result);
11749#else
11750 return result;
11751#endif
11752 }
11753
11754#if 0
11755 PRINT_NEW_LINE();
11756 PRINT_STRING("FALLBACK");
11757 PRINT_ITEM(called);
11758 PRINT_NEW_LINE();
11759#endif
11760
11761 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
11762
11763 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11764
11765 Py_DECREF(pos_args);
11766
11767 return result;
11768#endif
11769}
11770PyObject *CALL_METHODDESCR_WITH_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11771 CHECK_OBJECT(called);
11772 CHECK_OBJECTS(args, 4);
11773
11774#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11775 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11776 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11777 assert(func != NULL);
11778 PyObject *result = func(called, args, 4, NULL);
11779
11780#ifndef __NUITKA_NO_ASSERT__
11781 return Nuitka_CheckFunctionResult(tstate, called, result);
11782#else
11783 return result;
11784#endif
11785#else
11786 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11787 PyMethodDef *method_def = called_descr->d_method;
11788
11789 // Try to be fast about wrapping the arguments.
11790 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11791
11792 if (unlikely(flags & METH_NOARGS)) {
11793 PyCFunction method = method_def->ml_meth;
11794 PyObject *self = args[0];
11795
11796 PyObject *result = (*method)(self, NULL);
11797
11798#ifndef __NUITKA_NO_ASSERT__
11799 return Nuitka_CheckFunctionResult(tstate, called, result);
11800#else
11801 return result;
11802#endif
11803 } else if (unlikely(flags & METH_O)) {
11804 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
11805 method_def->ml_name);
11806 return NULL;
11807 } else if (flags & METH_VARARGS) {
11808 PyCFunction method = method_def->ml_meth;
11809 PyObject *self = args[0];
11810
11811 PyObject *result;
11812
11813#if PYTHON_VERSION < 0x360
11814 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11815
11816 if (flags & METH_KEYWORDS) {
11817 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11818 } else {
11819 result = (*method)(self, pos_args);
11820 }
11821
11822 Py_DECREF(pos_args);
11823#else
11824 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11825 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11826 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11827 Py_DECREF(pos_args);
11828 } else if (flags == METH_FASTCALL) {
11829#if PYTHON_VERSION < 0x370
11830 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 3, NULL);
11831#else
11832 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11833 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
11834 Py_DECREF(pos_args);
11835#endif
11836 } else {
11837 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11838 result = (*method)(self, pos_args);
11839 Py_DECREF(pos_args);
11840 }
11841#endif
11842#ifndef __NUITKA_NO_ASSERT__
11843 return Nuitka_CheckFunctionResult(tstate, called, result);
11844#else
11845 return result;
11846#endif
11847 }
11848
11849#if 0
11850 PRINT_NEW_LINE();
11851 PRINT_STRING("FALLBACK");
11852 PRINT_ITEM(called);
11853 PRINT_NEW_LINE();
11854#endif
11855
11856 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
11857
11858 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11859
11860 Py_DECREF(pos_args);
11861
11862 return result;
11863#endif
11864}
11865PyObject *CALL_METHOD_NO_ARGS(PyThreadState *tstate, PyObject *source, PyObject *attr_name) {
11866 CHECK_OBJECT(source);
11867 CHECK_OBJECT(attr_name);
11868
11869 PyTypeObject *type = Py_TYPE(source);
11870
11871 if (hasTypeGenericGetAttr(type)) {
11872 // Unfortunately this is required, although of cause rarely necessary.
11873 if (unlikely(type->tp_dict == NULL)) {
11874 if (unlikely(PyType_Ready(type) < 0)) {
11875 return NULL;
11876 }
11877 }
11878
11879 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
11880 descrgetfunc func = NULL;
11881
11882 if (descr != NULL) {
11883 Py_INCREF(descr);
11884
11885 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
11886 func = Py_TYPE(descr)->tp_descr_get;
11887
11888 if (func != NULL && Nuitka_Descr_IsData(descr)) {
11889 PyObject *called_object = func(descr, source, (PyObject *)type);
11890 Py_DECREF(descr);
11891
11892 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11893 Py_DECREF(called_object);
11894 return result;
11895 }
11896 }
11897 }
11898
11899 Py_ssize_t dictoffset = type->tp_dictoffset;
11900 PyObject *dict = NULL;
11901
11902 if (dictoffset != 0) {
11903 // Negative dictionary offsets have special meaning.
11904 if (dictoffset < 0) {
11905 Py_ssize_t tsize;
11906 size_t size;
11907
11908 tsize = ((PyVarObject *)source)->ob_size;
11909 if (tsize < 0) {
11910 tsize = -tsize;
11911 }
11912 size = _PyObject_VAR_SIZE(type, tsize);
11913
11914 dictoffset += (long)size;
11915 }
11916
11917 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
11918 dict = *dictptr;
11919 }
11920
11921 if (dict != NULL) {
11922 CHECK_OBJECT(dict);
11923
11924 Py_INCREF(dict);
11925
11926 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
11927
11928 if (called_object != NULL) {
11929 Py_XDECREF(descr);
11930 Py_DECREF(dict);
11931
11932 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11933 Py_DECREF(called_object);
11934 return result;
11935 }
11936
11937 Py_DECREF(dict);
11938 }
11939
11940 if (func != NULL) {
11941 if (func == Nuitka_Function_Type.tp_descr_get) {
11942 PyObject *result =
11943 Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)descr, source);
11944 Py_DECREF(descr);
11945
11946 return result;
11947 } else {
11948 PyObject *called_object = func(descr, source, (PyObject *)type);
11949 CHECK_OBJECT(called_object);
11950
11951 Py_DECREF(descr);
11952
11953 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11954 Py_DECREF(called_object);
11955 return result;
11956 }
11957 }
11958
11959 if (descr != NULL) {
11960 CHECK_OBJECT(descr);
11961
11962 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, descr);
11963 Py_DECREF(descr);
11964 return result;
11965 }
11966
11967#if PYTHON_VERSION < 0x300
11968 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
11969 PyString_AS_STRING(attr_name));
11970#else
11971 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
11972#endif
11973 return NULL;
11974 }
11975#if PYTHON_VERSION < 0x300
11976 else if (type == &PyInstance_Type) {
11977 PyInstanceObject *source_instance = (PyInstanceObject *)source;
11978
11979 // The special cases have their own variant on the code generation level
11980 // as we are called with constants only.
11981 assert(attr_name != const_str_plain___dict__);
11982 assert(attr_name != const_str_plain___class__);
11983
11984 // Try the instance dict first.
11985 PyObject *called_object =
11986 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
11987
11988 // Note: The "called_object" was found without taking a reference,
11989 // so we need not release it in this branch.
11990 if (called_object != NULL) {
11991 return CALL_FUNCTION_NO_ARGS(tstate, called_object);
11992 }
11993
11994 // Then check the class dictionaries.
11995 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
11996
11997 // Note: The "called_object" was found without taking a reference,
11998 // so we need not release it in this branch.
11999 if (called_object != NULL) {
12000 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12001
12002 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12003 return Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12004 source);
12005 } else if (descr_get != NULL) {
12006 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12007
12008 if (unlikely(method == NULL)) {
12009 return NULL;
12010 }
12011
12012 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, method);
12013 Py_DECREF(method);
12014 return result;
12015 } else {
12016 return CALL_FUNCTION_NO_ARGS(tstate, called_object);
12017 }
12018
12019 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12020 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12021 PyString_AS_STRING(source_instance->in_class->cl_name),
12022 PyString_AS_STRING(attr_name));
12023
12024 return NULL;
12025 } else {
12026 // Finally allow the "__getattr__" override to provide it or else
12027 // it's an error.
12028
12029 PyObject *args2[] = {source, attr_name};
12030
12031 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12032
12033 if (unlikely(called_object == NULL)) {
12034 return NULL;
12035 }
12036
12037 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12038 Py_DECREF(called_object);
12039 return result;
12040 }
12041 }
12042#endif
12043 else if (type->tp_getattro != NULL) {
12044 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12045
12046 if (unlikely(descr == NULL)) {
12047 return NULL;
12048 }
12049
12050 descrgetfunc func = NULL;
12051 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12052 func = Py_TYPE(descr)->tp_descr_get;
12053
12054 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12055 PyObject *called_object = func(descr, source, (PyObject *)type);
12056 Py_DECREF(descr);
12057
12058 if (unlikely(called_object == NULL)) {
12059 return NULL;
12060 }
12061
12062 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12063 Py_DECREF(called_object);
12064 return result;
12065 }
12066 }
12067
12068 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, descr);
12069 Py_DECREF(descr);
12070 return result;
12071 } else if (type->tp_getattr != NULL) {
12072 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12073
12074 if (unlikely(called_object == NULL)) {
12075 return NULL;
12076 }
12077
12078 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12079 Py_DECREF(called_object);
12080 return result;
12081 } else {
12082 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12083 Nuitka_String_AsString_Unchecked(attr_name));
12084
12085 return NULL;
12086 }
12087}
12088PyObject *CALL_METHOD_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *arg) {
12089 PyObject *const *args = &arg; // For easier code compatibility.
12090 CHECK_OBJECT(source);
12091 CHECK_OBJECT(attr_name);
12092
12093 CHECK_OBJECTS(args, 1);
12094
12095 PyTypeObject *type = Py_TYPE(source);
12096
12097 if (hasTypeGenericGetAttr(type)) {
12098 // Unfortunately this is required, although of cause rarely necessary.
12099 if (unlikely(type->tp_dict == NULL)) {
12100 if (unlikely(PyType_Ready(type) < 0)) {
12101 return NULL;
12102 }
12103 }
12104
12105 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12106 descrgetfunc func = NULL;
12107
12108 if (descr != NULL) {
12109 Py_INCREF(descr);
12110
12111 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12112 func = Py_TYPE(descr)->tp_descr_get;
12113
12114 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12115 PyObject *called_object = func(descr, source, (PyObject *)type);
12116 Py_DECREF(descr);
12117
12118 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12119 Py_DECREF(called_object);
12120 return result;
12121 }
12122 }
12123 }
12124
12125 Py_ssize_t dictoffset = type->tp_dictoffset;
12126 PyObject *dict = NULL;
12127
12128 if (dictoffset != 0) {
12129 // Negative dictionary offsets have special meaning.
12130 if (dictoffset < 0) {
12131 Py_ssize_t tsize;
12132 size_t size;
12133
12134 tsize = ((PyVarObject *)source)->ob_size;
12135 if (tsize < 0) {
12136 tsize = -tsize;
12137 }
12138 size = _PyObject_VAR_SIZE(type, tsize);
12139
12140 dictoffset += (long)size;
12141 }
12142
12143 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12144 dict = *dictptr;
12145 }
12146
12147 if (dict != NULL) {
12148 CHECK_OBJECT(dict);
12149
12150 Py_INCREF(dict);
12151
12152 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12153
12154 if (called_object != NULL) {
12155 Py_XDECREF(descr);
12156 Py_DECREF(dict);
12157
12158 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12159 Py_DECREF(called_object);
12160 return result;
12161 }
12162
12163 Py_DECREF(dict);
12164 }
12165
12166 if (func != NULL) {
12167 if (func == Nuitka_Function_Type.tp_descr_get) {
12168 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12169 source, args, 1);
12170 Py_DECREF(descr);
12171
12172 return result;
12173 } else {
12174 PyObject *called_object = func(descr, source, (PyObject *)type);
12175 CHECK_OBJECT(called_object);
12176
12177 Py_DECREF(descr);
12178
12179 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12180 Py_DECREF(called_object);
12181 return result;
12182 }
12183 }
12184
12185 if (descr != NULL) {
12186 CHECK_OBJECT(descr);
12187
12188 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, descr, args[0]);
12189 Py_DECREF(descr);
12190 return result;
12191 }
12192
12193#if PYTHON_VERSION < 0x300
12194 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12195 PyString_AS_STRING(attr_name));
12196#else
12197 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12198#endif
12199 return NULL;
12200 }
12201#if PYTHON_VERSION < 0x300
12202 else if (type == &PyInstance_Type) {
12203 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12204
12205 // The special cases have their own variant on the code generation level
12206 // as we are called with constants only.
12207 assert(attr_name != const_str_plain___dict__);
12208 assert(attr_name != const_str_plain___class__);
12209
12210 // Try the instance dict first.
12211 PyObject *called_object =
12212 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12213
12214 // Note: The "called_object" was found without taking a reference,
12215 // so we need not release it in this branch.
12216 if (called_object != NULL) {
12217 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12218 }
12219
12220 // Then check the class dictionaries.
12221 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12222
12223 // Note: The "called_object" was found without taking a reference,
12224 // so we need not release it in this branch.
12225 if (called_object != NULL) {
12226 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12227
12228 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12229 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12230 source, args, 1);
12231 } else if (descr_get != NULL) {
12232 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12233
12234 if (unlikely(method == NULL)) {
12235 return NULL;
12236 }
12237
12238 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, method, args[0]);
12239 Py_DECREF(method);
12240 return result;
12241 } else {
12242 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12243 }
12244
12245 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12246 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12247 PyString_AS_STRING(source_instance->in_class->cl_name),
12248 PyString_AS_STRING(attr_name));
12249
12250 return NULL;
12251 } else {
12252 // Finally allow the "__getattr__" override to provide it or else
12253 // it's an error.
12254
12255 PyObject *args2[] = {source, attr_name};
12256
12257 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12258
12259 if (unlikely(called_object == NULL)) {
12260 return NULL;
12261 }
12262
12263 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12264 Py_DECREF(called_object);
12265 return result;
12266 }
12267 }
12268#endif
12269 else if (type->tp_getattro != NULL) {
12270 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12271
12272 if (unlikely(descr == NULL)) {
12273 return NULL;
12274 }
12275
12276 descrgetfunc func = NULL;
12277 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12278 func = Py_TYPE(descr)->tp_descr_get;
12279
12280 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12281 PyObject *called_object = func(descr, source, (PyObject *)type);
12282 Py_DECREF(descr);
12283
12284 if (unlikely(called_object == NULL)) {
12285 return NULL;
12286 }
12287
12288 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12289 Py_DECREF(called_object);
12290 return result;
12291 }
12292 }
12293
12294 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, descr, args[0]);
12295 Py_DECREF(descr);
12296 return result;
12297 } else if (type->tp_getattr != NULL) {
12298 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12299
12300 if (unlikely(called_object == NULL)) {
12301 return NULL;
12302 }
12303
12304 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12305 Py_DECREF(called_object);
12306 return result;
12307 } else {
12308 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12309 Nuitka_String_AsString_Unchecked(attr_name));
12310
12311 return NULL;
12312 }
12313}
12314PyObject *CALL_METHOD_WITH_ARGS2(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12315 CHECK_OBJECT(source);
12316 CHECK_OBJECT(attr_name);
12317
12318 CHECK_OBJECTS(args, 2);
12319
12320 PyTypeObject *type = Py_TYPE(source);
12321
12322 if (hasTypeGenericGetAttr(type)) {
12323 // Unfortunately this is required, although of cause rarely necessary.
12324 if (unlikely(type->tp_dict == NULL)) {
12325 if (unlikely(PyType_Ready(type) < 0)) {
12326 return NULL;
12327 }
12328 }
12329
12330 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12331 descrgetfunc func = NULL;
12332
12333 if (descr != NULL) {
12334 Py_INCREF(descr);
12335
12336 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12337 func = Py_TYPE(descr)->tp_descr_get;
12338
12339 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12340 PyObject *called_object = func(descr, source, (PyObject *)type);
12341 Py_DECREF(descr);
12342
12343 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12344 Py_DECREF(called_object);
12345 return result;
12346 }
12347 }
12348 }
12349
12350 Py_ssize_t dictoffset = type->tp_dictoffset;
12351 PyObject *dict = NULL;
12352
12353 if (dictoffset != 0) {
12354 // Negative dictionary offsets have special meaning.
12355 if (dictoffset < 0) {
12356 Py_ssize_t tsize;
12357 size_t size;
12358
12359 tsize = ((PyVarObject *)source)->ob_size;
12360 if (tsize < 0) {
12361 tsize = -tsize;
12362 }
12363 size = _PyObject_VAR_SIZE(type, tsize);
12364
12365 dictoffset += (long)size;
12366 }
12367
12368 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12369 dict = *dictptr;
12370 }
12371
12372 if (dict != NULL) {
12373 CHECK_OBJECT(dict);
12374
12375 Py_INCREF(dict);
12376
12377 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12378
12379 if (called_object != NULL) {
12380 Py_XDECREF(descr);
12381 Py_DECREF(dict);
12382
12383 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12384 Py_DECREF(called_object);
12385 return result;
12386 }
12387
12388 Py_DECREF(dict);
12389 }
12390
12391 if (func != NULL) {
12392 if (func == Nuitka_Function_Type.tp_descr_get) {
12393 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12394 source, args, 2);
12395 Py_DECREF(descr);
12396
12397 return result;
12398 } else {
12399 PyObject *called_object = func(descr, source, (PyObject *)type);
12400 CHECK_OBJECT(called_object);
12401
12402 Py_DECREF(descr);
12403
12404 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12405 Py_DECREF(called_object);
12406 return result;
12407 }
12408 }
12409
12410 if (descr != NULL) {
12411 CHECK_OBJECT(descr);
12412
12413 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, descr, args);
12414 Py_DECREF(descr);
12415 return result;
12416 }
12417
12418#if PYTHON_VERSION < 0x300
12419 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12420 PyString_AS_STRING(attr_name));
12421#else
12422 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12423#endif
12424 return NULL;
12425 }
12426#if PYTHON_VERSION < 0x300
12427 else if (type == &PyInstance_Type) {
12428 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12429
12430 // The special cases have their own variant on the code generation level
12431 // as we are called with constants only.
12432 assert(attr_name != const_str_plain___dict__);
12433 assert(attr_name != const_str_plain___class__);
12434
12435 // Try the instance dict first.
12436 PyObject *called_object =
12437 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12438
12439 // Note: The "called_object" was found without taking a reference,
12440 // so we need not release it in this branch.
12441 if (called_object != NULL) {
12442 return CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12443 }
12444
12445 // Then check the class dictionaries.
12446 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12447
12448 // Note: The "called_object" was found without taking a reference,
12449 // so we need not release it in this branch.
12450 if (called_object != NULL) {
12451 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12452
12453 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12454 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12455 source, args, 2);
12456 } else if (descr_get != NULL) {
12457 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12458
12459 if (unlikely(method == NULL)) {
12460 return NULL;
12461 }
12462
12463 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, method, args);
12464 Py_DECREF(method);
12465 return result;
12466 } else {
12467 return CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12468 }
12469
12470 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12471 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12472 PyString_AS_STRING(source_instance->in_class->cl_name),
12473 PyString_AS_STRING(attr_name));
12474
12475 return NULL;
12476 } else {
12477 // Finally allow the "__getattr__" override to provide it or else
12478 // it's an error.
12479
12480 PyObject *args2[] = {source, attr_name};
12481
12482 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12483
12484 if (unlikely(called_object == NULL)) {
12485 return NULL;
12486 }
12487
12488 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12489 Py_DECREF(called_object);
12490 return result;
12491 }
12492 }
12493#endif
12494 else if (type->tp_getattro != NULL) {
12495 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12496
12497 if (unlikely(descr == NULL)) {
12498 return NULL;
12499 }
12500
12501 descrgetfunc func = NULL;
12502 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12503 func = Py_TYPE(descr)->tp_descr_get;
12504
12505 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12506 PyObject *called_object = func(descr, source, (PyObject *)type);
12507 Py_DECREF(descr);
12508
12509 if (unlikely(called_object == NULL)) {
12510 return NULL;
12511 }
12512
12513 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12514 Py_DECREF(called_object);
12515 return result;
12516 }
12517 }
12518
12519 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, descr, args);
12520 Py_DECREF(descr);
12521 return result;
12522 } else if (type->tp_getattr != NULL) {
12523 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12524
12525 if (unlikely(called_object == NULL)) {
12526 return NULL;
12527 }
12528
12529 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12530 Py_DECREF(called_object);
12531 return result;
12532 } else {
12533 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12534 Nuitka_String_AsString_Unchecked(attr_name));
12535
12536 return NULL;
12537 }
12538}
12539PyObject *CALL_METHOD_WITH_ARGS3(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12540 CHECK_OBJECT(source);
12541 CHECK_OBJECT(attr_name);
12542
12543 CHECK_OBJECTS(args, 3);
12544
12545 PyTypeObject *type = Py_TYPE(source);
12546
12547 if (hasTypeGenericGetAttr(type)) {
12548 // Unfortunately this is required, although of cause rarely necessary.
12549 if (unlikely(type->tp_dict == NULL)) {
12550 if (unlikely(PyType_Ready(type) < 0)) {
12551 return NULL;
12552 }
12553 }
12554
12555 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12556 descrgetfunc func = NULL;
12557
12558 if (descr != NULL) {
12559 Py_INCREF(descr);
12560
12561 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12562 func = Py_TYPE(descr)->tp_descr_get;
12563
12564 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12565 PyObject *called_object = func(descr, source, (PyObject *)type);
12566 Py_DECREF(descr);
12567
12568 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12569 Py_DECREF(called_object);
12570 return result;
12571 }
12572 }
12573 }
12574
12575 Py_ssize_t dictoffset = type->tp_dictoffset;
12576 PyObject *dict = NULL;
12577
12578 if (dictoffset != 0) {
12579 // Negative dictionary offsets have special meaning.
12580 if (dictoffset < 0) {
12581 Py_ssize_t tsize;
12582 size_t size;
12583
12584 tsize = ((PyVarObject *)source)->ob_size;
12585 if (tsize < 0) {
12586 tsize = -tsize;
12587 }
12588 size = _PyObject_VAR_SIZE(type, tsize);
12589
12590 dictoffset += (long)size;
12591 }
12592
12593 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12594 dict = *dictptr;
12595 }
12596
12597 if (dict != NULL) {
12598 CHECK_OBJECT(dict);
12599
12600 Py_INCREF(dict);
12601
12602 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12603
12604 if (called_object != NULL) {
12605 Py_XDECREF(descr);
12606 Py_DECREF(dict);
12607
12608 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12609 Py_DECREF(called_object);
12610 return result;
12611 }
12612
12613 Py_DECREF(dict);
12614 }
12615
12616 if (func != NULL) {
12617 if (func == Nuitka_Function_Type.tp_descr_get) {
12618 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12619 source, args, 3);
12620 Py_DECREF(descr);
12621
12622 return result;
12623 } else {
12624 PyObject *called_object = func(descr, source, (PyObject *)type);
12625 CHECK_OBJECT(called_object);
12626
12627 Py_DECREF(descr);
12628
12629 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12630 Py_DECREF(called_object);
12631 return result;
12632 }
12633 }
12634
12635 if (descr != NULL) {
12636 CHECK_OBJECT(descr);
12637
12638 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, descr, args);
12639 Py_DECREF(descr);
12640 return result;
12641 }
12642
12643#if PYTHON_VERSION < 0x300
12644 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12645 PyString_AS_STRING(attr_name));
12646#else
12647 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12648#endif
12649 return NULL;
12650 }
12651#if PYTHON_VERSION < 0x300
12652 else if (type == &PyInstance_Type) {
12653 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12654
12655 // The special cases have their own variant on the code generation level
12656 // as we are called with constants only.
12657 assert(attr_name != const_str_plain___dict__);
12658 assert(attr_name != const_str_plain___class__);
12659
12660 // Try the instance dict first.
12661 PyObject *called_object =
12662 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12663
12664 // Note: The "called_object" was found without taking a reference,
12665 // so we need not release it in this branch.
12666 if (called_object != NULL) {
12667 return CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12668 }
12669
12670 // Then check the class dictionaries.
12671 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12672
12673 // Note: The "called_object" was found without taking a reference,
12674 // so we need not release it in this branch.
12675 if (called_object != NULL) {
12676 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12677
12678 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12679 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12680 source, args, 3);
12681 } else if (descr_get != NULL) {
12682 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12683
12684 if (unlikely(method == NULL)) {
12685 return NULL;
12686 }
12687
12688 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, method, args);
12689 Py_DECREF(method);
12690 return result;
12691 } else {
12692 return CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12693 }
12694
12695 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12696 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12697 PyString_AS_STRING(source_instance->in_class->cl_name),
12698 PyString_AS_STRING(attr_name));
12699
12700 return NULL;
12701 } else {
12702 // Finally allow the "__getattr__" override to provide it or else
12703 // it's an error.
12704
12705 PyObject *args2[] = {source, attr_name};
12706
12707 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12708
12709 if (unlikely(called_object == NULL)) {
12710 return NULL;
12711 }
12712
12713 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12714 Py_DECREF(called_object);
12715 return result;
12716 }
12717 }
12718#endif
12719 else if (type->tp_getattro != NULL) {
12720 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12721
12722 if (unlikely(descr == NULL)) {
12723 return NULL;
12724 }
12725
12726 descrgetfunc func = NULL;
12727 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12728 func = Py_TYPE(descr)->tp_descr_get;
12729
12730 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12731 PyObject *called_object = func(descr, source, (PyObject *)type);
12732 Py_DECREF(descr);
12733
12734 if (unlikely(called_object == NULL)) {
12735 return NULL;
12736 }
12737
12738 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12739 Py_DECREF(called_object);
12740 return result;
12741 }
12742 }
12743
12744 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, descr, args);
12745 Py_DECREF(descr);
12746 return result;
12747 } else if (type->tp_getattr != NULL) {
12748 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12749
12750 if (unlikely(called_object == NULL)) {
12751 return NULL;
12752 }
12753
12754 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12755 Py_DECREF(called_object);
12756 return result;
12757 } else {
12758 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12759 Nuitka_String_AsString_Unchecked(attr_name));
12760
12761 return NULL;
12762 }
12763}
12764PyObject *CALL_METHOD_WITH_ARGS4(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12765 CHECK_OBJECT(source);
12766 CHECK_OBJECT(attr_name);
12767
12768 CHECK_OBJECTS(args, 4);
12769
12770 PyTypeObject *type = Py_TYPE(source);
12771
12772 if (hasTypeGenericGetAttr(type)) {
12773 // Unfortunately this is required, although of cause rarely necessary.
12774 if (unlikely(type->tp_dict == NULL)) {
12775 if (unlikely(PyType_Ready(type) < 0)) {
12776 return NULL;
12777 }
12778 }
12779
12780 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12781 descrgetfunc func = NULL;
12782
12783 if (descr != NULL) {
12784 Py_INCREF(descr);
12785
12786 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12787 func = Py_TYPE(descr)->tp_descr_get;
12788
12789 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12790 PyObject *called_object = func(descr, source, (PyObject *)type);
12791 Py_DECREF(descr);
12792
12793 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12794 Py_DECREF(called_object);
12795 return result;
12796 }
12797 }
12798 }
12799
12800 Py_ssize_t dictoffset = type->tp_dictoffset;
12801 PyObject *dict = NULL;
12802
12803 if (dictoffset != 0) {
12804 // Negative dictionary offsets have special meaning.
12805 if (dictoffset < 0) {
12806 Py_ssize_t tsize;
12807 size_t size;
12808
12809 tsize = ((PyVarObject *)source)->ob_size;
12810 if (tsize < 0) {
12811 tsize = -tsize;
12812 }
12813 size = _PyObject_VAR_SIZE(type, tsize);
12814
12815 dictoffset += (long)size;
12816 }
12817
12818 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12819 dict = *dictptr;
12820 }
12821
12822 if (dict != NULL) {
12823 CHECK_OBJECT(dict);
12824
12825 Py_INCREF(dict);
12826
12827 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12828
12829 if (called_object != NULL) {
12830 Py_XDECREF(descr);
12831 Py_DECREF(dict);
12832
12833 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12834 Py_DECREF(called_object);
12835 return result;
12836 }
12837
12838 Py_DECREF(dict);
12839 }
12840
12841 if (func != NULL) {
12842 if (func == Nuitka_Function_Type.tp_descr_get) {
12843 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12844 source, args, 4);
12845 Py_DECREF(descr);
12846
12847 return result;
12848 } else {
12849 PyObject *called_object = func(descr, source, (PyObject *)type);
12850 CHECK_OBJECT(called_object);
12851
12852 Py_DECREF(descr);
12853
12854 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12855 Py_DECREF(called_object);
12856 return result;
12857 }
12858 }
12859
12860 if (descr != NULL) {
12861 CHECK_OBJECT(descr);
12862
12863 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, descr, args);
12864 Py_DECREF(descr);
12865 return result;
12866 }
12867
12868#if PYTHON_VERSION < 0x300
12869 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12870 PyString_AS_STRING(attr_name));
12871#else
12872 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12873#endif
12874 return NULL;
12875 }
12876#if PYTHON_VERSION < 0x300
12877 else if (type == &PyInstance_Type) {
12878 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12879
12880 // The special cases have their own variant on the code generation level
12881 // as we are called with constants only.
12882 assert(attr_name != const_str_plain___dict__);
12883 assert(attr_name != const_str_plain___class__);
12884
12885 // Try the instance dict first.
12886 PyObject *called_object =
12887 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12888
12889 // Note: The "called_object" was found without taking a reference,
12890 // so we need not release it in this branch.
12891 if (called_object != NULL) {
12892 return CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12893 }
12894
12895 // Then check the class dictionaries.
12896 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12897
12898 // Note: The "called_object" was found without taking a reference,
12899 // so we need not release it in this branch.
12900 if (called_object != NULL) {
12901 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12902
12903 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12904 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12905 source, args, 4);
12906 } else if (descr_get != NULL) {
12907 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12908
12909 if (unlikely(method == NULL)) {
12910 return NULL;
12911 }
12912
12913 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, method, args);
12914 Py_DECREF(method);
12915 return result;
12916 } else {
12917 return CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12918 }
12919
12920 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12921 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12922 PyString_AS_STRING(source_instance->in_class->cl_name),
12923 PyString_AS_STRING(attr_name));
12924
12925 return NULL;
12926 } else {
12927 // Finally allow the "__getattr__" override to provide it or else
12928 // it's an error.
12929
12930 PyObject *args2[] = {source, attr_name};
12931
12932 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12933
12934 if (unlikely(called_object == NULL)) {
12935 return NULL;
12936 }
12937
12938 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12939 Py_DECREF(called_object);
12940 return result;
12941 }
12942 }
12943#endif
12944 else if (type->tp_getattro != NULL) {
12945 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12946
12947 if (unlikely(descr == NULL)) {
12948 return NULL;
12949 }
12950
12951 descrgetfunc func = NULL;
12952 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12953 func = Py_TYPE(descr)->tp_descr_get;
12954
12955 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12956 PyObject *called_object = func(descr, source, (PyObject *)type);
12957 Py_DECREF(descr);
12958
12959 if (unlikely(called_object == NULL)) {
12960 return NULL;
12961 }
12962
12963 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12964 Py_DECREF(called_object);
12965 return result;
12966 }
12967 }
12968
12969 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, descr, args);
12970 Py_DECREF(descr);
12971 return result;
12972 } else if (type->tp_getattr != NULL) {
12973 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12974
12975 if (unlikely(called_object == NULL)) {
12976 return NULL;
12977 }
12978
12979 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12980 Py_DECREF(called_object);
12981 return result;
12982 } else {
12983 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12984 Nuitka_String_AsString_Unchecked(attr_name));
12985
12986 return NULL;
12987 }
12988}
12989PyObject *CALL_METHOD_WITH_ARGS5(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12990 CHECK_OBJECT(source);
12991 CHECK_OBJECT(attr_name);
12992
12993 CHECK_OBJECTS(args, 5);
12994
12995 PyTypeObject *type = Py_TYPE(source);
12996
12997 if (hasTypeGenericGetAttr(type)) {
12998 // Unfortunately this is required, although of cause rarely necessary.
12999 if (unlikely(type->tp_dict == NULL)) {
13000 if (unlikely(PyType_Ready(type) < 0)) {
13001 return NULL;
13002 }
13003 }
13004
13005 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13006 descrgetfunc func = NULL;
13007
13008 if (descr != NULL) {
13009 Py_INCREF(descr);
13010
13011 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13012 func = Py_TYPE(descr)->tp_descr_get;
13013
13014 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13015 PyObject *called_object = func(descr, source, (PyObject *)type);
13016 Py_DECREF(descr);
13017
13018 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13019 Py_DECREF(called_object);
13020 return result;
13021 }
13022 }
13023 }
13024
13025 Py_ssize_t dictoffset = type->tp_dictoffset;
13026 PyObject *dict = NULL;
13027
13028 if (dictoffset != 0) {
13029 // Negative dictionary offsets have special meaning.
13030 if (dictoffset < 0) {
13031 Py_ssize_t tsize;
13032 size_t size;
13033
13034 tsize = ((PyVarObject *)source)->ob_size;
13035 if (tsize < 0) {
13036 tsize = -tsize;
13037 }
13038 size = _PyObject_VAR_SIZE(type, tsize);
13039
13040 dictoffset += (long)size;
13041 }
13042
13043 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13044 dict = *dictptr;
13045 }
13046
13047 if (dict != NULL) {
13048 CHECK_OBJECT(dict);
13049
13050 Py_INCREF(dict);
13051
13052 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13053
13054 if (called_object != NULL) {
13055 Py_XDECREF(descr);
13056 Py_DECREF(dict);
13057
13058 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13059 Py_DECREF(called_object);
13060 return result;
13061 }
13062
13063 Py_DECREF(dict);
13064 }
13065
13066 if (func != NULL) {
13067 if (func == Nuitka_Function_Type.tp_descr_get) {
13068 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13069 source, args, 5);
13070 Py_DECREF(descr);
13071
13072 return result;
13073 } else {
13074 PyObject *called_object = func(descr, source, (PyObject *)type);
13075 CHECK_OBJECT(called_object);
13076
13077 Py_DECREF(descr);
13078
13079 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13080 Py_DECREF(called_object);
13081 return result;
13082 }
13083 }
13084
13085 if (descr != NULL) {
13086 CHECK_OBJECT(descr);
13087
13088 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, descr, args);
13089 Py_DECREF(descr);
13090 return result;
13091 }
13092
13093#if PYTHON_VERSION < 0x300
13094 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13095 PyString_AS_STRING(attr_name));
13096#else
13097 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13098#endif
13099 return NULL;
13100 }
13101#if PYTHON_VERSION < 0x300
13102 else if (type == &PyInstance_Type) {
13103 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13104
13105 // The special cases have their own variant on the code generation level
13106 // as we are called with constants only.
13107 assert(attr_name != const_str_plain___dict__);
13108 assert(attr_name != const_str_plain___class__);
13109
13110 // Try the instance dict first.
13111 PyObject *called_object =
13112 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13113
13114 // Note: The "called_object" was found without taking a reference,
13115 // so we need not release it in this branch.
13116 if (called_object != NULL) {
13117 return CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13118 }
13119
13120 // Then check the class dictionaries.
13121 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13122
13123 // Note: The "called_object" was found without taking a reference,
13124 // so we need not release it in this branch.
13125 if (called_object != NULL) {
13126 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13127
13128 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13129 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13130 source, args, 5);
13131 } else if (descr_get != NULL) {
13132 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13133
13134 if (unlikely(method == NULL)) {
13135 return NULL;
13136 }
13137
13138 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, method, args);
13139 Py_DECREF(method);
13140 return result;
13141 } else {
13142 return CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13143 }
13144
13145 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13146 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13147 PyString_AS_STRING(source_instance->in_class->cl_name),
13148 PyString_AS_STRING(attr_name));
13149
13150 return NULL;
13151 } else {
13152 // Finally allow the "__getattr__" override to provide it or else
13153 // it's an error.
13154
13155 PyObject *args2[] = {source, attr_name};
13156
13157 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13158
13159 if (unlikely(called_object == NULL)) {
13160 return NULL;
13161 }
13162
13163 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13164 Py_DECREF(called_object);
13165 return result;
13166 }
13167 }
13168#endif
13169 else if (type->tp_getattro != NULL) {
13170 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13171
13172 if (unlikely(descr == NULL)) {
13173 return NULL;
13174 }
13175
13176 descrgetfunc func = NULL;
13177 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13178 func = Py_TYPE(descr)->tp_descr_get;
13179
13180 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13181 PyObject *called_object = func(descr, source, (PyObject *)type);
13182 Py_DECREF(descr);
13183
13184 if (unlikely(called_object == NULL)) {
13185 return NULL;
13186 }
13187
13188 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13189 Py_DECREF(called_object);
13190 return result;
13191 }
13192 }
13193
13194 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, descr, args);
13195 Py_DECREF(descr);
13196 return result;
13197 } else if (type->tp_getattr != NULL) {
13198 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13199
13200 if (unlikely(called_object == NULL)) {
13201 return NULL;
13202 }
13203
13204 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13205 Py_DECREF(called_object);
13206 return result;
13207 } else {
13208 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13209 Nuitka_String_AsString_Unchecked(attr_name));
13210
13211 return NULL;
13212 }
13213}
13214PyObject *CALL_METHOD_WITH_ARGS6(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13215 CHECK_OBJECT(source);
13216 CHECK_OBJECT(attr_name);
13217
13218 CHECK_OBJECTS(args, 6);
13219
13220 PyTypeObject *type = Py_TYPE(source);
13221
13222 if (hasTypeGenericGetAttr(type)) {
13223 // Unfortunately this is required, although of cause rarely necessary.
13224 if (unlikely(type->tp_dict == NULL)) {
13225 if (unlikely(PyType_Ready(type) < 0)) {
13226 return NULL;
13227 }
13228 }
13229
13230 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13231 descrgetfunc func = NULL;
13232
13233 if (descr != NULL) {
13234 Py_INCREF(descr);
13235
13236 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13237 func = Py_TYPE(descr)->tp_descr_get;
13238
13239 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13240 PyObject *called_object = func(descr, source, (PyObject *)type);
13241 Py_DECREF(descr);
13242
13243 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13244 Py_DECREF(called_object);
13245 return result;
13246 }
13247 }
13248 }
13249
13250 Py_ssize_t dictoffset = type->tp_dictoffset;
13251 PyObject *dict = NULL;
13252
13253 if (dictoffset != 0) {
13254 // Negative dictionary offsets have special meaning.
13255 if (dictoffset < 0) {
13256 Py_ssize_t tsize;
13257 size_t size;
13258
13259 tsize = ((PyVarObject *)source)->ob_size;
13260 if (tsize < 0) {
13261 tsize = -tsize;
13262 }
13263 size = _PyObject_VAR_SIZE(type, tsize);
13264
13265 dictoffset += (long)size;
13266 }
13267
13268 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13269 dict = *dictptr;
13270 }
13271
13272 if (dict != NULL) {
13273 CHECK_OBJECT(dict);
13274
13275 Py_INCREF(dict);
13276
13277 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13278
13279 if (called_object != NULL) {
13280 Py_XDECREF(descr);
13281 Py_DECREF(dict);
13282
13283 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13284 Py_DECREF(called_object);
13285 return result;
13286 }
13287
13288 Py_DECREF(dict);
13289 }
13290
13291 if (func != NULL) {
13292 if (func == Nuitka_Function_Type.tp_descr_get) {
13293 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13294 source, args, 6);
13295 Py_DECREF(descr);
13296
13297 return result;
13298 } else {
13299 PyObject *called_object = func(descr, source, (PyObject *)type);
13300 CHECK_OBJECT(called_object);
13301
13302 Py_DECREF(descr);
13303
13304 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13305 Py_DECREF(called_object);
13306 return result;
13307 }
13308 }
13309
13310 if (descr != NULL) {
13311 CHECK_OBJECT(descr);
13312
13313 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, descr, args);
13314 Py_DECREF(descr);
13315 return result;
13316 }
13317
13318#if PYTHON_VERSION < 0x300
13319 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13320 PyString_AS_STRING(attr_name));
13321#else
13322 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13323#endif
13324 return NULL;
13325 }
13326#if PYTHON_VERSION < 0x300
13327 else if (type == &PyInstance_Type) {
13328 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13329
13330 // The special cases have their own variant on the code generation level
13331 // as we are called with constants only.
13332 assert(attr_name != const_str_plain___dict__);
13333 assert(attr_name != const_str_plain___class__);
13334
13335 // Try the instance dict first.
13336 PyObject *called_object =
13337 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13338
13339 // Note: The "called_object" was found without taking a reference,
13340 // so we need not release it in this branch.
13341 if (called_object != NULL) {
13342 return CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13343 }
13344
13345 // Then check the class dictionaries.
13346 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13347
13348 // Note: The "called_object" was found without taking a reference,
13349 // so we need not release it in this branch.
13350 if (called_object != NULL) {
13351 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13352
13353 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13354 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13355 source, args, 6);
13356 } else if (descr_get != NULL) {
13357 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13358
13359 if (unlikely(method == NULL)) {
13360 return NULL;
13361 }
13362
13363 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, method, args);
13364 Py_DECREF(method);
13365 return result;
13366 } else {
13367 return CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13368 }
13369
13370 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13371 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13372 PyString_AS_STRING(source_instance->in_class->cl_name),
13373 PyString_AS_STRING(attr_name));
13374
13375 return NULL;
13376 } else {
13377 // Finally allow the "__getattr__" override to provide it or else
13378 // it's an error.
13379
13380 PyObject *args2[] = {source, attr_name};
13381
13382 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13383
13384 if (unlikely(called_object == NULL)) {
13385 return NULL;
13386 }
13387
13388 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13389 Py_DECREF(called_object);
13390 return result;
13391 }
13392 }
13393#endif
13394 else if (type->tp_getattro != NULL) {
13395 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13396
13397 if (unlikely(descr == NULL)) {
13398 return NULL;
13399 }
13400
13401 descrgetfunc func = NULL;
13402 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13403 func = Py_TYPE(descr)->tp_descr_get;
13404
13405 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13406 PyObject *called_object = func(descr, source, (PyObject *)type);
13407 Py_DECREF(descr);
13408
13409 if (unlikely(called_object == NULL)) {
13410 return NULL;
13411 }
13412
13413 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13414 Py_DECREF(called_object);
13415 return result;
13416 }
13417 }
13418
13419 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, descr, args);
13420 Py_DECREF(descr);
13421 return result;
13422 } else if (type->tp_getattr != NULL) {
13423 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13424
13425 if (unlikely(called_object == NULL)) {
13426 return NULL;
13427 }
13428
13429 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13430 Py_DECREF(called_object);
13431 return result;
13432 } else {
13433 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13434 Nuitka_String_AsString_Unchecked(attr_name));
13435
13436 return NULL;
13437 }
13438}
13439PyObject *CALL_METHOD_WITH_ARGS7(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13440 CHECK_OBJECT(source);
13441 CHECK_OBJECT(attr_name);
13442
13443 CHECK_OBJECTS(args, 7);
13444
13445 PyTypeObject *type = Py_TYPE(source);
13446
13447 if (hasTypeGenericGetAttr(type)) {
13448 // Unfortunately this is required, although of cause rarely necessary.
13449 if (unlikely(type->tp_dict == NULL)) {
13450 if (unlikely(PyType_Ready(type) < 0)) {
13451 return NULL;
13452 }
13453 }
13454
13455 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13456 descrgetfunc func = NULL;
13457
13458 if (descr != NULL) {
13459 Py_INCREF(descr);
13460
13461 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13462 func = Py_TYPE(descr)->tp_descr_get;
13463
13464 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13465 PyObject *called_object = func(descr, source, (PyObject *)type);
13466 Py_DECREF(descr);
13467
13468 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13469 Py_DECREF(called_object);
13470 return result;
13471 }
13472 }
13473 }
13474
13475 Py_ssize_t dictoffset = type->tp_dictoffset;
13476 PyObject *dict = NULL;
13477
13478 if (dictoffset != 0) {
13479 // Negative dictionary offsets have special meaning.
13480 if (dictoffset < 0) {
13481 Py_ssize_t tsize;
13482 size_t size;
13483
13484 tsize = ((PyVarObject *)source)->ob_size;
13485 if (tsize < 0) {
13486 tsize = -tsize;
13487 }
13488 size = _PyObject_VAR_SIZE(type, tsize);
13489
13490 dictoffset += (long)size;
13491 }
13492
13493 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13494 dict = *dictptr;
13495 }
13496
13497 if (dict != NULL) {
13498 CHECK_OBJECT(dict);
13499
13500 Py_INCREF(dict);
13501
13502 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13503
13504 if (called_object != NULL) {
13505 Py_XDECREF(descr);
13506 Py_DECREF(dict);
13507
13508 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13509 Py_DECREF(called_object);
13510 return result;
13511 }
13512
13513 Py_DECREF(dict);
13514 }
13515
13516 if (func != NULL) {
13517 if (func == Nuitka_Function_Type.tp_descr_get) {
13518 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13519 source, args, 7);
13520 Py_DECREF(descr);
13521
13522 return result;
13523 } else {
13524 PyObject *called_object = func(descr, source, (PyObject *)type);
13525 CHECK_OBJECT(called_object);
13526
13527 Py_DECREF(descr);
13528
13529 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13530 Py_DECREF(called_object);
13531 return result;
13532 }
13533 }
13534
13535 if (descr != NULL) {
13536 CHECK_OBJECT(descr);
13537
13538 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, descr, args);
13539 Py_DECREF(descr);
13540 return result;
13541 }
13542
13543#if PYTHON_VERSION < 0x300
13544 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13545 PyString_AS_STRING(attr_name));
13546#else
13547 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13548#endif
13549 return NULL;
13550 }
13551#if PYTHON_VERSION < 0x300
13552 else if (type == &PyInstance_Type) {
13553 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13554
13555 // The special cases have their own variant on the code generation level
13556 // as we are called with constants only.
13557 assert(attr_name != const_str_plain___dict__);
13558 assert(attr_name != const_str_plain___class__);
13559
13560 // Try the instance dict first.
13561 PyObject *called_object =
13562 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13563
13564 // Note: The "called_object" was found without taking a reference,
13565 // so we need not release it in this branch.
13566 if (called_object != NULL) {
13567 return CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13568 }
13569
13570 // Then check the class dictionaries.
13571 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13572
13573 // Note: The "called_object" was found without taking a reference,
13574 // so we need not release it in this branch.
13575 if (called_object != NULL) {
13576 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13577
13578 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13579 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13580 source, args, 7);
13581 } else if (descr_get != NULL) {
13582 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13583
13584 if (unlikely(method == NULL)) {
13585 return NULL;
13586 }
13587
13588 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, method, args);
13589 Py_DECREF(method);
13590 return result;
13591 } else {
13592 return CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13593 }
13594
13595 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13596 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13597 PyString_AS_STRING(source_instance->in_class->cl_name),
13598 PyString_AS_STRING(attr_name));
13599
13600 return NULL;
13601 } else {
13602 // Finally allow the "__getattr__" override to provide it or else
13603 // it's an error.
13604
13605 PyObject *args2[] = {source, attr_name};
13606
13607 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13608
13609 if (unlikely(called_object == NULL)) {
13610 return NULL;
13611 }
13612
13613 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13614 Py_DECREF(called_object);
13615 return result;
13616 }
13617 }
13618#endif
13619 else if (type->tp_getattro != NULL) {
13620 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13621
13622 if (unlikely(descr == NULL)) {
13623 return NULL;
13624 }
13625
13626 descrgetfunc func = NULL;
13627 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13628 func = Py_TYPE(descr)->tp_descr_get;
13629
13630 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13631 PyObject *called_object = func(descr, source, (PyObject *)type);
13632 Py_DECREF(descr);
13633
13634 if (unlikely(called_object == NULL)) {
13635 return NULL;
13636 }
13637
13638 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13639 Py_DECREF(called_object);
13640 return result;
13641 }
13642 }
13643
13644 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, descr, args);
13645 Py_DECREF(descr);
13646 return result;
13647 } else if (type->tp_getattr != NULL) {
13648 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13649
13650 if (unlikely(called_object == NULL)) {
13651 return NULL;
13652 }
13653
13654 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13655 Py_DECREF(called_object);
13656 return result;
13657 } else {
13658 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13659 Nuitka_String_AsString_Unchecked(attr_name));
13660
13661 return NULL;
13662 }
13663}
13664PyObject *CALL_METHOD_WITH_ARGS8(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13665 CHECK_OBJECT(source);
13666 CHECK_OBJECT(attr_name);
13667
13668 CHECK_OBJECTS(args, 8);
13669
13670 PyTypeObject *type = Py_TYPE(source);
13671
13672 if (hasTypeGenericGetAttr(type)) {
13673 // Unfortunately this is required, although of cause rarely necessary.
13674 if (unlikely(type->tp_dict == NULL)) {
13675 if (unlikely(PyType_Ready(type) < 0)) {
13676 return NULL;
13677 }
13678 }
13679
13680 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13681 descrgetfunc func = NULL;
13682
13683 if (descr != NULL) {
13684 Py_INCREF(descr);
13685
13686 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13687 func = Py_TYPE(descr)->tp_descr_get;
13688
13689 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13690 PyObject *called_object = func(descr, source, (PyObject *)type);
13691 Py_DECREF(descr);
13692
13693 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13694 Py_DECREF(called_object);
13695 return result;
13696 }
13697 }
13698 }
13699
13700 Py_ssize_t dictoffset = type->tp_dictoffset;
13701 PyObject *dict = NULL;
13702
13703 if (dictoffset != 0) {
13704 // Negative dictionary offsets have special meaning.
13705 if (dictoffset < 0) {
13706 Py_ssize_t tsize;
13707 size_t size;
13708
13709 tsize = ((PyVarObject *)source)->ob_size;
13710 if (tsize < 0) {
13711 tsize = -tsize;
13712 }
13713 size = _PyObject_VAR_SIZE(type, tsize);
13714
13715 dictoffset += (long)size;
13716 }
13717
13718 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13719 dict = *dictptr;
13720 }
13721
13722 if (dict != NULL) {
13723 CHECK_OBJECT(dict);
13724
13725 Py_INCREF(dict);
13726
13727 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13728
13729 if (called_object != NULL) {
13730 Py_XDECREF(descr);
13731 Py_DECREF(dict);
13732
13733 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13734 Py_DECREF(called_object);
13735 return result;
13736 }
13737
13738 Py_DECREF(dict);
13739 }
13740
13741 if (func != NULL) {
13742 if (func == Nuitka_Function_Type.tp_descr_get) {
13743 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13744 source, args, 8);
13745 Py_DECREF(descr);
13746
13747 return result;
13748 } else {
13749 PyObject *called_object = func(descr, source, (PyObject *)type);
13750 CHECK_OBJECT(called_object);
13751
13752 Py_DECREF(descr);
13753
13754 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13755 Py_DECREF(called_object);
13756 return result;
13757 }
13758 }
13759
13760 if (descr != NULL) {
13761 CHECK_OBJECT(descr);
13762
13763 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, descr, args);
13764 Py_DECREF(descr);
13765 return result;
13766 }
13767
13768#if PYTHON_VERSION < 0x300
13769 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13770 PyString_AS_STRING(attr_name));
13771#else
13772 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13773#endif
13774 return NULL;
13775 }
13776#if PYTHON_VERSION < 0x300
13777 else if (type == &PyInstance_Type) {
13778 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13779
13780 // The special cases have their own variant on the code generation level
13781 // as we are called with constants only.
13782 assert(attr_name != const_str_plain___dict__);
13783 assert(attr_name != const_str_plain___class__);
13784
13785 // Try the instance dict first.
13786 PyObject *called_object =
13787 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13788
13789 // Note: The "called_object" was found without taking a reference,
13790 // so we need not release it in this branch.
13791 if (called_object != NULL) {
13792 return CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13793 }
13794
13795 // Then check the class dictionaries.
13796 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13797
13798 // Note: The "called_object" was found without taking a reference,
13799 // so we need not release it in this branch.
13800 if (called_object != NULL) {
13801 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13802
13803 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13804 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13805 source, args, 8);
13806 } else if (descr_get != NULL) {
13807 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13808
13809 if (unlikely(method == NULL)) {
13810 return NULL;
13811 }
13812
13813 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, method, args);
13814 Py_DECREF(method);
13815 return result;
13816 } else {
13817 return CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13818 }
13819
13820 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13821 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13822 PyString_AS_STRING(source_instance->in_class->cl_name),
13823 PyString_AS_STRING(attr_name));
13824
13825 return NULL;
13826 } else {
13827 // Finally allow the "__getattr__" override to provide it or else
13828 // it's an error.
13829
13830 PyObject *args2[] = {source, attr_name};
13831
13832 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13833
13834 if (unlikely(called_object == NULL)) {
13835 return NULL;
13836 }
13837
13838 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13839 Py_DECREF(called_object);
13840 return result;
13841 }
13842 }
13843#endif
13844 else if (type->tp_getattro != NULL) {
13845 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13846
13847 if (unlikely(descr == NULL)) {
13848 return NULL;
13849 }
13850
13851 descrgetfunc func = NULL;
13852 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13853 func = Py_TYPE(descr)->tp_descr_get;
13854
13855 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13856 PyObject *called_object = func(descr, source, (PyObject *)type);
13857 Py_DECREF(descr);
13858
13859 if (unlikely(called_object == NULL)) {
13860 return NULL;
13861 }
13862
13863 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13864 Py_DECREF(called_object);
13865 return result;
13866 }
13867 }
13868
13869 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, descr, args);
13870 Py_DECREF(descr);
13871 return result;
13872 } else if (type->tp_getattr != NULL) {
13873 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13874
13875 if (unlikely(called_object == NULL)) {
13876 return NULL;
13877 }
13878
13879 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13880 Py_DECREF(called_object);
13881 return result;
13882 } else {
13883 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13884 Nuitka_String_AsString_Unchecked(attr_name));
13885
13886 return NULL;
13887 }
13888}
13889PyObject *CALL_METHOD_WITH_ARGS9(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13890 CHECK_OBJECT(source);
13891 CHECK_OBJECT(attr_name);
13892
13893 CHECK_OBJECTS(args, 9);
13894
13895 PyTypeObject *type = Py_TYPE(source);
13896
13897 if (hasTypeGenericGetAttr(type)) {
13898 // Unfortunately this is required, although of cause rarely necessary.
13899 if (unlikely(type->tp_dict == NULL)) {
13900 if (unlikely(PyType_Ready(type) < 0)) {
13901 return NULL;
13902 }
13903 }
13904
13905 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13906 descrgetfunc func = NULL;
13907
13908 if (descr != NULL) {
13909 Py_INCREF(descr);
13910
13911 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13912 func = Py_TYPE(descr)->tp_descr_get;
13913
13914 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13915 PyObject *called_object = func(descr, source, (PyObject *)type);
13916 Py_DECREF(descr);
13917
13918 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13919 Py_DECREF(called_object);
13920 return result;
13921 }
13922 }
13923 }
13924
13925 Py_ssize_t dictoffset = type->tp_dictoffset;
13926 PyObject *dict = NULL;
13927
13928 if (dictoffset != 0) {
13929 // Negative dictionary offsets have special meaning.
13930 if (dictoffset < 0) {
13931 Py_ssize_t tsize;
13932 size_t size;
13933
13934 tsize = ((PyVarObject *)source)->ob_size;
13935 if (tsize < 0) {
13936 tsize = -tsize;
13937 }
13938 size = _PyObject_VAR_SIZE(type, tsize);
13939
13940 dictoffset += (long)size;
13941 }
13942
13943 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13944 dict = *dictptr;
13945 }
13946
13947 if (dict != NULL) {
13948 CHECK_OBJECT(dict);
13949
13950 Py_INCREF(dict);
13951
13952 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13953
13954 if (called_object != NULL) {
13955 Py_XDECREF(descr);
13956 Py_DECREF(dict);
13957
13958 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13959 Py_DECREF(called_object);
13960 return result;
13961 }
13962
13963 Py_DECREF(dict);
13964 }
13965
13966 if (func != NULL) {
13967 if (func == Nuitka_Function_Type.tp_descr_get) {
13968 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13969 source, args, 9);
13970 Py_DECREF(descr);
13971
13972 return result;
13973 } else {
13974 PyObject *called_object = func(descr, source, (PyObject *)type);
13975 CHECK_OBJECT(called_object);
13976
13977 Py_DECREF(descr);
13978
13979 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13980 Py_DECREF(called_object);
13981 return result;
13982 }
13983 }
13984
13985 if (descr != NULL) {
13986 CHECK_OBJECT(descr);
13987
13988 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, descr, args);
13989 Py_DECREF(descr);
13990 return result;
13991 }
13992
13993#if PYTHON_VERSION < 0x300
13994 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13995 PyString_AS_STRING(attr_name));
13996#else
13997 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13998#endif
13999 return NULL;
14000 }
14001#if PYTHON_VERSION < 0x300
14002 else if (type == &PyInstance_Type) {
14003 PyInstanceObject *source_instance = (PyInstanceObject *)source;
14004
14005 // The special cases have their own variant on the code generation level
14006 // as we are called with constants only.
14007 assert(attr_name != const_str_plain___dict__);
14008 assert(attr_name != const_str_plain___class__);
14009
14010 // Try the instance dict first.
14011 PyObject *called_object =
14012 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
14013
14014 // Note: The "called_object" was found without taking a reference,
14015 // so we need not release it in this branch.
14016 if (called_object != NULL) {
14017 return CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14018 }
14019
14020 // Then check the class dictionaries.
14021 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
14022
14023 // Note: The "called_object" was found without taking a reference,
14024 // so we need not release it in this branch.
14025 if (called_object != NULL) {
14026 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
14027
14028 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
14029 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
14030 source, args, 9);
14031 } else if (descr_get != NULL) {
14032 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
14033
14034 if (unlikely(method == NULL)) {
14035 return NULL;
14036 }
14037
14038 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, method, args);
14039 Py_DECREF(method);
14040 return result;
14041 } else {
14042 return CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14043 }
14044
14045 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
14046 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
14047 PyString_AS_STRING(source_instance->in_class->cl_name),
14048 PyString_AS_STRING(attr_name));
14049
14050 return NULL;
14051 } else {
14052 // Finally allow the "__getattr__" override to provide it or else
14053 // it's an error.
14054
14055 PyObject *args2[] = {source, attr_name};
14056
14057 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
14058
14059 if (unlikely(called_object == NULL)) {
14060 return NULL;
14061 }
14062
14063 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14064 Py_DECREF(called_object);
14065 return result;
14066 }
14067 }
14068#endif
14069 else if (type->tp_getattro != NULL) {
14070 PyObject *descr = (*type->tp_getattro)(source, attr_name);
14071
14072 if (unlikely(descr == NULL)) {
14073 return NULL;
14074 }
14075
14076 descrgetfunc func = NULL;
14077 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14078 func = Py_TYPE(descr)->tp_descr_get;
14079
14080 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14081 PyObject *called_object = func(descr, source, (PyObject *)type);
14082 Py_DECREF(descr);
14083
14084 if (unlikely(called_object == NULL)) {
14085 return NULL;
14086 }
14087
14088 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14089 Py_DECREF(called_object);
14090 return result;
14091 }
14092 }
14093
14094 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, descr, args);
14095 Py_DECREF(descr);
14096 return result;
14097 } else if (type->tp_getattr != NULL) {
14098 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
14099
14100 if (unlikely(called_object == NULL)) {
14101 return NULL;
14102 }
14103
14104 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14105 Py_DECREF(called_object);
14106 return result;
14107 } else {
14108 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14109 Nuitka_String_AsString_Unchecked(attr_name));
14110
14111 return NULL;
14112 }
14113}
14114PyObject *CALL_METHOD_WITH_ARGS10(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
14115 CHECK_OBJECT(source);
14116 CHECK_OBJECT(attr_name);
14117
14118 CHECK_OBJECTS(args, 10);
14119
14120 PyTypeObject *type = Py_TYPE(source);
14121
14122 if (hasTypeGenericGetAttr(type)) {
14123 // Unfortunately this is required, although of cause rarely necessary.
14124 if (unlikely(type->tp_dict == NULL)) {
14125 if (unlikely(PyType_Ready(type) < 0)) {
14126 return NULL;
14127 }
14128 }
14129
14130 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
14131 descrgetfunc func = NULL;
14132
14133 if (descr != NULL) {
14134 Py_INCREF(descr);
14135
14136 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14137 func = Py_TYPE(descr)->tp_descr_get;
14138
14139 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14140 PyObject *called_object = func(descr, source, (PyObject *)type);
14141 Py_DECREF(descr);
14142
14143 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14144 Py_DECREF(called_object);
14145 return result;
14146 }
14147 }
14148 }
14149
14150 Py_ssize_t dictoffset = type->tp_dictoffset;
14151 PyObject *dict = NULL;
14152
14153 if (dictoffset != 0) {
14154 // Negative dictionary offsets have special meaning.
14155 if (dictoffset < 0) {
14156 Py_ssize_t tsize;
14157 size_t size;
14158
14159 tsize = ((PyVarObject *)source)->ob_size;
14160 if (tsize < 0) {
14161 tsize = -tsize;
14162 }
14163 size = _PyObject_VAR_SIZE(type, tsize);
14164
14165 dictoffset += (long)size;
14166 }
14167
14168 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
14169 dict = *dictptr;
14170 }
14171
14172 if (dict != NULL) {
14173 CHECK_OBJECT(dict);
14174
14175 Py_INCREF(dict);
14176
14177 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
14178
14179 if (called_object != NULL) {
14180 Py_XDECREF(descr);
14181 Py_DECREF(dict);
14182
14183 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14184 Py_DECREF(called_object);
14185 return result;
14186 }
14187
14188 Py_DECREF(dict);
14189 }
14190
14191 if (func != NULL) {
14192 if (func == Nuitka_Function_Type.tp_descr_get) {
14193 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
14194 source, args, 10);
14195 Py_DECREF(descr);
14196
14197 return result;
14198 } else {
14199 PyObject *called_object = func(descr, source, (PyObject *)type);
14200 CHECK_OBJECT(called_object);
14201
14202 Py_DECREF(descr);
14203
14204 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14205 Py_DECREF(called_object);
14206 return result;
14207 }
14208 }
14209
14210 if (descr != NULL) {
14211 CHECK_OBJECT(descr);
14212
14213 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, descr, args);
14214 Py_DECREF(descr);
14215 return result;
14216 }
14217
14218#if PYTHON_VERSION < 0x300
14219 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14220 PyString_AS_STRING(attr_name));
14221#else
14222 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
14223#endif
14224 return NULL;
14225 }
14226#if PYTHON_VERSION < 0x300
14227 else if (type == &PyInstance_Type) {
14228 PyInstanceObject *source_instance = (PyInstanceObject *)source;
14229
14230 // The special cases have their own variant on the code generation level
14231 // as we are called with constants only.
14232 assert(attr_name != const_str_plain___dict__);
14233 assert(attr_name != const_str_plain___class__);
14234
14235 // Try the instance dict first.
14236 PyObject *called_object =
14237 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
14238
14239 // Note: The "called_object" was found without taking a reference,
14240 // so we need not release it in this branch.
14241 if (called_object != NULL) {
14242 return CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14243 }
14244
14245 // Then check the class dictionaries.
14246 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
14247
14248 // Note: The "called_object" was found without taking a reference,
14249 // so we need not release it in this branch.
14250 if (called_object != NULL) {
14251 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
14252
14253 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
14254 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
14255 source, args, 10);
14256 } else if (descr_get != NULL) {
14257 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
14258
14259 if (unlikely(method == NULL)) {
14260 return NULL;
14261 }
14262
14263 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, method, args);
14264 Py_DECREF(method);
14265 return result;
14266 } else {
14267 return CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14268 }
14269
14270 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
14271 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
14272 PyString_AS_STRING(source_instance->in_class->cl_name),
14273 PyString_AS_STRING(attr_name));
14274
14275 return NULL;
14276 } else {
14277 // Finally allow the "__getattr__" override to provide it or else
14278 // it's an error.
14279
14280 PyObject *args2[] = {source, attr_name};
14281
14282 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
14283
14284 if (unlikely(called_object == NULL)) {
14285 return NULL;
14286 }
14287
14288 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14289 Py_DECREF(called_object);
14290 return result;
14291 }
14292 }
14293#endif
14294 else if (type->tp_getattro != NULL) {
14295 PyObject *descr = (*type->tp_getattro)(source, attr_name);
14296
14297 if (unlikely(descr == NULL)) {
14298 return NULL;
14299 }
14300
14301 descrgetfunc func = NULL;
14302 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14303 func = Py_TYPE(descr)->tp_descr_get;
14304
14305 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14306 PyObject *called_object = func(descr, source, (PyObject *)type);
14307 Py_DECREF(descr);
14308
14309 if (unlikely(called_object == NULL)) {
14310 return NULL;
14311 }
14312
14313 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14314 Py_DECREF(called_object);
14315 return result;
14316 }
14317 }
14318
14319 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, descr, args);
14320 Py_DECREF(descr);
14321 return result;
14322 } else if (type->tp_getattr != NULL) {
14323 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
14324
14325 if (unlikely(called_object == NULL)) {
14326 return NULL;
14327 }
14328
14329 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14330 Py_DECREF(called_object);
14331 return result;
14332 } else {
14333 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14334 Nuitka_String_AsString_Unchecked(attr_name));
14335
14336 return NULL;
14337 }
14338}
14339#if defined(__clang__)
14340#pragma clang diagnostic pop
14341#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
14342#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
14343#pragma GCC diagnostic pop
14344#endif
14345#endif
14346
14347// Part of "Nuitka", an optimizing Python compiler that is compatible and
14348// integrates with CPython, but also works on its own.
14349//
14350// Licensed under the GNU Affero General Public License, Version 3 (the "License");
14351// you may not use this file except in compliance with the License.
14352// You may obtain a copy of the License at
14353//
14354// http://www.gnu.org/licenses/agpl.txt
14355//
14356// Unless required by applicable law or agreed to in writing, software
14357// distributed under the License is distributed on an "AS IS" BASIS,
14358// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14359// See the License for the specific language governing permissions and
14360// limitations under the License.
Definition compiled_function.h:22
Definition compiled_method.h:16