Nuitka
The Python compiler
Loading...
Searching...
No Matches
HelpersCallingGenerated.c
1// Copyright 2025, 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#pragma GCC diagnostic push
18#pragma GCC diagnostic ignored "-Wparentheses"
19#endif
20
21PyObject *CALL_FUNCTION_NO_ARGS(PyThreadState *tstate, PyObject *called) {
22 CHECK_OBJECT(called);
23
24 if (Nuitka_Function_Check(called)) {
25 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
26 return NULL;
27 }
28
29 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
30 PyObject *result;
31
32 if (function->m_args_simple && 0 == function->m_args_positional_count) {
33 result = function->m_c_code(tstate, function, NULL);
34 } else if (function->m_args_simple && 0 + function->m_defaults_given == function->m_args_positional_count) {
35 PyObject **python_pars = &PyTuple_GET_ITEM(function->m_defaults, 0);
36
37 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
38 Py_INCREF(python_pars[i]);
39 }
40
41 result = function->m_c_code(tstate, function, python_pars);
42 } else {
43 result = Nuitka_CallFunctionNoArgs(tstate, function);
44 }
45
46 Py_LeaveRecursiveCall();
47
48 CHECK_OBJECT_X(result);
49
50 return result;
51 } else if (Nuitka_Method_Check(called)) {
52 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
53
54 if (method->m_object == NULL) {
55 PyErr_Format(
56 PyExc_TypeError,
57 "unbound compiled_method %s%s must be called with %s instance as first argument (got nothing instead)",
58 GET_CALLABLE_NAME((PyObject *)method->m_function), GET_CALLABLE_DESC((PyObject *)method->m_function),
59 GET_CLASS_NAME(method->m_class));
60 return NULL;
61 } else {
62 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
63 return NULL;
64 }
65
66 struct Nuitka_FunctionObject *function = method->m_function;
67
68 PyObject *result;
69
70 if (function->m_args_simple && 0 + 1 == function->m_args_positional_count) {
71 PyObject *python_pars[0 + 1];
72
73 python_pars[0] = method->m_object;
74 Py_INCREF(method->m_object);
75
76 result = function->m_c_code(tstate, function, python_pars);
77 } else if (function->m_args_simple &&
78 0 + 1 + function->m_defaults_given == function->m_args_positional_count) {
79 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
80
81 python_pars[0] = method->m_object;
82 Py_INCREF(method->m_object);
83
84 memcpy(python_pars + 1 + 0, &PyTuple_GET_ITEM(function->m_defaults, 0),
85 function->m_defaults_given * sizeof(PyObject *));
86
87 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
88 Py_INCREF(python_pars[i]);
89 }
90
91 result = function->m_c_code(tstate, function, python_pars);
92 } else {
93 result = Nuitka_CallMethodFunctionNoArgs(tstate, function, method->m_object);
94 }
95
96 Py_LeaveRecursiveCall();
97
98 CHECK_OBJECT_X(result);
99
100 return result;
101 }
102#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
103 } else if (PyCFunction_CheckExact(called)) {
104#if PYTHON_VERSION >= 0x380
105#ifdef _NUITKA_FULL_COMPAT
106 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
107 return NULL;
108 }
109#endif
110
111 int flags = PyCFunction_GET_FLAGS(called);
112
113 PyObject *result;
114
115 if (!(flags & METH_VARARGS)) {
116 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
117
118 assert(func != NULL);
119 result = func(called, NULL, 0, NULL);
120
121 CHECK_OBJECT_X(result);
122 } else {
123 PyCFunction method = PyCFunction_GET_FUNCTION(called);
124 PyObject *self = PyCFunction_GET_SELF(called);
125
126 PyObject *pos_args = const_tuple_empty;
127
128 if (flags & METH_KEYWORDS) {
129 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
130 } else {
131 result = (*method)(self, pos_args);
132 }
133 }
134
135#ifdef _NUITKA_FULL_COMPAT
136 Py_LeaveRecursiveCall();
137#endif
138 CHECK_OBJECT_X(result);
139
140 return Nuitka_CheckFunctionResult(tstate, called, result);
141#else
142 // Try to be fast about wrapping the arguments.
143 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
144
145 if (likely(flags & METH_NOARGS)) {
146 // Recursion guard is not strictly necessary, as we already have
147 // one on our way to here.
148#ifdef _NUITKA_FULL_COMPAT
149 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
150 return NULL;
151 }
152#endif
153 PyCFunction method = PyCFunction_GET_FUNCTION(called);
154 PyObject *self = PyCFunction_GET_SELF(called);
155
156 PyObject *result = (*method)(self, NULL);
157
158#ifdef _NUITKA_FULL_COMPAT
159 Py_LeaveRecursiveCall();
160#endif
161 CHECK_OBJECT_X(result);
162
163 return Nuitka_CheckFunctionResult(tstate, called, result);
164 } else if (unlikely(flags & METH_O)) {
165 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (0 given)",
166 ((PyCFunctionObject *)called)->m_ml->ml_name);
167 return NULL;
168 } else if (flags & METH_VARARGS) {
169 // Recursion guard is not strictly necessary, as we already have
170 // one on our way to here.
171#ifdef _NUITKA_FULL_COMPAT
172 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
173 return NULL;
174 }
175#endif
176 PyCFunction method = PyCFunction_GET_FUNCTION(called);
177 PyObject *self = PyCFunction_GET_SELF(called);
178
179 PyObject *result;
180
181#if PYTHON_VERSION < 0x360
182 PyObject *pos_args = const_tuple_empty;
183 if (flags & METH_KEYWORDS) {
184 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
185 } else {
186 result = (*method)(self, pos_args);
187 }
188
189#else
190 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
191 PyObject *pos_args = const_tuple_empty;
192 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
193 } else if (flags == METH_FASTCALL) {
194#if PYTHON_VERSION < 0x370
195 result = (*(_PyCFunctionFast)method)(self, NULL, 0, NULL);
196#else
197 PyObject *pos_args = const_tuple_empty;
198 result = (*(_PyCFunctionFast)method)(self, &pos_args, 0);
199#endif
200 } else {
201 PyObject *pos_args = const_tuple_empty;
202 result = (*method)(self, pos_args);
203 }
204#endif
205
206#ifdef _NUITKA_FULL_COMPAT
207 Py_LeaveRecursiveCall();
208#endif
209
210 CHECK_OBJECT_X(result);
211
212 return Nuitka_CheckFunctionResult(tstate, called, result);
213 }
214#endif
215#endif
216#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
217 } else if (PyFunction_Check(called)) {
218#if PYTHON_VERSION < 0x3b0
219 PyObject *result = callPythonFunctionNoArgs(called);
220#else
221 PyObject *result = _PyFunction_Vectorcall(called, NULL, 0, NULL);
222#endif
223 CHECK_OBJECT_X(result);
224
225 return result;
226#endif
227#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
228 } else if (PyType_Check(called)) {
229 PyTypeObject *type = Py_TYPE(called);
230
231 if (type->tp_call == PyType_Type.tp_call) {
232 PyTypeObject *called_type = (PyTypeObject *)(called);
233
234 if (unlikely(called_type->tp_new == NULL)) {
235 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
236 return NULL;
237 }
238
239 PyObject *pos_args = const_tuple_empty;
240 PyObject *obj;
241
242 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
243 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
244 formatCannotInstantiateAbstractClass(tstate, called_type);
245 return NULL;
246 }
247
248 obj = called_type->tp_alloc(called_type, 0);
249 CHECK_OBJECT(obj);
250 } else {
251 obj = called_type->tp_new(called_type, pos_args, NULL);
252 }
253
254 if (likely(obj != NULL)) {
255 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
256 return obj;
257 }
258
259 // Work on produced type.
260 type = Py_TYPE(obj);
261
262 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
263 if (type->tp_init == default_tp_init_wrapper) {
264
265 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
266
267 // Not really allowed, since we wouldn't have the default wrapper set.
268 assert(init_method != NULL);
269
270 bool is_compiled_function = false;
271 bool init_method_needs_release = false;
272
273 if (likely(init_method != NULL)) {
274 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
275
276 if (func == Nuitka_Function_Type.tp_descr_get) {
277 is_compiled_function = true;
278 } else if (func != NULL) {
279 init_method = func(init_method, obj, (PyObject *)(type));
280 init_method_needs_release = true;
281 }
282 }
283
284 if (unlikely(init_method == NULL)) {
285 if (!HAS_ERROR_OCCURRED(tstate)) {
286 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
287 const_str_plain___init__);
288 }
289
290 return NULL;
291 }
292
293 PyObject *result;
294 if (is_compiled_function) {
295 result = Nuitka_CallMethodFunctionNoArgs(
296 tstate, (struct Nuitka_FunctionObject const *)init_method, obj);
297 } else {
298 result = CALL_FUNCTION_NO_ARGS(tstate, init_method);
299
300 if (init_method_needs_release) {
301 Py_DECREF(init_method);
302 }
303 }
304
305 if (unlikely(result == NULL)) {
306 Py_DECREF(obj);
307 return NULL;
308 }
309
310 Py_DECREF(result);
311
312 if (unlikely(result != Py_None)) {
313 Py_DECREF(obj);
314
315 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
316 return NULL;
317 }
318 } else {
319
320 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
321 Py_DECREF(obj);
322 return NULL;
323 }
324 }
325 }
326 }
327
328 CHECK_OBJECT_X(obj);
329
330 return obj;
331 }
332#endif
333#if PYTHON_VERSION < 0x300
334 } else if (PyClass_Check(called)) {
335 PyObject *obj = PyInstance_NewRaw(called, NULL);
336
337 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
338
339 if ((init_method == NULL)) {
340 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
341 Py_DECREF(obj);
342 return NULL;
343 }
344
345 return obj;
346 }
347
348 bool is_compiled_function = false;
349
350 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
351
352 if (descr_get == NULL) {
353 Py_INCREF(init_method);
354 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
355 is_compiled_function = true;
356 } else if (descr_get != NULL) {
357 PyObject *descr_method = descr_get(init_method, obj, called);
358
359 if (unlikely(descr_method == NULL)) {
360 return NULL;
361 }
362
363 init_method = descr_method;
364 }
365
366 PyObject *result;
367 if (is_compiled_function) {
368 result = Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj);
369 } else {
370 result = CALL_FUNCTION_NO_ARGS(tstate, init_method);
371 Py_DECREF(init_method);
372 }
373 if (unlikely(result == NULL)) {
374 return NULL;
375 }
376
377 Py_DECREF(result);
378
379 if (unlikely(result != Py_None)) {
380 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
381 return NULL;
382 }
383
384 CHECK_OBJECT_X(obj);
385
386 return obj;
387#endif
388#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
389 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
390 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
391
392 if (likely(func != NULL)) {
393 PyObject *result = func(called, NULL, 0, NULL);
394
395 CHECK_OBJECT_X(result);
396
397 return Nuitka_CheckFunctionResult(tstate, called, result);
398 }
399#endif
400 }
401
402#if 0
403 PRINT_NEW_LINE();
404 PRINT_STRING("FALLBACK");
405 PRINT_ITEM(called);
406 PRINT_NEW_LINE();
407#endif
408
409 PyObject *result = CALL_FUNCTION(tstate, called, const_tuple_empty, NULL);
410
411 CHECK_OBJECT_X(result);
412
413 return result;
414}
415PyObject *CALL_FUNCTION_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg) {
416 PyObject *const *args = &arg; // For easier code compatibility.
417 CHECK_OBJECT(called);
418 CHECK_OBJECTS(args, 1);
419
420 if (Nuitka_Function_Check(called)) {
421 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
422 return NULL;
423 }
424
425 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
426 PyObject *result;
427
428 if (function->m_args_simple && 1 == function->m_args_positional_count) {
429 Py_INCREF(args[0]);
430 result = function->m_c_code(tstate, function, (PyObject **)args);
431 } else if (function->m_args_simple && 1 + function->m_defaults_given == function->m_args_positional_count) {
432 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
433
434 memcpy(python_pars, args, 1 * sizeof(PyObject *));
435 memcpy(python_pars + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
436 function->m_defaults_given * sizeof(PyObject *));
437
438 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
439 Py_INCREF(python_pars[i]);
440 }
441
442 result = function->m_c_code(tstate, function, python_pars);
443 } else {
444 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 1);
445 }
446
447 Py_LeaveRecursiveCall();
448
449 CHECK_OBJECT_X(result);
450
451 return result;
452 } else if (Nuitka_Method_Check(called)) {
453 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
454
455 if (method->m_object == NULL) {
456 PyObject *self = args[0];
457
458 int res = PyObject_IsInstance(self, method->m_class);
459
460 if (unlikely(res < 0)) {
461 return NULL;
462 } else if (unlikely(res == 0)) {
463 PyErr_Format(PyExc_TypeError,
464 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
465 "instance instead)",
466 GET_CALLABLE_NAME((PyObject *)method->m_function),
467 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
468 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
469
470 return NULL;
471 }
472
473 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 1);
474
475 CHECK_OBJECT_X(result);
476
477 return result;
478 } else {
479 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
480 return NULL;
481 }
482
483 struct Nuitka_FunctionObject *function = method->m_function;
484
485 PyObject *result;
486
487 if (function->m_args_simple && 1 + 1 == function->m_args_positional_count) {
488 PyObject *python_pars[1 + 1];
489
490 python_pars[0] = method->m_object;
491 Py_INCREF(method->m_object);
492
493 python_pars[1] = args[0];
494 Py_INCREF(args[0]);
495 result = function->m_c_code(tstate, function, python_pars);
496 } else if (function->m_args_simple &&
497 1 + 1 + function->m_defaults_given == function->m_args_positional_count) {
498 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
499
500 python_pars[0] = method->m_object;
501 Py_INCREF(method->m_object);
502
503 memcpy(python_pars + 1, args, 1 * sizeof(PyObject *));
504 memcpy(python_pars + 1 + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
505 function->m_defaults_given * sizeof(PyObject *));
506
507 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
508 Py_INCREF(python_pars[i]);
509 }
510
511 result = function->m_c_code(tstate, function, python_pars);
512 } else {
513 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 1);
514 }
515
516 Py_LeaveRecursiveCall();
517
518 CHECK_OBJECT_X(result);
519
520 return result;
521 }
522#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
523 } else if (PyCFunction_CheckExact(called)) {
524#if PYTHON_VERSION >= 0x380
525#ifdef _NUITKA_FULL_COMPAT
526 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
527 return NULL;
528 }
529#endif
530
531 int flags = PyCFunction_GET_FLAGS(called);
532
533 PyObject *result;
534
535 if (!(flags & METH_VARARGS)) {
536 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
537
538 assert(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 if (!(flags & METH_VARARGS)) {
989 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
990
991 assert(func != NULL);
992 result = func(called, args, 1, NULL);
993
994 CHECK_OBJECT_X(result);
995 } else {
996 PyCFunction method = PyCFunction_GET_FUNCTION(called);
997 PyObject *self = PyCFunction_GET_SELF(called);
998
999 if (flags & METH_KEYWORDS) {
1000 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1001 } else {
1002 result = (*method)(self, pos_args);
1003 }
1004 }
1005
1006#ifdef _NUITKA_FULL_COMPAT
1007 Py_LeaveRecursiveCall();
1008#endif
1009 CHECK_OBJECT_X(result);
1010
1011 return Nuitka_CheckFunctionResult(tstate, called, result);
1012#else
1013 // Try to be fast about wrapping the arguments.
1014 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1015
1016 if (unlikely(flags & METH_NOARGS)) {
1017 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (1 given)",
1018 ((PyCFunctionObject *)called)->m_ml->ml_name);
1019 return NULL;
1020 } else if ((flags & METH_O)) {
1021 // Recursion guard is not strictly necessary, as we already have
1022 // one on our way to here.
1023#ifdef _NUITKA_FULL_COMPAT
1024 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1025 return NULL;
1026 }
1027#endif
1028 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1029 PyObject *self = PyCFunction_GET_SELF(called);
1030
1031 PyObject *result = (*method)(self, args[0]);
1032
1033#ifdef _NUITKA_FULL_COMPAT
1034 Py_LeaveRecursiveCall();
1035#endif
1036
1037 CHECK_OBJECT_X(result);
1038
1039 return Nuitka_CheckFunctionResult(tstate, called, result);
1040 } else if (flags & METH_VARARGS) {
1041 // Recursion guard is not strictly necessary, as we already have
1042 // one on our way to here.
1043#ifdef _NUITKA_FULL_COMPAT
1044 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1045 return NULL;
1046 }
1047#endif
1048 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1049 PyObject *self = PyCFunction_GET_SELF(called);
1050
1051 PyObject *result;
1052
1053#if PYTHON_VERSION < 0x360
1054 if (flags & METH_KEYWORDS) {
1055 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1056 } else {
1057 result = (*method)(self, pos_args);
1058 }
1059
1060#else
1061 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1062 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1063 } else if (flags == METH_FASTCALL) {
1064#if PYTHON_VERSION < 0x370
1065 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 1, NULL);
1066#else
1067 result = (*(_PyCFunctionFast)method)(self, &pos_args, 1);
1068#endif
1069 } else {
1070 result = (*method)(self, pos_args);
1071 }
1072#endif
1073
1074#ifdef _NUITKA_FULL_COMPAT
1075 Py_LeaveRecursiveCall();
1076#endif
1077
1078 CHECK_OBJECT_X(result);
1079
1080 return Nuitka_CheckFunctionResult(tstate, called, result);
1081 }
1082#endif
1083#endif
1084#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1085 } else if (PyFunction_Check(called)) {
1086#if PYTHON_VERSION < 0x3b0
1087 PyObject *result = callPythonFunction(called, args, 1);
1088#else
1089 PyObject *result = _PyFunction_Vectorcall(called, args, 1, NULL);
1090#endif
1091 CHECK_OBJECT_X(result);
1092
1093 return result;
1094#endif
1095#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1096 } else if (PyType_Check(called)) {
1097 PyTypeObject *type = Py_TYPE(called);
1098
1099 if (type->tp_call == PyType_Type.tp_call) {
1100 PyTypeObject *called_type = (PyTypeObject *)(called);
1101
1102 if (unlikely(called == (PyObject *)&PyType_Type)) {
1103 PyObject *result = (PyObject *)Py_TYPE(args[0]);
1104 Py_INCREF(result);
1105 return result;
1106 }
1107
1108 if (unlikely(called_type->tp_new == NULL)) {
1109 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1110 return NULL;
1111 }
1112
1113 PyObject *obj;
1114
1115 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1116 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1117 formatCannotInstantiateAbstractClass(tstate, called_type);
1118 return NULL;
1119 }
1120
1121 obj = called_type->tp_alloc(called_type, 0);
1122 CHECK_OBJECT(obj);
1123 } else {
1124 obj = called_type->tp_new(called_type, pos_args, NULL);
1125 }
1126
1127 if (likely(obj != NULL)) {
1128 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1129 return obj;
1130 }
1131
1132 // Work on produced type.
1133 type = Py_TYPE(obj);
1134
1135 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1136 if (type->tp_init == default_tp_init_wrapper) {
1137
1138 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1139
1140 // Not really allowed, since we wouldn't have the default wrapper set.
1141 assert(init_method != NULL);
1142
1143 bool is_compiled_function = false;
1144 bool init_method_needs_release = false;
1145
1146 if (likely(init_method != NULL)) {
1147 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1148
1149 if (func == Nuitka_Function_Type.tp_descr_get) {
1150 is_compiled_function = true;
1151 } else if (func != NULL) {
1152 init_method = func(init_method, obj, (PyObject *)(type));
1153 init_method_needs_release = true;
1154 }
1155 }
1156
1157 if (unlikely(init_method == NULL)) {
1158 if (!HAS_ERROR_OCCURRED(tstate)) {
1159 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1160 const_str_plain___init__);
1161 }
1162
1163 return NULL;
1164 }
1165
1166 PyObject *result;
1167 if (is_compiled_function) {
1168 result = Nuitka_CallMethodFunctionPosArgs(
1169 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 1);
1170 } else {
1171 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
1172
1173 if (init_method_needs_release) {
1174 Py_DECREF(init_method);
1175 }
1176 }
1177
1178 if (unlikely(result == NULL)) {
1179 Py_DECREF(obj);
1180 return NULL;
1181 }
1182
1183 Py_DECREF(result);
1184
1185 if (unlikely(result != Py_None)) {
1186 Py_DECREF(obj);
1187
1188 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1189 return NULL;
1190 }
1191 } else {
1192
1193 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
1194 Py_DECREF(obj);
1195 return NULL;
1196 }
1197 }
1198 }
1199 }
1200
1201 CHECK_OBJECT_X(obj);
1202
1203 return obj;
1204 }
1205#endif
1206#if PYTHON_VERSION < 0x300
1207 } else if (PyClass_Check(called)) {
1208 PyObject *obj = PyInstance_NewRaw(called, NULL);
1209
1210 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
1211
1212 if (unlikely(init_method == NULL)) {
1213 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
1214 Py_DECREF(obj);
1215 return NULL;
1216 }
1217
1218 Py_DECREF(obj);
1219
1220 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
1221 return NULL;
1222 }
1223
1224 bool is_compiled_function = false;
1225
1226 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
1227
1228 if (descr_get == NULL) {
1229 Py_INCREF(init_method);
1230 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
1231 is_compiled_function = true;
1232 } else if (descr_get != NULL) {
1233 PyObject *descr_method = descr_get(init_method, obj, called);
1234
1235 if (unlikely(descr_method == NULL)) {
1236 return NULL;
1237 }
1238
1239 init_method = descr_method;
1240 }
1241
1242 PyObject *result;
1243 if (is_compiled_function) {
1244 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
1245 args, 1);
1246 } else {
1247 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
1248 Py_DECREF(init_method);
1249 }
1250 if (unlikely(result == NULL)) {
1251 return NULL;
1252 }
1253
1254 Py_DECREF(result);
1255
1256 if (unlikely(result != Py_None)) {
1257 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1258 return NULL;
1259 }
1260
1261 CHECK_OBJECT_X(obj);
1262
1263 return obj;
1264#endif
1265#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
1266 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
1267 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1268
1269 if (likely(func != NULL)) {
1270 PyObject *result = func(called, args, 1, NULL);
1271
1272 CHECK_OBJECT_X(result);
1273
1274 return Nuitka_CheckFunctionResult(tstate, called, result);
1275 }
1276#endif
1277 }
1278
1279#if 0
1280 PRINT_NEW_LINE();
1281 PRINT_STRING("FALLBACK");
1282 PRINT_ITEM(called);
1283 PRINT_NEW_LINE();
1284#endif
1285
1286 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
1287
1288 CHECK_OBJECT_X(result);
1289
1290 return result;
1291}
1292PyObject *CALL_FUNCTION_WITH_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
1293 CHECK_OBJECT(called);
1294 CHECK_OBJECTS(args, 2);
1295
1296 if (Nuitka_Function_Check(called)) {
1297 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1298 return NULL;
1299 }
1300
1301 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
1302 PyObject *result;
1303
1304 if (function->m_args_simple && 2 == function->m_args_positional_count) {
1305 for (Py_ssize_t i = 0; i < 2; i++) {
1306 Py_INCREF(args[i]);
1307 }
1308 result = function->m_c_code(tstate, function, (PyObject **)args);
1309 } else if (function->m_args_simple && 2 + function->m_defaults_given == function->m_args_positional_count) {
1310 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1311
1312 memcpy(python_pars, args, 2 * sizeof(PyObject *));
1313 memcpy(python_pars + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1314 function->m_defaults_given * sizeof(PyObject *));
1315
1316 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
1317 Py_INCREF(python_pars[i]);
1318 }
1319
1320 result = function->m_c_code(tstate, function, python_pars);
1321 } else {
1322 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 2);
1323 }
1324
1325 Py_LeaveRecursiveCall();
1326
1327 CHECK_OBJECT_X(result);
1328
1329 return result;
1330 } else if (Nuitka_Method_Check(called)) {
1331 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
1332
1333 if (method->m_object == NULL) {
1334 PyObject *self = args[0];
1335
1336 int res = PyObject_IsInstance(self, method->m_class);
1337
1338 if (unlikely(res < 0)) {
1339 return NULL;
1340 } else if (unlikely(res == 0)) {
1341 PyErr_Format(PyExc_TypeError,
1342 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
1343 "instance instead)",
1344 GET_CALLABLE_NAME((PyObject *)method->m_function),
1345 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
1346 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
1347
1348 return NULL;
1349 }
1350
1351 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 2);
1352
1353 CHECK_OBJECT_X(result);
1354
1355 return result;
1356 } else {
1357 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1358 return NULL;
1359 }
1360
1361 struct Nuitka_FunctionObject *function = method->m_function;
1362
1363 PyObject *result;
1364
1365 if (function->m_args_simple && 2 + 1 == function->m_args_positional_count) {
1366 PyObject *python_pars[2 + 1];
1367
1368 python_pars[0] = method->m_object;
1369 Py_INCREF(method->m_object);
1370
1371 for (Py_ssize_t i = 0; i < 2; i++) {
1372 python_pars[i + 1] = args[i];
1373 Py_INCREF(args[i]);
1374 }
1375 result = function->m_c_code(tstate, function, python_pars);
1376 } else if (function->m_args_simple &&
1377 2 + 1 + function->m_defaults_given == function->m_args_positional_count) {
1378 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1379
1380 python_pars[0] = method->m_object;
1381 Py_INCREF(method->m_object);
1382
1383 memcpy(python_pars + 1, args, 2 * sizeof(PyObject *));
1384 memcpy(python_pars + 1 + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1385 function->m_defaults_given * sizeof(PyObject *));
1386
1387 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
1388 Py_INCREF(python_pars[i]);
1389 }
1390
1391 result = function->m_c_code(tstate, function, python_pars);
1392 } else {
1393 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 2);
1394 }
1395
1396 Py_LeaveRecursiveCall();
1397
1398 CHECK_OBJECT_X(result);
1399
1400 return result;
1401 }
1402#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
1403 } else if (PyCFunction_CheckExact(called)) {
1404#if PYTHON_VERSION >= 0x380
1405#ifdef _NUITKA_FULL_COMPAT
1406 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1407 return NULL;
1408 }
1409#endif
1410
1411 int flags = PyCFunction_GET_FLAGS(called);
1412
1413 PyObject *result;
1414
1415 if (!(flags & METH_VARARGS)) {
1416 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1417
1418 assert(func != NULL);
1419 result = func(called, args, 2, NULL);
1420
1421 CHECK_OBJECT_X(result);
1422 } else {
1423 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1424 PyObject *self = PyCFunction_GET_SELF(called);
1425
1426 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1427
1428 if (flags & METH_KEYWORDS) {
1429 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1430 } else {
1431 result = (*method)(self, pos_args);
1432 }
1433
1434 Py_DECREF(pos_args);
1435 }
1436
1437#ifdef _NUITKA_FULL_COMPAT
1438 Py_LeaveRecursiveCall();
1439#endif
1440 CHECK_OBJECT_X(result);
1441
1442 return Nuitka_CheckFunctionResult(tstate, called, result);
1443#else
1444 // Try to be fast about wrapping the arguments.
1445 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1446
1447 if (unlikely(flags & METH_NOARGS)) {
1448 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (2 given)",
1449 ((PyCFunctionObject *)called)->m_ml->ml_name);
1450 return NULL;
1451 } else if (unlikely(flags & METH_O)) {
1452 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (2 given)",
1453 ((PyCFunctionObject *)called)->m_ml->ml_name);
1454 return NULL;
1455 } else if (flags & METH_VARARGS) {
1456 // Recursion guard is not strictly necessary, as we already have
1457 // one on our way to here.
1458#ifdef _NUITKA_FULL_COMPAT
1459 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1460 return NULL;
1461 }
1462#endif
1463 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1464 PyObject *self = PyCFunction_GET_SELF(called);
1465
1466 PyObject *result;
1467
1468#if PYTHON_VERSION < 0x360
1469 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1470 if (flags & METH_KEYWORDS) {
1471 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1472 } else {
1473 result = (*method)(self, pos_args);
1474 }
1475
1476 Py_DECREF(pos_args);
1477#else
1478 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1479 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1480 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1481 Py_DECREF(pos_args);
1482 } else if (flags == METH_FASTCALL) {
1483#if PYTHON_VERSION < 0x370
1484 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 2, NULL);
1485#else
1486 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1487 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
1488 Py_DECREF(pos_args);
1489#endif
1490 } else {
1491 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1492 result = (*method)(self, pos_args);
1493 Py_DECREF(pos_args);
1494 }
1495#endif
1496
1497#ifdef _NUITKA_FULL_COMPAT
1498 Py_LeaveRecursiveCall();
1499#endif
1500
1501 CHECK_OBJECT_X(result);
1502
1503 return Nuitka_CheckFunctionResult(tstate, called, result);
1504 }
1505#endif
1506#endif
1507#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1508 } else if (PyFunction_Check(called)) {
1509#if PYTHON_VERSION < 0x3b0
1510 PyObject *result = callPythonFunction(called, args, 2);
1511#else
1512 PyObject *result = _PyFunction_Vectorcall(called, args, 2, NULL);
1513#endif
1514 CHECK_OBJECT_X(result);
1515
1516 return result;
1517#endif
1518#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1519 } else if (PyType_Check(called)) {
1520 PyTypeObject *type = Py_TYPE(called);
1521
1522 if (type->tp_call == PyType_Type.tp_call) {
1523 PyTypeObject *called_type = (PyTypeObject *)(called);
1524
1525 if (unlikely(called_type->tp_new == NULL)) {
1526 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1527 return NULL;
1528 }
1529
1530 PyObject *pos_args = NULL;
1531 PyObject *obj;
1532
1533 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1534 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1535 formatCannotInstantiateAbstractClass(tstate, called_type);
1536 return NULL;
1537 }
1538
1539 obj = called_type->tp_alloc(called_type, 0);
1540 CHECK_OBJECT(obj);
1541 } else {
1542 pos_args = MAKE_TUPLE(tstate, args, 2);
1543 obj = called_type->tp_new(called_type, pos_args, NULL);
1544 }
1545
1546 if (likely(obj != NULL)) {
1547 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1548 Py_DECREF(pos_args);
1549 return obj;
1550 }
1551
1552 // Work on produced type.
1553 type = Py_TYPE(obj);
1554
1555 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1556 if (type->tp_init == default_tp_init_wrapper) {
1557 Py_XDECREF(pos_args);
1558 pos_args = NULL;
1559
1560 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1561
1562 // Not really allowed, since we wouldn't have the default wrapper set.
1563 assert(init_method != NULL);
1564
1565 bool is_compiled_function = false;
1566 bool init_method_needs_release = false;
1567
1568 if (likely(init_method != NULL)) {
1569 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1570
1571 if (func == Nuitka_Function_Type.tp_descr_get) {
1572 is_compiled_function = true;
1573 } else if (func != NULL) {
1574 init_method = func(init_method, obj, (PyObject *)(type));
1575 init_method_needs_release = true;
1576 }
1577 }
1578
1579 if (unlikely(init_method == NULL)) {
1580 if (!HAS_ERROR_OCCURRED(tstate)) {
1581 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1582 const_str_plain___init__);
1583 }
1584
1585 return NULL;
1586 }
1587
1588 PyObject *result;
1589 if (is_compiled_function) {
1590 result = Nuitka_CallMethodFunctionPosArgs(
1591 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 2);
1592 } else {
1593 result = CALL_FUNCTION_WITH_ARGS2(tstate, init_method, args);
1594 if (init_method_needs_release) {
1595 Py_DECREF(init_method);
1596 }
1597 }
1598
1599 if (unlikely(result == NULL)) {
1600 Py_DECREF(obj);
1601 return NULL;
1602 }
1603
1604 Py_DECREF(result);
1605
1606 if (unlikely(result != Py_None)) {
1607 Py_DECREF(obj);
1608
1609 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1610 return NULL;
1611 }
1612 } else {
1613 if (pos_args == NULL) {
1614 pos_args = MAKE_TUPLE(tstate, args, 2);
1615 }
1616
1617 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
1618 Py_DECREF(obj);
1619 Py_XDECREF(pos_args);
1620 return NULL;
1621 }
1622 }
1623 }
1624 }
1625
1626 Py_XDECREF(pos_args);
1627
1628 CHECK_OBJECT_X(obj);
1629
1630 return obj;
1631 }
1632#endif
1633#if PYTHON_VERSION < 0x300
1634 } else if (PyClass_Check(called)) {
1635 PyObject *obj = PyInstance_NewRaw(called, NULL);
1636
1637 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
1638
1639 if (unlikely(init_method == NULL)) {
1640 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
1641 Py_DECREF(obj);
1642 return NULL;
1643 }
1644
1645 Py_DECREF(obj);
1646
1647 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
1648 return NULL;
1649 }
1650
1651 bool is_compiled_function = false;
1652
1653 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
1654
1655 if (descr_get == NULL) {
1656 Py_INCREF(init_method);
1657 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
1658 is_compiled_function = true;
1659 } else if (descr_get != NULL) {
1660 PyObject *descr_method = descr_get(init_method, obj, called);
1661
1662 if (unlikely(descr_method == NULL)) {
1663 return NULL;
1664 }
1665
1666 init_method = descr_method;
1667 }
1668
1669 PyObject *result;
1670 if (is_compiled_function) {
1671 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
1672 args, 2);
1673 } else {
1674 result = CALL_FUNCTION_WITH_ARGS2(tstate, init_method, args);
1675 Py_DECREF(init_method);
1676 }
1677 if (unlikely(result == NULL)) {
1678 return NULL;
1679 }
1680
1681 Py_DECREF(result);
1682
1683 if (unlikely(result != Py_None)) {
1684 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1685 return NULL;
1686 }
1687
1688 CHECK_OBJECT_X(obj);
1689
1690 return obj;
1691#endif
1692#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
1693 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
1694 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1695
1696 if (likely(func != NULL)) {
1697 PyObject *result = func(called, args, 2, NULL);
1698
1699 CHECK_OBJECT_X(result);
1700
1701 return Nuitka_CheckFunctionResult(tstate, called, result);
1702 }
1703#endif
1704 }
1705
1706#if 0
1707 PRINT_NEW_LINE();
1708 PRINT_STRING("FALLBACK");
1709 PRINT_ITEM(called);
1710 PRINT_NEW_LINE();
1711#endif
1712
1713 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1714
1715 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
1716
1717 Py_DECREF(pos_args);
1718
1719 CHECK_OBJECT_X(result);
1720
1721 return result;
1722}
1723PyObject *CALL_FUNCTION_WITH_POS_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
1724 assert(PyTuple_CheckExact(pos_args));
1725 assert(PyTuple_GET_SIZE(pos_args) == 2);
1726 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
1727 CHECK_OBJECT(called);
1728 CHECK_OBJECTS(args, 2);
1729
1730 if (Nuitka_Function_Check(called)) {
1731 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1732 return NULL;
1733 }
1734
1735 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
1736 PyObject *result;
1737
1738 if (function->m_args_simple && 2 == function->m_args_positional_count) {
1739 for (Py_ssize_t i = 0; i < 2; i++) {
1740 Py_INCREF(args[i]);
1741 }
1742 result = function->m_c_code(tstate, function, (PyObject **)args);
1743 } else if (function->m_args_simple && 2 + function->m_defaults_given == function->m_args_positional_count) {
1744 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1745
1746 memcpy(python_pars, args, 2 * sizeof(PyObject *));
1747 memcpy(python_pars + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1748 function->m_defaults_given * sizeof(PyObject *));
1749
1750 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
1751 Py_INCREF(python_pars[i]);
1752 }
1753
1754 result = function->m_c_code(tstate, function, python_pars);
1755 } else {
1756 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 2);
1757 }
1758
1759 Py_LeaveRecursiveCall();
1760
1761 CHECK_OBJECT_X(result);
1762
1763 return result;
1764 } else if (Nuitka_Method_Check(called)) {
1765 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
1766
1767 if (method->m_object == NULL) {
1768 PyObject *self = args[0];
1769
1770 int res = PyObject_IsInstance(self, method->m_class);
1771
1772 if (unlikely(res < 0)) {
1773 return NULL;
1774 } else if (unlikely(res == 0)) {
1775 PyErr_Format(PyExc_TypeError,
1776 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
1777 "instance instead)",
1778 GET_CALLABLE_NAME((PyObject *)method->m_function),
1779 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
1780 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
1781
1782 return NULL;
1783 }
1784
1785 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 2);
1786
1787 CHECK_OBJECT_X(result);
1788
1789 return result;
1790 } else {
1791 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1792 return NULL;
1793 }
1794
1795 struct Nuitka_FunctionObject *function = method->m_function;
1796
1797 PyObject *result;
1798
1799 if (function->m_args_simple && 2 + 1 == function->m_args_positional_count) {
1800 PyObject *python_pars[2 + 1];
1801
1802 python_pars[0] = method->m_object;
1803 Py_INCREF(method->m_object);
1804
1805 for (Py_ssize_t i = 0; i < 2; i++) {
1806 python_pars[i + 1] = args[i];
1807 Py_INCREF(args[i]);
1808 }
1809 result = function->m_c_code(tstate, function, python_pars);
1810 } else if (function->m_args_simple &&
1811 2 + 1 + function->m_defaults_given == function->m_args_positional_count) {
1812 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1813
1814 python_pars[0] = method->m_object;
1815 Py_INCREF(method->m_object);
1816
1817 memcpy(python_pars + 1, args, 2 * sizeof(PyObject *));
1818 memcpy(python_pars + 1 + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1819 function->m_defaults_given * sizeof(PyObject *));
1820
1821 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
1822 Py_INCREF(python_pars[i]);
1823 }
1824
1825 result = function->m_c_code(tstate, function, python_pars);
1826 } else {
1827 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 2);
1828 }
1829
1830 Py_LeaveRecursiveCall();
1831
1832 CHECK_OBJECT_X(result);
1833
1834 return result;
1835 }
1836#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
1837 } else if (PyCFunction_CheckExact(called)) {
1838#if PYTHON_VERSION >= 0x380
1839#ifdef _NUITKA_FULL_COMPAT
1840 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1841 return NULL;
1842 }
1843#endif
1844
1845 int flags = PyCFunction_GET_FLAGS(called);
1846
1847 PyObject *result;
1848
1849 if (!(flags & METH_VARARGS)) {
1850 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1851
1852 assert(func != NULL);
1853 result = func(called, args, 2, NULL);
1854
1855 CHECK_OBJECT_X(result);
1856 } else {
1857 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1858 PyObject *self = PyCFunction_GET_SELF(called);
1859
1860 if (flags & METH_KEYWORDS) {
1861 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1862 } else {
1863 result = (*method)(self, pos_args);
1864 }
1865 }
1866
1867#ifdef _NUITKA_FULL_COMPAT
1868 Py_LeaveRecursiveCall();
1869#endif
1870 CHECK_OBJECT_X(result);
1871
1872 return Nuitka_CheckFunctionResult(tstate, called, result);
1873#else
1874 // Try to be fast about wrapping the arguments.
1875 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1876
1877 if (unlikely(flags & METH_NOARGS)) {
1878 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (2 given)",
1879 ((PyCFunctionObject *)called)->m_ml->ml_name);
1880 return NULL;
1881 } else if (unlikely(flags & METH_O)) {
1882 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (2 given)",
1883 ((PyCFunctionObject *)called)->m_ml->ml_name);
1884 return NULL;
1885 } else if (flags & METH_VARARGS) {
1886 // Recursion guard is not strictly necessary, as we already have
1887 // one on our way to here.
1888#ifdef _NUITKA_FULL_COMPAT
1889 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1890 return NULL;
1891 }
1892#endif
1893 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1894 PyObject *self = PyCFunction_GET_SELF(called);
1895
1896 PyObject *result;
1897
1898#if PYTHON_VERSION < 0x360
1899 if (flags & METH_KEYWORDS) {
1900 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1901 } else {
1902 result = (*method)(self, pos_args);
1903 }
1904
1905#else
1906 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1907 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1908 } else if (flags == METH_FASTCALL) {
1909#if PYTHON_VERSION < 0x370
1910 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 2, NULL);
1911#else
1912 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
1913#endif
1914 } else {
1915 result = (*method)(self, pos_args);
1916 }
1917#endif
1918
1919#ifdef _NUITKA_FULL_COMPAT
1920 Py_LeaveRecursiveCall();
1921#endif
1922
1923 CHECK_OBJECT_X(result);
1924
1925 return Nuitka_CheckFunctionResult(tstate, called, result);
1926 }
1927#endif
1928#endif
1929#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1930 } else if (PyFunction_Check(called)) {
1931#if PYTHON_VERSION < 0x3b0
1932 PyObject *result = callPythonFunction(called, args, 2);
1933#else
1934 PyObject *result = _PyFunction_Vectorcall(called, args, 2, NULL);
1935#endif
1936 CHECK_OBJECT_X(result);
1937
1938 return result;
1939#endif
1940#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1941 } else if (PyType_Check(called)) {
1942 PyTypeObject *type = Py_TYPE(called);
1943
1944 if (type->tp_call == PyType_Type.tp_call) {
1945 PyTypeObject *called_type = (PyTypeObject *)(called);
1946
1947 if (unlikely(called_type->tp_new == NULL)) {
1948 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1949 return NULL;
1950 }
1951
1952 PyObject *obj;
1953
1954 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1955 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1956 formatCannotInstantiateAbstractClass(tstate, called_type);
1957 return NULL;
1958 }
1959
1960 obj = called_type->tp_alloc(called_type, 0);
1961 CHECK_OBJECT(obj);
1962 } else {
1963 obj = called_type->tp_new(called_type, pos_args, NULL);
1964 }
1965
1966 if (likely(obj != NULL)) {
1967 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1968 return obj;
1969 }
1970
1971 // Work on produced type.
1972 type = Py_TYPE(obj);
1973
1974 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1975 if (type->tp_init == default_tp_init_wrapper) {
1976
1977 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1978
1979 // Not really allowed, since we wouldn't have the default wrapper set.
1980 assert(init_method != NULL);
1981
1982 bool is_compiled_function = false;
1983 bool init_method_needs_release = false;
1984
1985 if (likely(init_method != NULL)) {
1986 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1987
1988 if (func == Nuitka_Function_Type.tp_descr_get) {
1989 is_compiled_function = true;
1990 } else if (func != NULL) {
1991 init_method = func(init_method, obj, (PyObject *)(type));
1992 init_method_needs_release = true;
1993 }
1994 }
1995
1996 if (unlikely(init_method == NULL)) {
1997 if (!HAS_ERROR_OCCURRED(tstate)) {
1998 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1999 const_str_plain___init__);
2000 }
2001
2002 return NULL;
2003 }
2004
2005 PyObject *result;
2006 if (is_compiled_function) {
2007 result = Nuitka_CallMethodFunctionPosArgs(
2008 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 2);
2009 } else {
2010 result = CALL_FUNCTION_WITH_POS_ARGS2(tstate, init_method, pos_args);
2011 if (init_method_needs_release) {
2012 Py_DECREF(init_method);
2013 }
2014 }
2015
2016 if (unlikely(result == NULL)) {
2017 Py_DECREF(obj);
2018 return NULL;
2019 }
2020
2021 Py_DECREF(result);
2022
2023 if (unlikely(result != Py_None)) {
2024 Py_DECREF(obj);
2025
2026 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2027 return NULL;
2028 }
2029 } else {
2030
2031 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2032 Py_DECREF(obj);
2033 return NULL;
2034 }
2035 }
2036 }
2037 }
2038
2039 CHECK_OBJECT_X(obj);
2040
2041 return obj;
2042 }
2043#endif
2044#if PYTHON_VERSION < 0x300
2045 } else if (PyClass_Check(called)) {
2046 PyObject *obj = PyInstance_NewRaw(called, NULL);
2047
2048 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2049
2050 if (unlikely(init_method == NULL)) {
2051 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2052 Py_DECREF(obj);
2053 return NULL;
2054 }
2055
2056 Py_DECREF(obj);
2057
2058 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2059 return NULL;
2060 }
2061
2062 bool is_compiled_function = false;
2063
2064 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2065
2066 if (descr_get == NULL) {
2067 Py_INCREF(init_method);
2068 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2069 is_compiled_function = true;
2070 } else if (descr_get != NULL) {
2071 PyObject *descr_method = descr_get(init_method, obj, called);
2072
2073 if (unlikely(descr_method == NULL)) {
2074 return NULL;
2075 }
2076
2077 init_method = descr_method;
2078 }
2079
2080 PyObject *result;
2081 if (is_compiled_function) {
2082 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2083 args, 2);
2084 } else {
2085 result = CALL_FUNCTION_WITH_POS_ARGS2(tstate, init_method, pos_args);
2086 Py_DECREF(init_method);
2087 }
2088 if (unlikely(result == NULL)) {
2089 return NULL;
2090 }
2091
2092 Py_DECREF(result);
2093
2094 if (unlikely(result != Py_None)) {
2095 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2096 return NULL;
2097 }
2098
2099 CHECK_OBJECT_X(obj);
2100
2101 return obj;
2102#endif
2103#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2104 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2105 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2106
2107 if (likely(func != NULL)) {
2108 PyObject *result = func(called, args, 2, NULL);
2109
2110 CHECK_OBJECT_X(result);
2111
2112 return Nuitka_CheckFunctionResult(tstate, called, result);
2113 }
2114#endif
2115 }
2116
2117#if 0
2118 PRINT_NEW_LINE();
2119 PRINT_STRING("FALLBACK");
2120 PRINT_ITEM(called);
2121 PRINT_NEW_LINE();
2122#endif
2123
2124 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2125
2126 CHECK_OBJECT_X(result);
2127
2128 return result;
2129}
2130PyObject *CALL_FUNCTION_WITH_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
2131 CHECK_OBJECT(called);
2132 CHECK_OBJECTS(args, 3);
2133
2134 if (Nuitka_Function_Check(called)) {
2135 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2136 return NULL;
2137 }
2138
2139 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2140 PyObject *result;
2141
2142 if (function->m_args_simple && 3 == function->m_args_positional_count) {
2143 for (Py_ssize_t i = 0; i < 3; i++) {
2144 Py_INCREF(args[i]);
2145 }
2146 result = function->m_c_code(tstate, function, (PyObject **)args);
2147 } else if (function->m_args_simple && 3 + function->m_defaults_given == function->m_args_positional_count) {
2148 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2149
2150 memcpy(python_pars, args, 3 * sizeof(PyObject *));
2151 memcpy(python_pars + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2152 function->m_defaults_given * sizeof(PyObject *));
2153
2154 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2155 Py_INCREF(python_pars[i]);
2156 }
2157
2158 result = function->m_c_code(tstate, function, python_pars);
2159 } else {
2160 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 3);
2161 }
2162
2163 Py_LeaveRecursiveCall();
2164
2165 CHECK_OBJECT_X(result);
2166
2167 return result;
2168 } else if (Nuitka_Method_Check(called)) {
2169 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
2170
2171 if (method->m_object == NULL) {
2172 PyObject *self = args[0];
2173
2174 int res = PyObject_IsInstance(self, method->m_class);
2175
2176 if (unlikely(res < 0)) {
2177 return NULL;
2178 } else if (unlikely(res == 0)) {
2179 PyErr_Format(PyExc_TypeError,
2180 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
2181 "instance instead)",
2182 GET_CALLABLE_NAME((PyObject *)method->m_function),
2183 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
2184 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
2185
2186 return NULL;
2187 }
2188
2189 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 3);
2190
2191 CHECK_OBJECT_X(result);
2192
2193 return result;
2194 } else {
2195 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2196 return NULL;
2197 }
2198
2199 struct Nuitka_FunctionObject *function = method->m_function;
2200
2201 PyObject *result;
2202
2203 if (function->m_args_simple && 3 + 1 == function->m_args_positional_count) {
2204 PyObject *python_pars[3 + 1];
2205
2206 python_pars[0] = method->m_object;
2207 Py_INCREF(method->m_object);
2208
2209 for (Py_ssize_t i = 0; i < 3; i++) {
2210 python_pars[i + 1] = args[i];
2211 Py_INCREF(args[i]);
2212 }
2213 result = function->m_c_code(tstate, function, python_pars);
2214 } else if (function->m_args_simple &&
2215 3 + 1 + function->m_defaults_given == function->m_args_positional_count) {
2216 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2217
2218 python_pars[0] = method->m_object;
2219 Py_INCREF(method->m_object);
2220
2221 memcpy(python_pars + 1, args, 3 * sizeof(PyObject *));
2222 memcpy(python_pars + 1 + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2223 function->m_defaults_given * sizeof(PyObject *));
2224
2225 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
2226 Py_INCREF(python_pars[i]);
2227 }
2228
2229 result = function->m_c_code(tstate, function, python_pars);
2230 } else {
2231 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 3);
2232 }
2233
2234 Py_LeaveRecursiveCall();
2235
2236 CHECK_OBJECT_X(result);
2237
2238 return result;
2239 }
2240#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
2241 } else if (PyCFunction_CheckExact(called)) {
2242#if PYTHON_VERSION >= 0x380
2243#ifdef _NUITKA_FULL_COMPAT
2244 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2245 return NULL;
2246 }
2247#endif
2248
2249 int flags = PyCFunction_GET_FLAGS(called);
2250
2251 PyObject *result;
2252
2253 if (!(flags & METH_VARARGS)) {
2254 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2255
2256 assert(func != NULL);
2257 result = func(called, args, 3, NULL);
2258
2259 CHECK_OBJECT_X(result);
2260 } else {
2261 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2262 PyObject *self = PyCFunction_GET_SELF(called);
2263
2264 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2265
2266 if (flags & METH_KEYWORDS) {
2267 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
2268 } else {
2269 result = (*method)(self, pos_args);
2270 }
2271
2272 Py_DECREF(pos_args);
2273 }
2274
2275#ifdef _NUITKA_FULL_COMPAT
2276 Py_LeaveRecursiveCall();
2277#endif
2278 CHECK_OBJECT_X(result);
2279
2280 return Nuitka_CheckFunctionResult(tstate, called, result);
2281#else
2282 // Try to be fast about wrapping the arguments.
2283 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
2284
2285 if (unlikely(flags & METH_NOARGS)) {
2286 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (3 given)",
2287 ((PyCFunctionObject *)called)->m_ml->ml_name);
2288 return NULL;
2289 } else if (unlikely(flags & METH_O)) {
2290 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
2291 ((PyCFunctionObject *)called)->m_ml->ml_name);
2292 return NULL;
2293 } else if (flags & METH_VARARGS) {
2294 // Recursion guard is not strictly necessary, as we already have
2295 // one on our way to here.
2296#ifdef _NUITKA_FULL_COMPAT
2297 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2298 return NULL;
2299 }
2300#endif
2301 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2302 PyObject *self = PyCFunction_GET_SELF(called);
2303
2304 PyObject *result;
2305
2306#if PYTHON_VERSION < 0x360
2307 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2308 if (flags & METH_KEYWORDS) {
2309 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2310 } else {
2311 result = (*method)(self, pos_args);
2312 }
2313
2314 Py_DECREF(pos_args);
2315#else
2316 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
2317 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2318 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2319 Py_DECREF(pos_args);
2320 } else if (flags == METH_FASTCALL) {
2321#if PYTHON_VERSION < 0x370
2322 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 3, NULL);
2323#else
2324 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2325 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
2326 Py_DECREF(pos_args);
2327#endif
2328 } else {
2329 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2330 result = (*method)(self, pos_args);
2331 Py_DECREF(pos_args);
2332 }
2333#endif
2334
2335#ifdef _NUITKA_FULL_COMPAT
2336 Py_LeaveRecursiveCall();
2337#endif
2338
2339 CHECK_OBJECT_X(result);
2340
2341 return Nuitka_CheckFunctionResult(tstate, called, result);
2342 }
2343#endif
2344#endif
2345#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
2346 } else if (PyFunction_Check(called)) {
2347#if PYTHON_VERSION < 0x3b0
2348 PyObject *result = callPythonFunction(called, args, 3);
2349#else
2350 PyObject *result = _PyFunction_Vectorcall(called, args, 3, NULL);
2351#endif
2352 CHECK_OBJECT_X(result);
2353
2354 return result;
2355#endif
2356#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
2357 } else if (PyType_Check(called)) {
2358 PyTypeObject *type = Py_TYPE(called);
2359
2360 if (type->tp_call == PyType_Type.tp_call) {
2361 PyTypeObject *called_type = (PyTypeObject *)(called);
2362
2363 if (unlikely(called_type->tp_new == NULL)) {
2364 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
2365 return NULL;
2366 }
2367
2368 PyObject *pos_args = NULL;
2369 PyObject *obj;
2370
2371 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
2372 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
2373 formatCannotInstantiateAbstractClass(tstate, called_type);
2374 return NULL;
2375 }
2376
2377 obj = called_type->tp_alloc(called_type, 0);
2378 CHECK_OBJECT(obj);
2379 } else {
2380 pos_args = MAKE_TUPLE(tstate, args, 3);
2381 obj = called_type->tp_new(called_type, pos_args, NULL);
2382 }
2383
2384 if (likely(obj != NULL)) {
2385 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
2386 Py_DECREF(pos_args);
2387 return obj;
2388 }
2389
2390 // Work on produced type.
2391 type = Py_TYPE(obj);
2392
2393 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
2394 if (type->tp_init == default_tp_init_wrapper) {
2395 Py_XDECREF(pos_args);
2396 pos_args = NULL;
2397
2398 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
2399
2400 // Not really allowed, since we wouldn't have the default wrapper set.
2401 assert(init_method != NULL);
2402
2403 bool is_compiled_function = false;
2404 bool init_method_needs_release = false;
2405
2406 if (likely(init_method != NULL)) {
2407 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
2408
2409 if (func == Nuitka_Function_Type.tp_descr_get) {
2410 is_compiled_function = true;
2411 } else if (func != NULL) {
2412 init_method = func(init_method, obj, (PyObject *)(type));
2413 init_method_needs_release = true;
2414 }
2415 }
2416
2417 if (unlikely(init_method == NULL)) {
2418 if (!HAS_ERROR_OCCURRED(tstate)) {
2419 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2420 const_str_plain___init__);
2421 }
2422
2423 return NULL;
2424 }
2425
2426 PyObject *result;
2427 if (is_compiled_function) {
2428 result = Nuitka_CallMethodFunctionPosArgs(
2429 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 3);
2430 } else {
2431 result = CALL_FUNCTION_WITH_ARGS3(tstate, init_method, args);
2432 if (init_method_needs_release) {
2433 Py_DECREF(init_method);
2434 }
2435 }
2436
2437 if (unlikely(result == NULL)) {
2438 Py_DECREF(obj);
2439 return NULL;
2440 }
2441
2442 Py_DECREF(result);
2443
2444 if (unlikely(result != Py_None)) {
2445 Py_DECREF(obj);
2446
2447 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2448 return NULL;
2449 }
2450 } else {
2451 if (pos_args == NULL) {
2452 pos_args = MAKE_TUPLE(tstate, args, 3);
2453 }
2454
2455 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2456 Py_DECREF(obj);
2457 Py_XDECREF(pos_args);
2458 return NULL;
2459 }
2460 }
2461 }
2462 }
2463
2464 Py_XDECREF(pos_args);
2465
2466 CHECK_OBJECT_X(obj);
2467
2468 return obj;
2469 }
2470#endif
2471#if PYTHON_VERSION < 0x300
2472 } else if (PyClass_Check(called)) {
2473 PyObject *obj = PyInstance_NewRaw(called, NULL);
2474
2475 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2476
2477 if (unlikely(init_method == NULL)) {
2478 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2479 Py_DECREF(obj);
2480 return NULL;
2481 }
2482
2483 Py_DECREF(obj);
2484
2485 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2486 return NULL;
2487 }
2488
2489 bool is_compiled_function = false;
2490
2491 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2492
2493 if (descr_get == NULL) {
2494 Py_INCREF(init_method);
2495 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2496 is_compiled_function = true;
2497 } else if (descr_get != NULL) {
2498 PyObject *descr_method = descr_get(init_method, obj, called);
2499
2500 if (unlikely(descr_method == NULL)) {
2501 return NULL;
2502 }
2503
2504 init_method = descr_method;
2505 }
2506
2507 PyObject *result;
2508 if (is_compiled_function) {
2509 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2510 args, 3);
2511 } else {
2512 result = CALL_FUNCTION_WITH_ARGS3(tstate, init_method, args);
2513 Py_DECREF(init_method);
2514 }
2515 if (unlikely(result == NULL)) {
2516 return NULL;
2517 }
2518
2519 Py_DECREF(result);
2520
2521 if (unlikely(result != Py_None)) {
2522 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2523 return NULL;
2524 }
2525
2526 CHECK_OBJECT_X(obj);
2527
2528 return obj;
2529#endif
2530#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2531 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2532 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2533
2534 if (likely(func != NULL)) {
2535 PyObject *result = func(called, args, 3, NULL);
2536
2537 CHECK_OBJECT_X(result);
2538
2539 return Nuitka_CheckFunctionResult(tstate, called, result);
2540 }
2541#endif
2542 }
2543
2544#if 0
2545 PRINT_NEW_LINE();
2546 PRINT_STRING("FALLBACK");
2547 PRINT_ITEM(called);
2548 PRINT_NEW_LINE();
2549#endif
2550
2551 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2552
2553 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2554
2555 Py_DECREF(pos_args);
2556
2557 CHECK_OBJECT_X(result);
2558
2559 return result;
2560}
2561PyObject *CALL_FUNCTION_WITH_POS_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
2562 assert(PyTuple_CheckExact(pos_args));
2563 assert(PyTuple_GET_SIZE(pos_args) == 3);
2564 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
2565 CHECK_OBJECT(called);
2566 CHECK_OBJECTS(args, 3);
2567
2568 if (Nuitka_Function_Check(called)) {
2569 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2570 return NULL;
2571 }
2572
2573 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2574 PyObject *result;
2575
2576 if (function->m_args_simple && 3 == function->m_args_positional_count) {
2577 for (Py_ssize_t i = 0; i < 3; i++) {
2578 Py_INCREF(args[i]);
2579 }
2580 result = function->m_c_code(tstate, function, (PyObject **)args);
2581 } else if (function->m_args_simple && 3 + function->m_defaults_given == function->m_args_positional_count) {
2582 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2583
2584 memcpy(python_pars, args, 3 * sizeof(PyObject *));
2585 memcpy(python_pars + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2586 function->m_defaults_given * sizeof(PyObject *));
2587
2588 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2589 Py_INCREF(python_pars[i]);
2590 }
2591
2592 result = function->m_c_code(tstate, function, python_pars);
2593 } else {
2594 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 3);
2595 }
2596
2597 Py_LeaveRecursiveCall();
2598
2599 CHECK_OBJECT_X(result);
2600
2601 return result;
2602 } else if (Nuitka_Method_Check(called)) {
2603 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
2604
2605 if (method->m_object == NULL) {
2606 PyObject *self = args[0];
2607
2608 int res = PyObject_IsInstance(self, method->m_class);
2609
2610 if (unlikely(res < 0)) {
2611 return NULL;
2612 } else if (unlikely(res == 0)) {
2613 PyErr_Format(PyExc_TypeError,
2614 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
2615 "instance instead)",
2616 GET_CALLABLE_NAME((PyObject *)method->m_function),
2617 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
2618 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
2619
2620 return NULL;
2621 }
2622
2623 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 3);
2624
2625 CHECK_OBJECT_X(result);
2626
2627 return result;
2628 } else {
2629 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2630 return NULL;
2631 }
2632
2633 struct Nuitka_FunctionObject *function = method->m_function;
2634
2635 PyObject *result;
2636
2637 if (function->m_args_simple && 3 + 1 == function->m_args_positional_count) {
2638 PyObject *python_pars[3 + 1];
2639
2640 python_pars[0] = method->m_object;
2641 Py_INCREF(method->m_object);
2642
2643 for (Py_ssize_t i = 0; i < 3; i++) {
2644 python_pars[i + 1] = args[i];
2645 Py_INCREF(args[i]);
2646 }
2647 result = function->m_c_code(tstate, function, python_pars);
2648 } else if (function->m_args_simple &&
2649 3 + 1 + function->m_defaults_given == function->m_args_positional_count) {
2650 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2651
2652 python_pars[0] = method->m_object;
2653 Py_INCREF(method->m_object);
2654
2655 memcpy(python_pars + 1, args, 3 * sizeof(PyObject *));
2656 memcpy(python_pars + 1 + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2657 function->m_defaults_given * sizeof(PyObject *));
2658
2659 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
2660 Py_INCREF(python_pars[i]);
2661 }
2662
2663 result = function->m_c_code(tstate, function, python_pars);
2664 } else {
2665 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 3);
2666 }
2667
2668 Py_LeaveRecursiveCall();
2669
2670 CHECK_OBJECT_X(result);
2671
2672 return result;
2673 }
2674#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
2675 } else if (PyCFunction_CheckExact(called)) {
2676#if PYTHON_VERSION >= 0x380
2677#ifdef _NUITKA_FULL_COMPAT
2678 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2679 return NULL;
2680 }
2681#endif
2682
2683 int flags = PyCFunction_GET_FLAGS(called);
2684
2685 PyObject *result;
2686
2687 if (!(flags & METH_VARARGS)) {
2688 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2689
2690 assert(func != NULL);
2691 result = func(called, args, 3, NULL);
2692
2693 CHECK_OBJECT_X(result);
2694 } else {
2695 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2696 PyObject *self = PyCFunction_GET_SELF(called);
2697
2698 if (flags & METH_KEYWORDS) {
2699 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
2700 } else {
2701 result = (*method)(self, pos_args);
2702 }
2703 }
2704
2705#ifdef _NUITKA_FULL_COMPAT
2706 Py_LeaveRecursiveCall();
2707#endif
2708 CHECK_OBJECT_X(result);
2709
2710 return Nuitka_CheckFunctionResult(tstate, called, result);
2711#else
2712 // Try to be fast about wrapping the arguments.
2713 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
2714
2715 if (unlikely(flags & METH_NOARGS)) {
2716 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (3 given)",
2717 ((PyCFunctionObject *)called)->m_ml->ml_name);
2718 return NULL;
2719 } else if (unlikely(flags & METH_O)) {
2720 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
2721 ((PyCFunctionObject *)called)->m_ml->ml_name);
2722 return NULL;
2723 } else if (flags & METH_VARARGS) {
2724 // Recursion guard is not strictly necessary, as we already have
2725 // one on our way to here.
2726#ifdef _NUITKA_FULL_COMPAT
2727 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2728 return NULL;
2729 }
2730#endif
2731 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2732 PyObject *self = PyCFunction_GET_SELF(called);
2733
2734 PyObject *result;
2735
2736#if PYTHON_VERSION < 0x360
2737 if (flags & METH_KEYWORDS) {
2738 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2739 } else {
2740 result = (*method)(self, pos_args);
2741 }
2742
2743#else
2744 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
2745 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2746 } else if (flags == METH_FASTCALL) {
2747#if PYTHON_VERSION < 0x370
2748 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 3, NULL);
2749#else
2750 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
2751#endif
2752 } else {
2753 result = (*method)(self, pos_args);
2754 }
2755#endif
2756
2757#ifdef _NUITKA_FULL_COMPAT
2758 Py_LeaveRecursiveCall();
2759#endif
2760
2761 CHECK_OBJECT_X(result);
2762
2763 return Nuitka_CheckFunctionResult(tstate, called, result);
2764 }
2765#endif
2766#endif
2767#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
2768 } else if (PyFunction_Check(called)) {
2769#if PYTHON_VERSION < 0x3b0
2770 PyObject *result = callPythonFunction(called, args, 3);
2771#else
2772 PyObject *result = _PyFunction_Vectorcall(called, args, 3, NULL);
2773#endif
2774 CHECK_OBJECT_X(result);
2775
2776 return result;
2777#endif
2778#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
2779 } else if (PyType_Check(called)) {
2780 PyTypeObject *type = Py_TYPE(called);
2781
2782 if (type->tp_call == PyType_Type.tp_call) {
2783 PyTypeObject *called_type = (PyTypeObject *)(called);
2784
2785 if (unlikely(called_type->tp_new == NULL)) {
2786 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
2787 return NULL;
2788 }
2789
2790 PyObject *obj;
2791
2792 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
2793 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
2794 formatCannotInstantiateAbstractClass(tstate, called_type);
2795 return NULL;
2796 }
2797
2798 obj = called_type->tp_alloc(called_type, 0);
2799 CHECK_OBJECT(obj);
2800 } else {
2801 obj = called_type->tp_new(called_type, pos_args, NULL);
2802 }
2803
2804 if (likely(obj != NULL)) {
2805 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
2806 return obj;
2807 }
2808
2809 // Work on produced type.
2810 type = Py_TYPE(obj);
2811
2812 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
2813 if (type->tp_init == default_tp_init_wrapper) {
2814
2815 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
2816
2817 // Not really allowed, since we wouldn't have the default wrapper set.
2818 assert(init_method != NULL);
2819
2820 bool is_compiled_function = false;
2821 bool init_method_needs_release = false;
2822
2823 if (likely(init_method != NULL)) {
2824 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
2825
2826 if (func == Nuitka_Function_Type.tp_descr_get) {
2827 is_compiled_function = true;
2828 } else if (func != NULL) {
2829 init_method = func(init_method, obj, (PyObject *)(type));
2830 init_method_needs_release = true;
2831 }
2832 }
2833
2834 if (unlikely(init_method == NULL)) {
2835 if (!HAS_ERROR_OCCURRED(tstate)) {
2836 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2837 const_str_plain___init__);
2838 }
2839
2840 return NULL;
2841 }
2842
2843 PyObject *result;
2844 if (is_compiled_function) {
2845 result = Nuitka_CallMethodFunctionPosArgs(
2846 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 3);
2847 } else {
2848 result = CALL_FUNCTION_WITH_POS_ARGS3(tstate, init_method, pos_args);
2849 if (init_method_needs_release) {
2850 Py_DECREF(init_method);
2851 }
2852 }
2853
2854 if (unlikely(result == NULL)) {
2855 Py_DECREF(obj);
2856 return NULL;
2857 }
2858
2859 Py_DECREF(result);
2860
2861 if (unlikely(result != Py_None)) {
2862 Py_DECREF(obj);
2863
2864 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2865 return NULL;
2866 }
2867 } else {
2868
2869 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2870 Py_DECREF(obj);
2871 return NULL;
2872 }
2873 }
2874 }
2875 }
2876
2877 CHECK_OBJECT_X(obj);
2878
2879 return obj;
2880 }
2881#endif
2882#if PYTHON_VERSION < 0x300
2883 } else if (PyClass_Check(called)) {
2884 PyObject *obj = PyInstance_NewRaw(called, NULL);
2885
2886 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2887
2888 if (unlikely(init_method == NULL)) {
2889 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2890 Py_DECREF(obj);
2891 return NULL;
2892 }
2893
2894 Py_DECREF(obj);
2895
2896 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2897 return NULL;
2898 }
2899
2900 bool is_compiled_function = false;
2901
2902 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2903
2904 if (descr_get == NULL) {
2905 Py_INCREF(init_method);
2906 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2907 is_compiled_function = true;
2908 } else if (descr_get != NULL) {
2909 PyObject *descr_method = descr_get(init_method, obj, called);
2910
2911 if (unlikely(descr_method == NULL)) {
2912 return NULL;
2913 }
2914
2915 init_method = descr_method;
2916 }
2917
2918 PyObject *result;
2919 if (is_compiled_function) {
2920 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2921 args, 3);
2922 } else {
2923 result = CALL_FUNCTION_WITH_POS_ARGS3(tstate, init_method, pos_args);
2924 Py_DECREF(init_method);
2925 }
2926 if (unlikely(result == NULL)) {
2927 return NULL;
2928 }
2929
2930 Py_DECREF(result);
2931
2932 if (unlikely(result != Py_None)) {
2933 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2934 return NULL;
2935 }
2936
2937 CHECK_OBJECT_X(obj);
2938
2939 return obj;
2940#endif
2941#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2942 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2943 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2944
2945 if (likely(func != NULL)) {
2946 PyObject *result = func(called, args, 3, NULL);
2947
2948 CHECK_OBJECT_X(result);
2949
2950 return Nuitka_CheckFunctionResult(tstate, called, result);
2951 }
2952#endif
2953 }
2954
2955#if 0
2956 PRINT_NEW_LINE();
2957 PRINT_STRING("FALLBACK");
2958 PRINT_ITEM(called);
2959 PRINT_NEW_LINE();
2960#endif
2961
2962 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2963
2964 CHECK_OBJECT_X(result);
2965
2966 return result;
2967}
2968PyObject *CALL_FUNCTION_WITH_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
2969 CHECK_OBJECT(called);
2970 CHECK_OBJECTS(args, 4);
2971
2972 if (Nuitka_Function_Check(called)) {
2973 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2974 return NULL;
2975 }
2976
2977 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2978 PyObject *result;
2979
2980 if (function->m_args_simple && 4 == function->m_args_positional_count) {
2981 for (Py_ssize_t i = 0; i < 4; i++) {
2982 Py_INCREF(args[i]);
2983 }
2984 result = function->m_c_code(tstate, function, (PyObject **)args);
2985 } else if (function->m_args_simple && 4 + function->m_defaults_given == function->m_args_positional_count) {
2986 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2987
2988 memcpy(python_pars, args, 4 * sizeof(PyObject *));
2989 memcpy(python_pars + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
2990 function->m_defaults_given * sizeof(PyObject *));
2991
2992 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2993 Py_INCREF(python_pars[i]);
2994 }
2995
2996 result = function->m_c_code(tstate, function, python_pars);
2997 } else {
2998 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 4);
2999 }
3000
3001 Py_LeaveRecursiveCall();
3002
3003 CHECK_OBJECT_X(result);
3004
3005 return result;
3006 } else if (Nuitka_Method_Check(called)) {
3007 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3008
3009 if (method->m_object == NULL) {
3010 PyObject *self = args[0];
3011
3012 int res = PyObject_IsInstance(self, method->m_class);
3013
3014 if (unlikely(res < 0)) {
3015 return NULL;
3016 } else if (unlikely(res == 0)) {
3017 PyErr_Format(PyExc_TypeError,
3018 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3019 "instance instead)",
3020 GET_CALLABLE_NAME((PyObject *)method->m_function),
3021 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3022 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3023
3024 return NULL;
3025 }
3026
3027 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 4);
3028
3029 CHECK_OBJECT_X(result);
3030
3031 return result;
3032 } else {
3033 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3034 return NULL;
3035 }
3036
3037 struct Nuitka_FunctionObject *function = method->m_function;
3038
3039 PyObject *result;
3040
3041 if (function->m_args_simple && 4 + 1 == function->m_args_positional_count) {
3042 PyObject *python_pars[4 + 1];
3043
3044 python_pars[0] = method->m_object;
3045 Py_INCREF(method->m_object);
3046
3047 for (Py_ssize_t i = 0; i < 4; i++) {
3048 python_pars[i + 1] = args[i];
3049 Py_INCREF(args[i]);
3050 }
3051 result = function->m_c_code(tstate, function, python_pars);
3052 } else if (function->m_args_simple &&
3053 4 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3054 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3055
3056 python_pars[0] = method->m_object;
3057 Py_INCREF(method->m_object);
3058
3059 memcpy(python_pars + 1, args, 4 * sizeof(PyObject *));
3060 memcpy(python_pars + 1 + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3061 function->m_defaults_given * sizeof(PyObject *));
3062
3063 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3064 Py_INCREF(python_pars[i]);
3065 }
3066
3067 result = function->m_c_code(tstate, function, python_pars);
3068 } else {
3069 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 4);
3070 }
3071
3072 Py_LeaveRecursiveCall();
3073
3074 CHECK_OBJECT_X(result);
3075
3076 return result;
3077 }
3078#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3079 } else if (PyCFunction_CheckExact(called)) {
3080#if PYTHON_VERSION >= 0x380
3081#ifdef _NUITKA_FULL_COMPAT
3082 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3083 return NULL;
3084 }
3085#endif
3086
3087 int flags = PyCFunction_GET_FLAGS(called);
3088
3089 PyObject *result;
3090
3091 if (!(flags & METH_VARARGS)) {
3092 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3093
3094 assert(func != NULL);
3095 result = func(called, args, 4, NULL);
3096
3097 CHECK_OBJECT_X(result);
3098 } else {
3099 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3100 PyObject *self = PyCFunction_GET_SELF(called);
3101
3102 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3103
3104 if (flags & METH_KEYWORDS) {
3105 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3106 } else {
3107 result = (*method)(self, pos_args);
3108 }
3109
3110 Py_DECREF(pos_args);
3111 }
3112
3113#ifdef _NUITKA_FULL_COMPAT
3114 Py_LeaveRecursiveCall();
3115#endif
3116 CHECK_OBJECT_X(result);
3117
3118 return Nuitka_CheckFunctionResult(tstate, called, result);
3119#else
3120 // Try to be fast about wrapping the arguments.
3121 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3122
3123 if (unlikely(flags & METH_NOARGS)) {
3124 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (4 given)",
3125 ((PyCFunctionObject *)called)->m_ml->ml_name);
3126 return NULL;
3127 } else if (unlikely(flags & METH_O)) {
3128 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
3129 ((PyCFunctionObject *)called)->m_ml->ml_name);
3130 return NULL;
3131 } else if (flags & METH_VARARGS) {
3132 // Recursion guard is not strictly necessary, as we already have
3133 // one on our way to here.
3134#ifdef _NUITKA_FULL_COMPAT
3135 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3136 return NULL;
3137 }
3138#endif
3139 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3140 PyObject *self = PyCFunction_GET_SELF(called);
3141
3142 PyObject *result;
3143
3144#if PYTHON_VERSION < 0x360
3145 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3146 if (flags & METH_KEYWORDS) {
3147 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3148 } else {
3149 result = (*method)(self, pos_args);
3150 }
3151
3152 Py_DECREF(pos_args);
3153#else
3154 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3155 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3156 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3157 Py_DECREF(pos_args);
3158 } else if (flags == METH_FASTCALL) {
3159#if PYTHON_VERSION < 0x370
3160 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 4, NULL);
3161#else
3162 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3163 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
3164 Py_DECREF(pos_args);
3165#endif
3166 } else {
3167 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3168 result = (*method)(self, pos_args);
3169 Py_DECREF(pos_args);
3170 }
3171#endif
3172
3173#ifdef _NUITKA_FULL_COMPAT
3174 Py_LeaveRecursiveCall();
3175#endif
3176
3177 CHECK_OBJECT_X(result);
3178
3179 return Nuitka_CheckFunctionResult(tstate, called, result);
3180 }
3181#endif
3182#endif
3183#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
3184 } else if (PyFunction_Check(called)) {
3185#if PYTHON_VERSION < 0x3b0
3186 PyObject *result = callPythonFunction(called, args, 4);
3187#else
3188 PyObject *result = _PyFunction_Vectorcall(called, args, 4, NULL);
3189#endif
3190 CHECK_OBJECT_X(result);
3191
3192 return result;
3193#endif
3194#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
3195 } else if (PyType_Check(called)) {
3196 PyTypeObject *type = Py_TYPE(called);
3197
3198 if (type->tp_call == PyType_Type.tp_call) {
3199 PyTypeObject *called_type = (PyTypeObject *)(called);
3200
3201 if (unlikely(called_type->tp_new == NULL)) {
3202 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
3203 return NULL;
3204 }
3205
3206 PyObject *pos_args = NULL;
3207 PyObject *obj;
3208
3209 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
3210 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
3211 formatCannotInstantiateAbstractClass(tstate, called_type);
3212 return NULL;
3213 }
3214
3215 obj = called_type->tp_alloc(called_type, 0);
3216 CHECK_OBJECT(obj);
3217 } else {
3218 pos_args = MAKE_TUPLE(tstate, args, 4);
3219 obj = called_type->tp_new(called_type, pos_args, NULL);
3220 }
3221
3222 if (likely(obj != NULL)) {
3223 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
3224 Py_DECREF(pos_args);
3225 return obj;
3226 }
3227
3228 // Work on produced type.
3229 type = Py_TYPE(obj);
3230
3231 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
3232 if (type->tp_init == default_tp_init_wrapper) {
3233 Py_XDECREF(pos_args);
3234 pos_args = NULL;
3235
3236 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
3237
3238 // Not really allowed, since we wouldn't have the default wrapper set.
3239 assert(init_method != NULL);
3240
3241 bool is_compiled_function = false;
3242 bool init_method_needs_release = false;
3243
3244 if (likely(init_method != NULL)) {
3245 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
3246
3247 if (func == Nuitka_Function_Type.tp_descr_get) {
3248 is_compiled_function = true;
3249 } else if (func != NULL) {
3250 init_method = func(init_method, obj, (PyObject *)(type));
3251 init_method_needs_release = true;
3252 }
3253 }
3254
3255 if (unlikely(init_method == NULL)) {
3256 if (!HAS_ERROR_OCCURRED(tstate)) {
3257 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
3258 const_str_plain___init__);
3259 }
3260
3261 return NULL;
3262 }
3263
3264 PyObject *result;
3265 if (is_compiled_function) {
3266 result = Nuitka_CallMethodFunctionPosArgs(
3267 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 4);
3268 } else {
3269 result = CALL_FUNCTION_WITH_ARGS4(tstate, init_method, args);
3270 if (init_method_needs_release) {
3271 Py_DECREF(init_method);
3272 }
3273 }
3274
3275 if (unlikely(result == NULL)) {
3276 Py_DECREF(obj);
3277 return NULL;
3278 }
3279
3280 Py_DECREF(result);
3281
3282 if (unlikely(result != Py_None)) {
3283 Py_DECREF(obj);
3284
3285 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3286 return NULL;
3287 }
3288 } else {
3289 if (pos_args == NULL) {
3290 pos_args = MAKE_TUPLE(tstate, args, 4);
3291 }
3292
3293 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
3294 Py_DECREF(obj);
3295 Py_XDECREF(pos_args);
3296 return NULL;
3297 }
3298 }
3299 }
3300 }
3301
3302 Py_XDECREF(pos_args);
3303
3304 CHECK_OBJECT_X(obj);
3305
3306 return obj;
3307 }
3308#endif
3309#if PYTHON_VERSION < 0x300
3310 } else if (PyClass_Check(called)) {
3311 PyObject *obj = PyInstance_NewRaw(called, NULL);
3312
3313 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
3314
3315 if (unlikely(init_method == NULL)) {
3316 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
3317 Py_DECREF(obj);
3318 return NULL;
3319 }
3320
3321 Py_DECREF(obj);
3322
3323 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
3324 return NULL;
3325 }
3326
3327 bool is_compiled_function = false;
3328
3329 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
3330
3331 if (descr_get == NULL) {
3332 Py_INCREF(init_method);
3333 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
3334 is_compiled_function = true;
3335 } else if (descr_get != NULL) {
3336 PyObject *descr_method = descr_get(init_method, obj, called);
3337
3338 if (unlikely(descr_method == NULL)) {
3339 return NULL;
3340 }
3341
3342 init_method = descr_method;
3343 }
3344
3345 PyObject *result;
3346 if (is_compiled_function) {
3347 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
3348 args, 4);
3349 } else {
3350 result = CALL_FUNCTION_WITH_ARGS4(tstate, init_method, args);
3351 Py_DECREF(init_method);
3352 }
3353 if (unlikely(result == NULL)) {
3354 return NULL;
3355 }
3356
3357 Py_DECREF(result);
3358
3359 if (unlikely(result != Py_None)) {
3360 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3361 return NULL;
3362 }
3363
3364 CHECK_OBJECT_X(obj);
3365
3366 return obj;
3367#endif
3368#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
3369 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
3370 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3371
3372 if (likely(func != NULL)) {
3373 PyObject *result = func(called, args, 4, NULL);
3374
3375 CHECK_OBJECT_X(result);
3376
3377 return Nuitka_CheckFunctionResult(tstate, called, result);
3378 }
3379#endif
3380 }
3381
3382#if 0
3383 PRINT_NEW_LINE();
3384 PRINT_STRING("FALLBACK");
3385 PRINT_ITEM(called);
3386 PRINT_NEW_LINE();
3387#endif
3388
3389 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3390
3391 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
3392
3393 Py_DECREF(pos_args);
3394
3395 CHECK_OBJECT_X(result);
3396
3397 return result;
3398}
3399PyObject *CALL_FUNCTION_WITH_POS_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
3400 assert(PyTuple_CheckExact(pos_args));
3401 assert(PyTuple_GET_SIZE(pos_args) == 4);
3402 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
3403 CHECK_OBJECT(called);
3404 CHECK_OBJECTS(args, 4);
3405
3406 if (Nuitka_Function_Check(called)) {
3407 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3408 return NULL;
3409 }
3410
3411 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
3412 PyObject *result;
3413
3414 if (function->m_args_simple && 4 == function->m_args_positional_count) {
3415 for (Py_ssize_t i = 0; i < 4; i++) {
3416 Py_INCREF(args[i]);
3417 }
3418 result = function->m_c_code(tstate, function, (PyObject **)args);
3419 } else if (function->m_args_simple && 4 + function->m_defaults_given == function->m_args_positional_count) {
3420 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3421
3422 memcpy(python_pars, args, 4 * sizeof(PyObject *));
3423 memcpy(python_pars + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3424 function->m_defaults_given * sizeof(PyObject *));
3425
3426 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
3427 Py_INCREF(python_pars[i]);
3428 }
3429
3430 result = function->m_c_code(tstate, function, python_pars);
3431 } else {
3432 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 4);
3433 }
3434
3435 Py_LeaveRecursiveCall();
3436
3437 CHECK_OBJECT_X(result);
3438
3439 return result;
3440 } else if (Nuitka_Method_Check(called)) {
3441 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3442
3443 if (method->m_object == NULL) {
3444 PyObject *self = args[0];
3445
3446 int res = PyObject_IsInstance(self, method->m_class);
3447
3448 if (unlikely(res < 0)) {
3449 return NULL;
3450 } else if (unlikely(res == 0)) {
3451 PyErr_Format(PyExc_TypeError,
3452 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3453 "instance instead)",
3454 GET_CALLABLE_NAME((PyObject *)method->m_function),
3455 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3456 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3457
3458 return NULL;
3459 }
3460
3461 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 4);
3462
3463 CHECK_OBJECT_X(result);
3464
3465 return result;
3466 } else {
3467 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3468 return NULL;
3469 }
3470
3471 struct Nuitka_FunctionObject *function = method->m_function;
3472
3473 PyObject *result;
3474
3475 if (function->m_args_simple && 4 + 1 == function->m_args_positional_count) {
3476 PyObject *python_pars[4 + 1];
3477
3478 python_pars[0] = method->m_object;
3479 Py_INCREF(method->m_object);
3480
3481 for (Py_ssize_t i = 0; i < 4; i++) {
3482 python_pars[i + 1] = args[i];
3483 Py_INCREF(args[i]);
3484 }
3485 result = function->m_c_code(tstate, function, python_pars);
3486 } else if (function->m_args_simple &&
3487 4 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3488 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3489
3490 python_pars[0] = method->m_object;
3491 Py_INCREF(method->m_object);
3492
3493 memcpy(python_pars + 1, args, 4 * sizeof(PyObject *));
3494 memcpy(python_pars + 1 + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3495 function->m_defaults_given * sizeof(PyObject *));
3496
3497 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3498 Py_INCREF(python_pars[i]);
3499 }
3500
3501 result = function->m_c_code(tstate, function, python_pars);
3502 } else {
3503 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 4);
3504 }
3505
3506 Py_LeaveRecursiveCall();
3507
3508 CHECK_OBJECT_X(result);
3509
3510 return result;
3511 }
3512#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3513 } else if (PyCFunction_CheckExact(called)) {
3514#if PYTHON_VERSION >= 0x380
3515#ifdef _NUITKA_FULL_COMPAT
3516 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3517 return NULL;
3518 }
3519#endif
3520
3521 int flags = PyCFunction_GET_FLAGS(called);
3522
3523 PyObject *result;
3524
3525 if (!(flags & METH_VARARGS)) {
3526 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3527
3528 assert(func != NULL);
3529 result = func(called, args, 4, NULL);
3530
3531 CHECK_OBJECT_X(result);
3532 } else {
3533 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3534 PyObject *self = PyCFunction_GET_SELF(called);
3535
3536 if (flags & METH_KEYWORDS) {
3537 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3538 } else {
3539 result = (*method)(self, pos_args);
3540 }
3541 }
3542
3543#ifdef _NUITKA_FULL_COMPAT
3544 Py_LeaveRecursiveCall();
3545#endif
3546 CHECK_OBJECT_X(result);
3547
3548 return Nuitka_CheckFunctionResult(tstate, called, result);
3549#else
3550 // Try to be fast about wrapping the arguments.
3551 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3552
3553 if (unlikely(flags & METH_NOARGS)) {
3554 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (4 given)",
3555 ((PyCFunctionObject *)called)->m_ml->ml_name);
3556 return NULL;
3557 } else if (unlikely(flags & METH_O)) {
3558 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
3559 ((PyCFunctionObject *)called)->m_ml->ml_name);
3560 return NULL;
3561 } else if (flags & METH_VARARGS) {
3562 // Recursion guard is not strictly necessary, as we already have
3563 // one on our way to here.
3564#ifdef _NUITKA_FULL_COMPAT
3565 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3566 return NULL;
3567 }
3568#endif
3569 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3570 PyObject *self = PyCFunction_GET_SELF(called);
3571
3572 PyObject *result;
3573
3574#if PYTHON_VERSION < 0x360
3575 if (flags & METH_KEYWORDS) {
3576 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3577 } else {
3578 result = (*method)(self, pos_args);
3579 }
3580
3581#else
3582 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3583 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3584 } else if (flags == METH_FASTCALL) {
3585#if PYTHON_VERSION < 0x370
3586 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 4, NULL);
3587#else
3588 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
3589#endif
3590 } else {
3591 result = (*method)(self, pos_args);
3592 }
3593#endif
3594
3595#ifdef _NUITKA_FULL_COMPAT
3596 Py_LeaveRecursiveCall();
3597#endif
3598
3599 CHECK_OBJECT_X(result);
3600
3601 return Nuitka_CheckFunctionResult(tstate, called, result);
3602 }
3603#endif
3604#endif
3605#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
3606 } else if (PyFunction_Check(called)) {
3607#if PYTHON_VERSION < 0x3b0
3608 PyObject *result = callPythonFunction(called, args, 4);
3609#else
3610 PyObject *result = _PyFunction_Vectorcall(called, args, 4, NULL);
3611#endif
3612 CHECK_OBJECT_X(result);
3613
3614 return result;
3615#endif
3616#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
3617 } else if (PyType_Check(called)) {
3618 PyTypeObject *type = Py_TYPE(called);
3619
3620 if (type->tp_call == PyType_Type.tp_call) {
3621 PyTypeObject *called_type = (PyTypeObject *)(called);
3622
3623 if (unlikely(called_type->tp_new == NULL)) {
3624 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
3625 return NULL;
3626 }
3627
3628 PyObject *obj;
3629
3630 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
3631 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
3632 formatCannotInstantiateAbstractClass(tstate, called_type);
3633 return NULL;
3634 }
3635
3636 obj = called_type->tp_alloc(called_type, 0);
3637 CHECK_OBJECT(obj);
3638 } else {
3639 obj = called_type->tp_new(called_type, pos_args, NULL);
3640 }
3641
3642 if (likely(obj != NULL)) {
3643 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
3644 return obj;
3645 }
3646
3647 // Work on produced type.
3648 type = Py_TYPE(obj);
3649
3650 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
3651 if (type->tp_init == default_tp_init_wrapper) {
3652
3653 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
3654
3655 // Not really allowed, since we wouldn't have the default wrapper set.
3656 assert(init_method != NULL);
3657
3658 bool is_compiled_function = false;
3659 bool init_method_needs_release = false;
3660
3661 if (likely(init_method != NULL)) {
3662 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
3663
3664 if (func == Nuitka_Function_Type.tp_descr_get) {
3665 is_compiled_function = true;
3666 } else if (func != NULL) {
3667 init_method = func(init_method, obj, (PyObject *)(type));
3668 init_method_needs_release = true;
3669 }
3670 }
3671
3672 if (unlikely(init_method == NULL)) {
3673 if (!HAS_ERROR_OCCURRED(tstate)) {
3674 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
3675 const_str_plain___init__);
3676 }
3677
3678 return NULL;
3679 }
3680
3681 PyObject *result;
3682 if (is_compiled_function) {
3683 result = Nuitka_CallMethodFunctionPosArgs(
3684 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 4);
3685 } else {
3686 result = CALL_FUNCTION_WITH_POS_ARGS4(tstate, init_method, pos_args);
3687 if (init_method_needs_release) {
3688 Py_DECREF(init_method);
3689 }
3690 }
3691
3692 if (unlikely(result == NULL)) {
3693 Py_DECREF(obj);
3694 return NULL;
3695 }
3696
3697 Py_DECREF(result);
3698
3699 if (unlikely(result != Py_None)) {
3700 Py_DECREF(obj);
3701
3702 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3703 return NULL;
3704 }
3705 } else {
3706
3707 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
3708 Py_DECREF(obj);
3709 return NULL;
3710 }
3711 }
3712 }
3713 }
3714
3715 CHECK_OBJECT_X(obj);
3716
3717 return obj;
3718 }
3719#endif
3720#if PYTHON_VERSION < 0x300
3721 } else if (PyClass_Check(called)) {
3722 PyObject *obj = PyInstance_NewRaw(called, NULL);
3723
3724 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
3725
3726 if (unlikely(init_method == NULL)) {
3727 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
3728 Py_DECREF(obj);
3729 return NULL;
3730 }
3731
3732 Py_DECREF(obj);
3733
3734 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
3735 return NULL;
3736 }
3737
3738 bool is_compiled_function = false;
3739
3740 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
3741
3742 if (descr_get == NULL) {
3743 Py_INCREF(init_method);
3744 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
3745 is_compiled_function = true;
3746 } else if (descr_get != NULL) {
3747 PyObject *descr_method = descr_get(init_method, obj, called);
3748
3749 if (unlikely(descr_method == NULL)) {
3750 return NULL;
3751 }
3752
3753 init_method = descr_method;
3754 }
3755
3756 PyObject *result;
3757 if (is_compiled_function) {
3758 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
3759 args, 4);
3760 } else {
3761 result = CALL_FUNCTION_WITH_POS_ARGS4(tstate, init_method, pos_args);
3762 Py_DECREF(init_method);
3763 }
3764 if (unlikely(result == NULL)) {
3765 return NULL;
3766 }
3767
3768 Py_DECREF(result);
3769
3770 if (unlikely(result != Py_None)) {
3771 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3772 return NULL;
3773 }
3774
3775 CHECK_OBJECT_X(obj);
3776
3777 return obj;
3778#endif
3779#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
3780 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
3781 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3782
3783 if (likely(func != NULL)) {
3784 PyObject *result = func(called, args, 4, NULL);
3785
3786 CHECK_OBJECT_X(result);
3787
3788 return Nuitka_CheckFunctionResult(tstate, called, result);
3789 }
3790#endif
3791 }
3792
3793#if 0
3794 PRINT_NEW_LINE();
3795 PRINT_STRING("FALLBACK");
3796 PRINT_ITEM(called);
3797 PRINT_NEW_LINE();
3798#endif
3799
3800 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
3801
3802 CHECK_OBJECT_X(result);
3803
3804 return result;
3805}
3806PyObject *CALL_FUNCTION_WITH_ARGS5(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
3807 CHECK_OBJECT(called);
3808 CHECK_OBJECTS(args, 5);
3809
3810 if (Nuitka_Function_Check(called)) {
3811 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3812 return NULL;
3813 }
3814
3815 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
3816 PyObject *result;
3817
3818 if (function->m_args_simple && 5 == function->m_args_positional_count) {
3819 for (Py_ssize_t i = 0; i < 5; i++) {
3820 Py_INCREF(args[i]);
3821 }
3822 result = function->m_c_code(tstate, function, (PyObject **)args);
3823 } else if (function->m_args_simple && 5 + function->m_defaults_given == function->m_args_positional_count) {
3824 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3825
3826 memcpy(python_pars, args, 5 * sizeof(PyObject *));
3827 memcpy(python_pars + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
3828 function->m_defaults_given * sizeof(PyObject *));
3829
3830 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
3831 Py_INCREF(python_pars[i]);
3832 }
3833
3834 result = function->m_c_code(tstate, function, python_pars);
3835 } else {
3836 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 5);
3837 }
3838
3839 Py_LeaveRecursiveCall();
3840
3841 CHECK_OBJECT_X(result);
3842
3843 return result;
3844 } else if (Nuitka_Method_Check(called)) {
3845 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3846
3847 if (method->m_object == NULL) {
3848 PyObject *self = args[0];
3849
3850 int res = PyObject_IsInstance(self, method->m_class);
3851
3852 if (unlikely(res < 0)) {
3853 return NULL;
3854 } else if (unlikely(res == 0)) {
3855 PyErr_Format(PyExc_TypeError,
3856 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3857 "instance instead)",
3858 GET_CALLABLE_NAME((PyObject *)method->m_function),
3859 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3860 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3861
3862 return NULL;
3863 }
3864
3865 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 5);
3866
3867 CHECK_OBJECT_X(result);
3868
3869 return result;
3870 } else {
3871 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3872 return NULL;
3873 }
3874
3875 struct Nuitka_FunctionObject *function = method->m_function;
3876
3877 PyObject *result;
3878
3879 if (function->m_args_simple && 5 + 1 == function->m_args_positional_count) {
3880 PyObject *python_pars[5 + 1];
3881
3882 python_pars[0] = method->m_object;
3883 Py_INCREF(method->m_object);
3884
3885 for (Py_ssize_t i = 0; i < 5; i++) {
3886 python_pars[i + 1] = args[i];
3887 Py_INCREF(args[i]);
3888 }
3889 result = function->m_c_code(tstate, function, python_pars);
3890 } else if (function->m_args_simple &&
3891 5 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3892 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3893
3894 python_pars[0] = method->m_object;
3895 Py_INCREF(method->m_object);
3896
3897 memcpy(python_pars + 1, args, 5 * sizeof(PyObject *));
3898 memcpy(python_pars + 1 + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
3899 function->m_defaults_given * sizeof(PyObject *));
3900
3901 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3902 Py_INCREF(python_pars[i]);
3903 }
3904
3905 result = function->m_c_code(tstate, function, python_pars);
3906 } else {
3907 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 5);
3908 }
3909
3910 Py_LeaveRecursiveCall();
3911
3912 CHECK_OBJECT_X(result);
3913
3914 return result;
3915 }
3916#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3917 } else if (PyCFunction_CheckExact(called)) {
3918#if PYTHON_VERSION >= 0x380
3919#ifdef _NUITKA_FULL_COMPAT
3920 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3921 return NULL;
3922 }
3923#endif
3924
3925 int flags = PyCFunction_GET_FLAGS(called);
3926
3927 PyObject *result;
3928
3929 if (!(flags & METH_VARARGS)) {
3930 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3931
3932 assert(func != NULL);
3933 result = func(called, args, 5, NULL);
3934
3935 CHECK_OBJECT_X(result);
3936 } else {
3937 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3938 PyObject *self = PyCFunction_GET_SELF(called);
3939
3940 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3941
3942 if (flags & METH_KEYWORDS) {
3943 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3944 } else {
3945 result = (*method)(self, pos_args);
3946 }
3947
3948 Py_DECREF(pos_args);
3949 }
3950
3951#ifdef _NUITKA_FULL_COMPAT
3952 Py_LeaveRecursiveCall();
3953#endif
3954 CHECK_OBJECT_X(result);
3955
3956 return Nuitka_CheckFunctionResult(tstate, called, result);
3957#else
3958 // Try to be fast about wrapping the arguments.
3959 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3960
3961 if (unlikely(flags & METH_NOARGS)) {
3962 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (5 given)",
3963 ((PyCFunctionObject *)called)->m_ml->ml_name);
3964 return NULL;
3965 } else if (unlikely(flags & METH_O)) {
3966 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (5 given)",
3967 ((PyCFunctionObject *)called)->m_ml->ml_name);
3968 return NULL;
3969 } else if (flags & METH_VARARGS) {
3970 // Recursion guard is not strictly necessary, as we already have
3971 // one on our way to here.
3972#ifdef _NUITKA_FULL_COMPAT
3973 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3974 return NULL;
3975 }
3976#endif
3977 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3978 PyObject *self = PyCFunction_GET_SELF(called);
3979
3980 PyObject *result;
3981
3982#if PYTHON_VERSION < 0x360
3983 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3984 if (flags & METH_KEYWORDS) {
3985 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3986 } else {
3987 result = (*method)(self, pos_args);
3988 }
3989
3990 Py_DECREF(pos_args);
3991#else
3992 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3993 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3994 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3995 Py_DECREF(pos_args);
3996 } else if (flags == METH_FASTCALL) {
3997#if PYTHON_VERSION < 0x370
3998 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 5, NULL);
3999#else
4000 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4001 result = (*(_PyCFunctionFast)method)(self, &pos_args, 5);
4002 Py_DECREF(pos_args);
4003#endif
4004 } else {
4005 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4006 result = (*method)(self, pos_args);
4007 Py_DECREF(pos_args);
4008 }
4009#endif
4010
4011#ifdef _NUITKA_FULL_COMPAT
4012 Py_LeaveRecursiveCall();
4013#endif
4014
4015 CHECK_OBJECT_X(result);
4016
4017 return Nuitka_CheckFunctionResult(tstate, called, result);
4018 }
4019#endif
4020#endif
4021#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4022 } else if (PyFunction_Check(called)) {
4023#if PYTHON_VERSION < 0x3b0
4024 PyObject *result = callPythonFunction(called, args, 5);
4025#else
4026 PyObject *result = _PyFunction_Vectorcall(called, args, 5, NULL);
4027#endif
4028 CHECK_OBJECT_X(result);
4029
4030 return result;
4031#endif
4032#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4033 } else if (PyType_Check(called)) {
4034 PyTypeObject *type = Py_TYPE(called);
4035
4036 if (type->tp_call == PyType_Type.tp_call) {
4037 PyTypeObject *called_type = (PyTypeObject *)(called);
4038
4039 if (unlikely(called_type->tp_new == NULL)) {
4040 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4041 return NULL;
4042 }
4043
4044 PyObject *pos_args = NULL;
4045 PyObject *obj;
4046
4047 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4048 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4049 formatCannotInstantiateAbstractClass(tstate, called_type);
4050 return NULL;
4051 }
4052
4053 obj = called_type->tp_alloc(called_type, 0);
4054 CHECK_OBJECT(obj);
4055 } else {
4056 pos_args = MAKE_TUPLE(tstate, args, 5);
4057 obj = called_type->tp_new(called_type, pos_args, NULL);
4058 }
4059
4060 if (likely(obj != NULL)) {
4061 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4062 Py_DECREF(pos_args);
4063 return obj;
4064 }
4065
4066 // Work on produced type.
4067 type = Py_TYPE(obj);
4068
4069 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4070 if (type->tp_init == default_tp_init_wrapper) {
4071 Py_XDECREF(pos_args);
4072 pos_args = NULL;
4073
4074 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4075
4076 // Not really allowed, since we wouldn't have the default wrapper set.
4077 assert(init_method != NULL);
4078
4079 bool is_compiled_function = false;
4080 bool init_method_needs_release = false;
4081
4082 if (likely(init_method != NULL)) {
4083 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4084
4085 if (func == Nuitka_Function_Type.tp_descr_get) {
4086 is_compiled_function = true;
4087 } else if (func != NULL) {
4088 init_method = func(init_method, obj, (PyObject *)(type));
4089 init_method_needs_release = true;
4090 }
4091 }
4092
4093 if (unlikely(init_method == NULL)) {
4094 if (!HAS_ERROR_OCCURRED(tstate)) {
4095 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4096 const_str_plain___init__);
4097 }
4098
4099 return NULL;
4100 }
4101
4102 PyObject *result;
4103 if (is_compiled_function) {
4104 result = Nuitka_CallMethodFunctionPosArgs(
4105 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 5);
4106 } else {
4107 result = CALL_FUNCTION_WITH_ARGS5(tstate, init_method, args);
4108 if (init_method_needs_release) {
4109 Py_DECREF(init_method);
4110 }
4111 }
4112
4113 if (unlikely(result == NULL)) {
4114 Py_DECREF(obj);
4115 return NULL;
4116 }
4117
4118 Py_DECREF(result);
4119
4120 if (unlikely(result != Py_None)) {
4121 Py_DECREF(obj);
4122
4123 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4124 return NULL;
4125 }
4126 } else {
4127 if (pos_args == NULL) {
4128 pos_args = MAKE_TUPLE(tstate, args, 5);
4129 }
4130
4131 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4132 Py_DECREF(obj);
4133 Py_XDECREF(pos_args);
4134 return NULL;
4135 }
4136 }
4137 }
4138 }
4139
4140 Py_XDECREF(pos_args);
4141
4142 CHECK_OBJECT_X(obj);
4143
4144 return obj;
4145 }
4146#endif
4147#if PYTHON_VERSION < 0x300
4148 } else if (PyClass_Check(called)) {
4149 PyObject *obj = PyInstance_NewRaw(called, NULL);
4150
4151 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4152
4153 if (unlikely(init_method == NULL)) {
4154 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4155 Py_DECREF(obj);
4156 return NULL;
4157 }
4158
4159 Py_DECREF(obj);
4160
4161 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4162 return NULL;
4163 }
4164
4165 bool is_compiled_function = false;
4166
4167 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4168
4169 if (descr_get == NULL) {
4170 Py_INCREF(init_method);
4171 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
4172 is_compiled_function = true;
4173 } else if (descr_get != NULL) {
4174 PyObject *descr_method = descr_get(init_method, obj, called);
4175
4176 if (unlikely(descr_method == NULL)) {
4177 return NULL;
4178 }
4179
4180 init_method = descr_method;
4181 }
4182
4183 PyObject *result;
4184 if (is_compiled_function) {
4185 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
4186 args, 5);
4187 } else {
4188 result = CALL_FUNCTION_WITH_ARGS5(tstate, init_method, args);
4189 Py_DECREF(init_method);
4190 }
4191 if (unlikely(result == NULL)) {
4192 return NULL;
4193 }
4194
4195 Py_DECREF(result);
4196
4197 if (unlikely(result != Py_None)) {
4198 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4199 return NULL;
4200 }
4201
4202 CHECK_OBJECT_X(obj);
4203
4204 return obj;
4205#endif
4206#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
4207 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
4208 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4209
4210 if (likely(func != NULL)) {
4211 PyObject *result = func(called, args, 5, NULL);
4212
4213 CHECK_OBJECT_X(result);
4214
4215 return Nuitka_CheckFunctionResult(tstate, called, result);
4216 }
4217#endif
4218 }
4219
4220#if 0
4221 PRINT_NEW_LINE();
4222 PRINT_STRING("FALLBACK");
4223 PRINT_ITEM(called);
4224 PRINT_NEW_LINE();
4225#endif
4226
4227 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4228
4229 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
4230
4231 Py_DECREF(pos_args);
4232
4233 CHECK_OBJECT_X(result);
4234
4235 return result;
4236}
4237PyObject *CALL_FUNCTION_WITH_POS_ARGS5(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
4238 assert(PyTuple_CheckExact(pos_args));
4239 assert(PyTuple_GET_SIZE(pos_args) == 5);
4240 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
4241 CHECK_OBJECT(called);
4242 CHECK_OBJECTS(args, 5);
4243
4244 if (Nuitka_Function_Check(called)) {
4245 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4246 return NULL;
4247 }
4248
4249 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
4250 PyObject *result;
4251
4252 if (function->m_args_simple && 5 == function->m_args_positional_count) {
4253 for (Py_ssize_t i = 0; i < 5; i++) {
4254 Py_INCREF(args[i]);
4255 }
4256 result = function->m_c_code(tstate, function, (PyObject **)args);
4257 } else if (function->m_args_simple && 5 + function->m_defaults_given == function->m_args_positional_count) {
4258 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4259
4260 memcpy(python_pars, args, 5 * sizeof(PyObject *));
4261 memcpy(python_pars + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
4262 function->m_defaults_given * sizeof(PyObject *));
4263
4264 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
4265 Py_INCREF(python_pars[i]);
4266 }
4267
4268 result = function->m_c_code(tstate, function, python_pars);
4269 } else {
4270 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 5);
4271 }
4272
4273 Py_LeaveRecursiveCall();
4274
4275 CHECK_OBJECT_X(result);
4276
4277 return result;
4278 } else if (Nuitka_Method_Check(called)) {
4279 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
4280
4281 if (method->m_object == NULL) {
4282 PyObject *self = args[0];
4283
4284 int res = PyObject_IsInstance(self, method->m_class);
4285
4286 if (unlikely(res < 0)) {
4287 return NULL;
4288 } else if (unlikely(res == 0)) {
4289 PyErr_Format(PyExc_TypeError,
4290 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
4291 "instance instead)",
4292 GET_CALLABLE_NAME((PyObject *)method->m_function),
4293 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
4294 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
4295
4296 return NULL;
4297 }
4298
4299 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 5);
4300
4301 CHECK_OBJECT_X(result);
4302
4303 return result;
4304 } else {
4305 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4306 return NULL;
4307 }
4308
4309 struct Nuitka_FunctionObject *function = method->m_function;
4310
4311 PyObject *result;
4312
4313 if (function->m_args_simple && 5 + 1 == function->m_args_positional_count) {
4314 PyObject *python_pars[5 + 1];
4315
4316 python_pars[0] = method->m_object;
4317 Py_INCREF(method->m_object);
4318
4319 for (Py_ssize_t i = 0; i < 5; i++) {
4320 python_pars[i + 1] = args[i];
4321 Py_INCREF(args[i]);
4322 }
4323 result = function->m_c_code(tstate, function, python_pars);
4324 } else if (function->m_args_simple &&
4325 5 + 1 + function->m_defaults_given == function->m_args_positional_count) {
4326 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4327
4328 python_pars[0] = method->m_object;
4329 Py_INCREF(method->m_object);
4330
4331 memcpy(python_pars + 1, args, 5 * sizeof(PyObject *));
4332 memcpy(python_pars + 1 + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
4333 function->m_defaults_given * sizeof(PyObject *));
4334
4335 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
4336 Py_INCREF(python_pars[i]);
4337 }
4338
4339 result = function->m_c_code(tstate, function, python_pars);
4340 } else {
4341 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 5);
4342 }
4343
4344 Py_LeaveRecursiveCall();
4345
4346 CHECK_OBJECT_X(result);
4347
4348 return result;
4349 }
4350#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
4351 } else if (PyCFunction_CheckExact(called)) {
4352#if PYTHON_VERSION >= 0x380
4353#ifdef _NUITKA_FULL_COMPAT
4354 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4355 return NULL;
4356 }
4357#endif
4358
4359 int flags = PyCFunction_GET_FLAGS(called);
4360
4361 PyObject *result;
4362
4363 if (!(flags & METH_VARARGS)) {
4364 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4365
4366 assert(func != NULL);
4367 result = func(called, args, 5, NULL);
4368
4369 CHECK_OBJECT_X(result);
4370 } else {
4371 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4372 PyObject *self = PyCFunction_GET_SELF(called);
4373
4374 if (flags & METH_KEYWORDS) {
4375 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
4376 } else {
4377 result = (*method)(self, pos_args);
4378 }
4379 }
4380
4381#ifdef _NUITKA_FULL_COMPAT
4382 Py_LeaveRecursiveCall();
4383#endif
4384 CHECK_OBJECT_X(result);
4385
4386 return Nuitka_CheckFunctionResult(tstate, called, result);
4387#else
4388 // Try to be fast about wrapping the arguments.
4389 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
4390
4391 if (unlikely(flags & METH_NOARGS)) {
4392 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (5 given)",
4393 ((PyCFunctionObject *)called)->m_ml->ml_name);
4394 return NULL;
4395 } else if (unlikely(flags & METH_O)) {
4396 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (5 given)",
4397 ((PyCFunctionObject *)called)->m_ml->ml_name);
4398 return NULL;
4399 } else if (flags & METH_VARARGS) {
4400 // Recursion guard is not strictly necessary, as we already have
4401 // one on our way to here.
4402#ifdef _NUITKA_FULL_COMPAT
4403 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4404 return NULL;
4405 }
4406#endif
4407 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4408 PyObject *self = PyCFunction_GET_SELF(called);
4409
4410 PyObject *result;
4411
4412#if PYTHON_VERSION < 0x360
4413 if (flags & METH_KEYWORDS) {
4414 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4415 } else {
4416 result = (*method)(self, pos_args);
4417 }
4418
4419#else
4420 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
4421 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4422 } else if (flags == METH_FASTCALL) {
4423#if PYTHON_VERSION < 0x370
4424 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 5, NULL);
4425#else
4426 result = (*(_PyCFunctionFast)method)(self, &pos_args, 5);
4427#endif
4428 } else {
4429 result = (*method)(self, pos_args);
4430 }
4431#endif
4432
4433#ifdef _NUITKA_FULL_COMPAT
4434 Py_LeaveRecursiveCall();
4435#endif
4436
4437 CHECK_OBJECT_X(result);
4438
4439 return Nuitka_CheckFunctionResult(tstate, called, result);
4440 }
4441#endif
4442#endif
4443#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4444 } else if (PyFunction_Check(called)) {
4445#if PYTHON_VERSION < 0x3b0
4446 PyObject *result = callPythonFunction(called, args, 5);
4447#else
4448 PyObject *result = _PyFunction_Vectorcall(called, args, 5, NULL);
4449#endif
4450 CHECK_OBJECT_X(result);
4451
4452 return result;
4453#endif
4454#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4455 } else if (PyType_Check(called)) {
4456 PyTypeObject *type = Py_TYPE(called);
4457
4458 if (type->tp_call == PyType_Type.tp_call) {
4459 PyTypeObject *called_type = (PyTypeObject *)(called);
4460
4461 if (unlikely(called_type->tp_new == NULL)) {
4462 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4463 return NULL;
4464 }
4465
4466 PyObject *obj;
4467
4468 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4469 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4470 formatCannotInstantiateAbstractClass(tstate, called_type);
4471 return NULL;
4472 }
4473
4474 obj = called_type->tp_alloc(called_type, 0);
4475 CHECK_OBJECT(obj);
4476 } else {
4477 obj = called_type->tp_new(called_type, pos_args, NULL);
4478 }
4479
4480 if (likely(obj != NULL)) {
4481 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4482 return obj;
4483 }
4484
4485 // Work on produced type.
4486 type = Py_TYPE(obj);
4487
4488 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4489 if (type->tp_init == default_tp_init_wrapper) {
4490
4491 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4492
4493 // Not really allowed, since we wouldn't have the default wrapper set.
4494 assert(init_method != NULL);
4495
4496 bool is_compiled_function = false;
4497 bool init_method_needs_release = false;
4498
4499 if (likely(init_method != NULL)) {
4500 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4501
4502 if (func == Nuitka_Function_Type.tp_descr_get) {
4503 is_compiled_function = true;
4504 } else if (func != NULL) {
4505 init_method = func(init_method, obj, (PyObject *)(type));
4506 init_method_needs_release = true;
4507 }
4508 }
4509
4510 if (unlikely(init_method == NULL)) {
4511 if (!HAS_ERROR_OCCURRED(tstate)) {
4512 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4513 const_str_plain___init__);
4514 }
4515
4516 return NULL;
4517 }
4518
4519 PyObject *result;
4520 if (is_compiled_function) {
4521 result = Nuitka_CallMethodFunctionPosArgs(
4522 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 5);
4523 } else {
4524 result = CALL_FUNCTION_WITH_POS_ARGS5(tstate, init_method, pos_args);
4525 if (init_method_needs_release) {
4526 Py_DECREF(init_method);
4527 }
4528 }
4529
4530 if (unlikely(result == NULL)) {
4531 Py_DECREF(obj);
4532 return NULL;
4533 }
4534
4535 Py_DECREF(result);
4536
4537 if (unlikely(result != Py_None)) {
4538 Py_DECREF(obj);
4539
4540 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4541 return NULL;
4542 }
4543 } else {
4544
4545 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4546 Py_DECREF(obj);
4547 return NULL;
4548 }
4549 }
4550 }
4551 }
4552
4553 CHECK_OBJECT_X(obj);
4554
4555 return obj;
4556 }
4557#endif
4558#if PYTHON_VERSION < 0x300
4559 } else if (PyClass_Check(called)) {
4560 PyObject *obj = PyInstance_NewRaw(called, NULL);
4561
4562 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4563
4564 if (unlikely(init_method == NULL)) {
4565 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4566 Py_DECREF(obj);
4567 return NULL;
4568 }
4569
4570 Py_DECREF(obj);
4571
4572 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4573 return NULL;
4574 }
4575
4576 bool is_compiled_function = false;
4577
4578 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4579
4580 if (descr_get == NULL) {
4581 Py_INCREF(init_method);
4582 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
4583 is_compiled_function = true;
4584 } else if (descr_get != NULL) {
4585 PyObject *descr_method = descr_get(init_method, obj, called);
4586
4587 if (unlikely(descr_method == NULL)) {
4588 return NULL;
4589 }
4590
4591 init_method = descr_method;
4592 }
4593
4594 PyObject *result;
4595 if (is_compiled_function) {
4596 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
4597 args, 5);
4598 } else {
4599 result = CALL_FUNCTION_WITH_POS_ARGS5(tstate, init_method, pos_args);
4600 Py_DECREF(init_method);
4601 }
4602 if (unlikely(result == NULL)) {
4603 return NULL;
4604 }
4605
4606 Py_DECREF(result);
4607
4608 if (unlikely(result != Py_None)) {
4609 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4610 return NULL;
4611 }
4612
4613 CHECK_OBJECT_X(obj);
4614
4615 return obj;
4616#endif
4617#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
4618 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
4619 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4620
4621 if (likely(func != NULL)) {
4622 PyObject *result = func(called, args, 5, NULL);
4623
4624 CHECK_OBJECT_X(result);
4625
4626 return Nuitka_CheckFunctionResult(tstate, called, result);
4627 }
4628#endif
4629 }
4630
4631#if 0
4632 PRINT_NEW_LINE();
4633 PRINT_STRING("FALLBACK");
4634 PRINT_ITEM(called);
4635 PRINT_NEW_LINE();
4636#endif
4637
4638 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
4639
4640 CHECK_OBJECT_X(result);
4641
4642 return result;
4643}
4644PyObject *CALL_FUNCTION_WITH_ARGS6(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
4645 CHECK_OBJECT(called);
4646 CHECK_OBJECTS(args, 6);
4647
4648 if (Nuitka_Function_Check(called)) {
4649 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4650 return NULL;
4651 }
4652
4653 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
4654 PyObject *result;
4655
4656 if (function->m_args_simple && 6 == function->m_args_positional_count) {
4657 for (Py_ssize_t i = 0; i < 6; i++) {
4658 Py_INCREF(args[i]);
4659 }
4660 result = function->m_c_code(tstate, function, (PyObject **)args);
4661 } else if (function->m_args_simple && 6 + function->m_defaults_given == function->m_args_positional_count) {
4662 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4663
4664 memcpy(python_pars, args, 6 * sizeof(PyObject *));
4665 memcpy(python_pars + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
4666 function->m_defaults_given * sizeof(PyObject *));
4667
4668 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
4669 Py_INCREF(python_pars[i]);
4670 }
4671
4672 result = function->m_c_code(tstate, function, python_pars);
4673 } else {
4674 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 6);
4675 }
4676
4677 Py_LeaveRecursiveCall();
4678
4679 CHECK_OBJECT_X(result);
4680
4681 return result;
4682 } else if (Nuitka_Method_Check(called)) {
4683 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
4684
4685 if (method->m_object == NULL) {
4686 PyObject *self = args[0];
4687
4688 int res = PyObject_IsInstance(self, method->m_class);
4689
4690 if (unlikely(res < 0)) {
4691 return NULL;
4692 } else if (unlikely(res == 0)) {
4693 PyErr_Format(PyExc_TypeError,
4694 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
4695 "instance instead)",
4696 GET_CALLABLE_NAME((PyObject *)method->m_function),
4697 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
4698 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
4699
4700 return NULL;
4701 }
4702
4703 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 6);
4704
4705 CHECK_OBJECT_X(result);
4706
4707 return result;
4708 } else {
4709 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4710 return NULL;
4711 }
4712
4713 struct Nuitka_FunctionObject *function = method->m_function;
4714
4715 PyObject *result;
4716
4717 if (function->m_args_simple && 6 + 1 == function->m_args_positional_count) {
4718 PyObject *python_pars[6 + 1];
4719
4720 python_pars[0] = method->m_object;
4721 Py_INCREF(method->m_object);
4722
4723 for (Py_ssize_t i = 0; i < 6; i++) {
4724 python_pars[i + 1] = args[i];
4725 Py_INCREF(args[i]);
4726 }
4727 result = function->m_c_code(tstate, function, python_pars);
4728 } else if (function->m_args_simple &&
4729 6 + 1 + function->m_defaults_given == function->m_args_positional_count) {
4730 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4731
4732 python_pars[0] = method->m_object;
4733 Py_INCREF(method->m_object);
4734
4735 memcpy(python_pars + 1, args, 6 * sizeof(PyObject *));
4736 memcpy(python_pars + 1 + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
4737 function->m_defaults_given * sizeof(PyObject *));
4738
4739 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
4740 Py_INCREF(python_pars[i]);
4741 }
4742
4743 result = function->m_c_code(tstate, function, python_pars);
4744 } else {
4745 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 6);
4746 }
4747
4748 Py_LeaveRecursiveCall();
4749
4750 CHECK_OBJECT_X(result);
4751
4752 return result;
4753 }
4754#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
4755 } else if (PyCFunction_CheckExact(called)) {
4756#if PYTHON_VERSION >= 0x380
4757#ifdef _NUITKA_FULL_COMPAT
4758 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4759 return NULL;
4760 }
4761#endif
4762
4763 int flags = PyCFunction_GET_FLAGS(called);
4764
4765 PyObject *result;
4766
4767 if (!(flags & METH_VARARGS)) {
4768 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4769
4770 assert(func != NULL);
4771 result = func(called, args, 6, NULL);
4772
4773 CHECK_OBJECT_X(result);
4774 } else {
4775 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4776 PyObject *self = PyCFunction_GET_SELF(called);
4777
4778 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4779
4780 if (flags & METH_KEYWORDS) {
4781 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
4782 } else {
4783 result = (*method)(self, pos_args);
4784 }
4785
4786 Py_DECREF(pos_args);
4787 }
4788
4789#ifdef _NUITKA_FULL_COMPAT
4790 Py_LeaveRecursiveCall();
4791#endif
4792 CHECK_OBJECT_X(result);
4793
4794 return Nuitka_CheckFunctionResult(tstate, called, result);
4795#else
4796 // Try to be fast about wrapping the arguments.
4797 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
4798
4799 if (unlikely(flags & METH_NOARGS)) {
4800 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (6 given)",
4801 ((PyCFunctionObject *)called)->m_ml->ml_name);
4802 return NULL;
4803 } else if (unlikely(flags & METH_O)) {
4804 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (6 given)",
4805 ((PyCFunctionObject *)called)->m_ml->ml_name);
4806 return NULL;
4807 } else if (flags & METH_VARARGS) {
4808 // Recursion guard is not strictly necessary, as we already have
4809 // one on our way to here.
4810#ifdef _NUITKA_FULL_COMPAT
4811 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4812 return NULL;
4813 }
4814#endif
4815 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4816 PyObject *self = PyCFunction_GET_SELF(called);
4817
4818 PyObject *result;
4819
4820#if PYTHON_VERSION < 0x360
4821 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4822 if (flags & METH_KEYWORDS) {
4823 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4824 } else {
4825 result = (*method)(self, pos_args);
4826 }
4827
4828 Py_DECREF(pos_args);
4829#else
4830 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
4831 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4832 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4833 Py_DECREF(pos_args);
4834 } else if (flags == METH_FASTCALL) {
4835#if PYTHON_VERSION < 0x370
4836 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 6, NULL);
4837#else
4838 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4839 result = (*(_PyCFunctionFast)method)(self, &pos_args, 6);
4840 Py_DECREF(pos_args);
4841#endif
4842 } else {
4843 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4844 result = (*method)(self, pos_args);
4845 Py_DECREF(pos_args);
4846 }
4847#endif
4848
4849#ifdef _NUITKA_FULL_COMPAT
4850 Py_LeaveRecursiveCall();
4851#endif
4852
4853 CHECK_OBJECT_X(result);
4854
4855 return Nuitka_CheckFunctionResult(tstate, called, result);
4856 }
4857#endif
4858#endif
4859#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4860 } else if (PyFunction_Check(called)) {
4861#if PYTHON_VERSION < 0x3b0
4862 PyObject *result = callPythonFunction(called, args, 6);
4863#else
4864 PyObject *result = _PyFunction_Vectorcall(called, args, 6, NULL);
4865#endif
4866 CHECK_OBJECT_X(result);
4867
4868 return result;
4869#endif
4870#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4871 } else if (PyType_Check(called)) {
4872 PyTypeObject *type = Py_TYPE(called);
4873
4874 if (type->tp_call == PyType_Type.tp_call) {
4875 PyTypeObject *called_type = (PyTypeObject *)(called);
4876
4877 if (unlikely(called_type->tp_new == NULL)) {
4878 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4879 return NULL;
4880 }
4881
4882 PyObject *pos_args = NULL;
4883 PyObject *obj;
4884
4885 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4886 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4887 formatCannotInstantiateAbstractClass(tstate, called_type);
4888 return NULL;
4889 }
4890
4891 obj = called_type->tp_alloc(called_type, 0);
4892 CHECK_OBJECT(obj);
4893 } else {
4894 pos_args = MAKE_TUPLE(tstate, args, 6);
4895 obj = called_type->tp_new(called_type, pos_args, NULL);
4896 }
4897
4898 if (likely(obj != NULL)) {
4899 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4900 Py_DECREF(pos_args);
4901 return obj;
4902 }
4903
4904 // Work on produced type.
4905 type = Py_TYPE(obj);
4906
4907 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4908 if (type->tp_init == default_tp_init_wrapper) {
4909 Py_XDECREF(pos_args);
4910 pos_args = NULL;
4911
4912 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4913
4914 // Not really allowed, since we wouldn't have the default wrapper set.
4915 assert(init_method != NULL);
4916
4917 bool is_compiled_function = false;
4918 bool init_method_needs_release = false;
4919
4920 if (likely(init_method != NULL)) {
4921 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4922
4923 if (func == Nuitka_Function_Type.tp_descr_get) {
4924 is_compiled_function = true;
4925 } else if (func != NULL) {
4926 init_method = func(init_method, obj, (PyObject *)(type));
4927 init_method_needs_release = true;
4928 }
4929 }
4930
4931 if (unlikely(init_method == NULL)) {
4932 if (!HAS_ERROR_OCCURRED(tstate)) {
4933 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4934 const_str_plain___init__);
4935 }
4936
4937 return NULL;
4938 }
4939
4940 PyObject *result;
4941 if (is_compiled_function) {
4942 result = Nuitka_CallMethodFunctionPosArgs(
4943 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 6);
4944 } else {
4945 result = CALL_FUNCTION_WITH_ARGS6(tstate, init_method, args);
4946 if (init_method_needs_release) {
4947 Py_DECREF(init_method);
4948 }
4949 }
4950
4951 if (unlikely(result == NULL)) {
4952 Py_DECREF(obj);
4953 return NULL;
4954 }
4955
4956 Py_DECREF(result);
4957
4958 if (unlikely(result != Py_None)) {
4959 Py_DECREF(obj);
4960
4961 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4962 return NULL;
4963 }
4964 } else {
4965 if (pos_args == NULL) {
4966 pos_args = MAKE_TUPLE(tstate, args, 6);
4967 }
4968
4969 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4970 Py_DECREF(obj);
4971 Py_XDECREF(pos_args);
4972 return NULL;
4973 }
4974 }
4975 }
4976 }
4977
4978 Py_XDECREF(pos_args);
4979
4980 CHECK_OBJECT_X(obj);
4981
4982 return obj;
4983 }
4984#endif
4985#if PYTHON_VERSION < 0x300
4986 } else if (PyClass_Check(called)) {
4987 PyObject *obj = PyInstance_NewRaw(called, NULL);
4988
4989 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4990
4991 if (unlikely(init_method == NULL)) {
4992 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4993 Py_DECREF(obj);
4994 return NULL;
4995 }
4996
4997 Py_DECREF(obj);
4998
4999 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5000 return NULL;
5001 }
5002
5003 bool is_compiled_function = false;
5004
5005 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5006
5007 if (descr_get == NULL) {
5008 Py_INCREF(init_method);
5009 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5010 is_compiled_function = true;
5011 } else if (descr_get != NULL) {
5012 PyObject *descr_method = descr_get(init_method, obj, called);
5013
5014 if (unlikely(descr_method == NULL)) {
5015 return NULL;
5016 }
5017
5018 init_method = descr_method;
5019 }
5020
5021 PyObject *result;
5022 if (is_compiled_function) {
5023 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5024 args, 6);
5025 } else {
5026 result = CALL_FUNCTION_WITH_ARGS6(tstate, init_method, args);
5027 Py_DECREF(init_method);
5028 }
5029 if (unlikely(result == NULL)) {
5030 return NULL;
5031 }
5032
5033 Py_DECREF(result);
5034
5035 if (unlikely(result != Py_None)) {
5036 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5037 return NULL;
5038 }
5039
5040 CHECK_OBJECT_X(obj);
5041
5042 return obj;
5043#endif
5044#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5045 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5046 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5047
5048 if (likely(func != NULL)) {
5049 PyObject *result = func(called, args, 6, NULL);
5050
5051 CHECK_OBJECT_X(result);
5052
5053 return Nuitka_CheckFunctionResult(tstate, called, result);
5054 }
5055#endif
5056 }
5057
5058#if 0
5059 PRINT_NEW_LINE();
5060 PRINT_STRING("FALLBACK");
5061 PRINT_ITEM(called);
5062 PRINT_NEW_LINE();
5063#endif
5064
5065 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
5066
5067 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5068
5069 Py_DECREF(pos_args);
5070
5071 CHECK_OBJECT_X(result);
5072
5073 return result;
5074}
5075PyObject *CALL_FUNCTION_WITH_POS_ARGS6(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
5076 assert(PyTuple_CheckExact(pos_args));
5077 assert(PyTuple_GET_SIZE(pos_args) == 6);
5078 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
5079 CHECK_OBJECT(called);
5080 CHECK_OBJECTS(args, 6);
5081
5082 if (Nuitka_Function_Check(called)) {
5083 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5084 return NULL;
5085 }
5086
5087 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5088 PyObject *result;
5089
5090 if (function->m_args_simple && 6 == function->m_args_positional_count) {
5091 for (Py_ssize_t i = 0; i < 6; i++) {
5092 Py_INCREF(args[i]);
5093 }
5094 result = function->m_c_code(tstate, function, (PyObject **)args);
5095 } else if (function->m_args_simple && 6 + function->m_defaults_given == function->m_args_positional_count) {
5096 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5097
5098 memcpy(python_pars, args, 6 * sizeof(PyObject *));
5099 memcpy(python_pars + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
5100 function->m_defaults_given * sizeof(PyObject *));
5101
5102 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5103 Py_INCREF(python_pars[i]);
5104 }
5105
5106 result = function->m_c_code(tstate, function, python_pars);
5107 } else {
5108 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 6);
5109 }
5110
5111 Py_LeaveRecursiveCall();
5112
5113 CHECK_OBJECT_X(result);
5114
5115 return result;
5116 } else if (Nuitka_Method_Check(called)) {
5117 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5118
5119 if (method->m_object == NULL) {
5120 PyObject *self = args[0];
5121
5122 int res = PyObject_IsInstance(self, method->m_class);
5123
5124 if (unlikely(res < 0)) {
5125 return NULL;
5126 } else if (unlikely(res == 0)) {
5127 PyErr_Format(PyExc_TypeError,
5128 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5129 "instance instead)",
5130 GET_CALLABLE_NAME((PyObject *)method->m_function),
5131 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5132 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5133
5134 return NULL;
5135 }
5136
5137 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 6);
5138
5139 CHECK_OBJECT_X(result);
5140
5141 return result;
5142 } else {
5143 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5144 return NULL;
5145 }
5146
5147 struct Nuitka_FunctionObject *function = method->m_function;
5148
5149 PyObject *result;
5150
5151 if (function->m_args_simple && 6 + 1 == function->m_args_positional_count) {
5152 PyObject *python_pars[6 + 1];
5153
5154 python_pars[0] = method->m_object;
5155 Py_INCREF(method->m_object);
5156
5157 for (Py_ssize_t i = 0; i < 6; i++) {
5158 python_pars[i + 1] = args[i];
5159 Py_INCREF(args[i]);
5160 }
5161 result = function->m_c_code(tstate, function, python_pars);
5162 } else if (function->m_args_simple &&
5163 6 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5164 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5165
5166 python_pars[0] = method->m_object;
5167 Py_INCREF(method->m_object);
5168
5169 memcpy(python_pars + 1, args, 6 * sizeof(PyObject *));
5170 memcpy(python_pars + 1 + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
5171 function->m_defaults_given * sizeof(PyObject *));
5172
5173 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
5174 Py_INCREF(python_pars[i]);
5175 }
5176
5177 result = function->m_c_code(tstate, function, python_pars);
5178 } else {
5179 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 6);
5180 }
5181
5182 Py_LeaveRecursiveCall();
5183
5184 CHECK_OBJECT_X(result);
5185
5186 return result;
5187 }
5188#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
5189 } else if (PyCFunction_CheckExact(called)) {
5190#if PYTHON_VERSION >= 0x380
5191#ifdef _NUITKA_FULL_COMPAT
5192 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5193 return NULL;
5194 }
5195#endif
5196
5197 int flags = PyCFunction_GET_FLAGS(called);
5198
5199 PyObject *result;
5200
5201 if (!(flags & METH_VARARGS)) {
5202 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5203
5204 assert(func != NULL);
5205 result = func(called, args, 6, NULL);
5206
5207 CHECK_OBJECT_X(result);
5208 } else {
5209 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5210 PyObject *self = PyCFunction_GET_SELF(called);
5211
5212 if (flags & METH_KEYWORDS) {
5213 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
5214 } else {
5215 result = (*method)(self, pos_args);
5216 }
5217 }
5218
5219#ifdef _NUITKA_FULL_COMPAT
5220 Py_LeaveRecursiveCall();
5221#endif
5222 CHECK_OBJECT_X(result);
5223
5224 return Nuitka_CheckFunctionResult(tstate, called, result);
5225#else
5226 // Try to be fast about wrapping the arguments.
5227 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
5228
5229 if (unlikely(flags & METH_NOARGS)) {
5230 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (6 given)",
5231 ((PyCFunctionObject *)called)->m_ml->ml_name);
5232 return NULL;
5233 } else if (unlikely(flags & METH_O)) {
5234 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (6 given)",
5235 ((PyCFunctionObject *)called)->m_ml->ml_name);
5236 return NULL;
5237 } else if (flags & METH_VARARGS) {
5238 // Recursion guard is not strictly necessary, as we already have
5239 // one on our way to here.
5240#ifdef _NUITKA_FULL_COMPAT
5241 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5242 return NULL;
5243 }
5244#endif
5245 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5246 PyObject *self = PyCFunction_GET_SELF(called);
5247
5248 PyObject *result;
5249
5250#if PYTHON_VERSION < 0x360
5251 if (flags & METH_KEYWORDS) {
5252 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5253 } else {
5254 result = (*method)(self, pos_args);
5255 }
5256
5257#else
5258 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
5259 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5260 } else if (flags == METH_FASTCALL) {
5261#if PYTHON_VERSION < 0x370
5262 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 6, NULL);
5263#else
5264 result = (*(_PyCFunctionFast)method)(self, &pos_args, 6);
5265#endif
5266 } else {
5267 result = (*method)(self, pos_args);
5268 }
5269#endif
5270
5271#ifdef _NUITKA_FULL_COMPAT
5272 Py_LeaveRecursiveCall();
5273#endif
5274
5275 CHECK_OBJECT_X(result);
5276
5277 return Nuitka_CheckFunctionResult(tstate, called, result);
5278 }
5279#endif
5280#endif
5281#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
5282 } else if (PyFunction_Check(called)) {
5283#if PYTHON_VERSION < 0x3b0
5284 PyObject *result = callPythonFunction(called, args, 6);
5285#else
5286 PyObject *result = _PyFunction_Vectorcall(called, args, 6, NULL);
5287#endif
5288 CHECK_OBJECT_X(result);
5289
5290 return result;
5291#endif
5292#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
5293 } else if (PyType_Check(called)) {
5294 PyTypeObject *type = Py_TYPE(called);
5295
5296 if (type->tp_call == PyType_Type.tp_call) {
5297 PyTypeObject *called_type = (PyTypeObject *)(called);
5298
5299 if (unlikely(called_type->tp_new == NULL)) {
5300 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
5301 return NULL;
5302 }
5303
5304 PyObject *obj;
5305
5306 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
5307 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
5308 formatCannotInstantiateAbstractClass(tstate, called_type);
5309 return NULL;
5310 }
5311
5312 obj = called_type->tp_alloc(called_type, 0);
5313 CHECK_OBJECT(obj);
5314 } else {
5315 obj = called_type->tp_new(called_type, pos_args, NULL);
5316 }
5317
5318 if (likely(obj != NULL)) {
5319 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
5320 return obj;
5321 }
5322
5323 // Work on produced type.
5324 type = Py_TYPE(obj);
5325
5326 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
5327 if (type->tp_init == default_tp_init_wrapper) {
5328
5329 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
5330
5331 // Not really allowed, since we wouldn't have the default wrapper set.
5332 assert(init_method != NULL);
5333
5334 bool is_compiled_function = false;
5335 bool init_method_needs_release = false;
5336
5337 if (likely(init_method != NULL)) {
5338 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
5339
5340 if (func == Nuitka_Function_Type.tp_descr_get) {
5341 is_compiled_function = true;
5342 } else if (func != NULL) {
5343 init_method = func(init_method, obj, (PyObject *)(type));
5344 init_method_needs_release = true;
5345 }
5346 }
5347
5348 if (unlikely(init_method == NULL)) {
5349 if (!HAS_ERROR_OCCURRED(tstate)) {
5350 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
5351 const_str_plain___init__);
5352 }
5353
5354 return NULL;
5355 }
5356
5357 PyObject *result;
5358 if (is_compiled_function) {
5359 result = Nuitka_CallMethodFunctionPosArgs(
5360 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 6);
5361 } else {
5362 result = CALL_FUNCTION_WITH_POS_ARGS6(tstate, init_method, pos_args);
5363 if (init_method_needs_release) {
5364 Py_DECREF(init_method);
5365 }
5366 }
5367
5368 if (unlikely(result == NULL)) {
5369 Py_DECREF(obj);
5370 return NULL;
5371 }
5372
5373 Py_DECREF(result);
5374
5375 if (unlikely(result != Py_None)) {
5376 Py_DECREF(obj);
5377
5378 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5379 return NULL;
5380 }
5381 } else {
5382
5383 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
5384 Py_DECREF(obj);
5385 return NULL;
5386 }
5387 }
5388 }
5389 }
5390
5391 CHECK_OBJECT_X(obj);
5392
5393 return obj;
5394 }
5395#endif
5396#if PYTHON_VERSION < 0x300
5397 } else if (PyClass_Check(called)) {
5398 PyObject *obj = PyInstance_NewRaw(called, NULL);
5399
5400 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
5401
5402 if (unlikely(init_method == NULL)) {
5403 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
5404 Py_DECREF(obj);
5405 return NULL;
5406 }
5407
5408 Py_DECREF(obj);
5409
5410 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5411 return NULL;
5412 }
5413
5414 bool is_compiled_function = false;
5415
5416 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5417
5418 if (descr_get == NULL) {
5419 Py_INCREF(init_method);
5420 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5421 is_compiled_function = true;
5422 } else if (descr_get != NULL) {
5423 PyObject *descr_method = descr_get(init_method, obj, called);
5424
5425 if (unlikely(descr_method == NULL)) {
5426 return NULL;
5427 }
5428
5429 init_method = descr_method;
5430 }
5431
5432 PyObject *result;
5433 if (is_compiled_function) {
5434 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5435 args, 6);
5436 } else {
5437 result = CALL_FUNCTION_WITH_POS_ARGS6(tstate, init_method, pos_args);
5438 Py_DECREF(init_method);
5439 }
5440 if (unlikely(result == NULL)) {
5441 return NULL;
5442 }
5443
5444 Py_DECREF(result);
5445
5446 if (unlikely(result != Py_None)) {
5447 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5448 return NULL;
5449 }
5450
5451 CHECK_OBJECT_X(obj);
5452
5453 return obj;
5454#endif
5455#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5456 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5457 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5458
5459 if (likely(func != NULL)) {
5460 PyObject *result = func(called, args, 6, NULL);
5461
5462 CHECK_OBJECT_X(result);
5463
5464 return Nuitka_CheckFunctionResult(tstate, called, result);
5465 }
5466#endif
5467 }
5468
5469#if 0
5470 PRINT_NEW_LINE();
5471 PRINT_STRING("FALLBACK");
5472 PRINT_ITEM(called);
5473 PRINT_NEW_LINE();
5474#endif
5475
5476 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5477
5478 CHECK_OBJECT_X(result);
5479
5480 return result;
5481}
5482PyObject *CALL_FUNCTION_WITH_ARGS7(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
5483 CHECK_OBJECT(called);
5484 CHECK_OBJECTS(args, 7);
5485
5486 if (Nuitka_Function_Check(called)) {
5487 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5488 return NULL;
5489 }
5490
5491 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5492 PyObject *result;
5493
5494 if (function->m_args_simple && 7 == function->m_args_positional_count) {
5495 for (Py_ssize_t i = 0; i < 7; i++) {
5496 Py_INCREF(args[i]);
5497 }
5498 result = function->m_c_code(tstate, function, (PyObject **)args);
5499 } else if (function->m_args_simple && 7 + function->m_defaults_given == function->m_args_positional_count) {
5500 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5501
5502 memcpy(python_pars, args, 7 * sizeof(PyObject *));
5503 memcpy(python_pars + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5504 function->m_defaults_given * sizeof(PyObject *));
5505
5506 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5507 Py_INCREF(python_pars[i]);
5508 }
5509
5510 result = function->m_c_code(tstate, function, python_pars);
5511 } else {
5512 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 7);
5513 }
5514
5515 Py_LeaveRecursiveCall();
5516
5517 CHECK_OBJECT_X(result);
5518
5519 return result;
5520 } else if (Nuitka_Method_Check(called)) {
5521 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5522
5523 if (method->m_object == NULL) {
5524 PyObject *self = args[0];
5525
5526 int res = PyObject_IsInstance(self, method->m_class);
5527
5528 if (unlikely(res < 0)) {
5529 return NULL;
5530 } else if (unlikely(res == 0)) {
5531 PyErr_Format(PyExc_TypeError,
5532 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5533 "instance instead)",
5534 GET_CALLABLE_NAME((PyObject *)method->m_function),
5535 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5536 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5537
5538 return NULL;
5539 }
5540
5541 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 7);
5542
5543 CHECK_OBJECT_X(result);
5544
5545 return result;
5546 } else {
5547 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5548 return NULL;
5549 }
5550
5551 struct Nuitka_FunctionObject *function = method->m_function;
5552
5553 PyObject *result;
5554
5555 if (function->m_args_simple && 7 + 1 == function->m_args_positional_count) {
5556 PyObject *python_pars[7 + 1];
5557
5558 python_pars[0] = method->m_object;
5559 Py_INCREF(method->m_object);
5560
5561 for (Py_ssize_t i = 0; i < 7; i++) {
5562 python_pars[i + 1] = args[i];
5563 Py_INCREF(args[i]);
5564 }
5565 result = function->m_c_code(tstate, function, python_pars);
5566 } else if (function->m_args_simple &&
5567 7 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5568 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5569
5570 python_pars[0] = method->m_object;
5571 Py_INCREF(method->m_object);
5572
5573 memcpy(python_pars + 1, args, 7 * sizeof(PyObject *));
5574 memcpy(python_pars + 1 + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5575 function->m_defaults_given * sizeof(PyObject *));
5576
5577 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
5578 Py_INCREF(python_pars[i]);
5579 }
5580
5581 result = function->m_c_code(tstate, function, python_pars);
5582 } else {
5583 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 7);
5584 }
5585
5586 Py_LeaveRecursiveCall();
5587
5588 CHECK_OBJECT_X(result);
5589
5590 return result;
5591 }
5592#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
5593 } else if (PyCFunction_CheckExact(called)) {
5594#if PYTHON_VERSION >= 0x380
5595#ifdef _NUITKA_FULL_COMPAT
5596 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5597 return NULL;
5598 }
5599#endif
5600
5601 int flags = PyCFunction_GET_FLAGS(called);
5602
5603 PyObject *result;
5604
5605 if (!(flags & METH_VARARGS)) {
5606 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5607
5608 assert(func != NULL);
5609 result = func(called, args, 7, NULL);
5610
5611 CHECK_OBJECT_X(result);
5612 } else {
5613 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5614 PyObject *self = PyCFunction_GET_SELF(called);
5615
5616 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5617
5618 if (flags & METH_KEYWORDS) {
5619 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
5620 } else {
5621 result = (*method)(self, pos_args);
5622 }
5623
5624 Py_DECREF(pos_args);
5625 }
5626
5627#ifdef _NUITKA_FULL_COMPAT
5628 Py_LeaveRecursiveCall();
5629#endif
5630 CHECK_OBJECT_X(result);
5631
5632 return Nuitka_CheckFunctionResult(tstate, called, result);
5633#else
5634 // Try to be fast about wrapping the arguments.
5635 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
5636
5637 if (unlikely(flags & METH_NOARGS)) {
5638 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (7 given)",
5639 ((PyCFunctionObject *)called)->m_ml->ml_name);
5640 return NULL;
5641 } else if (unlikely(flags & METH_O)) {
5642 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (7 given)",
5643 ((PyCFunctionObject *)called)->m_ml->ml_name);
5644 return NULL;
5645 } else if (flags & METH_VARARGS) {
5646 // Recursion guard is not strictly necessary, as we already have
5647 // one on our way to here.
5648#ifdef _NUITKA_FULL_COMPAT
5649 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5650 return NULL;
5651 }
5652#endif
5653 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5654 PyObject *self = PyCFunction_GET_SELF(called);
5655
5656 PyObject *result;
5657
5658#if PYTHON_VERSION < 0x360
5659 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5660 if (flags & METH_KEYWORDS) {
5661 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5662 } else {
5663 result = (*method)(self, pos_args);
5664 }
5665
5666 Py_DECREF(pos_args);
5667#else
5668 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
5669 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5670 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5671 Py_DECREF(pos_args);
5672 } else if (flags == METH_FASTCALL) {
5673#if PYTHON_VERSION < 0x370
5674 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 7, NULL);
5675#else
5676 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5677 result = (*(_PyCFunctionFast)method)(self, &pos_args, 7);
5678 Py_DECREF(pos_args);
5679#endif
5680 } else {
5681 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5682 result = (*method)(self, pos_args);
5683 Py_DECREF(pos_args);
5684 }
5685#endif
5686
5687#ifdef _NUITKA_FULL_COMPAT
5688 Py_LeaveRecursiveCall();
5689#endif
5690
5691 CHECK_OBJECT_X(result);
5692
5693 return Nuitka_CheckFunctionResult(tstate, called, result);
5694 }
5695#endif
5696#endif
5697#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
5698 } else if (PyFunction_Check(called)) {
5699#if PYTHON_VERSION < 0x3b0
5700 PyObject *result = callPythonFunction(called, args, 7);
5701#else
5702 PyObject *result = _PyFunction_Vectorcall(called, args, 7, NULL);
5703#endif
5704 CHECK_OBJECT_X(result);
5705
5706 return result;
5707#endif
5708#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
5709 } else if (PyType_Check(called)) {
5710 PyTypeObject *type = Py_TYPE(called);
5711
5712 if (type->tp_call == PyType_Type.tp_call) {
5713 PyTypeObject *called_type = (PyTypeObject *)(called);
5714
5715 if (unlikely(called_type->tp_new == NULL)) {
5716 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
5717 return NULL;
5718 }
5719
5720 PyObject *pos_args = NULL;
5721 PyObject *obj;
5722
5723 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
5724 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
5725 formatCannotInstantiateAbstractClass(tstate, called_type);
5726 return NULL;
5727 }
5728
5729 obj = called_type->tp_alloc(called_type, 0);
5730 CHECK_OBJECT(obj);
5731 } else {
5732 pos_args = MAKE_TUPLE(tstate, args, 7);
5733 obj = called_type->tp_new(called_type, pos_args, NULL);
5734 }
5735
5736 if (likely(obj != NULL)) {
5737 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
5738 Py_DECREF(pos_args);
5739 return obj;
5740 }
5741
5742 // Work on produced type.
5743 type = Py_TYPE(obj);
5744
5745 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
5746 if (type->tp_init == default_tp_init_wrapper) {
5747 Py_XDECREF(pos_args);
5748 pos_args = NULL;
5749
5750 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
5751
5752 // Not really allowed, since we wouldn't have the default wrapper set.
5753 assert(init_method != NULL);
5754
5755 bool is_compiled_function = false;
5756 bool init_method_needs_release = false;
5757
5758 if (likely(init_method != NULL)) {
5759 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
5760
5761 if (func == Nuitka_Function_Type.tp_descr_get) {
5762 is_compiled_function = true;
5763 } else if (func != NULL) {
5764 init_method = func(init_method, obj, (PyObject *)(type));
5765 init_method_needs_release = true;
5766 }
5767 }
5768
5769 if (unlikely(init_method == NULL)) {
5770 if (!HAS_ERROR_OCCURRED(tstate)) {
5771 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
5772 const_str_plain___init__);
5773 }
5774
5775 return NULL;
5776 }
5777
5778 PyObject *result;
5779 if (is_compiled_function) {
5780 result = Nuitka_CallMethodFunctionPosArgs(
5781 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 7);
5782 } else {
5783 result = CALL_FUNCTION_WITH_ARGS7(tstate, init_method, args);
5784 if (init_method_needs_release) {
5785 Py_DECREF(init_method);
5786 }
5787 }
5788
5789 if (unlikely(result == NULL)) {
5790 Py_DECREF(obj);
5791 return NULL;
5792 }
5793
5794 Py_DECREF(result);
5795
5796 if (unlikely(result != Py_None)) {
5797 Py_DECREF(obj);
5798
5799 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5800 return NULL;
5801 }
5802 } else {
5803 if (pos_args == NULL) {
5804 pos_args = MAKE_TUPLE(tstate, args, 7);
5805 }
5806
5807 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
5808 Py_DECREF(obj);
5809 Py_XDECREF(pos_args);
5810 return NULL;
5811 }
5812 }
5813 }
5814 }
5815
5816 Py_XDECREF(pos_args);
5817
5818 CHECK_OBJECT_X(obj);
5819
5820 return obj;
5821 }
5822#endif
5823#if PYTHON_VERSION < 0x300
5824 } else if (PyClass_Check(called)) {
5825 PyObject *obj = PyInstance_NewRaw(called, NULL);
5826
5827 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
5828
5829 if (unlikely(init_method == NULL)) {
5830 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
5831 Py_DECREF(obj);
5832 return NULL;
5833 }
5834
5835 Py_DECREF(obj);
5836
5837 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5838 return NULL;
5839 }
5840
5841 bool is_compiled_function = false;
5842
5843 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5844
5845 if (descr_get == NULL) {
5846 Py_INCREF(init_method);
5847 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5848 is_compiled_function = true;
5849 } else if (descr_get != NULL) {
5850 PyObject *descr_method = descr_get(init_method, obj, called);
5851
5852 if (unlikely(descr_method == NULL)) {
5853 return NULL;
5854 }
5855
5856 init_method = descr_method;
5857 }
5858
5859 PyObject *result;
5860 if (is_compiled_function) {
5861 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5862 args, 7);
5863 } else {
5864 result = CALL_FUNCTION_WITH_ARGS7(tstate, init_method, args);
5865 Py_DECREF(init_method);
5866 }
5867 if (unlikely(result == NULL)) {
5868 return NULL;
5869 }
5870
5871 Py_DECREF(result);
5872
5873 if (unlikely(result != Py_None)) {
5874 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5875 return NULL;
5876 }
5877
5878 CHECK_OBJECT_X(obj);
5879
5880 return obj;
5881#endif
5882#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5883 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5884 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5885
5886 if (likely(func != NULL)) {
5887 PyObject *result = func(called, args, 7, NULL);
5888
5889 CHECK_OBJECT_X(result);
5890
5891 return Nuitka_CheckFunctionResult(tstate, called, result);
5892 }
5893#endif
5894 }
5895
5896#if 0
5897 PRINT_NEW_LINE();
5898 PRINT_STRING("FALLBACK");
5899 PRINT_ITEM(called);
5900 PRINT_NEW_LINE();
5901#endif
5902
5903 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5904
5905 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5906
5907 Py_DECREF(pos_args);
5908
5909 CHECK_OBJECT_X(result);
5910
5911 return result;
5912}
5913PyObject *CALL_FUNCTION_WITH_POS_ARGS7(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
5914 assert(PyTuple_CheckExact(pos_args));
5915 assert(PyTuple_GET_SIZE(pos_args) == 7);
5916 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
5917 CHECK_OBJECT(called);
5918 CHECK_OBJECTS(args, 7);
5919
5920 if (Nuitka_Function_Check(called)) {
5921 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5922 return NULL;
5923 }
5924
5925 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5926 PyObject *result;
5927
5928 if (function->m_args_simple && 7 == function->m_args_positional_count) {
5929 for (Py_ssize_t i = 0; i < 7; i++) {
5930 Py_INCREF(args[i]);
5931 }
5932 result = function->m_c_code(tstate, function, (PyObject **)args);
5933 } else if (function->m_args_simple && 7 + function->m_defaults_given == function->m_args_positional_count) {
5934 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5935
5936 memcpy(python_pars, args, 7 * sizeof(PyObject *));
5937 memcpy(python_pars + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5938 function->m_defaults_given * sizeof(PyObject *));
5939
5940 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5941 Py_INCREF(python_pars[i]);
5942 }
5943
5944 result = function->m_c_code(tstate, function, python_pars);
5945 } else {
5946 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 7);
5947 }
5948
5949 Py_LeaveRecursiveCall();
5950
5951 CHECK_OBJECT_X(result);
5952
5953 return result;
5954 } else if (Nuitka_Method_Check(called)) {
5955 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5956
5957 if (method->m_object == NULL) {
5958 PyObject *self = args[0];
5959
5960 int res = PyObject_IsInstance(self, method->m_class);
5961
5962 if (unlikely(res < 0)) {
5963 return NULL;
5964 } else if (unlikely(res == 0)) {
5965 PyErr_Format(PyExc_TypeError,
5966 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5967 "instance instead)",
5968 GET_CALLABLE_NAME((PyObject *)method->m_function),
5969 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5970 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5971
5972 return NULL;
5973 }
5974
5975 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 7);
5976
5977 CHECK_OBJECT_X(result);
5978
5979 return result;
5980 } else {
5981 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5982 return NULL;
5983 }
5984
5985 struct Nuitka_FunctionObject *function = method->m_function;
5986
5987 PyObject *result;
5988
5989 if (function->m_args_simple && 7 + 1 == function->m_args_positional_count) {
5990 PyObject *python_pars[7 + 1];
5991
5992 python_pars[0] = method->m_object;
5993 Py_INCREF(method->m_object);
5994
5995 for (Py_ssize_t i = 0; i < 7; i++) {
5996 python_pars[i + 1] = args[i];
5997 Py_INCREF(args[i]);
5998 }
5999 result = function->m_c_code(tstate, function, python_pars);
6000 } else if (function->m_args_simple &&
6001 7 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6002 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6003
6004 python_pars[0] = method->m_object;
6005 Py_INCREF(method->m_object);
6006
6007 memcpy(python_pars + 1, args, 7 * sizeof(PyObject *));
6008 memcpy(python_pars + 1 + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
6009 function->m_defaults_given * sizeof(PyObject *));
6010
6011 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6012 Py_INCREF(python_pars[i]);
6013 }
6014
6015 result = function->m_c_code(tstate, function, python_pars);
6016 } else {
6017 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 7);
6018 }
6019
6020 Py_LeaveRecursiveCall();
6021
6022 CHECK_OBJECT_X(result);
6023
6024 return result;
6025 }
6026#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6027 } else if (PyCFunction_CheckExact(called)) {
6028#if PYTHON_VERSION >= 0x380
6029#ifdef _NUITKA_FULL_COMPAT
6030 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6031 return NULL;
6032 }
6033#endif
6034
6035 int flags = PyCFunction_GET_FLAGS(called);
6036
6037 PyObject *result;
6038
6039 if (!(flags & METH_VARARGS)) {
6040 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6041
6042 assert(func != NULL);
6043 result = func(called, args, 7, NULL);
6044
6045 CHECK_OBJECT_X(result);
6046 } else {
6047 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6048 PyObject *self = PyCFunction_GET_SELF(called);
6049
6050 if (flags & METH_KEYWORDS) {
6051 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6052 } else {
6053 result = (*method)(self, pos_args);
6054 }
6055 }
6056
6057#ifdef _NUITKA_FULL_COMPAT
6058 Py_LeaveRecursiveCall();
6059#endif
6060 CHECK_OBJECT_X(result);
6061
6062 return Nuitka_CheckFunctionResult(tstate, called, result);
6063#else
6064 // Try to be fast about wrapping the arguments.
6065 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6066
6067 if (unlikely(flags & METH_NOARGS)) {
6068 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (7 given)",
6069 ((PyCFunctionObject *)called)->m_ml->ml_name);
6070 return NULL;
6071 } else if (unlikely(flags & METH_O)) {
6072 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (7 given)",
6073 ((PyCFunctionObject *)called)->m_ml->ml_name);
6074 return NULL;
6075 } else if (flags & METH_VARARGS) {
6076 // Recursion guard is not strictly necessary, as we already have
6077 // one on our way to here.
6078#ifdef _NUITKA_FULL_COMPAT
6079 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6080 return NULL;
6081 }
6082#endif
6083 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6084 PyObject *self = PyCFunction_GET_SELF(called);
6085
6086 PyObject *result;
6087
6088#if PYTHON_VERSION < 0x360
6089 if (flags & METH_KEYWORDS) {
6090 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6091 } else {
6092 result = (*method)(self, pos_args);
6093 }
6094
6095#else
6096 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6097 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6098 } else if (flags == METH_FASTCALL) {
6099#if PYTHON_VERSION < 0x370
6100 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 7, NULL);
6101#else
6102 result = (*(_PyCFunctionFast)method)(self, &pos_args, 7);
6103#endif
6104 } else {
6105 result = (*method)(self, pos_args);
6106 }
6107#endif
6108
6109#ifdef _NUITKA_FULL_COMPAT
6110 Py_LeaveRecursiveCall();
6111#endif
6112
6113 CHECK_OBJECT_X(result);
6114
6115 return Nuitka_CheckFunctionResult(tstate, called, result);
6116 }
6117#endif
6118#endif
6119#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6120 } else if (PyFunction_Check(called)) {
6121#if PYTHON_VERSION < 0x3b0
6122 PyObject *result = callPythonFunction(called, args, 7);
6123#else
6124 PyObject *result = _PyFunction_Vectorcall(called, args, 7, NULL);
6125#endif
6126 CHECK_OBJECT_X(result);
6127
6128 return result;
6129#endif
6130#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6131 } else if (PyType_Check(called)) {
6132 PyTypeObject *type = Py_TYPE(called);
6133
6134 if (type->tp_call == PyType_Type.tp_call) {
6135 PyTypeObject *called_type = (PyTypeObject *)(called);
6136
6137 if (unlikely(called_type->tp_new == NULL)) {
6138 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6139 return NULL;
6140 }
6141
6142 PyObject *obj;
6143
6144 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6145 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6146 formatCannotInstantiateAbstractClass(tstate, called_type);
6147 return NULL;
6148 }
6149
6150 obj = called_type->tp_alloc(called_type, 0);
6151 CHECK_OBJECT(obj);
6152 } else {
6153 obj = called_type->tp_new(called_type, pos_args, NULL);
6154 }
6155
6156 if (likely(obj != NULL)) {
6157 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6158 return obj;
6159 }
6160
6161 // Work on produced type.
6162 type = Py_TYPE(obj);
6163
6164 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6165 if (type->tp_init == default_tp_init_wrapper) {
6166
6167 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6168
6169 // Not really allowed, since we wouldn't have the default wrapper set.
6170 assert(init_method != NULL);
6171
6172 bool is_compiled_function = false;
6173 bool init_method_needs_release = false;
6174
6175 if (likely(init_method != NULL)) {
6176 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
6177
6178 if (func == Nuitka_Function_Type.tp_descr_get) {
6179 is_compiled_function = true;
6180 } else if (func != NULL) {
6181 init_method = func(init_method, obj, (PyObject *)(type));
6182 init_method_needs_release = true;
6183 }
6184 }
6185
6186 if (unlikely(init_method == NULL)) {
6187 if (!HAS_ERROR_OCCURRED(tstate)) {
6188 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
6189 const_str_plain___init__);
6190 }
6191
6192 return NULL;
6193 }
6194
6195 PyObject *result;
6196 if (is_compiled_function) {
6197 result = Nuitka_CallMethodFunctionPosArgs(
6198 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 7);
6199 } else {
6200 result = CALL_FUNCTION_WITH_POS_ARGS7(tstate, init_method, pos_args);
6201 if (init_method_needs_release) {
6202 Py_DECREF(init_method);
6203 }
6204 }
6205
6206 if (unlikely(result == NULL)) {
6207 Py_DECREF(obj);
6208 return NULL;
6209 }
6210
6211 Py_DECREF(result);
6212
6213 if (unlikely(result != Py_None)) {
6214 Py_DECREF(obj);
6215
6216 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6217 return NULL;
6218 }
6219 } else {
6220
6221 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
6222 Py_DECREF(obj);
6223 return NULL;
6224 }
6225 }
6226 }
6227 }
6228
6229 CHECK_OBJECT_X(obj);
6230
6231 return obj;
6232 }
6233#endif
6234#if PYTHON_VERSION < 0x300
6235 } else if (PyClass_Check(called)) {
6236 PyObject *obj = PyInstance_NewRaw(called, NULL);
6237
6238 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
6239
6240 if (unlikely(init_method == NULL)) {
6241 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
6242 Py_DECREF(obj);
6243 return NULL;
6244 }
6245
6246 Py_DECREF(obj);
6247
6248 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
6249 return NULL;
6250 }
6251
6252 bool is_compiled_function = false;
6253
6254 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
6255
6256 if (descr_get == NULL) {
6257 Py_INCREF(init_method);
6258 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
6259 is_compiled_function = true;
6260 } else if (descr_get != NULL) {
6261 PyObject *descr_method = descr_get(init_method, obj, called);
6262
6263 if (unlikely(descr_method == NULL)) {
6264 return NULL;
6265 }
6266
6267 init_method = descr_method;
6268 }
6269
6270 PyObject *result;
6271 if (is_compiled_function) {
6272 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
6273 args, 7);
6274 } else {
6275 result = CALL_FUNCTION_WITH_POS_ARGS7(tstate, init_method, pos_args);
6276 Py_DECREF(init_method);
6277 }
6278 if (unlikely(result == NULL)) {
6279 return NULL;
6280 }
6281
6282 Py_DECREF(result);
6283
6284 if (unlikely(result != Py_None)) {
6285 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6286 return NULL;
6287 }
6288
6289 CHECK_OBJECT_X(obj);
6290
6291 return obj;
6292#endif
6293#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
6294 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
6295 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6296
6297 if (likely(func != NULL)) {
6298 PyObject *result = func(called, args, 7, NULL);
6299
6300 CHECK_OBJECT_X(result);
6301
6302 return Nuitka_CheckFunctionResult(tstate, called, result);
6303 }
6304#endif
6305 }
6306
6307#if 0
6308 PRINT_NEW_LINE();
6309 PRINT_STRING("FALLBACK");
6310 PRINT_ITEM(called);
6311 PRINT_NEW_LINE();
6312#endif
6313
6314 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
6315
6316 CHECK_OBJECT_X(result);
6317
6318 return result;
6319}
6320PyObject *CALL_FUNCTION_WITH_ARGS8(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
6321 CHECK_OBJECT(called);
6322 CHECK_OBJECTS(args, 8);
6323
6324 if (Nuitka_Function_Check(called)) {
6325 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6326 return NULL;
6327 }
6328
6329 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
6330 PyObject *result;
6331
6332 if (function->m_args_simple && 8 == function->m_args_positional_count) {
6333 for (Py_ssize_t i = 0; i < 8; i++) {
6334 Py_INCREF(args[i]);
6335 }
6336 result = function->m_c_code(tstate, function, (PyObject **)args);
6337 } else if (function->m_args_simple && 8 + function->m_defaults_given == function->m_args_positional_count) {
6338 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6339
6340 memcpy(python_pars, args, 8 * sizeof(PyObject *));
6341 memcpy(python_pars + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6342 function->m_defaults_given * sizeof(PyObject *));
6343
6344 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
6345 Py_INCREF(python_pars[i]);
6346 }
6347
6348 result = function->m_c_code(tstate, function, python_pars);
6349 } else {
6350 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 8);
6351 }
6352
6353 Py_LeaveRecursiveCall();
6354
6355 CHECK_OBJECT_X(result);
6356
6357 return result;
6358 } else if (Nuitka_Method_Check(called)) {
6359 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
6360
6361 if (method->m_object == NULL) {
6362 PyObject *self = args[0];
6363
6364 int res = PyObject_IsInstance(self, method->m_class);
6365
6366 if (unlikely(res < 0)) {
6367 return NULL;
6368 } else if (unlikely(res == 0)) {
6369 PyErr_Format(PyExc_TypeError,
6370 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
6371 "instance instead)",
6372 GET_CALLABLE_NAME((PyObject *)method->m_function),
6373 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
6374 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
6375
6376 return NULL;
6377 }
6378
6379 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 8);
6380
6381 CHECK_OBJECT_X(result);
6382
6383 return result;
6384 } else {
6385 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6386 return NULL;
6387 }
6388
6389 struct Nuitka_FunctionObject *function = method->m_function;
6390
6391 PyObject *result;
6392
6393 if (function->m_args_simple && 8 + 1 == function->m_args_positional_count) {
6394 PyObject *python_pars[8 + 1];
6395
6396 python_pars[0] = method->m_object;
6397 Py_INCREF(method->m_object);
6398
6399 for (Py_ssize_t i = 0; i < 8; i++) {
6400 python_pars[i + 1] = args[i];
6401 Py_INCREF(args[i]);
6402 }
6403 result = function->m_c_code(tstate, function, python_pars);
6404 } else if (function->m_args_simple &&
6405 8 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6406 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6407
6408 python_pars[0] = method->m_object;
6409 Py_INCREF(method->m_object);
6410
6411 memcpy(python_pars + 1, args, 8 * sizeof(PyObject *));
6412 memcpy(python_pars + 1 + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6413 function->m_defaults_given * sizeof(PyObject *));
6414
6415 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6416 Py_INCREF(python_pars[i]);
6417 }
6418
6419 result = function->m_c_code(tstate, function, python_pars);
6420 } else {
6421 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 8);
6422 }
6423
6424 Py_LeaveRecursiveCall();
6425
6426 CHECK_OBJECT_X(result);
6427
6428 return result;
6429 }
6430#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6431 } else if (PyCFunction_CheckExact(called)) {
6432#if PYTHON_VERSION >= 0x380
6433#ifdef _NUITKA_FULL_COMPAT
6434 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6435 return NULL;
6436 }
6437#endif
6438
6439 int flags = PyCFunction_GET_FLAGS(called);
6440
6441 PyObject *result;
6442
6443 if (!(flags & METH_VARARGS)) {
6444 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6445
6446 assert(func != NULL);
6447 result = func(called, args, 8, NULL);
6448
6449 CHECK_OBJECT_X(result);
6450 } else {
6451 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6452 PyObject *self = PyCFunction_GET_SELF(called);
6453
6454 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6455
6456 if (flags & METH_KEYWORDS) {
6457 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6458 } else {
6459 result = (*method)(self, pos_args);
6460 }
6461
6462 Py_DECREF(pos_args);
6463 }
6464
6465#ifdef _NUITKA_FULL_COMPAT
6466 Py_LeaveRecursiveCall();
6467#endif
6468 CHECK_OBJECT_X(result);
6469
6470 return Nuitka_CheckFunctionResult(tstate, called, result);
6471#else
6472 // Try to be fast about wrapping the arguments.
6473 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6474
6475 if (unlikely(flags & METH_NOARGS)) {
6476 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (8 given)",
6477 ((PyCFunctionObject *)called)->m_ml->ml_name);
6478 return NULL;
6479 } else if (unlikely(flags & METH_O)) {
6480 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (8 given)",
6481 ((PyCFunctionObject *)called)->m_ml->ml_name);
6482 return NULL;
6483 } else if (flags & METH_VARARGS) {
6484 // Recursion guard is not strictly necessary, as we already have
6485 // one on our way to here.
6486#ifdef _NUITKA_FULL_COMPAT
6487 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6488 return NULL;
6489 }
6490#endif
6491 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6492 PyObject *self = PyCFunction_GET_SELF(called);
6493
6494 PyObject *result;
6495
6496#if PYTHON_VERSION < 0x360
6497 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6498 if (flags & METH_KEYWORDS) {
6499 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6500 } else {
6501 result = (*method)(self, pos_args);
6502 }
6503
6504 Py_DECREF(pos_args);
6505#else
6506 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6507 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6508 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6509 Py_DECREF(pos_args);
6510 } else if (flags == METH_FASTCALL) {
6511#if PYTHON_VERSION < 0x370
6512 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 8, NULL);
6513#else
6514 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6515 result = (*(_PyCFunctionFast)method)(self, &pos_args, 8);
6516 Py_DECREF(pos_args);
6517#endif
6518 } else {
6519 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6520 result = (*method)(self, pos_args);
6521 Py_DECREF(pos_args);
6522 }
6523#endif
6524
6525#ifdef _NUITKA_FULL_COMPAT
6526 Py_LeaveRecursiveCall();
6527#endif
6528
6529 CHECK_OBJECT_X(result);
6530
6531 return Nuitka_CheckFunctionResult(tstate, called, result);
6532 }
6533#endif
6534#endif
6535#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6536 } else if (PyFunction_Check(called)) {
6537#if PYTHON_VERSION < 0x3b0
6538 PyObject *result = callPythonFunction(called, args, 8);
6539#else
6540 PyObject *result = _PyFunction_Vectorcall(called, args, 8, NULL);
6541#endif
6542 CHECK_OBJECT_X(result);
6543
6544 return result;
6545#endif
6546#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6547 } else if (PyType_Check(called)) {
6548 PyTypeObject *type = Py_TYPE(called);
6549
6550 if (type->tp_call == PyType_Type.tp_call) {
6551 PyTypeObject *called_type = (PyTypeObject *)(called);
6552
6553 if (unlikely(called_type->tp_new == NULL)) {
6554 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6555 return NULL;
6556 }
6557
6558 PyObject *pos_args = NULL;
6559 PyObject *obj;
6560
6561 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6562 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6563 formatCannotInstantiateAbstractClass(tstate, called_type);
6564 return NULL;
6565 }
6566
6567 obj = called_type->tp_alloc(called_type, 0);
6568 CHECK_OBJECT(obj);
6569 } else {
6570 pos_args = MAKE_TUPLE(tstate, args, 8);
6571 obj = called_type->tp_new(called_type, pos_args, NULL);
6572 }
6573
6574 if (likely(obj != NULL)) {
6575 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6576 Py_DECREF(pos_args);
6577 return obj;
6578 }
6579
6580 // Work on produced type.
6581 type = Py_TYPE(obj);
6582
6583 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6584 if (type->tp_init == default_tp_init_wrapper) {
6585 Py_XDECREF(pos_args);
6586 pos_args = NULL;
6587
6588 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6589
6590 // Not really allowed, since we wouldn't have the default wrapper set.
6591 assert(init_method != NULL);
6592
6593 bool is_compiled_function = false;
6594 bool init_method_needs_release = false;
6595
6596 if (likely(init_method != NULL)) {
6597 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
6598
6599 if (func == Nuitka_Function_Type.tp_descr_get) {
6600 is_compiled_function = true;
6601 } else if (func != NULL) {
6602 init_method = func(init_method, obj, (PyObject *)(type));
6603 init_method_needs_release = true;
6604 }
6605 }
6606
6607 if (unlikely(init_method == NULL)) {
6608 if (!HAS_ERROR_OCCURRED(tstate)) {
6609 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
6610 const_str_plain___init__);
6611 }
6612
6613 return NULL;
6614 }
6615
6616 PyObject *result;
6617 if (is_compiled_function) {
6618 result = Nuitka_CallMethodFunctionPosArgs(
6619 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 8);
6620 } else {
6621 result = CALL_FUNCTION_WITH_ARGS8(tstate, init_method, args);
6622 if (init_method_needs_release) {
6623 Py_DECREF(init_method);
6624 }
6625 }
6626
6627 if (unlikely(result == NULL)) {
6628 Py_DECREF(obj);
6629 return NULL;
6630 }
6631
6632 Py_DECREF(result);
6633
6634 if (unlikely(result != Py_None)) {
6635 Py_DECREF(obj);
6636
6637 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6638 return NULL;
6639 }
6640 } else {
6641 if (pos_args == NULL) {
6642 pos_args = MAKE_TUPLE(tstate, args, 8);
6643 }
6644
6645 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
6646 Py_DECREF(obj);
6647 Py_XDECREF(pos_args);
6648 return NULL;
6649 }
6650 }
6651 }
6652 }
6653
6654 Py_XDECREF(pos_args);
6655
6656 CHECK_OBJECT_X(obj);
6657
6658 return obj;
6659 }
6660#endif
6661#if PYTHON_VERSION < 0x300
6662 } else if (PyClass_Check(called)) {
6663 PyObject *obj = PyInstance_NewRaw(called, NULL);
6664
6665 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
6666
6667 if (unlikely(init_method == NULL)) {
6668 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
6669 Py_DECREF(obj);
6670 return NULL;
6671 }
6672
6673 Py_DECREF(obj);
6674
6675 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
6676 return NULL;
6677 }
6678
6679 bool is_compiled_function = false;
6680
6681 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
6682
6683 if (descr_get == NULL) {
6684 Py_INCREF(init_method);
6685 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
6686 is_compiled_function = true;
6687 } else if (descr_get != NULL) {
6688 PyObject *descr_method = descr_get(init_method, obj, called);
6689
6690 if (unlikely(descr_method == NULL)) {
6691 return NULL;
6692 }
6693
6694 init_method = descr_method;
6695 }
6696
6697 PyObject *result;
6698 if (is_compiled_function) {
6699 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
6700 args, 8);
6701 } else {
6702 result = CALL_FUNCTION_WITH_ARGS8(tstate, init_method, args);
6703 Py_DECREF(init_method);
6704 }
6705 if (unlikely(result == NULL)) {
6706 return NULL;
6707 }
6708
6709 Py_DECREF(result);
6710
6711 if (unlikely(result != Py_None)) {
6712 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6713 return NULL;
6714 }
6715
6716 CHECK_OBJECT_X(obj);
6717
6718 return obj;
6719#endif
6720#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
6721 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
6722 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6723
6724 if (likely(func != NULL)) {
6725 PyObject *result = func(called, args, 8, NULL);
6726
6727 CHECK_OBJECT_X(result);
6728
6729 return Nuitka_CheckFunctionResult(tstate, called, result);
6730 }
6731#endif
6732 }
6733
6734#if 0
6735 PRINT_NEW_LINE();
6736 PRINT_STRING("FALLBACK");
6737 PRINT_ITEM(called);
6738 PRINT_NEW_LINE();
6739#endif
6740
6741 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6742
6743 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
6744
6745 Py_DECREF(pos_args);
6746
6747 CHECK_OBJECT_X(result);
6748
6749 return result;
6750}
6751PyObject *CALL_FUNCTION_WITH_POS_ARGS8(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
6752 assert(PyTuple_CheckExact(pos_args));
6753 assert(PyTuple_GET_SIZE(pos_args) == 8);
6754 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
6755 CHECK_OBJECT(called);
6756 CHECK_OBJECTS(args, 8);
6757
6758 if (Nuitka_Function_Check(called)) {
6759 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6760 return NULL;
6761 }
6762
6763 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
6764 PyObject *result;
6765
6766 if (function->m_args_simple && 8 == function->m_args_positional_count) {
6767 for (Py_ssize_t i = 0; i < 8; i++) {
6768 Py_INCREF(args[i]);
6769 }
6770 result = function->m_c_code(tstate, function, (PyObject **)args);
6771 } else if (function->m_args_simple && 8 + function->m_defaults_given == function->m_args_positional_count) {
6772 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6773
6774 memcpy(python_pars, args, 8 * sizeof(PyObject *));
6775 memcpy(python_pars + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6776 function->m_defaults_given * sizeof(PyObject *));
6777
6778 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
6779 Py_INCREF(python_pars[i]);
6780 }
6781
6782 result = function->m_c_code(tstate, function, python_pars);
6783 } else {
6784 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 8);
6785 }
6786
6787 Py_LeaveRecursiveCall();
6788
6789 CHECK_OBJECT_X(result);
6790
6791 return result;
6792 } else if (Nuitka_Method_Check(called)) {
6793 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
6794
6795 if (method->m_object == NULL) {
6796 PyObject *self = args[0];
6797
6798 int res = PyObject_IsInstance(self, method->m_class);
6799
6800 if (unlikely(res < 0)) {
6801 return NULL;
6802 } else if (unlikely(res == 0)) {
6803 PyErr_Format(PyExc_TypeError,
6804 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
6805 "instance instead)",
6806 GET_CALLABLE_NAME((PyObject *)method->m_function),
6807 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
6808 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
6809
6810 return NULL;
6811 }
6812
6813 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 8);
6814
6815 CHECK_OBJECT_X(result);
6816
6817 return result;
6818 } else {
6819 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6820 return NULL;
6821 }
6822
6823 struct Nuitka_FunctionObject *function = method->m_function;
6824
6825 PyObject *result;
6826
6827 if (function->m_args_simple && 8 + 1 == function->m_args_positional_count) {
6828 PyObject *python_pars[8 + 1];
6829
6830 python_pars[0] = method->m_object;
6831 Py_INCREF(method->m_object);
6832
6833 for (Py_ssize_t i = 0; i < 8; i++) {
6834 python_pars[i + 1] = args[i];
6835 Py_INCREF(args[i]);
6836 }
6837 result = function->m_c_code(tstate, function, python_pars);
6838 } else if (function->m_args_simple &&
6839 8 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6840 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6841
6842 python_pars[0] = method->m_object;
6843 Py_INCREF(method->m_object);
6844
6845 memcpy(python_pars + 1, args, 8 * sizeof(PyObject *));
6846 memcpy(python_pars + 1 + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6847 function->m_defaults_given * sizeof(PyObject *));
6848
6849 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6850 Py_INCREF(python_pars[i]);
6851 }
6852
6853 result = function->m_c_code(tstate, function, python_pars);
6854 } else {
6855 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 8);
6856 }
6857
6858 Py_LeaveRecursiveCall();
6859
6860 CHECK_OBJECT_X(result);
6861
6862 return result;
6863 }
6864#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6865 } else if (PyCFunction_CheckExact(called)) {
6866#if PYTHON_VERSION >= 0x380
6867#ifdef _NUITKA_FULL_COMPAT
6868 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6869 return NULL;
6870 }
6871#endif
6872
6873 int flags = PyCFunction_GET_FLAGS(called);
6874
6875 PyObject *result;
6876
6877 if (!(flags & METH_VARARGS)) {
6878 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6879
6880 assert(func != NULL);
6881 result = func(called, args, 8, NULL);
6882
6883 CHECK_OBJECT_X(result);
6884 } else {
6885 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6886 PyObject *self = PyCFunction_GET_SELF(called);
6887
6888 if (flags & METH_KEYWORDS) {
6889 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6890 } else {
6891 result = (*method)(self, pos_args);
6892 }
6893 }
6894
6895#ifdef _NUITKA_FULL_COMPAT
6896 Py_LeaveRecursiveCall();
6897#endif
6898 CHECK_OBJECT_X(result);
6899
6900 return Nuitka_CheckFunctionResult(tstate, called, result);
6901#else
6902 // Try to be fast about wrapping the arguments.
6903 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6904
6905 if (unlikely(flags & METH_NOARGS)) {
6906 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (8 given)",
6907 ((PyCFunctionObject *)called)->m_ml->ml_name);
6908 return NULL;
6909 } else if (unlikely(flags & METH_O)) {
6910 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (8 given)",
6911 ((PyCFunctionObject *)called)->m_ml->ml_name);
6912 return NULL;
6913 } else if (flags & METH_VARARGS) {
6914 // Recursion guard is not strictly necessary, as we already have
6915 // one on our way to here.
6916#ifdef _NUITKA_FULL_COMPAT
6917 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6918 return NULL;
6919 }
6920#endif
6921 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6922 PyObject *self = PyCFunction_GET_SELF(called);
6923
6924 PyObject *result;
6925
6926#if PYTHON_VERSION < 0x360
6927 if (flags & METH_KEYWORDS) {
6928 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6929 } else {
6930 result = (*method)(self, pos_args);
6931 }
6932
6933#else
6934 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6935 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6936 } else if (flags == METH_FASTCALL) {
6937#if PYTHON_VERSION < 0x370
6938 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 8, NULL);
6939#else
6940 result = (*(_PyCFunctionFast)method)(self, &pos_args, 8);
6941#endif
6942 } else {
6943 result = (*method)(self, pos_args);
6944 }
6945#endif
6946
6947#ifdef _NUITKA_FULL_COMPAT
6948 Py_LeaveRecursiveCall();
6949#endif
6950
6951 CHECK_OBJECT_X(result);
6952
6953 return Nuitka_CheckFunctionResult(tstate, called, result);
6954 }
6955#endif
6956#endif
6957#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6958 } else if (PyFunction_Check(called)) {
6959#if PYTHON_VERSION < 0x3b0
6960 PyObject *result = callPythonFunction(called, args, 8);
6961#else
6962 PyObject *result = _PyFunction_Vectorcall(called, args, 8, NULL);
6963#endif
6964 CHECK_OBJECT_X(result);
6965
6966 return result;
6967#endif
6968#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6969 } else if (PyType_Check(called)) {
6970 PyTypeObject *type = Py_TYPE(called);
6971
6972 if (type->tp_call == PyType_Type.tp_call) {
6973 PyTypeObject *called_type = (PyTypeObject *)(called);
6974
6975 if (unlikely(called_type->tp_new == NULL)) {
6976 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6977 return NULL;
6978 }
6979
6980 PyObject *obj;
6981
6982 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6983 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6984 formatCannotInstantiateAbstractClass(tstate, called_type);
6985 return NULL;
6986 }
6987
6988 obj = called_type->tp_alloc(called_type, 0);
6989 CHECK_OBJECT(obj);
6990 } else {
6991 obj = called_type->tp_new(called_type, pos_args, NULL);
6992 }
6993
6994 if (likely(obj != NULL)) {
6995 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6996 return obj;
6997 }
6998
6999 // Work on produced type.
7000 type = Py_TYPE(obj);
7001
7002 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7003 if (type->tp_init == default_tp_init_wrapper) {
7004
7005 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7006
7007 // Not really allowed, since we wouldn't have the default wrapper set.
7008 assert(init_method != NULL);
7009
7010 bool is_compiled_function = false;
7011 bool init_method_needs_release = false;
7012
7013 if (likely(init_method != NULL)) {
7014 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7015
7016 if (func == Nuitka_Function_Type.tp_descr_get) {
7017 is_compiled_function = true;
7018 } else if (func != NULL) {
7019 init_method = func(init_method, obj, (PyObject *)(type));
7020 init_method_needs_release = true;
7021 }
7022 }
7023
7024 if (unlikely(init_method == NULL)) {
7025 if (!HAS_ERROR_OCCURRED(tstate)) {
7026 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7027 const_str_plain___init__);
7028 }
7029
7030 return NULL;
7031 }
7032
7033 PyObject *result;
7034 if (is_compiled_function) {
7035 result = Nuitka_CallMethodFunctionPosArgs(
7036 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 8);
7037 } else {
7038 result = CALL_FUNCTION_WITH_POS_ARGS8(tstate, init_method, pos_args);
7039 if (init_method_needs_release) {
7040 Py_DECREF(init_method);
7041 }
7042 }
7043
7044 if (unlikely(result == NULL)) {
7045 Py_DECREF(obj);
7046 return NULL;
7047 }
7048
7049 Py_DECREF(result);
7050
7051 if (unlikely(result != Py_None)) {
7052 Py_DECREF(obj);
7053
7054 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7055 return NULL;
7056 }
7057 } else {
7058
7059 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7060 Py_DECREF(obj);
7061 return NULL;
7062 }
7063 }
7064 }
7065 }
7066
7067 CHECK_OBJECT_X(obj);
7068
7069 return obj;
7070 }
7071#endif
7072#if PYTHON_VERSION < 0x300
7073 } else if (PyClass_Check(called)) {
7074 PyObject *obj = PyInstance_NewRaw(called, NULL);
7075
7076 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7077
7078 if (unlikely(init_method == NULL)) {
7079 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7080 Py_DECREF(obj);
7081 return NULL;
7082 }
7083
7084 Py_DECREF(obj);
7085
7086 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7087 return NULL;
7088 }
7089
7090 bool is_compiled_function = false;
7091
7092 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7093
7094 if (descr_get == NULL) {
7095 Py_INCREF(init_method);
7096 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7097 is_compiled_function = true;
7098 } else if (descr_get != NULL) {
7099 PyObject *descr_method = descr_get(init_method, obj, called);
7100
7101 if (unlikely(descr_method == NULL)) {
7102 return NULL;
7103 }
7104
7105 init_method = descr_method;
7106 }
7107
7108 PyObject *result;
7109 if (is_compiled_function) {
7110 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7111 args, 8);
7112 } else {
7113 result = CALL_FUNCTION_WITH_POS_ARGS8(tstate, init_method, pos_args);
7114 Py_DECREF(init_method);
7115 }
7116 if (unlikely(result == NULL)) {
7117 return NULL;
7118 }
7119
7120 Py_DECREF(result);
7121
7122 if (unlikely(result != Py_None)) {
7123 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7124 return NULL;
7125 }
7126
7127 CHECK_OBJECT_X(obj);
7128
7129 return obj;
7130#endif
7131#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7132 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7133 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7134
7135 if (likely(func != NULL)) {
7136 PyObject *result = func(called, args, 8, NULL);
7137
7138 CHECK_OBJECT_X(result);
7139
7140 return Nuitka_CheckFunctionResult(tstate, called, result);
7141 }
7142#endif
7143 }
7144
7145#if 0
7146 PRINT_NEW_LINE();
7147 PRINT_STRING("FALLBACK");
7148 PRINT_ITEM(called);
7149 PRINT_NEW_LINE();
7150#endif
7151
7152 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7153
7154 CHECK_OBJECT_X(result);
7155
7156 return result;
7157}
7158PyObject *CALL_FUNCTION_WITH_ARGS9(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
7159 CHECK_OBJECT(called);
7160 CHECK_OBJECTS(args, 9);
7161
7162 if (Nuitka_Function_Check(called)) {
7163 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7164 return NULL;
7165 }
7166
7167 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7168 PyObject *result;
7169
7170 if (function->m_args_simple && 9 == function->m_args_positional_count) {
7171 for (Py_ssize_t i = 0; i < 9; i++) {
7172 Py_INCREF(args[i]);
7173 }
7174 result = function->m_c_code(tstate, function, (PyObject **)args);
7175 } else if (function->m_args_simple && 9 + function->m_defaults_given == function->m_args_positional_count) {
7176 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7177
7178 memcpy(python_pars, args, 9 * sizeof(PyObject *));
7179 memcpy(python_pars + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7180 function->m_defaults_given * sizeof(PyObject *));
7181
7182 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
7183 Py_INCREF(python_pars[i]);
7184 }
7185
7186 result = function->m_c_code(tstate, function, python_pars);
7187 } else {
7188 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 9);
7189 }
7190
7191 Py_LeaveRecursiveCall();
7192
7193 CHECK_OBJECT_X(result);
7194
7195 return result;
7196 } else if (Nuitka_Method_Check(called)) {
7197 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
7198
7199 if (method->m_object == NULL) {
7200 PyObject *self = args[0];
7201
7202 int res = PyObject_IsInstance(self, method->m_class);
7203
7204 if (unlikely(res < 0)) {
7205 return NULL;
7206 } else if (unlikely(res == 0)) {
7207 PyErr_Format(PyExc_TypeError,
7208 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
7209 "instance instead)",
7210 GET_CALLABLE_NAME((PyObject *)method->m_function),
7211 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
7212 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
7213
7214 return NULL;
7215 }
7216
7217 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 9);
7218
7219 CHECK_OBJECT_X(result);
7220
7221 return result;
7222 } else {
7223 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7224 return NULL;
7225 }
7226
7227 struct Nuitka_FunctionObject *function = method->m_function;
7228
7229 PyObject *result;
7230
7231 if (function->m_args_simple && 9 + 1 == function->m_args_positional_count) {
7232 PyObject *python_pars[9 + 1];
7233
7234 python_pars[0] = method->m_object;
7235 Py_INCREF(method->m_object);
7236
7237 for (Py_ssize_t i = 0; i < 9; i++) {
7238 python_pars[i + 1] = args[i];
7239 Py_INCREF(args[i]);
7240 }
7241 result = function->m_c_code(tstate, function, python_pars);
7242 } else if (function->m_args_simple &&
7243 9 + 1 + function->m_defaults_given == function->m_args_positional_count) {
7244 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7245
7246 python_pars[0] = method->m_object;
7247 Py_INCREF(method->m_object);
7248
7249 memcpy(python_pars + 1, args, 9 * sizeof(PyObject *));
7250 memcpy(python_pars + 1 + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7251 function->m_defaults_given * sizeof(PyObject *));
7252
7253 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
7254 Py_INCREF(python_pars[i]);
7255 }
7256
7257 result = function->m_c_code(tstate, function, python_pars);
7258 } else {
7259 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 9);
7260 }
7261
7262 Py_LeaveRecursiveCall();
7263
7264 CHECK_OBJECT_X(result);
7265
7266 return result;
7267 }
7268#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
7269 } else if (PyCFunction_CheckExact(called)) {
7270#if PYTHON_VERSION >= 0x380
7271#ifdef _NUITKA_FULL_COMPAT
7272 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7273 return NULL;
7274 }
7275#endif
7276
7277 int flags = PyCFunction_GET_FLAGS(called);
7278
7279 PyObject *result;
7280
7281 if (!(flags & METH_VARARGS)) {
7282 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7283
7284 assert(func != NULL);
7285 result = func(called, args, 9, NULL);
7286
7287 CHECK_OBJECT_X(result);
7288 } else {
7289 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7290 PyObject *self = PyCFunction_GET_SELF(called);
7291
7292 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7293
7294 if (flags & METH_KEYWORDS) {
7295 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
7296 } else {
7297 result = (*method)(self, pos_args);
7298 }
7299
7300 Py_DECREF(pos_args);
7301 }
7302
7303#ifdef _NUITKA_FULL_COMPAT
7304 Py_LeaveRecursiveCall();
7305#endif
7306 CHECK_OBJECT_X(result);
7307
7308 return Nuitka_CheckFunctionResult(tstate, called, result);
7309#else
7310 // Try to be fast about wrapping the arguments.
7311 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
7312
7313 if (unlikely(flags & METH_NOARGS)) {
7314 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (9 given)",
7315 ((PyCFunctionObject *)called)->m_ml->ml_name);
7316 return NULL;
7317 } else if (unlikely(flags & METH_O)) {
7318 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (9 given)",
7319 ((PyCFunctionObject *)called)->m_ml->ml_name);
7320 return NULL;
7321 } else if (flags & METH_VARARGS) {
7322 // Recursion guard is not strictly necessary, as we already have
7323 // one on our way to here.
7324#ifdef _NUITKA_FULL_COMPAT
7325 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7326 return NULL;
7327 }
7328#endif
7329 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7330 PyObject *self = PyCFunction_GET_SELF(called);
7331
7332 PyObject *result;
7333
7334#if PYTHON_VERSION < 0x360
7335 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7336 if (flags & METH_KEYWORDS) {
7337 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7338 } else {
7339 result = (*method)(self, pos_args);
7340 }
7341
7342 Py_DECREF(pos_args);
7343#else
7344 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
7345 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7346 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7347 Py_DECREF(pos_args);
7348 } else if (flags == METH_FASTCALL) {
7349#if PYTHON_VERSION < 0x370
7350 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 9, NULL);
7351#else
7352 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7353 result = (*(_PyCFunctionFast)method)(self, &pos_args, 9);
7354 Py_DECREF(pos_args);
7355#endif
7356 } else {
7357 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7358 result = (*method)(self, pos_args);
7359 Py_DECREF(pos_args);
7360 }
7361#endif
7362
7363#ifdef _NUITKA_FULL_COMPAT
7364 Py_LeaveRecursiveCall();
7365#endif
7366
7367 CHECK_OBJECT_X(result);
7368
7369 return Nuitka_CheckFunctionResult(tstate, called, result);
7370 }
7371#endif
7372#endif
7373#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
7374 } else if (PyFunction_Check(called)) {
7375#if PYTHON_VERSION < 0x3b0
7376 PyObject *result = callPythonFunction(called, args, 9);
7377#else
7378 PyObject *result = _PyFunction_Vectorcall(called, args, 9, NULL);
7379#endif
7380 CHECK_OBJECT_X(result);
7381
7382 return result;
7383#endif
7384#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
7385 } else if (PyType_Check(called)) {
7386 PyTypeObject *type = Py_TYPE(called);
7387
7388 if (type->tp_call == PyType_Type.tp_call) {
7389 PyTypeObject *called_type = (PyTypeObject *)(called);
7390
7391 if (unlikely(called_type->tp_new == NULL)) {
7392 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
7393 return NULL;
7394 }
7395
7396 PyObject *pos_args = NULL;
7397 PyObject *obj;
7398
7399 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
7400 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
7401 formatCannotInstantiateAbstractClass(tstate, called_type);
7402 return NULL;
7403 }
7404
7405 obj = called_type->tp_alloc(called_type, 0);
7406 CHECK_OBJECT(obj);
7407 } else {
7408 pos_args = MAKE_TUPLE(tstate, args, 9);
7409 obj = called_type->tp_new(called_type, pos_args, NULL);
7410 }
7411
7412 if (likely(obj != NULL)) {
7413 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
7414 Py_DECREF(pos_args);
7415 return obj;
7416 }
7417
7418 // Work on produced type.
7419 type = Py_TYPE(obj);
7420
7421 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7422 if (type->tp_init == default_tp_init_wrapper) {
7423 Py_XDECREF(pos_args);
7424 pos_args = NULL;
7425
7426 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7427
7428 // Not really allowed, since we wouldn't have the default wrapper set.
7429 assert(init_method != NULL);
7430
7431 bool is_compiled_function = false;
7432 bool init_method_needs_release = false;
7433
7434 if (likely(init_method != NULL)) {
7435 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7436
7437 if (func == Nuitka_Function_Type.tp_descr_get) {
7438 is_compiled_function = true;
7439 } else if (func != NULL) {
7440 init_method = func(init_method, obj, (PyObject *)(type));
7441 init_method_needs_release = true;
7442 }
7443 }
7444
7445 if (unlikely(init_method == NULL)) {
7446 if (!HAS_ERROR_OCCURRED(tstate)) {
7447 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7448 const_str_plain___init__);
7449 }
7450
7451 return NULL;
7452 }
7453
7454 PyObject *result;
7455 if (is_compiled_function) {
7456 result = Nuitka_CallMethodFunctionPosArgs(
7457 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 9);
7458 } else {
7459 result = CALL_FUNCTION_WITH_ARGS9(tstate, init_method, args);
7460 if (init_method_needs_release) {
7461 Py_DECREF(init_method);
7462 }
7463 }
7464
7465 if (unlikely(result == NULL)) {
7466 Py_DECREF(obj);
7467 return NULL;
7468 }
7469
7470 Py_DECREF(result);
7471
7472 if (unlikely(result != Py_None)) {
7473 Py_DECREF(obj);
7474
7475 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7476 return NULL;
7477 }
7478 } else {
7479 if (pos_args == NULL) {
7480 pos_args = MAKE_TUPLE(tstate, args, 9);
7481 }
7482
7483 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7484 Py_DECREF(obj);
7485 Py_XDECREF(pos_args);
7486 return NULL;
7487 }
7488 }
7489 }
7490 }
7491
7492 Py_XDECREF(pos_args);
7493
7494 CHECK_OBJECT_X(obj);
7495
7496 return obj;
7497 }
7498#endif
7499#if PYTHON_VERSION < 0x300
7500 } else if (PyClass_Check(called)) {
7501 PyObject *obj = PyInstance_NewRaw(called, NULL);
7502
7503 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7504
7505 if (unlikely(init_method == NULL)) {
7506 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7507 Py_DECREF(obj);
7508 return NULL;
7509 }
7510
7511 Py_DECREF(obj);
7512
7513 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7514 return NULL;
7515 }
7516
7517 bool is_compiled_function = false;
7518
7519 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7520
7521 if (descr_get == NULL) {
7522 Py_INCREF(init_method);
7523 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7524 is_compiled_function = true;
7525 } else if (descr_get != NULL) {
7526 PyObject *descr_method = descr_get(init_method, obj, called);
7527
7528 if (unlikely(descr_method == NULL)) {
7529 return NULL;
7530 }
7531
7532 init_method = descr_method;
7533 }
7534
7535 PyObject *result;
7536 if (is_compiled_function) {
7537 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7538 args, 9);
7539 } else {
7540 result = CALL_FUNCTION_WITH_ARGS9(tstate, init_method, args);
7541 Py_DECREF(init_method);
7542 }
7543 if (unlikely(result == NULL)) {
7544 return NULL;
7545 }
7546
7547 Py_DECREF(result);
7548
7549 if (unlikely(result != Py_None)) {
7550 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7551 return NULL;
7552 }
7553
7554 CHECK_OBJECT_X(obj);
7555
7556 return obj;
7557#endif
7558#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7559 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7560 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7561
7562 if (likely(func != NULL)) {
7563 PyObject *result = func(called, args, 9, NULL);
7564
7565 CHECK_OBJECT_X(result);
7566
7567 return Nuitka_CheckFunctionResult(tstate, called, result);
7568 }
7569#endif
7570 }
7571
7572#if 0
7573 PRINT_NEW_LINE();
7574 PRINT_STRING("FALLBACK");
7575 PRINT_ITEM(called);
7576 PRINT_NEW_LINE();
7577#endif
7578
7579 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7580
7581 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7582
7583 Py_DECREF(pos_args);
7584
7585 CHECK_OBJECT_X(result);
7586
7587 return result;
7588}
7589PyObject *CALL_FUNCTION_WITH_POS_ARGS9(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
7590 assert(PyTuple_CheckExact(pos_args));
7591 assert(PyTuple_GET_SIZE(pos_args) == 9);
7592 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
7593 CHECK_OBJECT(called);
7594 CHECK_OBJECTS(args, 9);
7595
7596 if (Nuitka_Function_Check(called)) {
7597 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7598 return NULL;
7599 }
7600
7601 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7602 PyObject *result;
7603
7604 if (function->m_args_simple && 9 == function->m_args_positional_count) {
7605 for (Py_ssize_t i = 0; i < 9; i++) {
7606 Py_INCREF(args[i]);
7607 }
7608 result = function->m_c_code(tstate, function, (PyObject **)args);
7609 } else if (function->m_args_simple && 9 + function->m_defaults_given == function->m_args_positional_count) {
7610 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7611
7612 memcpy(python_pars, args, 9 * sizeof(PyObject *));
7613 memcpy(python_pars + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7614 function->m_defaults_given * sizeof(PyObject *));
7615
7616 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
7617 Py_INCREF(python_pars[i]);
7618 }
7619
7620 result = function->m_c_code(tstate, function, python_pars);
7621 } else {
7622 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 9);
7623 }
7624
7625 Py_LeaveRecursiveCall();
7626
7627 CHECK_OBJECT_X(result);
7628
7629 return result;
7630 } else if (Nuitka_Method_Check(called)) {
7631 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
7632
7633 if (method->m_object == NULL) {
7634 PyObject *self = args[0];
7635
7636 int res = PyObject_IsInstance(self, method->m_class);
7637
7638 if (unlikely(res < 0)) {
7639 return NULL;
7640 } else if (unlikely(res == 0)) {
7641 PyErr_Format(PyExc_TypeError,
7642 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
7643 "instance instead)",
7644 GET_CALLABLE_NAME((PyObject *)method->m_function),
7645 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
7646 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
7647
7648 return NULL;
7649 }
7650
7651 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 9);
7652
7653 CHECK_OBJECT_X(result);
7654
7655 return result;
7656 } else {
7657 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7658 return NULL;
7659 }
7660
7661 struct Nuitka_FunctionObject *function = method->m_function;
7662
7663 PyObject *result;
7664
7665 if (function->m_args_simple && 9 + 1 == function->m_args_positional_count) {
7666 PyObject *python_pars[9 + 1];
7667
7668 python_pars[0] = method->m_object;
7669 Py_INCREF(method->m_object);
7670
7671 for (Py_ssize_t i = 0; i < 9; i++) {
7672 python_pars[i + 1] = args[i];
7673 Py_INCREF(args[i]);
7674 }
7675 result = function->m_c_code(tstate, function, python_pars);
7676 } else if (function->m_args_simple &&
7677 9 + 1 + function->m_defaults_given == function->m_args_positional_count) {
7678 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7679
7680 python_pars[0] = method->m_object;
7681 Py_INCREF(method->m_object);
7682
7683 memcpy(python_pars + 1, args, 9 * sizeof(PyObject *));
7684 memcpy(python_pars + 1 + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7685 function->m_defaults_given * sizeof(PyObject *));
7686
7687 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
7688 Py_INCREF(python_pars[i]);
7689 }
7690
7691 result = function->m_c_code(tstate, function, python_pars);
7692 } else {
7693 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 9);
7694 }
7695
7696 Py_LeaveRecursiveCall();
7697
7698 CHECK_OBJECT_X(result);
7699
7700 return result;
7701 }
7702#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
7703 } else if (PyCFunction_CheckExact(called)) {
7704#if PYTHON_VERSION >= 0x380
7705#ifdef _NUITKA_FULL_COMPAT
7706 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7707 return NULL;
7708 }
7709#endif
7710
7711 int flags = PyCFunction_GET_FLAGS(called);
7712
7713 PyObject *result;
7714
7715 if (!(flags & METH_VARARGS)) {
7716 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7717
7718 assert(func != NULL);
7719 result = func(called, args, 9, NULL);
7720
7721 CHECK_OBJECT_X(result);
7722 } else {
7723 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7724 PyObject *self = PyCFunction_GET_SELF(called);
7725
7726 if (flags & METH_KEYWORDS) {
7727 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
7728 } else {
7729 result = (*method)(self, pos_args);
7730 }
7731 }
7732
7733#ifdef _NUITKA_FULL_COMPAT
7734 Py_LeaveRecursiveCall();
7735#endif
7736 CHECK_OBJECT_X(result);
7737
7738 return Nuitka_CheckFunctionResult(tstate, called, result);
7739#else
7740 // Try to be fast about wrapping the arguments.
7741 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
7742
7743 if (unlikely(flags & METH_NOARGS)) {
7744 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (9 given)",
7745 ((PyCFunctionObject *)called)->m_ml->ml_name);
7746 return NULL;
7747 } else if (unlikely(flags & METH_O)) {
7748 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (9 given)",
7749 ((PyCFunctionObject *)called)->m_ml->ml_name);
7750 return NULL;
7751 } else if (flags & METH_VARARGS) {
7752 // Recursion guard is not strictly necessary, as we already have
7753 // one on our way to here.
7754#ifdef _NUITKA_FULL_COMPAT
7755 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7756 return NULL;
7757 }
7758#endif
7759 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7760 PyObject *self = PyCFunction_GET_SELF(called);
7761
7762 PyObject *result;
7763
7764#if PYTHON_VERSION < 0x360
7765 if (flags & METH_KEYWORDS) {
7766 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7767 } else {
7768 result = (*method)(self, pos_args);
7769 }
7770
7771#else
7772 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
7773 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7774 } else if (flags == METH_FASTCALL) {
7775#if PYTHON_VERSION < 0x370
7776 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 9, NULL);
7777#else
7778 result = (*(_PyCFunctionFast)method)(self, &pos_args, 9);
7779#endif
7780 } else {
7781 result = (*method)(self, pos_args);
7782 }
7783#endif
7784
7785#ifdef _NUITKA_FULL_COMPAT
7786 Py_LeaveRecursiveCall();
7787#endif
7788
7789 CHECK_OBJECT_X(result);
7790
7791 return Nuitka_CheckFunctionResult(tstate, called, result);
7792 }
7793#endif
7794#endif
7795#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
7796 } else if (PyFunction_Check(called)) {
7797#if PYTHON_VERSION < 0x3b0
7798 PyObject *result = callPythonFunction(called, args, 9);
7799#else
7800 PyObject *result = _PyFunction_Vectorcall(called, args, 9, NULL);
7801#endif
7802 CHECK_OBJECT_X(result);
7803
7804 return result;
7805#endif
7806#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
7807 } else if (PyType_Check(called)) {
7808 PyTypeObject *type = Py_TYPE(called);
7809
7810 if (type->tp_call == PyType_Type.tp_call) {
7811 PyTypeObject *called_type = (PyTypeObject *)(called);
7812
7813 if (unlikely(called_type->tp_new == NULL)) {
7814 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
7815 return NULL;
7816 }
7817
7818 PyObject *obj;
7819
7820 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
7821 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
7822 formatCannotInstantiateAbstractClass(tstate, called_type);
7823 return NULL;
7824 }
7825
7826 obj = called_type->tp_alloc(called_type, 0);
7827 CHECK_OBJECT(obj);
7828 } else {
7829 obj = called_type->tp_new(called_type, pos_args, NULL);
7830 }
7831
7832 if (likely(obj != NULL)) {
7833 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
7834 return obj;
7835 }
7836
7837 // Work on produced type.
7838 type = Py_TYPE(obj);
7839
7840 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7841 if (type->tp_init == default_tp_init_wrapper) {
7842
7843 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7844
7845 // Not really allowed, since we wouldn't have the default wrapper set.
7846 assert(init_method != NULL);
7847
7848 bool is_compiled_function = false;
7849 bool init_method_needs_release = false;
7850
7851 if (likely(init_method != NULL)) {
7852 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7853
7854 if (func == Nuitka_Function_Type.tp_descr_get) {
7855 is_compiled_function = true;
7856 } else if (func != NULL) {
7857 init_method = func(init_method, obj, (PyObject *)(type));
7858 init_method_needs_release = true;
7859 }
7860 }
7861
7862 if (unlikely(init_method == NULL)) {
7863 if (!HAS_ERROR_OCCURRED(tstate)) {
7864 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7865 const_str_plain___init__);
7866 }
7867
7868 return NULL;
7869 }
7870
7871 PyObject *result;
7872 if (is_compiled_function) {
7873 result = Nuitka_CallMethodFunctionPosArgs(
7874 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 9);
7875 } else {
7876 result = CALL_FUNCTION_WITH_POS_ARGS9(tstate, init_method, pos_args);
7877 if (init_method_needs_release) {
7878 Py_DECREF(init_method);
7879 }
7880 }
7881
7882 if (unlikely(result == NULL)) {
7883 Py_DECREF(obj);
7884 return NULL;
7885 }
7886
7887 Py_DECREF(result);
7888
7889 if (unlikely(result != Py_None)) {
7890 Py_DECREF(obj);
7891
7892 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7893 return NULL;
7894 }
7895 } else {
7896
7897 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7898 Py_DECREF(obj);
7899 return NULL;
7900 }
7901 }
7902 }
7903 }
7904
7905 CHECK_OBJECT_X(obj);
7906
7907 return obj;
7908 }
7909#endif
7910#if PYTHON_VERSION < 0x300
7911 } else if (PyClass_Check(called)) {
7912 PyObject *obj = PyInstance_NewRaw(called, NULL);
7913
7914 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7915
7916 if (unlikely(init_method == NULL)) {
7917 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7918 Py_DECREF(obj);
7919 return NULL;
7920 }
7921
7922 Py_DECREF(obj);
7923
7924 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7925 return NULL;
7926 }
7927
7928 bool is_compiled_function = false;
7929
7930 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7931
7932 if (descr_get == NULL) {
7933 Py_INCREF(init_method);
7934 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7935 is_compiled_function = true;
7936 } else if (descr_get != NULL) {
7937 PyObject *descr_method = descr_get(init_method, obj, called);
7938
7939 if (unlikely(descr_method == NULL)) {
7940 return NULL;
7941 }
7942
7943 init_method = descr_method;
7944 }
7945
7946 PyObject *result;
7947 if (is_compiled_function) {
7948 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7949 args, 9);
7950 } else {
7951 result = CALL_FUNCTION_WITH_POS_ARGS9(tstate, init_method, pos_args);
7952 Py_DECREF(init_method);
7953 }
7954 if (unlikely(result == NULL)) {
7955 return NULL;
7956 }
7957
7958 Py_DECREF(result);
7959
7960 if (unlikely(result != Py_None)) {
7961 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7962 return NULL;
7963 }
7964
7965 CHECK_OBJECT_X(obj);
7966
7967 return obj;
7968#endif
7969#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7970 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7971 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7972
7973 if (likely(func != NULL)) {
7974 PyObject *result = func(called, args, 9, NULL);
7975
7976 CHECK_OBJECT_X(result);
7977
7978 return Nuitka_CheckFunctionResult(tstate, called, result);
7979 }
7980#endif
7981 }
7982
7983#if 0
7984 PRINT_NEW_LINE();
7985 PRINT_STRING("FALLBACK");
7986 PRINT_ITEM(called);
7987 PRINT_NEW_LINE();
7988#endif
7989
7990 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7991
7992 CHECK_OBJECT_X(result);
7993
7994 return result;
7995}
7996PyObject *CALL_FUNCTION_WITH_ARGS10(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
7997 CHECK_OBJECT(called);
7998 CHECK_OBJECTS(args, 10);
7999
8000 if (Nuitka_Function_Check(called)) {
8001 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8002 return NULL;
8003 }
8004
8005 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8006 PyObject *result;
8007
8008 if (function->m_args_simple && 10 == function->m_args_positional_count) {
8009 for (Py_ssize_t i = 0; i < 10; i++) {
8010 Py_INCREF(args[i]);
8011 }
8012 result = function->m_c_code(tstate, function, (PyObject **)args);
8013 } else if (function->m_args_simple && 10 + function->m_defaults_given == function->m_args_positional_count) {
8014 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8015
8016 memcpy(python_pars, args, 10 * sizeof(PyObject *));
8017 memcpy(python_pars + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8018 function->m_defaults_given * sizeof(PyObject *));
8019
8020 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
8021 Py_INCREF(python_pars[i]);
8022 }
8023
8024 result = function->m_c_code(tstate, function, python_pars);
8025 } else {
8026 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 10);
8027 }
8028
8029 Py_LeaveRecursiveCall();
8030
8031 CHECK_OBJECT_X(result);
8032
8033 return result;
8034 } else if (Nuitka_Method_Check(called)) {
8035 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
8036
8037 if (method->m_object == NULL) {
8038 PyObject *self = args[0];
8039
8040 int res = PyObject_IsInstance(self, method->m_class);
8041
8042 if (unlikely(res < 0)) {
8043 return NULL;
8044 } else if (unlikely(res == 0)) {
8045 PyErr_Format(PyExc_TypeError,
8046 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
8047 "instance instead)",
8048 GET_CALLABLE_NAME((PyObject *)method->m_function),
8049 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
8050 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
8051
8052 return NULL;
8053 }
8054
8055 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 10);
8056
8057 CHECK_OBJECT_X(result);
8058
8059 return result;
8060 } else {
8061 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8062 return NULL;
8063 }
8064
8065 struct Nuitka_FunctionObject *function = method->m_function;
8066
8067 PyObject *result;
8068
8069 if (function->m_args_simple && 10 + 1 == function->m_args_positional_count) {
8070 PyObject *python_pars[10 + 1];
8071
8072 python_pars[0] = method->m_object;
8073 Py_INCREF(method->m_object);
8074
8075 for (Py_ssize_t i = 0; i < 10; i++) {
8076 python_pars[i + 1] = args[i];
8077 Py_INCREF(args[i]);
8078 }
8079 result = function->m_c_code(tstate, function, python_pars);
8080 } else if (function->m_args_simple &&
8081 10 + 1 + function->m_defaults_given == function->m_args_positional_count) {
8082 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8083
8084 python_pars[0] = method->m_object;
8085 Py_INCREF(method->m_object);
8086
8087 memcpy(python_pars + 1, args, 10 * sizeof(PyObject *));
8088 memcpy(python_pars + 1 + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8089 function->m_defaults_given * sizeof(PyObject *));
8090
8091 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
8092 Py_INCREF(python_pars[i]);
8093 }
8094
8095 result = function->m_c_code(tstate, function, python_pars);
8096 } else {
8097 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 10);
8098 }
8099
8100 Py_LeaveRecursiveCall();
8101
8102 CHECK_OBJECT_X(result);
8103
8104 return result;
8105 }
8106#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
8107 } else if (PyCFunction_CheckExact(called)) {
8108#if PYTHON_VERSION >= 0x380
8109#ifdef _NUITKA_FULL_COMPAT
8110 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8111 return NULL;
8112 }
8113#endif
8114
8115 int flags = PyCFunction_GET_FLAGS(called);
8116
8117 PyObject *result;
8118
8119 if (!(flags & METH_VARARGS)) {
8120 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8121
8122 assert(func != NULL);
8123 result = func(called, args, 10, NULL);
8124
8125 CHECK_OBJECT_X(result);
8126 } else {
8127 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8128 PyObject *self = PyCFunction_GET_SELF(called);
8129
8130 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8131
8132 if (flags & METH_KEYWORDS) {
8133 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
8134 } else {
8135 result = (*method)(self, pos_args);
8136 }
8137
8138 Py_DECREF(pos_args);
8139 }
8140
8141#ifdef _NUITKA_FULL_COMPAT
8142 Py_LeaveRecursiveCall();
8143#endif
8144 CHECK_OBJECT_X(result);
8145
8146 return Nuitka_CheckFunctionResult(tstate, called, result);
8147#else
8148 // Try to be fast about wrapping the arguments.
8149 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
8150
8151 if (unlikely(flags & METH_NOARGS)) {
8152 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (10 given)",
8153 ((PyCFunctionObject *)called)->m_ml->ml_name);
8154 return NULL;
8155 } else if (unlikely(flags & METH_O)) {
8156 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (10 given)",
8157 ((PyCFunctionObject *)called)->m_ml->ml_name);
8158 return NULL;
8159 } else if (flags & METH_VARARGS) {
8160 // Recursion guard is not strictly necessary, as we already have
8161 // one on our way to here.
8162#ifdef _NUITKA_FULL_COMPAT
8163 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8164 return NULL;
8165 }
8166#endif
8167 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8168 PyObject *self = PyCFunction_GET_SELF(called);
8169
8170 PyObject *result;
8171
8172#if PYTHON_VERSION < 0x360
8173 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8174 if (flags & METH_KEYWORDS) {
8175 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8176 } else {
8177 result = (*method)(self, pos_args);
8178 }
8179
8180 Py_DECREF(pos_args);
8181#else
8182 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
8183 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8184 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8185 Py_DECREF(pos_args);
8186 } else if (flags == METH_FASTCALL) {
8187#if PYTHON_VERSION < 0x370
8188 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 10, NULL);
8189#else
8190 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8191 result = (*(_PyCFunctionFast)method)(self, &pos_args, 10);
8192 Py_DECREF(pos_args);
8193#endif
8194 } else {
8195 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8196 result = (*method)(self, pos_args);
8197 Py_DECREF(pos_args);
8198 }
8199#endif
8200
8201#ifdef _NUITKA_FULL_COMPAT
8202 Py_LeaveRecursiveCall();
8203#endif
8204
8205 CHECK_OBJECT_X(result);
8206
8207 return Nuitka_CheckFunctionResult(tstate, called, result);
8208 }
8209#endif
8210#endif
8211#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
8212 } else if (PyFunction_Check(called)) {
8213#if PYTHON_VERSION < 0x3b0
8214 PyObject *result = callPythonFunction(called, args, 10);
8215#else
8216 PyObject *result = _PyFunction_Vectorcall(called, args, 10, NULL);
8217#endif
8218 CHECK_OBJECT_X(result);
8219
8220 return result;
8221#endif
8222#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
8223 } else if (PyType_Check(called)) {
8224 PyTypeObject *type = Py_TYPE(called);
8225
8226 if (type->tp_call == PyType_Type.tp_call) {
8227 PyTypeObject *called_type = (PyTypeObject *)(called);
8228
8229 if (unlikely(called_type->tp_new == NULL)) {
8230 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
8231 return NULL;
8232 }
8233
8234 PyObject *pos_args = NULL;
8235 PyObject *obj;
8236
8237 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
8238 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
8239 formatCannotInstantiateAbstractClass(tstate, called_type);
8240 return NULL;
8241 }
8242
8243 obj = called_type->tp_alloc(called_type, 0);
8244 CHECK_OBJECT(obj);
8245 } else {
8246 pos_args = MAKE_TUPLE(tstate, args, 10);
8247 obj = called_type->tp_new(called_type, pos_args, NULL);
8248 }
8249
8250 if (likely(obj != NULL)) {
8251 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
8252 Py_DECREF(pos_args);
8253 return obj;
8254 }
8255
8256 // Work on produced type.
8257 type = Py_TYPE(obj);
8258
8259 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
8260 if (type->tp_init == default_tp_init_wrapper) {
8261 Py_XDECREF(pos_args);
8262 pos_args = NULL;
8263
8264 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
8265
8266 // Not really allowed, since we wouldn't have the default wrapper set.
8267 assert(init_method != NULL);
8268
8269 bool is_compiled_function = false;
8270 bool init_method_needs_release = false;
8271
8272 if (likely(init_method != NULL)) {
8273 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
8274
8275 if (func == Nuitka_Function_Type.tp_descr_get) {
8276 is_compiled_function = true;
8277 } else if (func != NULL) {
8278 init_method = func(init_method, obj, (PyObject *)(type));
8279 init_method_needs_release = true;
8280 }
8281 }
8282
8283 if (unlikely(init_method == NULL)) {
8284 if (!HAS_ERROR_OCCURRED(tstate)) {
8285 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
8286 const_str_plain___init__);
8287 }
8288
8289 return NULL;
8290 }
8291
8292 PyObject *result;
8293 if (is_compiled_function) {
8294 result = Nuitka_CallMethodFunctionPosArgs(
8295 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 10);
8296 } else {
8297 result = CALL_FUNCTION_WITH_ARGS10(tstate, init_method, args);
8298 if (init_method_needs_release) {
8299 Py_DECREF(init_method);
8300 }
8301 }
8302
8303 if (unlikely(result == NULL)) {
8304 Py_DECREF(obj);
8305 return NULL;
8306 }
8307
8308 Py_DECREF(result);
8309
8310 if (unlikely(result != Py_None)) {
8311 Py_DECREF(obj);
8312
8313 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8314 return NULL;
8315 }
8316 } else {
8317 if (pos_args == NULL) {
8318 pos_args = MAKE_TUPLE(tstate, args, 10);
8319 }
8320
8321 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
8322 Py_DECREF(obj);
8323 Py_XDECREF(pos_args);
8324 return NULL;
8325 }
8326 }
8327 }
8328 }
8329
8330 Py_XDECREF(pos_args);
8331
8332 CHECK_OBJECT_X(obj);
8333
8334 return obj;
8335 }
8336#endif
8337#if PYTHON_VERSION < 0x300
8338 } else if (PyClass_Check(called)) {
8339 PyObject *obj = PyInstance_NewRaw(called, NULL);
8340
8341 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
8342
8343 if (unlikely(init_method == NULL)) {
8344 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
8345 Py_DECREF(obj);
8346 return NULL;
8347 }
8348
8349 Py_DECREF(obj);
8350
8351 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
8352 return NULL;
8353 }
8354
8355 bool is_compiled_function = false;
8356
8357 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
8358
8359 if (descr_get == NULL) {
8360 Py_INCREF(init_method);
8361 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
8362 is_compiled_function = true;
8363 } else if (descr_get != NULL) {
8364 PyObject *descr_method = descr_get(init_method, obj, called);
8365
8366 if (unlikely(descr_method == NULL)) {
8367 return NULL;
8368 }
8369
8370 init_method = descr_method;
8371 }
8372
8373 PyObject *result;
8374 if (is_compiled_function) {
8375 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
8376 args, 10);
8377 } else {
8378 result = CALL_FUNCTION_WITH_ARGS10(tstate, init_method, args);
8379 Py_DECREF(init_method);
8380 }
8381 if (unlikely(result == NULL)) {
8382 return NULL;
8383 }
8384
8385 Py_DECREF(result);
8386
8387 if (unlikely(result != Py_None)) {
8388 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8389 return NULL;
8390 }
8391
8392 CHECK_OBJECT_X(obj);
8393
8394 return obj;
8395#endif
8396#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8397 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8398 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8399
8400 if (likely(func != NULL)) {
8401 PyObject *result = func(called, args, 10, NULL);
8402
8403 CHECK_OBJECT_X(result);
8404
8405 return Nuitka_CheckFunctionResult(tstate, called, result);
8406 }
8407#endif
8408 }
8409
8410#if 0
8411 PRINT_NEW_LINE();
8412 PRINT_STRING("FALLBACK");
8413 PRINT_ITEM(called);
8414 PRINT_NEW_LINE();
8415#endif
8416
8417 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8418
8419 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
8420
8421 Py_DECREF(pos_args);
8422
8423 CHECK_OBJECT_X(result);
8424
8425 return result;
8426}
8427PyObject *CALL_FUNCTION_WITH_POS_ARGS10(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
8428 assert(PyTuple_CheckExact(pos_args));
8429 assert(PyTuple_GET_SIZE(pos_args) == 10);
8430 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
8431 CHECK_OBJECT(called);
8432 CHECK_OBJECTS(args, 10);
8433
8434 if (Nuitka_Function_Check(called)) {
8435 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8436 return NULL;
8437 }
8438
8439 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8440 PyObject *result;
8441
8442 if (function->m_args_simple && 10 == function->m_args_positional_count) {
8443 for (Py_ssize_t i = 0; i < 10; i++) {
8444 Py_INCREF(args[i]);
8445 }
8446 result = function->m_c_code(tstate, function, (PyObject **)args);
8447 } else if (function->m_args_simple && 10 + function->m_defaults_given == function->m_args_positional_count) {
8448 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8449
8450 memcpy(python_pars, args, 10 * sizeof(PyObject *));
8451 memcpy(python_pars + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8452 function->m_defaults_given * sizeof(PyObject *));
8453
8454 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
8455 Py_INCREF(python_pars[i]);
8456 }
8457
8458 result = function->m_c_code(tstate, function, python_pars);
8459 } else {
8460 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 10);
8461 }
8462
8463 Py_LeaveRecursiveCall();
8464
8465 CHECK_OBJECT_X(result);
8466
8467 return result;
8468 } else if (Nuitka_Method_Check(called)) {
8469 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
8470
8471 if (method->m_object == NULL) {
8472 PyObject *self = args[0];
8473
8474 int res = PyObject_IsInstance(self, method->m_class);
8475
8476 if (unlikely(res < 0)) {
8477 return NULL;
8478 } else if (unlikely(res == 0)) {
8479 PyErr_Format(PyExc_TypeError,
8480 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
8481 "instance instead)",
8482 GET_CALLABLE_NAME((PyObject *)method->m_function),
8483 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
8484 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
8485
8486 return NULL;
8487 }
8488
8489 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 10);
8490
8491 CHECK_OBJECT_X(result);
8492
8493 return result;
8494 } else {
8495 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8496 return NULL;
8497 }
8498
8499 struct Nuitka_FunctionObject *function = method->m_function;
8500
8501 PyObject *result;
8502
8503 if (function->m_args_simple && 10 + 1 == function->m_args_positional_count) {
8504 PyObject *python_pars[10 + 1];
8505
8506 python_pars[0] = method->m_object;
8507 Py_INCREF(method->m_object);
8508
8509 for (Py_ssize_t i = 0; i < 10; i++) {
8510 python_pars[i + 1] = args[i];
8511 Py_INCREF(args[i]);
8512 }
8513 result = function->m_c_code(tstate, function, python_pars);
8514 } else if (function->m_args_simple &&
8515 10 + 1 + function->m_defaults_given == function->m_args_positional_count) {
8516 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8517
8518 python_pars[0] = method->m_object;
8519 Py_INCREF(method->m_object);
8520
8521 memcpy(python_pars + 1, args, 10 * sizeof(PyObject *));
8522 memcpy(python_pars + 1 + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8523 function->m_defaults_given * sizeof(PyObject *));
8524
8525 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
8526 Py_INCREF(python_pars[i]);
8527 }
8528
8529 result = function->m_c_code(tstate, function, python_pars);
8530 } else {
8531 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 10);
8532 }
8533
8534 Py_LeaveRecursiveCall();
8535
8536 CHECK_OBJECT_X(result);
8537
8538 return result;
8539 }
8540#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
8541 } else if (PyCFunction_CheckExact(called)) {
8542#if PYTHON_VERSION >= 0x380
8543#ifdef _NUITKA_FULL_COMPAT
8544 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8545 return NULL;
8546 }
8547#endif
8548
8549 int flags = PyCFunction_GET_FLAGS(called);
8550
8551 PyObject *result;
8552
8553 if (!(flags & METH_VARARGS)) {
8554 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8555
8556 assert(func != NULL);
8557 result = func(called, args, 10, NULL);
8558
8559 CHECK_OBJECT_X(result);
8560 } else {
8561 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8562 PyObject *self = PyCFunction_GET_SELF(called);
8563
8564 if (flags & METH_KEYWORDS) {
8565 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
8566 } else {
8567 result = (*method)(self, pos_args);
8568 }
8569 }
8570
8571#ifdef _NUITKA_FULL_COMPAT
8572 Py_LeaveRecursiveCall();
8573#endif
8574 CHECK_OBJECT_X(result);
8575
8576 return Nuitka_CheckFunctionResult(tstate, called, result);
8577#else
8578 // Try to be fast about wrapping the arguments.
8579 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
8580
8581 if (unlikely(flags & METH_NOARGS)) {
8582 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (10 given)",
8583 ((PyCFunctionObject *)called)->m_ml->ml_name);
8584 return NULL;
8585 } else if (unlikely(flags & METH_O)) {
8586 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (10 given)",
8587 ((PyCFunctionObject *)called)->m_ml->ml_name);
8588 return NULL;
8589 } else if (flags & METH_VARARGS) {
8590 // Recursion guard is not strictly necessary, as we already have
8591 // one on our way to here.
8592#ifdef _NUITKA_FULL_COMPAT
8593 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8594 return NULL;
8595 }
8596#endif
8597 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8598 PyObject *self = PyCFunction_GET_SELF(called);
8599
8600 PyObject *result;
8601
8602#if PYTHON_VERSION < 0x360
8603 if (flags & METH_KEYWORDS) {
8604 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8605 } else {
8606 result = (*method)(self, pos_args);
8607 }
8608
8609#else
8610 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
8611 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8612 } else if (flags == METH_FASTCALL) {
8613#if PYTHON_VERSION < 0x370
8614 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 10, NULL);
8615#else
8616 result = (*(_PyCFunctionFast)method)(self, &pos_args, 10);
8617#endif
8618 } else {
8619 result = (*method)(self, pos_args);
8620 }
8621#endif
8622
8623#ifdef _NUITKA_FULL_COMPAT
8624 Py_LeaveRecursiveCall();
8625#endif
8626
8627 CHECK_OBJECT_X(result);
8628
8629 return Nuitka_CheckFunctionResult(tstate, called, result);
8630 }
8631#endif
8632#endif
8633#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
8634 } else if (PyFunction_Check(called)) {
8635#if PYTHON_VERSION < 0x3b0
8636 PyObject *result = callPythonFunction(called, args, 10);
8637#else
8638 PyObject *result = _PyFunction_Vectorcall(called, args, 10, NULL);
8639#endif
8640 CHECK_OBJECT_X(result);
8641
8642 return result;
8643#endif
8644#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
8645 } else if (PyType_Check(called)) {
8646 PyTypeObject *type = Py_TYPE(called);
8647
8648 if (type->tp_call == PyType_Type.tp_call) {
8649 PyTypeObject *called_type = (PyTypeObject *)(called);
8650
8651 if (unlikely(called_type->tp_new == NULL)) {
8652 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
8653 return NULL;
8654 }
8655
8656 PyObject *obj;
8657
8658 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
8659 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
8660 formatCannotInstantiateAbstractClass(tstate, called_type);
8661 return NULL;
8662 }
8663
8664 obj = called_type->tp_alloc(called_type, 0);
8665 CHECK_OBJECT(obj);
8666 } else {
8667 obj = called_type->tp_new(called_type, pos_args, NULL);
8668 }
8669
8670 if (likely(obj != NULL)) {
8671 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
8672 return obj;
8673 }
8674
8675 // Work on produced type.
8676 type = Py_TYPE(obj);
8677
8678 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
8679 if (type->tp_init == default_tp_init_wrapper) {
8680
8681 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
8682
8683 // Not really allowed, since we wouldn't have the default wrapper set.
8684 assert(init_method != NULL);
8685
8686 bool is_compiled_function = false;
8687 bool init_method_needs_release = false;
8688
8689 if (likely(init_method != NULL)) {
8690 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
8691
8692 if (func == Nuitka_Function_Type.tp_descr_get) {
8693 is_compiled_function = true;
8694 } else if (func != NULL) {
8695 init_method = func(init_method, obj, (PyObject *)(type));
8696 init_method_needs_release = true;
8697 }
8698 }
8699
8700 if (unlikely(init_method == NULL)) {
8701 if (!HAS_ERROR_OCCURRED(tstate)) {
8702 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
8703 const_str_plain___init__);
8704 }
8705
8706 return NULL;
8707 }
8708
8709 PyObject *result;
8710 if (is_compiled_function) {
8711 result = Nuitka_CallMethodFunctionPosArgs(
8712 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 10);
8713 } else {
8714 result = CALL_FUNCTION_WITH_POS_ARGS10(tstate, init_method, pos_args);
8715 if (init_method_needs_release) {
8716 Py_DECREF(init_method);
8717 }
8718 }
8719
8720 if (unlikely(result == NULL)) {
8721 Py_DECREF(obj);
8722 return NULL;
8723 }
8724
8725 Py_DECREF(result);
8726
8727 if (unlikely(result != Py_None)) {
8728 Py_DECREF(obj);
8729
8730 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8731 return NULL;
8732 }
8733 } else {
8734
8735 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
8736 Py_DECREF(obj);
8737 return NULL;
8738 }
8739 }
8740 }
8741 }
8742
8743 CHECK_OBJECT_X(obj);
8744
8745 return obj;
8746 }
8747#endif
8748#if PYTHON_VERSION < 0x300
8749 } else if (PyClass_Check(called)) {
8750 PyObject *obj = PyInstance_NewRaw(called, NULL);
8751
8752 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
8753
8754 if (unlikely(init_method == NULL)) {
8755 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
8756 Py_DECREF(obj);
8757 return NULL;
8758 }
8759
8760 Py_DECREF(obj);
8761
8762 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
8763 return NULL;
8764 }
8765
8766 bool is_compiled_function = false;
8767
8768 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
8769
8770 if (descr_get == NULL) {
8771 Py_INCREF(init_method);
8772 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
8773 is_compiled_function = true;
8774 } else if (descr_get != NULL) {
8775 PyObject *descr_method = descr_get(init_method, obj, called);
8776
8777 if (unlikely(descr_method == NULL)) {
8778 return NULL;
8779 }
8780
8781 init_method = descr_method;
8782 }
8783
8784 PyObject *result;
8785 if (is_compiled_function) {
8786 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
8787 args, 10);
8788 } else {
8789 result = CALL_FUNCTION_WITH_POS_ARGS10(tstate, init_method, pos_args);
8790 Py_DECREF(init_method);
8791 }
8792 if (unlikely(result == NULL)) {
8793 return NULL;
8794 }
8795
8796 Py_DECREF(result);
8797
8798 if (unlikely(result != Py_None)) {
8799 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8800 return NULL;
8801 }
8802
8803 CHECK_OBJECT_X(obj);
8804
8805 return obj;
8806#endif
8807#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8808 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8809 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8810
8811 if (likely(func != NULL)) {
8812 PyObject *result = func(called, args, 10, NULL);
8813
8814 CHECK_OBJECT_X(result);
8815
8816 return Nuitka_CheckFunctionResult(tstate, called, result);
8817 }
8818#endif
8819 }
8820
8821#if 0
8822 PRINT_NEW_LINE();
8823 PRINT_STRING("FALLBACK");
8824 PRINT_ITEM(called);
8825 PRINT_NEW_LINE();
8826#endif
8827
8828 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
8829
8830 CHECK_OBJECT_X(result);
8831
8832 return result;
8833}
8834PyObject *CALL_FUNCTION_WITH_NO_ARGS_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *kw_values,
8835 PyObject *kw_names) {
8836
8837 CHECK_OBJECT(kw_names);
8838 assert(PyTuple_CheckExact(kw_names));
8839 CHECK_OBJECT(called);
8840
8841 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
8842
8843 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
8844
8845 if (Nuitka_Function_Check(called)) {
8846 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8847 return NULL;
8848 }
8849
8850 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8851
8852 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, NULL, 0, kw_values, kw_names);
8853
8854 Py_LeaveRecursiveCall();
8855
8856 CHECK_OBJECT_X(result);
8857
8858 return result;
8859#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8860 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8861 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8862
8863 if (likely(func != NULL)) {
8864 PyObject *result = func(called, kw_values, 0, kw_names);
8865
8866 CHECK_OBJECT_X(result);
8867
8868 return Nuitka_CheckFunctionResult(tstate, called, result);
8869 }
8870#endif
8871 }
8872
8873#if 0
8874 PRINT_STRING("FALLBACK");
8875 PRINT_ITEM(called);
8876 PRINT_NEW_LINE();
8877#endif
8878
8879 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
8880
8881 if (unlikely(call_slot == NULL)) {
8882 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
8883
8884 return NULL;
8885 }
8886
8887 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8888 return NULL;
8889 }
8890
8891 PyObject *pos_args = const_tuple_empty;
8892
8893 PyObject *named_args = _PyDict_NewPresized(nkwargs);
8894
8895 for (Py_ssize_t i = 0; i < nkwargs; i++) {
8896 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
8897
8898 PyObject *value = kw_values[i];
8899
8900 CHECK_OBJECT(key);
8901 CHECK_OBJECT(value);
8902
8903 DICT_SET_ITEM(named_args, key, value);
8904 }
8905
8906 PyObject *result = (*call_slot)(called, pos_args, named_args);
8907
8908 Py_DECREF(named_args);
8909
8910 Py_LeaveRecursiveCall();
8911
8912 CHECK_OBJECT_X(result);
8913
8914 return Nuitka_CheckFunctionResult(tstate, called, result);
8915}
8916PyObject *CALL_FUNCTION_WITH_ARGS1_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
8917 PyObject *kw_names) {
8918 CHECK_OBJECTS(args, 1);
8919 CHECK_OBJECT(kw_names);
8920 assert(PyTuple_CheckExact(kw_names));
8921 CHECK_OBJECT(called);
8922
8923 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
8924
8925 CHECK_OBJECTS(&args[1], nkwargs);
8926
8927 if (Nuitka_Function_Check(called)) {
8928 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8929 return NULL;
8930 }
8931
8932 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8933
8934 PyObject *result =
8935 Nuitka_CallFunctionVectorcall(tstate, function, args, 1, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
8936
8937 Py_LeaveRecursiveCall();
8938
8939 CHECK_OBJECT_X(result);
8940
8941 return result;
8942#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8943 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8944 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8945
8946 if (likely(func != NULL)) {
8947 PyObject *result = func(called, args, 1, kw_names);
8948
8949 CHECK_OBJECT_X(result);
8950
8951 return Nuitka_CheckFunctionResult(tstate, called, result);
8952 }
8953#endif
8954 }
8955
8956#if 0
8957 PRINT_STRING("FALLBACK");
8958 PRINT_ITEM(called);
8959 PRINT_NEW_LINE();
8960#endif
8961
8962 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
8963
8964 if (unlikely(call_slot == NULL)) {
8965 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
8966
8967 return NULL;
8968 }
8969
8970 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8971 return NULL;
8972 }
8973
8974 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
8975
8976 PyObject *named_args = _PyDict_NewPresized(nkwargs);
8977
8978 for (Py_ssize_t i = 0; i < nkwargs; i++) {
8979 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
8980
8981 PyObject *value = args[1 + i];
8982
8983 CHECK_OBJECT(key);
8984 CHECK_OBJECT(value);
8985
8986 DICT_SET_ITEM(named_args, key, value);
8987 }
8988
8989 PyObject *result = (*call_slot)(called, pos_args, named_args);
8990
8991 Py_DECREF(pos_args);
8992 Py_DECREF(named_args);
8993
8994 Py_LeaveRecursiveCall();
8995
8996 CHECK_OBJECT_X(result);
8997
8998 return Nuitka_CheckFunctionResult(tstate, called, result);
8999}
9000PyObject *CALL_FUNCTION_WITH_ARGS1_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9001 PyObject *const *kw_values, PyObject *kw_names) {
9002 CHECK_OBJECTS(args, 1);
9003 CHECK_OBJECT(kw_names);
9004 assert(PyTuple_CheckExact(kw_names));
9005 CHECK_OBJECT(called);
9006
9007 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9008
9009 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9010
9011 if (Nuitka_Function_Check(called)) {
9012 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9013 return NULL;
9014 }
9015
9016 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9017
9018 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 1, kw_values, kw_names);
9019
9020 Py_LeaveRecursiveCall();
9021
9022 CHECK_OBJECT_X(result);
9023
9024 return result;
9025#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9026 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9027 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9028
9029 if (likely(func != NULL)) {
9030 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 1 + nkwargs);
9031
9032 memcpy(vectorcall_args, args, 1 * sizeof(PyObject *));
9033 memcpy(&vectorcall_args[1], kw_values, nkwargs * sizeof(PyObject *));
9034
9035 PyObject *result = func(called, vectorcall_args, 1, kw_names);
9036
9037 CHECK_OBJECT_X(result);
9038
9039 return Nuitka_CheckFunctionResult(tstate, called, result);
9040 }
9041#endif
9042 }
9043
9044#if 0
9045 PRINT_STRING("FALLBACK");
9046 PRINT_ITEM(called);
9047 PRINT_NEW_LINE();
9048#endif
9049
9050 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9051
9052 if (unlikely(call_slot == NULL)) {
9053 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9054
9055 return NULL;
9056 }
9057
9058 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9059 return NULL;
9060 }
9061
9062 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
9063
9064 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9065
9066 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9067 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9068
9069 PyObject *value = kw_values[i];
9070
9071 CHECK_OBJECT(key);
9072 CHECK_OBJECT(value);
9073
9074 DICT_SET_ITEM(named_args, key, value);
9075 }
9076
9077 PyObject *result = (*call_slot)(called, pos_args, named_args);
9078
9079 Py_DECREF(pos_args);
9080 Py_DECREF(named_args);
9081
9082 Py_LeaveRecursiveCall();
9083
9084 CHECK_OBJECT_X(result);
9085
9086 return Nuitka_CheckFunctionResult(tstate, called, result);
9087}
9088PyObject *CALL_FUNCTION_WITH_POS_ARGS1_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9089 PyObject *const *kw_values, PyObject *kw_names) {
9090 assert(PyTuple_CheckExact(pos_args));
9091 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9092 CHECK_OBJECTS(args, 1);
9093 CHECK_OBJECT(kw_names);
9094 assert(PyTuple_CheckExact(kw_names));
9095 CHECK_OBJECT(called);
9096
9097 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9098
9099 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9100
9101 if (Nuitka_Function_Check(called)) {
9102 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9103 return NULL;
9104 }
9105
9106 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9107
9108 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 1, kw_values, kw_names);
9109
9110 Py_LeaveRecursiveCall();
9111
9112 CHECK_OBJECT_X(result);
9113
9114 return result;
9115#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9116 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9117 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9118
9119 if (likely(func != NULL)) {
9120 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 1 + nkwargs);
9121
9122 memcpy(vectorcall_args, args, 1 * sizeof(PyObject *));
9123 memcpy(&vectorcall_args[1], kw_values, nkwargs * sizeof(PyObject *));
9124
9125 PyObject *result = func(called, vectorcall_args, 1, kw_names);
9126
9127 CHECK_OBJECT_X(result);
9128
9129 return Nuitka_CheckFunctionResult(tstate, called, result);
9130 }
9131#endif
9132 }
9133
9134#if 0
9135 PRINT_STRING("FALLBACK");
9136 PRINT_ITEM(called);
9137 PRINT_NEW_LINE();
9138#endif
9139
9140 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9141
9142 if (unlikely(call_slot == NULL)) {
9143 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9144
9145 return NULL;
9146 }
9147
9148 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9149 return NULL;
9150 }
9151
9152 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9153
9154 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9155 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9156
9157 PyObject *value = kw_values[i];
9158
9159 CHECK_OBJECT(key);
9160 CHECK_OBJECT(value);
9161
9162 DICT_SET_ITEM(named_args, key, value);
9163 }
9164
9165 PyObject *result = (*call_slot)(called, pos_args, named_args);
9166
9167 Py_DECREF(named_args);
9168
9169 Py_LeaveRecursiveCall();
9170
9171 CHECK_OBJECT_X(result);
9172
9173 return Nuitka_CheckFunctionResult(tstate, called, result);
9174}
9175PyObject *CALL_FUNCTION_WITH_ARGS2_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9176 PyObject *kw_names) {
9177 CHECK_OBJECTS(args, 2);
9178 CHECK_OBJECT(kw_names);
9179 assert(PyTuple_CheckExact(kw_names));
9180 CHECK_OBJECT(called);
9181
9182 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9183
9184 CHECK_OBJECTS(&args[2], nkwargs);
9185
9186 if (Nuitka_Function_Check(called)) {
9187 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9188 return NULL;
9189 }
9190
9191 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9192
9193 PyObject *result =
9194 Nuitka_CallFunctionVectorcall(tstate, function, args, 2, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9195
9196 Py_LeaveRecursiveCall();
9197
9198 CHECK_OBJECT_X(result);
9199
9200 return result;
9201#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9202 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9203 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9204
9205 if (likely(func != NULL)) {
9206 PyObject *result = func(called, args, 2, kw_names);
9207
9208 CHECK_OBJECT_X(result);
9209
9210 return Nuitka_CheckFunctionResult(tstate, called, result);
9211 }
9212#endif
9213 }
9214
9215#if 0
9216 PRINT_STRING("FALLBACK");
9217 PRINT_ITEM(called);
9218 PRINT_NEW_LINE();
9219#endif
9220
9221 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9222
9223 if (unlikely(call_slot == NULL)) {
9224 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9225
9226 return NULL;
9227 }
9228
9229 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9230 return NULL;
9231 }
9232
9233 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
9234
9235 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9236
9237 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9238 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9239
9240 PyObject *value = args[2 + i];
9241
9242 CHECK_OBJECT(key);
9243 CHECK_OBJECT(value);
9244
9245 DICT_SET_ITEM(named_args, key, value);
9246 }
9247
9248 PyObject *result = (*call_slot)(called, pos_args, named_args);
9249
9250 Py_DECREF(pos_args);
9251 Py_DECREF(named_args);
9252
9253 Py_LeaveRecursiveCall();
9254
9255 CHECK_OBJECT_X(result);
9256
9257 return Nuitka_CheckFunctionResult(tstate, called, result);
9258}
9259PyObject *CALL_FUNCTION_WITH_ARGS2_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9260 PyObject *const *kw_values, PyObject *kw_names) {
9261 CHECK_OBJECTS(args, 2);
9262 CHECK_OBJECT(kw_names);
9263 assert(PyTuple_CheckExact(kw_names));
9264 CHECK_OBJECT(called);
9265
9266 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9267
9268 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9269
9270 if (Nuitka_Function_Check(called)) {
9271 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9272 return NULL;
9273 }
9274
9275 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9276
9277 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 2, kw_values, kw_names);
9278
9279 Py_LeaveRecursiveCall();
9280
9281 CHECK_OBJECT_X(result);
9282
9283 return result;
9284#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9285 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9286 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9287
9288 if (likely(func != NULL)) {
9289 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 2 + nkwargs);
9290
9291 memcpy(vectorcall_args, args, 2 * sizeof(PyObject *));
9292 memcpy(&vectorcall_args[2], kw_values, nkwargs * sizeof(PyObject *));
9293
9294 PyObject *result = func(called, vectorcall_args, 2, kw_names);
9295
9296 CHECK_OBJECT_X(result);
9297
9298 return Nuitka_CheckFunctionResult(tstate, called, result);
9299 }
9300#endif
9301 }
9302
9303#if 0
9304 PRINT_STRING("FALLBACK");
9305 PRINT_ITEM(called);
9306 PRINT_NEW_LINE();
9307#endif
9308
9309 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9310
9311 if (unlikely(call_slot == NULL)) {
9312 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9313
9314 return NULL;
9315 }
9316
9317 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9318 return NULL;
9319 }
9320
9321 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
9322
9323 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9324
9325 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9326 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9327
9328 PyObject *value = kw_values[i];
9329
9330 CHECK_OBJECT(key);
9331 CHECK_OBJECT(value);
9332
9333 DICT_SET_ITEM(named_args, key, value);
9334 }
9335
9336 PyObject *result = (*call_slot)(called, pos_args, named_args);
9337
9338 Py_DECREF(pos_args);
9339 Py_DECREF(named_args);
9340
9341 Py_LeaveRecursiveCall();
9342
9343 CHECK_OBJECT_X(result);
9344
9345 return Nuitka_CheckFunctionResult(tstate, called, result);
9346}
9347PyObject *CALL_FUNCTION_WITH_POS_ARGS2_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9348 PyObject *const *kw_values, PyObject *kw_names) {
9349 assert(PyTuple_CheckExact(pos_args));
9350 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9351 CHECK_OBJECTS(args, 2);
9352 CHECK_OBJECT(kw_names);
9353 assert(PyTuple_CheckExact(kw_names));
9354 CHECK_OBJECT(called);
9355
9356 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9357
9358 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9359
9360 if (Nuitka_Function_Check(called)) {
9361 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9362 return NULL;
9363 }
9364
9365 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9366
9367 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 2, kw_values, kw_names);
9368
9369 Py_LeaveRecursiveCall();
9370
9371 CHECK_OBJECT_X(result);
9372
9373 return result;
9374#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9375 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9376 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9377
9378 if (likely(func != NULL)) {
9379 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 2 + nkwargs);
9380
9381 memcpy(vectorcall_args, args, 2 * sizeof(PyObject *));
9382 memcpy(&vectorcall_args[2], kw_values, nkwargs * sizeof(PyObject *));
9383
9384 PyObject *result = func(called, vectorcall_args, 2, kw_names);
9385
9386 CHECK_OBJECT_X(result);
9387
9388 return Nuitka_CheckFunctionResult(tstate, called, result);
9389 }
9390#endif
9391 }
9392
9393#if 0
9394 PRINT_STRING("FALLBACK");
9395 PRINT_ITEM(called);
9396 PRINT_NEW_LINE();
9397#endif
9398
9399 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9400
9401 if (unlikely(call_slot == NULL)) {
9402 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9403
9404 return NULL;
9405 }
9406
9407 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9408 return NULL;
9409 }
9410
9411 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9412
9413 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9414 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9415
9416 PyObject *value = kw_values[i];
9417
9418 CHECK_OBJECT(key);
9419 CHECK_OBJECT(value);
9420
9421 DICT_SET_ITEM(named_args, key, value);
9422 }
9423
9424 PyObject *result = (*call_slot)(called, pos_args, named_args);
9425
9426 Py_DECREF(named_args);
9427
9428 Py_LeaveRecursiveCall();
9429
9430 CHECK_OBJECT_X(result);
9431
9432 return Nuitka_CheckFunctionResult(tstate, called, result);
9433}
9434PyObject *CALL_FUNCTION_WITH_ARGS3_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9435 PyObject *kw_names) {
9436 CHECK_OBJECTS(args, 3);
9437 CHECK_OBJECT(kw_names);
9438 assert(PyTuple_CheckExact(kw_names));
9439 CHECK_OBJECT(called);
9440
9441 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9442
9443 CHECK_OBJECTS(&args[3], nkwargs);
9444
9445 if (Nuitka_Function_Check(called)) {
9446 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9447 return NULL;
9448 }
9449
9450 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9451
9452 PyObject *result =
9453 Nuitka_CallFunctionVectorcall(tstate, function, args, 3, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9454
9455 Py_LeaveRecursiveCall();
9456
9457 CHECK_OBJECT_X(result);
9458
9459 return result;
9460#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9461 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9462 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9463
9464 if (likely(func != NULL)) {
9465 PyObject *result = func(called, args, 3, kw_names);
9466
9467 CHECK_OBJECT_X(result);
9468
9469 return Nuitka_CheckFunctionResult(tstate, called, result);
9470 }
9471#endif
9472 }
9473
9474#if 0
9475 PRINT_STRING("FALLBACK");
9476 PRINT_ITEM(called);
9477 PRINT_NEW_LINE();
9478#endif
9479
9480 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9481
9482 if (unlikely(call_slot == NULL)) {
9483 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9484
9485 return NULL;
9486 }
9487
9488 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9489 return NULL;
9490 }
9491
9492 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
9493
9494 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9495
9496 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9497 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9498
9499 PyObject *value = args[3 + i];
9500
9501 CHECK_OBJECT(key);
9502 CHECK_OBJECT(value);
9503
9504 DICT_SET_ITEM(named_args, key, value);
9505 }
9506
9507 PyObject *result = (*call_slot)(called, pos_args, named_args);
9508
9509 Py_DECREF(pos_args);
9510 Py_DECREF(named_args);
9511
9512 Py_LeaveRecursiveCall();
9513
9514 CHECK_OBJECT_X(result);
9515
9516 return Nuitka_CheckFunctionResult(tstate, called, result);
9517}
9518PyObject *CALL_FUNCTION_WITH_ARGS3_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9519 PyObject *const *kw_values, PyObject *kw_names) {
9520 CHECK_OBJECTS(args, 3);
9521 CHECK_OBJECT(kw_names);
9522 assert(PyTuple_CheckExact(kw_names));
9523 CHECK_OBJECT(called);
9524
9525 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9526
9527 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9528
9529 if (Nuitka_Function_Check(called)) {
9530 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9531 return NULL;
9532 }
9533
9534 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9535
9536 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 3, kw_values, kw_names);
9537
9538 Py_LeaveRecursiveCall();
9539
9540 CHECK_OBJECT_X(result);
9541
9542 return result;
9543#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9544 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9545 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9546
9547 if (likely(func != NULL)) {
9548 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 3 + nkwargs);
9549
9550 memcpy(vectorcall_args, args, 3 * sizeof(PyObject *));
9551 memcpy(&vectorcall_args[3], kw_values, nkwargs * sizeof(PyObject *));
9552
9553 PyObject *result = func(called, vectorcall_args, 3, kw_names);
9554
9555 CHECK_OBJECT_X(result);
9556
9557 return Nuitka_CheckFunctionResult(tstate, called, result);
9558 }
9559#endif
9560 }
9561
9562#if 0
9563 PRINT_STRING("FALLBACK");
9564 PRINT_ITEM(called);
9565 PRINT_NEW_LINE();
9566#endif
9567
9568 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9569
9570 if (unlikely(call_slot == NULL)) {
9571 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9572
9573 return NULL;
9574 }
9575
9576 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9577 return NULL;
9578 }
9579
9580 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
9581
9582 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9583
9584 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9585 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9586
9587 PyObject *value = kw_values[i];
9588
9589 CHECK_OBJECT(key);
9590 CHECK_OBJECT(value);
9591
9592 DICT_SET_ITEM(named_args, key, value);
9593 }
9594
9595 PyObject *result = (*call_slot)(called, pos_args, named_args);
9596
9597 Py_DECREF(pos_args);
9598 Py_DECREF(named_args);
9599
9600 Py_LeaveRecursiveCall();
9601
9602 CHECK_OBJECT_X(result);
9603
9604 return Nuitka_CheckFunctionResult(tstate, called, result);
9605}
9606PyObject *CALL_FUNCTION_WITH_POS_ARGS3_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9607 PyObject *const *kw_values, PyObject *kw_names) {
9608 assert(PyTuple_CheckExact(pos_args));
9609 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9610 CHECK_OBJECTS(args, 3);
9611 CHECK_OBJECT(kw_names);
9612 assert(PyTuple_CheckExact(kw_names));
9613 CHECK_OBJECT(called);
9614
9615 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9616
9617 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9618
9619 if (Nuitka_Function_Check(called)) {
9620 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9621 return NULL;
9622 }
9623
9624 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9625
9626 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 3, kw_values, kw_names);
9627
9628 Py_LeaveRecursiveCall();
9629
9630 CHECK_OBJECT_X(result);
9631
9632 return result;
9633#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9634 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9635 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9636
9637 if (likely(func != NULL)) {
9638 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 3 + nkwargs);
9639
9640 memcpy(vectorcall_args, args, 3 * sizeof(PyObject *));
9641 memcpy(&vectorcall_args[3], kw_values, nkwargs * sizeof(PyObject *));
9642
9643 PyObject *result = func(called, vectorcall_args, 3, kw_names);
9644
9645 CHECK_OBJECT_X(result);
9646
9647 return Nuitka_CheckFunctionResult(tstate, called, result);
9648 }
9649#endif
9650 }
9651
9652#if 0
9653 PRINT_STRING("FALLBACK");
9654 PRINT_ITEM(called);
9655 PRINT_NEW_LINE();
9656#endif
9657
9658 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9659
9660 if (unlikely(call_slot == NULL)) {
9661 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9662
9663 return NULL;
9664 }
9665
9666 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9667 return NULL;
9668 }
9669
9670 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9671
9672 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9673 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9674
9675 PyObject *value = kw_values[i];
9676
9677 CHECK_OBJECT(key);
9678 CHECK_OBJECT(value);
9679
9680 DICT_SET_ITEM(named_args, key, value);
9681 }
9682
9683 PyObject *result = (*call_slot)(called, pos_args, named_args);
9684
9685 Py_DECREF(named_args);
9686
9687 Py_LeaveRecursiveCall();
9688
9689 CHECK_OBJECT_X(result);
9690
9691 return Nuitka_CheckFunctionResult(tstate, called, result);
9692}
9693PyObject *CALL_FUNCTION_WITH_ARGS4_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9694 PyObject *kw_names) {
9695 CHECK_OBJECTS(args, 4);
9696 CHECK_OBJECT(kw_names);
9697 assert(PyTuple_CheckExact(kw_names));
9698 CHECK_OBJECT(called);
9699
9700 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9701
9702 CHECK_OBJECTS(&args[4], nkwargs);
9703
9704 if (Nuitka_Function_Check(called)) {
9705 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9706 return NULL;
9707 }
9708
9709 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9710
9711 PyObject *result =
9712 Nuitka_CallFunctionVectorcall(tstate, function, args, 4, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9713
9714 Py_LeaveRecursiveCall();
9715
9716 CHECK_OBJECT_X(result);
9717
9718 return result;
9719#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9720 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9721 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9722
9723 if (likely(func != NULL)) {
9724 PyObject *result = func(called, args, 4, kw_names);
9725
9726 CHECK_OBJECT_X(result);
9727
9728 return Nuitka_CheckFunctionResult(tstate, called, result);
9729 }
9730#endif
9731 }
9732
9733#if 0
9734 PRINT_STRING("FALLBACK");
9735 PRINT_ITEM(called);
9736 PRINT_NEW_LINE();
9737#endif
9738
9739 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9740
9741 if (unlikely(call_slot == NULL)) {
9742 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9743
9744 return NULL;
9745 }
9746
9747 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9748 return NULL;
9749 }
9750
9751 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
9752
9753 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9754
9755 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9756 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9757
9758 PyObject *value = args[4 + i];
9759
9760 CHECK_OBJECT(key);
9761 CHECK_OBJECT(value);
9762
9763 DICT_SET_ITEM(named_args, key, value);
9764 }
9765
9766 PyObject *result = (*call_slot)(called, pos_args, named_args);
9767
9768 Py_DECREF(pos_args);
9769 Py_DECREF(named_args);
9770
9771 Py_LeaveRecursiveCall();
9772
9773 CHECK_OBJECT_X(result);
9774
9775 return Nuitka_CheckFunctionResult(tstate, called, result);
9776}
9777PyObject *CALL_FUNCTION_WITH_ARGS4_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9778 PyObject *const *kw_values, PyObject *kw_names) {
9779 CHECK_OBJECTS(args, 4);
9780 CHECK_OBJECT(kw_names);
9781 assert(PyTuple_CheckExact(kw_names));
9782 CHECK_OBJECT(called);
9783
9784 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9785
9786 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9787
9788 if (Nuitka_Function_Check(called)) {
9789 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9790 return NULL;
9791 }
9792
9793 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9794
9795 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 4, kw_values, kw_names);
9796
9797 Py_LeaveRecursiveCall();
9798
9799 CHECK_OBJECT_X(result);
9800
9801 return result;
9802#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9803 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9804 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9805
9806 if (likely(func != NULL)) {
9807 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 4 + nkwargs);
9808
9809 memcpy(vectorcall_args, args, 4 * sizeof(PyObject *));
9810 memcpy(&vectorcall_args[4], kw_values, nkwargs * sizeof(PyObject *));
9811
9812 PyObject *result = func(called, vectorcall_args, 4, kw_names);
9813
9814 CHECK_OBJECT_X(result);
9815
9816 return Nuitka_CheckFunctionResult(tstate, called, result);
9817 }
9818#endif
9819 }
9820
9821#if 0
9822 PRINT_STRING("FALLBACK");
9823 PRINT_ITEM(called);
9824 PRINT_NEW_LINE();
9825#endif
9826
9827 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9828
9829 if (unlikely(call_slot == NULL)) {
9830 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9831
9832 return NULL;
9833 }
9834
9835 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9836 return NULL;
9837 }
9838
9839 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
9840
9841 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9842
9843 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9844 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9845
9846 PyObject *value = kw_values[i];
9847
9848 CHECK_OBJECT(key);
9849 CHECK_OBJECT(value);
9850
9851 DICT_SET_ITEM(named_args, key, value);
9852 }
9853
9854 PyObject *result = (*call_slot)(called, pos_args, named_args);
9855
9856 Py_DECREF(pos_args);
9857 Py_DECREF(named_args);
9858
9859 Py_LeaveRecursiveCall();
9860
9861 CHECK_OBJECT_X(result);
9862
9863 return Nuitka_CheckFunctionResult(tstate, called, result);
9864}
9865PyObject *CALL_FUNCTION_WITH_POS_ARGS4_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9866 PyObject *const *kw_values, PyObject *kw_names) {
9867 assert(PyTuple_CheckExact(pos_args));
9868 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9869 CHECK_OBJECTS(args, 4);
9870 CHECK_OBJECT(kw_names);
9871 assert(PyTuple_CheckExact(kw_names));
9872 CHECK_OBJECT(called);
9873
9874 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9875
9876 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9877
9878 if (Nuitka_Function_Check(called)) {
9879 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9880 return NULL;
9881 }
9882
9883 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9884
9885 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 4, kw_values, kw_names);
9886
9887 Py_LeaveRecursiveCall();
9888
9889 CHECK_OBJECT_X(result);
9890
9891 return result;
9892#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9893 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9894 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9895
9896 if (likely(func != NULL)) {
9897 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 4 + nkwargs);
9898
9899 memcpy(vectorcall_args, args, 4 * sizeof(PyObject *));
9900 memcpy(&vectorcall_args[4], kw_values, nkwargs * sizeof(PyObject *));
9901
9902 PyObject *result = func(called, vectorcall_args, 4, kw_names);
9903
9904 CHECK_OBJECT_X(result);
9905
9906 return Nuitka_CheckFunctionResult(tstate, called, result);
9907 }
9908#endif
9909 }
9910
9911#if 0
9912 PRINT_STRING("FALLBACK");
9913 PRINT_ITEM(called);
9914 PRINT_NEW_LINE();
9915#endif
9916
9917 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9918
9919 if (unlikely(call_slot == NULL)) {
9920 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9921
9922 return NULL;
9923 }
9924
9925 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9926 return NULL;
9927 }
9928
9929 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9930
9931 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9932 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9933
9934 PyObject *value = kw_values[i];
9935
9936 CHECK_OBJECT(key);
9937 CHECK_OBJECT(value);
9938
9939 DICT_SET_ITEM(named_args, key, value);
9940 }
9941
9942 PyObject *result = (*call_slot)(called, pos_args, named_args);
9943
9944 Py_DECREF(named_args);
9945
9946 Py_LeaveRecursiveCall();
9947
9948 CHECK_OBJECT_X(result);
9949
9950 return Nuitka_CheckFunctionResult(tstate, called, result);
9951}
9952PyObject *CALL_FUNCTION_WITH_ARGS5_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9953 PyObject *kw_names) {
9954 CHECK_OBJECTS(args, 5);
9955 CHECK_OBJECT(kw_names);
9956 assert(PyTuple_CheckExact(kw_names));
9957 CHECK_OBJECT(called);
9958
9959 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9960
9961 CHECK_OBJECTS(&args[5], nkwargs);
9962
9963 if (Nuitka_Function_Check(called)) {
9964 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9965 return NULL;
9966 }
9967
9968 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9969
9970 PyObject *result =
9971 Nuitka_CallFunctionVectorcall(tstate, function, args, 5, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9972
9973 Py_LeaveRecursiveCall();
9974
9975 CHECK_OBJECT_X(result);
9976
9977 return result;
9978#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9979 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9980 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9981
9982 if (likely(func != NULL)) {
9983 PyObject *result = func(called, args, 5, kw_names);
9984
9985 CHECK_OBJECT_X(result);
9986
9987 return Nuitka_CheckFunctionResult(tstate, called, result);
9988 }
9989#endif
9990 }
9991
9992#if 0
9993 PRINT_STRING("FALLBACK");
9994 PRINT_ITEM(called);
9995 PRINT_NEW_LINE();
9996#endif
9997
9998 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9999
10000 if (unlikely(call_slot == NULL)) {
10001 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10002
10003 return NULL;
10004 }
10005
10006 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10007 return NULL;
10008 }
10009
10010 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
10011
10012 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10013
10014 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10015 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10016
10017 PyObject *value = args[5 + i];
10018
10019 CHECK_OBJECT(key);
10020 CHECK_OBJECT(value);
10021
10022 DICT_SET_ITEM(named_args, key, value);
10023 }
10024
10025 PyObject *result = (*call_slot)(called, pos_args, named_args);
10026
10027 Py_DECREF(pos_args);
10028 Py_DECREF(named_args);
10029
10030 Py_LeaveRecursiveCall();
10031
10032 CHECK_OBJECT_X(result);
10033
10034 return Nuitka_CheckFunctionResult(tstate, called, result);
10035}
10036PyObject *CALL_FUNCTION_WITH_ARGS5_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10037 PyObject *const *kw_values, PyObject *kw_names) {
10038 CHECK_OBJECTS(args, 5);
10039 CHECK_OBJECT(kw_names);
10040 assert(PyTuple_CheckExact(kw_names));
10041 CHECK_OBJECT(called);
10042
10043 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10044
10045 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10046
10047 if (Nuitka_Function_Check(called)) {
10048 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10049 return NULL;
10050 }
10051
10052 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10053
10054 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 5, kw_values, kw_names);
10055
10056 Py_LeaveRecursiveCall();
10057
10058 CHECK_OBJECT_X(result);
10059
10060 return result;
10061#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10062 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10063 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10064
10065 if (likely(func != NULL)) {
10066 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 5 + nkwargs);
10067
10068 memcpy(vectorcall_args, args, 5 * sizeof(PyObject *));
10069 memcpy(&vectorcall_args[5], kw_values, nkwargs * sizeof(PyObject *));
10070
10071 PyObject *result = func(called, vectorcall_args, 5, kw_names);
10072
10073 CHECK_OBJECT_X(result);
10074
10075 return Nuitka_CheckFunctionResult(tstate, called, result);
10076 }
10077#endif
10078 }
10079
10080#if 0
10081 PRINT_STRING("FALLBACK");
10082 PRINT_ITEM(called);
10083 PRINT_NEW_LINE();
10084#endif
10085
10086 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10087
10088 if (unlikely(call_slot == NULL)) {
10089 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10090
10091 return NULL;
10092 }
10093
10094 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10095 return NULL;
10096 }
10097
10098 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
10099
10100 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10101
10102 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10103 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10104
10105 PyObject *value = kw_values[i];
10106
10107 CHECK_OBJECT(key);
10108 CHECK_OBJECT(value);
10109
10110 DICT_SET_ITEM(named_args, key, value);
10111 }
10112
10113 PyObject *result = (*call_slot)(called, pos_args, named_args);
10114
10115 Py_DECREF(pos_args);
10116 Py_DECREF(named_args);
10117
10118 Py_LeaveRecursiveCall();
10119
10120 CHECK_OBJECT_X(result);
10121
10122 return Nuitka_CheckFunctionResult(tstate, called, result);
10123}
10124PyObject *CALL_FUNCTION_WITH_POS_ARGS5_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10125 PyObject *const *kw_values, PyObject *kw_names) {
10126 assert(PyTuple_CheckExact(pos_args));
10127 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10128 CHECK_OBJECTS(args, 5);
10129 CHECK_OBJECT(kw_names);
10130 assert(PyTuple_CheckExact(kw_names));
10131 CHECK_OBJECT(called);
10132
10133 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10134
10135 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10136
10137 if (Nuitka_Function_Check(called)) {
10138 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10139 return NULL;
10140 }
10141
10142 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10143
10144 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 5, kw_values, kw_names);
10145
10146 Py_LeaveRecursiveCall();
10147
10148 CHECK_OBJECT_X(result);
10149
10150 return result;
10151#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10152 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10153 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10154
10155 if (likely(func != NULL)) {
10156 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 5 + nkwargs);
10157
10158 memcpy(vectorcall_args, args, 5 * sizeof(PyObject *));
10159 memcpy(&vectorcall_args[5], kw_values, nkwargs * sizeof(PyObject *));
10160
10161 PyObject *result = func(called, vectorcall_args, 5, kw_names);
10162
10163 CHECK_OBJECT_X(result);
10164
10165 return Nuitka_CheckFunctionResult(tstate, called, result);
10166 }
10167#endif
10168 }
10169
10170#if 0
10171 PRINT_STRING("FALLBACK");
10172 PRINT_ITEM(called);
10173 PRINT_NEW_LINE();
10174#endif
10175
10176 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10177
10178 if (unlikely(call_slot == NULL)) {
10179 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10180
10181 return NULL;
10182 }
10183
10184 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10185 return NULL;
10186 }
10187
10188 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10189
10190 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10191 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10192
10193 PyObject *value = kw_values[i];
10194
10195 CHECK_OBJECT(key);
10196 CHECK_OBJECT(value);
10197
10198 DICT_SET_ITEM(named_args, key, value);
10199 }
10200
10201 PyObject *result = (*call_slot)(called, pos_args, named_args);
10202
10203 Py_DECREF(named_args);
10204
10205 Py_LeaveRecursiveCall();
10206
10207 CHECK_OBJECT_X(result);
10208
10209 return Nuitka_CheckFunctionResult(tstate, called, result);
10210}
10211PyObject *CALL_FUNCTION_WITH_ARGS6_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10212 PyObject *kw_names) {
10213 CHECK_OBJECTS(args, 6);
10214 CHECK_OBJECT(kw_names);
10215 assert(PyTuple_CheckExact(kw_names));
10216 CHECK_OBJECT(called);
10217
10218 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10219
10220 CHECK_OBJECTS(&args[6], nkwargs);
10221
10222 if (Nuitka_Function_Check(called)) {
10223 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10224 return NULL;
10225 }
10226
10227 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10228
10229 PyObject *result =
10230 Nuitka_CallFunctionVectorcall(tstate, function, args, 6, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
10231
10232 Py_LeaveRecursiveCall();
10233
10234 CHECK_OBJECT_X(result);
10235
10236 return result;
10237#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10238 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10239 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10240
10241 if (likely(func != NULL)) {
10242 PyObject *result = func(called, args, 6, kw_names);
10243
10244 CHECK_OBJECT_X(result);
10245
10246 return Nuitka_CheckFunctionResult(tstate, called, result);
10247 }
10248#endif
10249 }
10250
10251#if 0
10252 PRINT_STRING("FALLBACK");
10253 PRINT_ITEM(called);
10254 PRINT_NEW_LINE();
10255#endif
10256
10257 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10258
10259 if (unlikely(call_slot == NULL)) {
10260 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10261
10262 return NULL;
10263 }
10264
10265 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10266 return NULL;
10267 }
10268
10269 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
10270
10271 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10272
10273 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10274 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10275
10276 PyObject *value = args[6 + i];
10277
10278 CHECK_OBJECT(key);
10279 CHECK_OBJECT(value);
10280
10281 DICT_SET_ITEM(named_args, key, value);
10282 }
10283
10284 PyObject *result = (*call_slot)(called, pos_args, named_args);
10285
10286 Py_DECREF(pos_args);
10287 Py_DECREF(named_args);
10288
10289 Py_LeaveRecursiveCall();
10290
10291 CHECK_OBJECT_X(result);
10292
10293 return Nuitka_CheckFunctionResult(tstate, called, result);
10294}
10295PyObject *CALL_FUNCTION_WITH_ARGS6_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10296 PyObject *const *kw_values, PyObject *kw_names) {
10297 CHECK_OBJECTS(args, 6);
10298 CHECK_OBJECT(kw_names);
10299 assert(PyTuple_CheckExact(kw_names));
10300 CHECK_OBJECT(called);
10301
10302 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10303
10304 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10305
10306 if (Nuitka_Function_Check(called)) {
10307 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10308 return NULL;
10309 }
10310
10311 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10312
10313 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 6, kw_values, kw_names);
10314
10315 Py_LeaveRecursiveCall();
10316
10317 CHECK_OBJECT_X(result);
10318
10319 return result;
10320#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10321 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10322 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10323
10324 if (likely(func != NULL)) {
10325 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 6 + nkwargs);
10326
10327 memcpy(vectorcall_args, args, 6 * sizeof(PyObject *));
10328 memcpy(&vectorcall_args[6], kw_values, nkwargs * sizeof(PyObject *));
10329
10330 PyObject *result = func(called, vectorcall_args, 6, kw_names);
10331
10332 CHECK_OBJECT_X(result);
10333
10334 return Nuitka_CheckFunctionResult(tstate, called, result);
10335 }
10336#endif
10337 }
10338
10339#if 0
10340 PRINT_STRING("FALLBACK");
10341 PRINT_ITEM(called);
10342 PRINT_NEW_LINE();
10343#endif
10344
10345 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10346
10347 if (unlikely(call_slot == NULL)) {
10348 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10349
10350 return NULL;
10351 }
10352
10353 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10354 return NULL;
10355 }
10356
10357 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
10358
10359 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10360
10361 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10362 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10363
10364 PyObject *value = kw_values[i];
10365
10366 CHECK_OBJECT(key);
10367 CHECK_OBJECT(value);
10368
10369 DICT_SET_ITEM(named_args, key, value);
10370 }
10371
10372 PyObject *result = (*call_slot)(called, pos_args, named_args);
10373
10374 Py_DECREF(pos_args);
10375 Py_DECREF(named_args);
10376
10377 Py_LeaveRecursiveCall();
10378
10379 CHECK_OBJECT_X(result);
10380
10381 return Nuitka_CheckFunctionResult(tstate, called, result);
10382}
10383PyObject *CALL_FUNCTION_WITH_POS_ARGS6_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10384 PyObject *const *kw_values, PyObject *kw_names) {
10385 assert(PyTuple_CheckExact(pos_args));
10386 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10387 CHECK_OBJECTS(args, 6);
10388 CHECK_OBJECT(kw_names);
10389 assert(PyTuple_CheckExact(kw_names));
10390 CHECK_OBJECT(called);
10391
10392 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10393
10394 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10395
10396 if (Nuitka_Function_Check(called)) {
10397 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10398 return NULL;
10399 }
10400
10401 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10402
10403 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 6, kw_values, kw_names);
10404
10405 Py_LeaveRecursiveCall();
10406
10407 CHECK_OBJECT_X(result);
10408
10409 return result;
10410#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10411 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10412 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10413
10414 if (likely(func != NULL)) {
10415 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 6 + nkwargs);
10416
10417 memcpy(vectorcall_args, args, 6 * sizeof(PyObject *));
10418 memcpy(&vectorcall_args[6], kw_values, nkwargs * sizeof(PyObject *));
10419
10420 PyObject *result = func(called, vectorcall_args, 6, kw_names);
10421
10422 CHECK_OBJECT_X(result);
10423
10424 return Nuitka_CheckFunctionResult(tstate, called, result);
10425 }
10426#endif
10427 }
10428
10429#if 0
10430 PRINT_STRING("FALLBACK");
10431 PRINT_ITEM(called);
10432 PRINT_NEW_LINE();
10433#endif
10434
10435 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10436
10437 if (unlikely(call_slot == NULL)) {
10438 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10439
10440 return NULL;
10441 }
10442
10443 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10444 return NULL;
10445 }
10446
10447 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10448
10449 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10450 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10451
10452 PyObject *value = kw_values[i];
10453
10454 CHECK_OBJECT(key);
10455 CHECK_OBJECT(value);
10456
10457 DICT_SET_ITEM(named_args, key, value);
10458 }
10459
10460 PyObject *result = (*call_slot)(called, pos_args, named_args);
10461
10462 Py_DECREF(named_args);
10463
10464 Py_LeaveRecursiveCall();
10465
10466 CHECK_OBJECT_X(result);
10467
10468 return Nuitka_CheckFunctionResult(tstate, called, result);
10469}
10470PyObject *CALL_FUNCTION_WITH_ARGS7_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10471 PyObject *kw_names) {
10472 CHECK_OBJECTS(args, 7);
10473 CHECK_OBJECT(kw_names);
10474 assert(PyTuple_CheckExact(kw_names));
10475 CHECK_OBJECT(called);
10476
10477 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10478
10479 CHECK_OBJECTS(&args[7], nkwargs);
10480
10481 if (Nuitka_Function_Check(called)) {
10482 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10483 return NULL;
10484 }
10485
10486 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10487
10488 PyObject *result =
10489 Nuitka_CallFunctionVectorcall(tstate, function, args, 7, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
10490
10491 Py_LeaveRecursiveCall();
10492
10493 CHECK_OBJECT_X(result);
10494
10495 return result;
10496#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10497 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10498 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10499
10500 if (likely(func != NULL)) {
10501 PyObject *result = func(called, args, 7, kw_names);
10502
10503 CHECK_OBJECT_X(result);
10504
10505 return Nuitka_CheckFunctionResult(tstate, called, result);
10506 }
10507#endif
10508 }
10509
10510#if 0
10511 PRINT_STRING("FALLBACK");
10512 PRINT_ITEM(called);
10513 PRINT_NEW_LINE();
10514#endif
10515
10516 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10517
10518 if (unlikely(call_slot == NULL)) {
10519 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10520
10521 return NULL;
10522 }
10523
10524 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10525 return NULL;
10526 }
10527
10528 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
10529
10530 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10531
10532 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10533 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10534
10535 PyObject *value = args[7 + i];
10536
10537 CHECK_OBJECT(key);
10538 CHECK_OBJECT(value);
10539
10540 DICT_SET_ITEM(named_args, key, value);
10541 }
10542
10543 PyObject *result = (*call_slot)(called, pos_args, named_args);
10544
10545 Py_DECREF(pos_args);
10546 Py_DECREF(named_args);
10547
10548 Py_LeaveRecursiveCall();
10549
10550 CHECK_OBJECT_X(result);
10551
10552 return Nuitka_CheckFunctionResult(tstate, called, result);
10553}
10554PyObject *CALL_FUNCTION_WITH_ARGS7_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10555 PyObject *const *kw_values, PyObject *kw_names) {
10556 CHECK_OBJECTS(args, 7);
10557 CHECK_OBJECT(kw_names);
10558 assert(PyTuple_CheckExact(kw_names));
10559 CHECK_OBJECT(called);
10560
10561 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10562
10563 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10564
10565 if (Nuitka_Function_Check(called)) {
10566 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10567 return NULL;
10568 }
10569
10570 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10571
10572 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 7, kw_values, kw_names);
10573
10574 Py_LeaveRecursiveCall();
10575
10576 CHECK_OBJECT_X(result);
10577
10578 return result;
10579#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10580 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10581 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10582
10583 if (likely(func != NULL)) {
10584 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 7 + nkwargs);
10585
10586 memcpy(vectorcall_args, args, 7 * sizeof(PyObject *));
10587 memcpy(&vectorcall_args[7], kw_values, nkwargs * sizeof(PyObject *));
10588
10589 PyObject *result = func(called, vectorcall_args, 7, kw_names);
10590
10591 CHECK_OBJECT_X(result);
10592
10593 return Nuitka_CheckFunctionResult(tstate, called, result);
10594 }
10595#endif
10596 }
10597
10598#if 0
10599 PRINT_STRING("FALLBACK");
10600 PRINT_ITEM(called);
10601 PRINT_NEW_LINE();
10602#endif
10603
10604 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10605
10606 if (unlikely(call_slot == NULL)) {
10607 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10608
10609 return NULL;
10610 }
10611
10612 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10613 return NULL;
10614 }
10615
10616 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
10617
10618 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10619
10620 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10621 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10622
10623 PyObject *value = kw_values[i];
10624
10625 CHECK_OBJECT(key);
10626 CHECK_OBJECT(value);
10627
10628 DICT_SET_ITEM(named_args, key, value);
10629 }
10630
10631 PyObject *result = (*call_slot)(called, pos_args, named_args);
10632
10633 Py_DECREF(pos_args);
10634 Py_DECREF(named_args);
10635
10636 Py_LeaveRecursiveCall();
10637
10638 CHECK_OBJECT_X(result);
10639
10640 return Nuitka_CheckFunctionResult(tstate, called, result);
10641}
10642PyObject *CALL_FUNCTION_WITH_POS_ARGS7_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10643 PyObject *const *kw_values, PyObject *kw_names) {
10644 assert(PyTuple_CheckExact(pos_args));
10645 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10646 CHECK_OBJECTS(args, 7);
10647 CHECK_OBJECT(kw_names);
10648 assert(PyTuple_CheckExact(kw_names));
10649 CHECK_OBJECT(called);
10650
10651 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10652
10653 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10654
10655 if (Nuitka_Function_Check(called)) {
10656 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10657 return NULL;
10658 }
10659
10660 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10661
10662 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 7, kw_values, kw_names);
10663
10664 Py_LeaveRecursiveCall();
10665
10666 CHECK_OBJECT_X(result);
10667
10668 return result;
10669#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10670 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10671 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10672
10673 if (likely(func != NULL)) {
10674 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 7 + nkwargs);
10675
10676 memcpy(vectorcall_args, args, 7 * sizeof(PyObject *));
10677 memcpy(&vectorcall_args[7], kw_values, nkwargs * sizeof(PyObject *));
10678
10679 PyObject *result = func(called, vectorcall_args, 7, kw_names);
10680
10681 CHECK_OBJECT_X(result);
10682
10683 return Nuitka_CheckFunctionResult(tstate, called, result);
10684 }
10685#endif
10686 }
10687
10688#if 0
10689 PRINT_STRING("FALLBACK");
10690 PRINT_ITEM(called);
10691 PRINT_NEW_LINE();
10692#endif
10693
10694 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10695
10696 if (unlikely(call_slot == NULL)) {
10697 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10698
10699 return NULL;
10700 }
10701
10702 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10703 return NULL;
10704 }
10705
10706 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10707
10708 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10709 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10710
10711 PyObject *value = kw_values[i];
10712
10713 CHECK_OBJECT(key);
10714 CHECK_OBJECT(value);
10715
10716 DICT_SET_ITEM(named_args, key, value);
10717 }
10718
10719 PyObject *result = (*call_slot)(called, pos_args, named_args);
10720
10721 Py_DECREF(named_args);
10722
10723 Py_LeaveRecursiveCall();
10724
10725 CHECK_OBJECT_X(result);
10726
10727 return Nuitka_CheckFunctionResult(tstate, called, result);
10728}
10729PyObject *CALL_FUNCTION_WITH_ARGS8_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10730 PyObject *kw_names) {
10731 CHECK_OBJECTS(args, 8);
10732 CHECK_OBJECT(kw_names);
10733 assert(PyTuple_CheckExact(kw_names));
10734 CHECK_OBJECT(called);
10735
10736 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10737
10738 CHECK_OBJECTS(&args[8], nkwargs);
10739
10740 if (Nuitka_Function_Check(called)) {
10741 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10742 return NULL;
10743 }
10744
10745 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10746
10747 PyObject *result =
10748 Nuitka_CallFunctionVectorcall(tstate, function, args, 8, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
10749
10750 Py_LeaveRecursiveCall();
10751
10752 CHECK_OBJECT_X(result);
10753
10754 return result;
10755#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10756 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10757 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10758
10759 if (likely(func != NULL)) {
10760 PyObject *result = func(called, args, 8, kw_names);
10761
10762 CHECK_OBJECT_X(result);
10763
10764 return Nuitka_CheckFunctionResult(tstate, called, result);
10765 }
10766#endif
10767 }
10768
10769#if 0
10770 PRINT_STRING("FALLBACK");
10771 PRINT_ITEM(called);
10772 PRINT_NEW_LINE();
10773#endif
10774
10775 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10776
10777 if (unlikely(call_slot == NULL)) {
10778 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10779
10780 return NULL;
10781 }
10782
10783 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10784 return NULL;
10785 }
10786
10787 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
10788
10789 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10790
10791 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10792 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10793
10794 PyObject *value = args[8 + i];
10795
10796 CHECK_OBJECT(key);
10797 CHECK_OBJECT(value);
10798
10799 DICT_SET_ITEM(named_args, key, value);
10800 }
10801
10802 PyObject *result = (*call_slot)(called, pos_args, named_args);
10803
10804 Py_DECREF(pos_args);
10805 Py_DECREF(named_args);
10806
10807 Py_LeaveRecursiveCall();
10808
10809 CHECK_OBJECT_X(result);
10810
10811 return Nuitka_CheckFunctionResult(tstate, called, result);
10812}
10813PyObject *CALL_FUNCTION_WITH_ARGS8_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10814 PyObject *const *kw_values, PyObject *kw_names) {
10815 CHECK_OBJECTS(args, 8);
10816 CHECK_OBJECT(kw_names);
10817 assert(PyTuple_CheckExact(kw_names));
10818 CHECK_OBJECT(called);
10819
10820 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10821
10822 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10823
10824 if (Nuitka_Function_Check(called)) {
10825 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10826 return NULL;
10827 }
10828
10829 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10830
10831 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 8, kw_values, kw_names);
10832
10833 Py_LeaveRecursiveCall();
10834
10835 CHECK_OBJECT_X(result);
10836
10837 return result;
10838#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10839 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10840 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10841
10842 if (likely(func != NULL)) {
10843 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 8 + nkwargs);
10844
10845 memcpy(vectorcall_args, args, 8 * sizeof(PyObject *));
10846 memcpy(&vectorcall_args[8], kw_values, nkwargs * sizeof(PyObject *));
10847
10848 PyObject *result = func(called, vectorcall_args, 8, kw_names);
10849
10850 CHECK_OBJECT_X(result);
10851
10852 return Nuitka_CheckFunctionResult(tstate, called, result);
10853 }
10854#endif
10855 }
10856
10857#if 0
10858 PRINT_STRING("FALLBACK");
10859 PRINT_ITEM(called);
10860 PRINT_NEW_LINE();
10861#endif
10862
10863 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10864
10865 if (unlikely(call_slot == NULL)) {
10866 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10867
10868 return NULL;
10869 }
10870
10871 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10872 return NULL;
10873 }
10874
10875 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
10876
10877 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10878
10879 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10880 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10881
10882 PyObject *value = kw_values[i];
10883
10884 CHECK_OBJECT(key);
10885 CHECK_OBJECT(value);
10886
10887 DICT_SET_ITEM(named_args, key, value);
10888 }
10889
10890 PyObject *result = (*call_slot)(called, pos_args, named_args);
10891
10892 Py_DECREF(pos_args);
10893 Py_DECREF(named_args);
10894
10895 Py_LeaveRecursiveCall();
10896
10897 CHECK_OBJECT_X(result);
10898
10899 return Nuitka_CheckFunctionResult(tstate, called, result);
10900}
10901PyObject *CALL_FUNCTION_WITH_POS_ARGS8_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10902 PyObject *const *kw_values, PyObject *kw_names) {
10903 assert(PyTuple_CheckExact(pos_args));
10904 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10905 CHECK_OBJECTS(args, 8);
10906 CHECK_OBJECT(kw_names);
10907 assert(PyTuple_CheckExact(kw_names));
10908 CHECK_OBJECT(called);
10909
10910 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10911
10912 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10913
10914 if (Nuitka_Function_Check(called)) {
10915 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10916 return NULL;
10917 }
10918
10919 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10920
10921 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 8, kw_values, kw_names);
10922
10923 Py_LeaveRecursiveCall();
10924
10925 CHECK_OBJECT_X(result);
10926
10927 return result;
10928#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10929 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10930 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10931
10932 if (likely(func != NULL)) {
10933 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 8 + nkwargs);
10934
10935 memcpy(vectorcall_args, args, 8 * sizeof(PyObject *));
10936 memcpy(&vectorcall_args[8], kw_values, nkwargs * sizeof(PyObject *));
10937
10938 PyObject *result = func(called, vectorcall_args, 8, kw_names);
10939
10940 CHECK_OBJECT_X(result);
10941
10942 return Nuitka_CheckFunctionResult(tstate, called, result);
10943 }
10944#endif
10945 }
10946
10947#if 0
10948 PRINT_STRING("FALLBACK");
10949 PRINT_ITEM(called);
10950 PRINT_NEW_LINE();
10951#endif
10952
10953 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10954
10955 if (unlikely(call_slot == NULL)) {
10956 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10957
10958 return NULL;
10959 }
10960
10961 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10962 return NULL;
10963 }
10964
10965 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10966
10967 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10968 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10969
10970 PyObject *value = kw_values[i];
10971
10972 CHECK_OBJECT(key);
10973 CHECK_OBJECT(value);
10974
10975 DICT_SET_ITEM(named_args, key, value);
10976 }
10977
10978 PyObject *result = (*call_slot)(called, pos_args, named_args);
10979
10980 Py_DECREF(named_args);
10981
10982 Py_LeaveRecursiveCall();
10983
10984 CHECK_OBJECT_X(result);
10985
10986 return Nuitka_CheckFunctionResult(tstate, called, result);
10987}
10988PyObject *CALL_FUNCTION_WITH_ARGS9_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10989 PyObject *kw_names) {
10990 CHECK_OBJECTS(args, 9);
10991 CHECK_OBJECT(kw_names);
10992 assert(PyTuple_CheckExact(kw_names));
10993 CHECK_OBJECT(called);
10994
10995 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10996
10997 CHECK_OBJECTS(&args[9], nkwargs);
10998
10999 if (Nuitka_Function_Check(called)) {
11000 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11001 return NULL;
11002 }
11003
11004 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11005
11006 PyObject *result =
11007 Nuitka_CallFunctionVectorcall(tstate, function, args, 9, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
11008
11009 Py_LeaveRecursiveCall();
11010
11011 CHECK_OBJECT_X(result);
11012
11013 return result;
11014#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11015 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11016 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11017
11018 if (likely(func != NULL)) {
11019 PyObject *result = func(called, args, 9, kw_names);
11020
11021 CHECK_OBJECT_X(result);
11022
11023 return Nuitka_CheckFunctionResult(tstate, called, result);
11024 }
11025#endif
11026 }
11027
11028#if 0
11029 PRINT_STRING("FALLBACK");
11030 PRINT_ITEM(called);
11031 PRINT_NEW_LINE();
11032#endif
11033
11034 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11035
11036 if (unlikely(call_slot == NULL)) {
11037 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11038
11039 return NULL;
11040 }
11041
11042 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11043 return NULL;
11044 }
11045
11046 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
11047
11048 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11049
11050 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11051 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11052
11053 PyObject *value = args[9 + i];
11054
11055 CHECK_OBJECT(key);
11056 CHECK_OBJECT(value);
11057
11058 DICT_SET_ITEM(named_args, key, value);
11059 }
11060
11061 PyObject *result = (*call_slot)(called, pos_args, named_args);
11062
11063 Py_DECREF(pos_args);
11064 Py_DECREF(named_args);
11065
11066 Py_LeaveRecursiveCall();
11067
11068 CHECK_OBJECT_X(result);
11069
11070 return Nuitka_CheckFunctionResult(tstate, called, result);
11071}
11072PyObject *CALL_FUNCTION_WITH_ARGS9_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11073 PyObject *const *kw_values, PyObject *kw_names) {
11074 CHECK_OBJECTS(args, 9);
11075 CHECK_OBJECT(kw_names);
11076 assert(PyTuple_CheckExact(kw_names));
11077 CHECK_OBJECT(called);
11078
11079 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11080
11081 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11082
11083 if (Nuitka_Function_Check(called)) {
11084 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11085 return NULL;
11086 }
11087
11088 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11089
11090 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 9, kw_values, kw_names);
11091
11092 Py_LeaveRecursiveCall();
11093
11094 CHECK_OBJECT_X(result);
11095
11096 return result;
11097#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11098 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11099 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11100
11101 if (likely(func != NULL)) {
11102 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 9 + nkwargs);
11103
11104 memcpy(vectorcall_args, args, 9 * sizeof(PyObject *));
11105 memcpy(&vectorcall_args[9], kw_values, nkwargs * sizeof(PyObject *));
11106
11107 PyObject *result = func(called, vectorcall_args, 9, kw_names);
11108
11109 CHECK_OBJECT_X(result);
11110
11111 return Nuitka_CheckFunctionResult(tstate, called, result);
11112 }
11113#endif
11114 }
11115
11116#if 0
11117 PRINT_STRING("FALLBACK");
11118 PRINT_ITEM(called);
11119 PRINT_NEW_LINE();
11120#endif
11121
11122 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11123
11124 if (unlikely(call_slot == NULL)) {
11125 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11126
11127 return NULL;
11128 }
11129
11130 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11131 return NULL;
11132 }
11133
11134 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
11135
11136 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11137
11138 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11139 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11140
11141 PyObject *value = kw_values[i];
11142
11143 CHECK_OBJECT(key);
11144 CHECK_OBJECT(value);
11145
11146 DICT_SET_ITEM(named_args, key, value);
11147 }
11148
11149 PyObject *result = (*call_slot)(called, pos_args, named_args);
11150
11151 Py_DECREF(pos_args);
11152 Py_DECREF(named_args);
11153
11154 Py_LeaveRecursiveCall();
11155
11156 CHECK_OBJECT_X(result);
11157
11158 return Nuitka_CheckFunctionResult(tstate, called, result);
11159}
11160PyObject *CALL_FUNCTION_WITH_POS_ARGS9_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
11161 PyObject *const *kw_values, PyObject *kw_names) {
11162 assert(PyTuple_CheckExact(pos_args));
11163 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
11164 CHECK_OBJECTS(args, 9);
11165 CHECK_OBJECT(kw_names);
11166 assert(PyTuple_CheckExact(kw_names));
11167 CHECK_OBJECT(called);
11168
11169 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11170
11171 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11172
11173 if (Nuitka_Function_Check(called)) {
11174 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11175 return NULL;
11176 }
11177
11178 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11179
11180 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 9, kw_values, kw_names);
11181
11182 Py_LeaveRecursiveCall();
11183
11184 CHECK_OBJECT_X(result);
11185
11186 return result;
11187#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11188 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11189 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11190
11191 if (likely(func != NULL)) {
11192 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 9 + nkwargs);
11193
11194 memcpy(vectorcall_args, args, 9 * sizeof(PyObject *));
11195 memcpy(&vectorcall_args[9], kw_values, nkwargs * sizeof(PyObject *));
11196
11197 PyObject *result = func(called, vectorcall_args, 9, kw_names);
11198
11199 CHECK_OBJECT_X(result);
11200
11201 return Nuitka_CheckFunctionResult(tstate, called, result);
11202 }
11203#endif
11204 }
11205
11206#if 0
11207 PRINT_STRING("FALLBACK");
11208 PRINT_ITEM(called);
11209 PRINT_NEW_LINE();
11210#endif
11211
11212 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11213
11214 if (unlikely(call_slot == NULL)) {
11215 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11216
11217 return NULL;
11218 }
11219
11220 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11221 return NULL;
11222 }
11223
11224 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11225
11226 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11227 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11228
11229 PyObject *value = kw_values[i];
11230
11231 CHECK_OBJECT(key);
11232 CHECK_OBJECT(value);
11233
11234 DICT_SET_ITEM(named_args, key, value);
11235 }
11236
11237 PyObject *result = (*call_slot)(called, pos_args, named_args);
11238
11239 Py_DECREF(named_args);
11240
11241 Py_LeaveRecursiveCall();
11242
11243 CHECK_OBJECT_X(result);
11244
11245 return Nuitka_CheckFunctionResult(tstate, called, result);
11246}
11247PyObject *CALL_FUNCTION_WITH_ARGS10_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11248 PyObject *kw_names) {
11249 CHECK_OBJECTS(args, 10);
11250 CHECK_OBJECT(kw_names);
11251 assert(PyTuple_CheckExact(kw_names));
11252 CHECK_OBJECT(called);
11253
11254 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11255
11256 CHECK_OBJECTS(&args[10], nkwargs);
11257
11258 if (Nuitka_Function_Check(called)) {
11259 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11260 return NULL;
11261 }
11262
11263 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11264
11265 PyObject *result =
11266 Nuitka_CallFunctionVectorcall(tstate, function, args, 10, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
11267
11268 Py_LeaveRecursiveCall();
11269
11270 CHECK_OBJECT_X(result);
11271
11272 return result;
11273#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11274 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11275 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11276
11277 if (likely(func != NULL)) {
11278 PyObject *result = func(called, args, 10, kw_names);
11279
11280 CHECK_OBJECT_X(result);
11281
11282 return Nuitka_CheckFunctionResult(tstate, called, result);
11283 }
11284#endif
11285 }
11286
11287#if 0
11288 PRINT_STRING("FALLBACK");
11289 PRINT_ITEM(called);
11290 PRINT_NEW_LINE();
11291#endif
11292
11293 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11294
11295 if (unlikely(call_slot == NULL)) {
11296 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11297
11298 return NULL;
11299 }
11300
11301 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11302 return NULL;
11303 }
11304
11305 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
11306
11307 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11308
11309 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11310 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11311
11312 PyObject *value = args[10 + i];
11313
11314 CHECK_OBJECT(key);
11315 CHECK_OBJECT(value);
11316
11317 DICT_SET_ITEM(named_args, key, value);
11318 }
11319
11320 PyObject *result = (*call_slot)(called, pos_args, named_args);
11321
11322 Py_DECREF(pos_args);
11323 Py_DECREF(named_args);
11324
11325 Py_LeaveRecursiveCall();
11326
11327 CHECK_OBJECT_X(result);
11328
11329 return Nuitka_CheckFunctionResult(tstate, called, result);
11330}
11331PyObject *CALL_FUNCTION_WITH_ARGS10_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11332 PyObject *const *kw_values, PyObject *kw_names) {
11333 CHECK_OBJECTS(args, 10);
11334 CHECK_OBJECT(kw_names);
11335 assert(PyTuple_CheckExact(kw_names));
11336 CHECK_OBJECT(called);
11337
11338 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11339
11340 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11341
11342 if (Nuitka_Function_Check(called)) {
11343 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11344 return NULL;
11345 }
11346
11347 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11348
11349 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 10, kw_values, kw_names);
11350
11351 Py_LeaveRecursiveCall();
11352
11353 CHECK_OBJECT_X(result);
11354
11355 return result;
11356#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11357 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11358 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11359
11360 if (likely(func != NULL)) {
11361 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 10 + nkwargs);
11362
11363 memcpy(vectorcall_args, args, 10 * sizeof(PyObject *));
11364 memcpy(&vectorcall_args[10], kw_values, nkwargs * sizeof(PyObject *));
11365
11366 PyObject *result = func(called, vectorcall_args, 10, kw_names);
11367
11368 CHECK_OBJECT_X(result);
11369
11370 return Nuitka_CheckFunctionResult(tstate, called, result);
11371 }
11372#endif
11373 }
11374
11375#if 0
11376 PRINT_STRING("FALLBACK");
11377 PRINT_ITEM(called);
11378 PRINT_NEW_LINE();
11379#endif
11380
11381 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11382
11383 if (unlikely(call_slot == NULL)) {
11384 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11385
11386 return NULL;
11387 }
11388
11389 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11390 return NULL;
11391 }
11392
11393 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
11394
11395 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11396
11397 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11398 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11399
11400 PyObject *value = kw_values[i];
11401
11402 CHECK_OBJECT(key);
11403 CHECK_OBJECT(value);
11404
11405 DICT_SET_ITEM(named_args, key, value);
11406 }
11407
11408 PyObject *result = (*call_slot)(called, pos_args, named_args);
11409
11410 Py_DECREF(pos_args);
11411 Py_DECREF(named_args);
11412
11413 Py_LeaveRecursiveCall();
11414
11415 CHECK_OBJECT_X(result);
11416
11417 return Nuitka_CheckFunctionResult(tstate, called, result);
11418}
11419PyObject *CALL_FUNCTION_WITH_POS_ARGS10_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
11420 PyObject *const *kw_values, PyObject *kw_names) {
11421 assert(PyTuple_CheckExact(pos_args));
11422 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
11423 CHECK_OBJECTS(args, 10);
11424 CHECK_OBJECT(kw_names);
11425 assert(PyTuple_CheckExact(kw_names));
11426 CHECK_OBJECT(called);
11427
11428 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11429
11430 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11431
11432 if (Nuitka_Function_Check(called)) {
11433 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11434 return NULL;
11435 }
11436
11437 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11438
11439 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 10, kw_values, kw_names);
11440
11441 Py_LeaveRecursiveCall();
11442
11443 CHECK_OBJECT_X(result);
11444
11445 return result;
11446#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11447 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11448 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11449
11450 if (likely(func != NULL)) {
11451 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 10 + nkwargs);
11452
11453 memcpy(vectorcall_args, args, 10 * sizeof(PyObject *));
11454 memcpy(&vectorcall_args[10], kw_values, nkwargs * sizeof(PyObject *));
11455
11456 PyObject *result = func(called, vectorcall_args, 10, kw_names);
11457
11458 CHECK_OBJECT_X(result);
11459
11460 return Nuitka_CheckFunctionResult(tstate, called, result);
11461 }
11462#endif
11463 }
11464
11465#if 0
11466 PRINT_STRING("FALLBACK");
11467 PRINT_ITEM(called);
11468 PRINT_NEW_LINE();
11469#endif
11470
11471 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11472
11473 if (unlikely(call_slot == NULL)) {
11474 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11475
11476 return NULL;
11477 }
11478
11479 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11480 return NULL;
11481 }
11482
11483 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11484
11485 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11486 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11487
11488 PyObject *value = kw_values[i];
11489
11490 CHECK_OBJECT(key);
11491 CHECK_OBJECT(value);
11492
11493 DICT_SET_ITEM(named_args, key, value);
11494 }
11495
11496 PyObject *result = (*call_slot)(called, pos_args, named_args);
11497
11498 Py_DECREF(named_args);
11499
11500 Py_LeaveRecursiveCall();
11501
11502 CHECK_OBJECT_X(result);
11503
11504 return Nuitka_CheckFunctionResult(tstate, called, result);
11505}
11506PyObject *CALL_METHODDESCR_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg) {
11507 PyObject *const *args = &arg; // For easier code compatibility.
11508 CHECK_OBJECT(called);
11509 CHECK_OBJECTS(args, 1);
11510
11511#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11512 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11513 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11514 assert(func != NULL);
11515 PyObject *result = func(called, args, 1, NULL);
11516
11517#ifndef __NUITKA_NO_ASSERT__
11518 return Nuitka_CheckFunctionResult(tstate, called, result);
11519#else
11520 return result;
11521#endif
11522#else
11523 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11524 PyMethodDef *method_def = called_descr->d_method;
11525
11526 // Try to be fast about wrapping the arguments.
11527 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11528
11529 if (likely(flags & METH_NOARGS)) {
11530 PyCFunction method = method_def->ml_meth;
11531 PyObject *self = args[0];
11532
11533 PyObject *result = (*method)(self, NULL);
11534
11535#ifndef __NUITKA_NO_ASSERT__
11536 return Nuitka_CheckFunctionResult(tstate, called, result);
11537#else
11538 return result;
11539#endif
11540 } else if ((flags & METH_O)) {
11541 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (1 given)",
11542 method_def->ml_name);
11543 return NULL;
11544 } else if (flags & METH_VARARGS) {
11545 PyCFunction method = method_def->ml_meth;
11546 PyObject *self = args[0];
11547
11548 PyObject *result;
11549
11550#if PYTHON_VERSION < 0x360
11551 if (flags & METH_KEYWORDS) {
11552 result = (*(PyCFunctionWithKeywords)method)(self, const_tuple_empty, NULL);
11553 } else {
11554 result = (*method)(self, const_tuple_empty);
11555 }
11556#else
11557 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11558 result = (*(PyCFunctionWithKeywords)method)(self, const_tuple_empty, NULL);
11559 } else if (flags == METH_FASTCALL) {
11560#if PYTHON_VERSION < 0x370
11561 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 0, NULL);
11562#else
11563 result = (*(_PyCFunctionFast)method)(self, &const_tuple_empty, 1);
11564#endif
11565 } else {
11566 result = (*method)(self, const_tuple_empty);
11567 }
11568#endif
11569#ifndef __NUITKA_NO_ASSERT__
11570 return Nuitka_CheckFunctionResult(tstate, called, result);
11571#else
11572 return result;
11573#endif
11574 }
11575
11576#if 0
11577 PRINT_NEW_LINE();
11578 PRINT_STRING("FALLBACK");
11579 PRINT_ITEM(called);
11580 PRINT_NEW_LINE();
11581#endif
11582
11583 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
11584
11585 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11586
11587 Py_DECREF(pos_args);
11588
11589 return result;
11590#endif
11591}
11592PyObject *CALL_METHODDESCR_WITH_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11593 CHECK_OBJECT(called);
11594 CHECK_OBJECTS(args, 2);
11595
11596#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11597 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11598 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11599 assert(func != NULL);
11600 PyObject *result = func(called, args, 2, NULL);
11601
11602#ifndef __NUITKA_NO_ASSERT__
11603 return Nuitka_CheckFunctionResult(tstate, called, result);
11604#else
11605 return result;
11606#endif
11607#else
11608 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11609 PyMethodDef *method_def = called_descr->d_method;
11610
11611 // Try to be fast about wrapping the arguments.
11612 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11613
11614 if (unlikely(flags & METH_NOARGS)) {
11615 PyCFunction method = method_def->ml_meth;
11616 PyObject *self = args[0];
11617
11618 PyObject *result = (*method)(self, NULL);
11619
11620#ifndef __NUITKA_NO_ASSERT__
11621 return Nuitka_CheckFunctionResult(tstate, called, result);
11622#else
11623 return result;
11624#endif
11625 } else if (unlikely(flags & METH_O)) {
11626 PyCFunction method = method_def->ml_meth;
11627 PyObject *self = args[0];
11628
11629 PyObject *result = (*method)(self, args[1]);
11630
11631#ifndef __NUITKA_NO_ASSERT__
11632 return Nuitka_CheckFunctionResult(tstate, called, result);
11633#else
11634 return result;
11635#endif
11636 } else if (flags & METH_VARARGS) {
11637 PyCFunction method = method_def->ml_meth;
11638 PyObject *self = args[0];
11639
11640 PyObject *result;
11641
11642#if PYTHON_VERSION < 0x360
11643 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11644
11645 if (flags & METH_KEYWORDS) {
11646 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11647 } else {
11648 result = (*method)(self, pos_args);
11649 }
11650
11651 Py_DECREF(pos_args);
11652#else
11653 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11654 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11655 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11656 Py_DECREF(pos_args);
11657 } else if (flags == METH_FASTCALL) {
11658#if PYTHON_VERSION < 0x370
11659 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 1, NULL);
11660#else
11661 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11662 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
11663 Py_DECREF(pos_args);
11664#endif
11665 } else {
11666 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11667 result = (*method)(self, pos_args);
11668 Py_DECREF(pos_args);
11669 }
11670#endif
11671#ifndef __NUITKA_NO_ASSERT__
11672 return Nuitka_CheckFunctionResult(tstate, called, result);
11673#else
11674 return result;
11675#endif
11676 }
11677
11678#if 0
11679 PRINT_NEW_LINE();
11680 PRINT_STRING("FALLBACK");
11681 PRINT_ITEM(called);
11682 PRINT_NEW_LINE();
11683#endif
11684
11685 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
11686
11687 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11688
11689 Py_DECREF(pos_args);
11690
11691 return result;
11692#endif
11693}
11694PyObject *CALL_METHODDESCR_WITH_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11695 CHECK_OBJECT(called);
11696 CHECK_OBJECTS(args, 3);
11697
11698#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11699 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11700 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11701 assert(func != NULL);
11702 PyObject *result = func(called, args, 3, NULL);
11703
11704#ifndef __NUITKA_NO_ASSERT__
11705 return Nuitka_CheckFunctionResult(tstate, called, result);
11706#else
11707 return result;
11708#endif
11709#else
11710 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11711 PyMethodDef *method_def = called_descr->d_method;
11712
11713 // Try to be fast about wrapping the arguments.
11714 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11715
11716 if (unlikely(flags & METH_NOARGS)) {
11717 PyCFunction method = method_def->ml_meth;
11718 PyObject *self = args[0];
11719
11720 PyObject *result = (*method)(self, NULL);
11721
11722#ifndef __NUITKA_NO_ASSERT__
11723 return Nuitka_CheckFunctionResult(tstate, called, result);
11724#else
11725 return result;
11726#endif
11727 } else if (unlikely(flags & METH_O)) {
11728 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
11729 method_def->ml_name);
11730 return NULL;
11731 } else if (flags & METH_VARARGS) {
11732 PyCFunction method = method_def->ml_meth;
11733 PyObject *self = args[0];
11734
11735 PyObject *result;
11736
11737#if PYTHON_VERSION < 0x360
11738 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11739
11740 if (flags & METH_KEYWORDS) {
11741 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11742 } else {
11743 result = (*method)(self, pos_args);
11744 }
11745
11746 Py_DECREF(pos_args);
11747#else
11748 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11749 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11750 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11751 Py_DECREF(pos_args);
11752 } else if (flags == METH_FASTCALL) {
11753#if PYTHON_VERSION < 0x370
11754 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 2, NULL);
11755#else
11756 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11757 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
11758 Py_DECREF(pos_args);
11759#endif
11760 } else {
11761 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11762 result = (*method)(self, pos_args);
11763 Py_DECREF(pos_args);
11764 }
11765#endif
11766#ifndef __NUITKA_NO_ASSERT__
11767 return Nuitka_CheckFunctionResult(tstate, called, result);
11768#else
11769 return result;
11770#endif
11771 }
11772
11773#if 0
11774 PRINT_NEW_LINE();
11775 PRINT_STRING("FALLBACK");
11776 PRINT_ITEM(called);
11777 PRINT_NEW_LINE();
11778#endif
11779
11780 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
11781
11782 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11783
11784 Py_DECREF(pos_args);
11785
11786 return result;
11787#endif
11788}
11789PyObject *CALL_METHODDESCR_WITH_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11790 CHECK_OBJECT(called);
11791 CHECK_OBJECTS(args, 4);
11792
11793#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11794 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11795 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11796 assert(func != NULL);
11797 PyObject *result = func(called, args, 4, NULL);
11798
11799#ifndef __NUITKA_NO_ASSERT__
11800 return Nuitka_CheckFunctionResult(tstate, called, result);
11801#else
11802 return result;
11803#endif
11804#else
11805 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11806 PyMethodDef *method_def = called_descr->d_method;
11807
11808 // Try to be fast about wrapping the arguments.
11809 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11810
11811 if (unlikely(flags & METH_NOARGS)) {
11812 PyCFunction method = method_def->ml_meth;
11813 PyObject *self = args[0];
11814
11815 PyObject *result = (*method)(self, NULL);
11816
11817#ifndef __NUITKA_NO_ASSERT__
11818 return Nuitka_CheckFunctionResult(tstate, called, result);
11819#else
11820 return result;
11821#endif
11822 } else if (unlikely(flags & METH_O)) {
11823 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
11824 method_def->ml_name);
11825 return NULL;
11826 } else if (flags & METH_VARARGS) {
11827 PyCFunction method = method_def->ml_meth;
11828 PyObject *self = args[0];
11829
11830 PyObject *result;
11831
11832#if PYTHON_VERSION < 0x360
11833 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11834
11835 if (flags & METH_KEYWORDS) {
11836 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11837 } else {
11838 result = (*method)(self, pos_args);
11839 }
11840
11841 Py_DECREF(pos_args);
11842#else
11843 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11844 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11845 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11846 Py_DECREF(pos_args);
11847 } else if (flags == METH_FASTCALL) {
11848#if PYTHON_VERSION < 0x370
11849 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 3, NULL);
11850#else
11851 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11852 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
11853 Py_DECREF(pos_args);
11854#endif
11855 } else {
11856 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11857 result = (*method)(self, pos_args);
11858 Py_DECREF(pos_args);
11859 }
11860#endif
11861#ifndef __NUITKA_NO_ASSERT__
11862 return Nuitka_CheckFunctionResult(tstate, called, result);
11863#else
11864 return result;
11865#endif
11866 }
11867
11868#if 0
11869 PRINT_NEW_LINE();
11870 PRINT_STRING("FALLBACK");
11871 PRINT_ITEM(called);
11872 PRINT_NEW_LINE();
11873#endif
11874
11875 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
11876
11877 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11878
11879 Py_DECREF(pos_args);
11880
11881 return result;
11882#endif
11883}
11884PyObject *CALL_METHOD_NO_ARGS(PyThreadState *tstate, PyObject *source, PyObject *attr_name) {
11885 CHECK_OBJECT(source);
11886 CHECK_OBJECT(attr_name);
11887
11888 PyTypeObject *type = Py_TYPE(source);
11889
11890 if (hasTypeGenericGetAttr(type)) {
11891 // Unfortunately this is required, although of cause rarely necessary.
11892 if (unlikely(type->tp_dict == NULL)) {
11893 if (unlikely(PyType_Ready(type) < 0)) {
11894 return NULL;
11895 }
11896 }
11897
11898 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
11899 descrgetfunc func = NULL;
11900
11901 if (descr != NULL) {
11902 Py_INCREF(descr);
11903
11904 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
11905 func = Py_TYPE(descr)->tp_descr_get;
11906
11907 if (func != NULL && Nuitka_Descr_IsData(descr)) {
11908 PyObject *called_object = func(descr, source, (PyObject *)type);
11909 Py_DECREF(descr);
11910
11911 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11912 Py_DECREF(called_object);
11913 return result;
11914 }
11915 }
11916 }
11917
11918 Py_ssize_t dictoffset = type->tp_dictoffset;
11919 PyObject *dict = NULL;
11920
11921 if (dictoffset != 0) {
11922 // Negative dictionary offsets have special meaning.
11923 if (dictoffset < 0) {
11924 Py_ssize_t tsize;
11925 size_t size;
11926
11927 tsize = ((PyVarObject *)source)->ob_size;
11928 if (tsize < 0) {
11929 tsize = -tsize;
11930 }
11931 size = _PyObject_VAR_SIZE(type, tsize);
11932
11933 dictoffset += (long)size;
11934 }
11935
11936 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
11937 dict = *dictptr;
11938 }
11939
11940 if (dict != NULL) {
11941 CHECK_OBJECT(dict);
11942
11943 Py_INCREF(dict);
11944
11945 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
11946
11947 if (called_object != NULL) {
11948 Py_XDECREF(descr);
11949 Py_DECREF(dict);
11950
11951 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11952 Py_DECREF(called_object);
11953 return result;
11954 }
11955
11956 Py_DECREF(dict);
11957 }
11958
11959 if (func != NULL) {
11960 if (func == Nuitka_Function_Type.tp_descr_get) {
11961 PyObject *result =
11962 Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)descr, source);
11963 Py_DECREF(descr);
11964
11965 return result;
11966 } else {
11967 PyObject *called_object = func(descr, source, (PyObject *)type);
11968 CHECK_OBJECT(called_object);
11969
11970 Py_DECREF(descr);
11971
11972 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11973 Py_DECREF(called_object);
11974 return result;
11975 }
11976 }
11977
11978 if (descr != NULL) {
11979 CHECK_OBJECT(descr);
11980
11981 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, descr);
11982 Py_DECREF(descr);
11983 return result;
11984 }
11985
11986#if PYTHON_VERSION < 0x300
11987 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
11988 PyString_AS_STRING(attr_name));
11989#else
11990 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
11991#endif
11992 return NULL;
11993 }
11994#if PYTHON_VERSION < 0x300
11995 else if (type == &PyInstance_Type) {
11996 PyInstanceObject *source_instance = (PyInstanceObject *)source;
11997
11998 // The special cases have their own variant on the code generation level
11999 // as we are called with constants only.
12000 assert(attr_name != const_str_plain___dict__);
12001 assert(attr_name != const_str_plain___class__);
12002
12003 // Try the instance dict first.
12004 PyObject *called_object =
12005 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12006
12007 // Note: The "called_object" was found without taking a reference,
12008 // so we need not release it in this branch.
12009 if (called_object != NULL) {
12010 return CALL_FUNCTION_NO_ARGS(tstate, called_object);
12011 }
12012
12013 // Then check the class dictionaries.
12014 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12015
12016 // Note: The "called_object" was found without taking a reference,
12017 // so we need not release it in this branch.
12018 if (called_object != NULL) {
12019 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12020
12021 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12022 return Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12023 source);
12024 } else if (descr_get != NULL) {
12025 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12026
12027 if (unlikely(method == NULL)) {
12028 return NULL;
12029 }
12030
12031 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, method);
12032 Py_DECREF(method);
12033 return result;
12034 } else {
12035 return CALL_FUNCTION_NO_ARGS(tstate, called_object);
12036 }
12037
12038 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12039 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12040 PyString_AS_STRING(source_instance->in_class->cl_name),
12041 PyString_AS_STRING(attr_name));
12042
12043 return NULL;
12044 } else {
12045 // Finally allow the "__getattr__" override to provide it or else
12046 // it's an error.
12047
12048 PyObject *args2[] = {source, attr_name};
12049
12050 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12051
12052 if (unlikely(called_object == NULL)) {
12053 return NULL;
12054 }
12055
12056 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12057 Py_DECREF(called_object);
12058 return result;
12059 }
12060 }
12061#endif
12062 else if (type->tp_getattro != NULL) {
12063 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12064
12065 if (unlikely(descr == NULL)) {
12066 return NULL;
12067 }
12068
12069 descrgetfunc func = NULL;
12070 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12071 func = Py_TYPE(descr)->tp_descr_get;
12072
12073 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12074 PyObject *called_object = func(descr, source, (PyObject *)type);
12075 Py_DECREF(descr);
12076
12077 if (unlikely(called_object == NULL)) {
12078 return NULL;
12079 }
12080
12081 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12082 Py_DECREF(called_object);
12083 return result;
12084 }
12085 }
12086
12087 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, descr);
12088 Py_DECREF(descr);
12089 return result;
12090 } else if (type->tp_getattr != NULL) {
12091 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12092
12093 if (unlikely(called_object == NULL)) {
12094 return NULL;
12095 }
12096
12097 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12098 Py_DECREF(called_object);
12099 return result;
12100 } else {
12101 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12102 Nuitka_String_AsString_Unchecked(attr_name));
12103
12104 return NULL;
12105 }
12106}
12107PyObject *CALL_METHOD_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *arg) {
12108 PyObject *const *args = &arg; // For easier code compatibility.
12109 CHECK_OBJECT(source);
12110 CHECK_OBJECT(attr_name);
12111
12112 CHECK_OBJECTS(args, 1);
12113
12114 PyTypeObject *type = Py_TYPE(source);
12115
12116 if (hasTypeGenericGetAttr(type)) {
12117 // Unfortunately this is required, although of cause rarely necessary.
12118 if (unlikely(type->tp_dict == NULL)) {
12119 if (unlikely(PyType_Ready(type) < 0)) {
12120 return NULL;
12121 }
12122 }
12123
12124 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12125 descrgetfunc func = NULL;
12126
12127 if (descr != NULL) {
12128 Py_INCREF(descr);
12129
12130 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12131 func = Py_TYPE(descr)->tp_descr_get;
12132
12133 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12134 PyObject *called_object = func(descr, source, (PyObject *)type);
12135 Py_DECREF(descr);
12136
12137 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12138 Py_DECREF(called_object);
12139 return result;
12140 }
12141 }
12142 }
12143
12144 Py_ssize_t dictoffset = type->tp_dictoffset;
12145 PyObject *dict = NULL;
12146
12147 if (dictoffset != 0) {
12148 // Negative dictionary offsets have special meaning.
12149 if (dictoffset < 0) {
12150 Py_ssize_t tsize;
12151 size_t size;
12152
12153 tsize = ((PyVarObject *)source)->ob_size;
12154 if (tsize < 0) {
12155 tsize = -tsize;
12156 }
12157 size = _PyObject_VAR_SIZE(type, tsize);
12158
12159 dictoffset += (long)size;
12160 }
12161
12162 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12163 dict = *dictptr;
12164 }
12165
12166 if (dict != NULL) {
12167 CHECK_OBJECT(dict);
12168
12169 Py_INCREF(dict);
12170
12171 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12172
12173 if (called_object != NULL) {
12174 Py_XDECREF(descr);
12175 Py_DECREF(dict);
12176
12177 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12178 Py_DECREF(called_object);
12179 return result;
12180 }
12181
12182 Py_DECREF(dict);
12183 }
12184
12185 if (func != NULL) {
12186 if (func == Nuitka_Function_Type.tp_descr_get) {
12187 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12188 source, args, 1);
12189 Py_DECREF(descr);
12190
12191 return result;
12192 } else {
12193 PyObject *called_object = func(descr, source, (PyObject *)type);
12194 CHECK_OBJECT(called_object);
12195
12196 Py_DECREF(descr);
12197
12198 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12199 Py_DECREF(called_object);
12200 return result;
12201 }
12202 }
12203
12204 if (descr != NULL) {
12205 CHECK_OBJECT(descr);
12206
12207 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, descr, args[0]);
12208 Py_DECREF(descr);
12209 return result;
12210 }
12211
12212#if PYTHON_VERSION < 0x300
12213 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12214 PyString_AS_STRING(attr_name));
12215#else
12216 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12217#endif
12218 return NULL;
12219 }
12220#if PYTHON_VERSION < 0x300
12221 else if (type == &PyInstance_Type) {
12222 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12223
12224 // The special cases have their own variant on the code generation level
12225 // as we are called with constants only.
12226 assert(attr_name != const_str_plain___dict__);
12227 assert(attr_name != const_str_plain___class__);
12228
12229 // Try the instance dict first.
12230 PyObject *called_object =
12231 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12232
12233 // Note: The "called_object" was found without taking a reference,
12234 // so we need not release it in this branch.
12235 if (called_object != NULL) {
12236 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12237 }
12238
12239 // Then check the class dictionaries.
12240 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12241
12242 // Note: The "called_object" was found without taking a reference,
12243 // so we need not release it in this branch.
12244 if (called_object != NULL) {
12245 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12246
12247 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12248 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12249 source, args, 1);
12250 } else if (descr_get != NULL) {
12251 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12252
12253 if (unlikely(method == NULL)) {
12254 return NULL;
12255 }
12256
12257 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, method, args[0]);
12258 Py_DECREF(method);
12259 return result;
12260 } else {
12261 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12262 }
12263
12264 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12265 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12266 PyString_AS_STRING(source_instance->in_class->cl_name),
12267 PyString_AS_STRING(attr_name));
12268
12269 return NULL;
12270 } else {
12271 // Finally allow the "__getattr__" override to provide it or else
12272 // it's an error.
12273
12274 PyObject *args2[] = {source, attr_name};
12275
12276 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12277
12278 if (unlikely(called_object == NULL)) {
12279 return NULL;
12280 }
12281
12282 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12283 Py_DECREF(called_object);
12284 return result;
12285 }
12286 }
12287#endif
12288 else if (type->tp_getattro != NULL) {
12289 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12290
12291 if (unlikely(descr == NULL)) {
12292 return NULL;
12293 }
12294
12295 descrgetfunc func = NULL;
12296 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12297 func = Py_TYPE(descr)->tp_descr_get;
12298
12299 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12300 PyObject *called_object = func(descr, source, (PyObject *)type);
12301 Py_DECREF(descr);
12302
12303 if (unlikely(called_object == NULL)) {
12304 return NULL;
12305 }
12306
12307 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12308 Py_DECREF(called_object);
12309 return result;
12310 }
12311 }
12312
12313 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, descr, args[0]);
12314 Py_DECREF(descr);
12315 return result;
12316 } else if (type->tp_getattr != NULL) {
12317 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12318
12319 if (unlikely(called_object == NULL)) {
12320 return NULL;
12321 }
12322
12323 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12324 Py_DECREF(called_object);
12325 return result;
12326 } else {
12327 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12328 Nuitka_String_AsString_Unchecked(attr_name));
12329
12330 return NULL;
12331 }
12332}
12333PyObject *CALL_METHOD_WITH_ARGS2(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12334 CHECK_OBJECT(source);
12335 CHECK_OBJECT(attr_name);
12336
12337 CHECK_OBJECTS(args, 2);
12338
12339 PyTypeObject *type = Py_TYPE(source);
12340
12341 if (hasTypeGenericGetAttr(type)) {
12342 // Unfortunately this is required, although of cause rarely necessary.
12343 if (unlikely(type->tp_dict == NULL)) {
12344 if (unlikely(PyType_Ready(type) < 0)) {
12345 return NULL;
12346 }
12347 }
12348
12349 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12350 descrgetfunc func = NULL;
12351
12352 if (descr != NULL) {
12353 Py_INCREF(descr);
12354
12355 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12356 func = Py_TYPE(descr)->tp_descr_get;
12357
12358 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12359 PyObject *called_object = func(descr, source, (PyObject *)type);
12360 Py_DECREF(descr);
12361
12362 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12363 Py_DECREF(called_object);
12364 return result;
12365 }
12366 }
12367 }
12368
12369 Py_ssize_t dictoffset = type->tp_dictoffset;
12370 PyObject *dict = NULL;
12371
12372 if (dictoffset != 0) {
12373 // Negative dictionary offsets have special meaning.
12374 if (dictoffset < 0) {
12375 Py_ssize_t tsize;
12376 size_t size;
12377
12378 tsize = ((PyVarObject *)source)->ob_size;
12379 if (tsize < 0) {
12380 tsize = -tsize;
12381 }
12382 size = _PyObject_VAR_SIZE(type, tsize);
12383
12384 dictoffset += (long)size;
12385 }
12386
12387 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12388 dict = *dictptr;
12389 }
12390
12391 if (dict != NULL) {
12392 CHECK_OBJECT(dict);
12393
12394 Py_INCREF(dict);
12395
12396 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12397
12398 if (called_object != NULL) {
12399 Py_XDECREF(descr);
12400 Py_DECREF(dict);
12401
12402 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12403 Py_DECREF(called_object);
12404 return result;
12405 }
12406
12407 Py_DECREF(dict);
12408 }
12409
12410 if (func != NULL) {
12411 if (func == Nuitka_Function_Type.tp_descr_get) {
12412 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12413 source, args, 2);
12414 Py_DECREF(descr);
12415
12416 return result;
12417 } else {
12418 PyObject *called_object = func(descr, source, (PyObject *)type);
12419 CHECK_OBJECT(called_object);
12420
12421 Py_DECREF(descr);
12422
12423 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12424 Py_DECREF(called_object);
12425 return result;
12426 }
12427 }
12428
12429 if (descr != NULL) {
12430 CHECK_OBJECT(descr);
12431
12432 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, descr, args);
12433 Py_DECREF(descr);
12434 return result;
12435 }
12436
12437#if PYTHON_VERSION < 0x300
12438 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12439 PyString_AS_STRING(attr_name));
12440#else
12441 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12442#endif
12443 return NULL;
12444 }
12445#if PYTHON_VERSION < 0x300
12446 else if (type == &PyInstance_Type) {
12447 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12448
12449 // The special cases have their own variant on the code generation level
12450 // as we are called with constants only.
12451 assert(attr_name != const_str_plain___dict__);
12452 assert(attr_name != const_str_plain___class__);
12453
12454 // Try the instance dict first.
12455 PyObject *called_object =
12456 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12457
12458 // Note: The "called_object" was found without taking a reference,
12459 // so we need not release it in this branch.
12460 if (called_object != NULL) {
12461 return CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12462 }
12463
12464 // Then check the class dictionaries.
12465 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12466
12467 // Note: The "called_object" was found without taking a reference,
12468 // so we need not release it in this branch.
12469 if (called_object != NULL) {
12470 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12471
12472 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12473 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12474 source, args, 2);
12475 } else if (descr_get != NULL) {
12476 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12477
12478 if (unlikely(method == NULL)) {
12479 return NULL;
12480 }
12481
12482 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, method, args);
12483 Py_DECREF(method);
12484 return result;
12485 } else {
12486 return CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12487 }
12488
12489 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12490 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12491 PyString_AS_STRING(source_instance->in_class->cl_name),
12492 PyString_AS_STRING(attr_name));
12493
12494 return NULL;
12495 } else {
12496 // Finally allow the "__getattr__" override to provide it or else
12497 // it's an error.
12498
12499 PyObject *args2[] = {source, attr_name};
12500
12501 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12502
12503 if (unlikely(called_object == NULL)) {
12504 return NULL;
12505 }
12506
12507 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12508 Py_DECREF(called_object);
12509 return result;
12510 }
12511 }
12512#endif
12513 else if (type->tp_getattro != NULL) {
12514 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12515
12516 if (unlikely(descr == NULL)) {
12517 return NULL;
12518 }
12519
12520 descrgetfunc func = NULL;
12521 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12522 func = Py_TYPE(descr)->tp_descr_get;
12523
12524 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12525 PyObject *called_object = func(descr, source, (PyObject *)type);
12526 Py_DECREF(descr);
12527
12528 if (unlikely(called_object == NULL)) {
12529 return NULL;
12530 }
12531
12532 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12533 Py_DECREF(called_object);
12534 return result;
12535 }
12536 }
12537
12538 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, descr, args);
12539 Py_DECREF(descr);
12540 return result;
12541 } else if (type->tp_getattr != NULL) {
12542 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12543
12544 if (unlikely(called_object == NULL)) {
12545 return NULL;
12546 }
12547
12548 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12549 Py_DECREF(called_object);
12550 return result;
12551 } else {
12552 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12553 Nuitka_String_AsString_Unchecked(attr_name));
12554
12555 return NULL;
12556 }
12557}
12558PyObject *CALL_METHOD_WITH_ARGS3(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12559 CHECK_OBJECT(source);
12560 CHECK_OBJECT(attr_name);
12561
12562 CHECK_OBJECTS(args, 3);
12563
12564 PyTypeObject *type = Py_TYPE(source);
12565
12566 if (hasTypeGenericGetAttr(type)) {
12567 // Unfortunately this is required, although of cause rarely necessary.
12568 if (unlikely(type->tp_dict == NULL)) {
12569 if (unlikely(PyType_Ready(type) < 0)) {
12570 return NULL;
12571 }
12572 }
12573
12574 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12575 descrgetfunc func = NULL;
12576
12577 if (descr != NULL) {
12578 Py_INCREF(descr);
12579
12580 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12581 func = Py_TYPE(descr)->tp_descr_get;
12582
12583 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12584 PyObject *called_object = func(descr, source, (PyObject *)type);
12585 Py_DECREF(descr);
12586
12587 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12588 Py_DECREF(called_object);
12589 return result;
12590 }
12591 }
12592 }
12593
12594 Py_ssize_t dictoffset = type->tp_dictoffset;
12595 PyObject *dict = NULL;
12596
12597 if (dictoffset != 0) {
12598 // Negative dictionary offsets have special meaning.
12599 if (dictoffset < 0) {
12600 Py_ssize_t tsize;
12601 size_t size;
12602
12603 tsize = ((PyVarObject *)source)->ob_size;
12604 if (tsize < 0) {
12605 tsize = -tsize;
12606 }
12607 size = _PyObject_VAR_SIZE(type, tsize);
12608
12609 dictoffset += (long)size;
12610 }
12611
12612 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12613 dict = *dictptr;
12614 }
12615
12616 if (dict != NULL) {
12617 CHECK_OBJECT(dict);
12618
12619 Py_INCREF(dict);
12620
12621 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12622
12623 if (called_object != NULL) {
12624 Py_XDECREF(descr);
12625 Py_DECREF(dict);
12626
12627 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12628 Py_DECREF(called_object);
12629 return result;
12630 }
12631
12632 Py_DECREF(dict);
12633 }
12634
12635 if (func != NULL) {
12636 if (func == Nuitka_Function_Type.tp_descr_get) {
12637 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12638 source, args, 3);
12639 Py_DECREF(descr);
12640
12641 return result;
12642 } else {
12643 PyObject *called_object = func(descr, source, (PyObject *)type);
12644 CHECK_OBJECT(called_object);
12645
12646 Py_DECREF(descr);
12647
12648 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12649 Py_DECREF(called_object);
12650 return result;
12651 }
12652 }
12653
12654 if (descr != NULL) {
12655 CHECK_OBJECT(descr);
12656
12657 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, descr, args);
12658 Py_DECREF(descr);
12659 return result;
12660 }
12661
12662#if PYTHON_VERSION < 0x300
12663 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12664 PyString_AS_STRING(attr_name));
12665#else
12666 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12667#endif
12668 return NULL;
12669 }
12670#if PYTHON_VERSION < 0x300
12671 else if (type == &PyInstance_Type) {
12672 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12673
12674 // The special cases have their own variant on the code generation level
12675 // as we are called with constants only.
12676 assert(attr_name != const_str_plain___dict__);
12677 assert(attr_name != const_str_plain___class__);
12678
12679 // Try the instance dict first.
12680 PyObject *called_object =
12681 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12682
12683 // Note: The "called_object" was found without taking a reference,
12684 // so we need not release it in this branch.
12685 if (called_object != NULL) {
12686 return CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12687 }
12688
12689 // Then check the class dictionaries.
12690 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12691
12692 // Note: The "called_object" was found without taking a reference,
12693 // so we need not release it in this branch.
12694 if (called_object != NULL) {
12695 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12696
12697 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12698 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12699 source, args, 3);
12700 } else if (descr_get != NULL) {
12701 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12702
12703 if (unlikely(method == NULL)) {
12704 return NULL;
12705 }
12706
12707 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, method, args);
12708 Py_DECREF(method);
12709 return result;
12710 } else {
12711 return CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12712 }
12713
12714 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12715 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12716 PyString_AS_STRING(source_instance->in_class->cl_name),
12717 PyString_AS_STRING(attr_name));
12718
12719 return NULL;
12720 } else {
12721 // Finally allow the "__getattr__" override to provide it or else
12722 // it's an error.
12723
12724 PyObject *args2[] = {source, attr_name};
12725
12726 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12727
12728 if (unlikely(called_object == NULL)) {
12729 return NULL;
12730 }
12731
12732 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12733 Py_DECREF(called_object);
12734 return result;
12735 }
12736 }
12737#endif
12738 else if (type->tp_getattro != NULL) {
12739 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12740
12741 if (unlikely(descr == NULL)) {
12742 return NULL;
12743 }
12744
12745 descrgetfunc func = NULL;
12746 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12747 func = Py_TYPE(descr)->tp_descr_get;
12748
12749 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12750 PyObject *called_object = func(descr, source, (PyObject *)type);
12751 Py_DECREF(descr);
12752
12753 if (unlikely(called_object == NULL)) {
12754 return NULL;
12755 }
12756
12757 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12758 Py_DECREF(called_object);
12759 return result;
12760 }
12761 }
12762
12763 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, descr, args);
12764 Py_DECREF(descr);
12765 return result;
12766 } else if (type->tp_getattr != NULL) {
12767 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12768
12769 if (unlikely(called_object == NULL)) {
12770 return NULL;
12771 }
12772
12773 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12774 Py_DECREF(called_object);
12775 return result;
12776 } else {
12777 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12778 Nuitka_String_AsString_Unchecked(attr_name));
12779
12780 return NULL;
12781 }
12782}
12783PyObject *CALL_METHOD_WITH_ARGS4(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12784 CHECK_OBJECT(source);
12785 CHECK_OBJECT(attr_name);
12786
12787 CHECK_OBJECTS(args, 4);
12788
12789 PyTypeObject *type = Py_TYPE(source);
12790
12791 if (hasTypeGenericGetAttr(type)) {
12792 // Unfortunately this is required, although of cause rarely necessary.
12793 if (unlikely(type->tp_dict == NULL)) {
12794 if (unlikely(PyType_Ready(type) < 0)) {
12795 return NULL;
12796 }
12797 }
12798
12799 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12800 descrgetfunc func = NULL;
12801
12802 if (descr != NULL) {
12803 Py_INCREF(descr);
12804
12805 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12806 func = Py_TYPE(descr)->tp_descr_get;
12807
12808 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12809 PyObject *called_object = func(descr, source, (PyObject *)type);
12810 Py_DECREF(descr);
12811
12812 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12813 Py_DECREF(called_object);
12814 return result;
12815 }
12816 }
12817 }
12818
12819 Py_ssize_t dictoffset = type->tp_dictoffset;
12820 PyObject *dict = NULL;
12821
12822 if (dictoffset != 0) {
12823 // Negative dictionary offsets have special meaning.
12824 if (dictoffset < 0) {
12825 Py_ssize_t tsize;
12826 size_t size;
12827
12828 tsize = ((PyVarObject *)source)->ob_size;
12829 if (tsize < 0) {
12830 tsize = -tsize;
12831 }
12832 size = _PyObject_VAR_SIZE(type, tsize);
12833
12834 dictoffset += (long)size;
12835 }
12836
12837 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12838 dict = *dictptr;
12839 }
12840
12841 if (dict != NULL) {
12842 CHECK_OBJECT(dict);
12843
12844 Py_INCREF(dict);
12845
12846 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12847
12848 if (called_object != NULL) {
12849 Py_XDECREF(descr);
12850 Py_DECREF(dict);
12851
12852 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12853 Py_DECREF(called_object);
12854 return result;
12855 }
12856
12857 Py_DECREF(dict);
12858 }
12859
12860 if (func != NULL) {
12861 if (func == Nuitka_Function_Type.tp_descr_get) {
12862 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12863 source, args, 4);
12864 Py_DECREF(descr);
12865
12866 return result;
12867 } else {
12868 PyObject *called_object = func(descr, source, (PyObject *)type);
12869 CHECK_OBJECT(called_object);
12870
12871 Py_DECREF(descr);
12872
12873 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12874 Py_DECREF(called_object);
12875 return result;
12876 }
12877 }
12878
12879 if (descr != NULL) {
12880 CHECK_OBJECT(descr);
12881
12882 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, descr, args);
12883 Py_DECREF(descr);
12884 return result;
12885 }
12886
12887#if PYTHON_VERSION < 0x300
12888 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12889 PyString_AS_STRING(attr_name));
12890#else
12891 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12892#endif
12893 return NULL;
12894 }
12895#if PYTHON_VERSION < 0x300
12896 else if (type == &PyInstance_Type) {
12897 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12898
12899 // The special cases have their own variant on the code generation level
12900 // as we are called with constants only.
12901 assert(attr_name != const_str_plain___dict__);
12902 assert(attr_name != const_str_plain___class__);
12903
12904 // Try the instance dict first.
12905 PyObject *called_object =
12906 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12907
12908 // Note: The "called_object" was found without taking a reference,
12909 // so we need not release it in this branch.
12910 if (called_object != NULL) {
12911 return CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12912 }
12913
12914 // Then check the class dictionaries.
12915 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12916
12917 // Note: The "called_object" was found without taking a reference,
12918 // so we need not release it in this branch.
12919 if (called_object != NULL) {
12920 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12921
12922 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12923 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12924 source, args, 4);
12925 } else if (descr_get != NULL) {
12926 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12927
12928 if (unlikely(method == NULL)) {
12929 return NULL;
12930 }
12931
12932 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, method, args);
12933 Py_DECREF(method);
12934 return result;
12935 } else {
12936 return CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12937 }
12938
12939 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12940 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12941 PyString_AS_STRING(source_instance->in_class->cl_name),
12942 PyString_AS_STRING(attr_name));
12943
12944 return NULL;
12945 } else {
12946 // Finally allow the "__getattr__" override to provide it or else
12947 // it's an error.
12948
12949 PyObject *args2[] = {source, attr_name};
12950
12951 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12952
12953 if (unlikely(called_object == NULL)) {
12954 return NULL;
12955 }
12956
12957 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12958 Py_DECREF(called_object);
12959 return result;
12960 }
12961 }
12962#endif
12963 else if (type->tp_getattro != NULL) {
12964 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12965
12966 if (unlikely(descr == NULL)) {
12967 return NULL;
12968 }
12969
12970 descrgetfunc func = NULL;
12971 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12972 func = Py_TYPE(descr)->tp_descr_get;
12973
12974 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12975 PyObject *called_object = func(descr, source, (PyObject *)type);
12976 Py_DECREF(descr);
12977
12978 if (unlikely(called_object == NULL)) {
12979 return NULL;
12980 }
12981
12982 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12983 Py_DECREF(called_object);
12984 return result;
12985 }
12986 }
12987
12988 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, descr, args);
12989 Py_DECREF(descr);
12990 return result;
12991 } else if (type->tp_getattr != NULL) {
12992 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12993
12994 if (unlikely(called_object == NULL)) {
12995 return NULL;
12996 }
12997
12998 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12999 Py_DECREF(called_object);
13000 return result;
13001 } else {
13002 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13003 Nuitka_String_AsString_Unchecked(attr_name));
13004
13005 return NULL;
13006 }
13007}
13008PyObject *CALL_METHOD_WITH_ARGS5(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13009 CHECK_OBJECT(source);
13010 CHECK_OBJECT(attr_name);
13011
13012 CHECK_OBJECTS(args, 5);
13013
13014 PyTypeObject *type = Py_TYPE(source);
13015
13016 if (hasTypeGenericGetAttr(type)) {
13017 // Unfortunately this is required, although of cause rarely necessary.
13018 if (unlikely(type->tp_dict == NULL)) {
13019 if (unlikely(PyType_Ready(type) < 0)) {
13020 return NULL;
13021 }
13022 }
13023
13024 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13025 descrgetfunc func = NULL;
13026
13027 if (descr != NULL) {
13028 Py_INCREF(descr);
13029
13030 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13031 func = Py_TYPE(descr)->tp_descr_get;
13032
13033 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13034 PyObject *called_object = func(descr, source, (PyObject *)type);
13035 Py_DECREF(descr);
13036
13037 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13038 Py_DECREF(called_object);
13039 return result;
13040 }
13041 }
13042 }
13043
13044 Py_ssize_t dictoffset = type->tp_dictoffset;
13045 PyObject *dict = NULL;
13046
13047 if (dictoffset != 0) {
13048 // Negative dictionary offsets have special meaning.
13049 if (dictoffset < 0) {
13050 Py_ssize_t tsize;
13051 size_t size;
13052
13053 tsize = ((PyVarObject *)source)->ob_size;
13054 if (tsize < 0) {
13055 tsize = -tsize;
13056 }
13057 size = _PyObject_VAR_SIZE(type, tsize);
13058
13059 dictoffset += (long)size;
13060 }
13061
13062 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13063 dict = *dictptr;
13064 }
13065
13066 if (dict != NULL) {
13067 CHECK_OBJECT(dict);
13068
13069 Py_INCREF(dict);
13070
13071 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13072
13073 if (called_object != NULL) {
13074 Py_XDECREF(descr);
13075 Py_DECREF(dict);
13076
13077 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13078 Py_DECREF(called_object);
13079 return result;
13080 }
13081
13082 Py_DECREF(dict);
13083 }
13084
13085 if (func != NULL) {
13086 if (func == Nuitka_Function_Type.tp_descr_get) {
13087 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13088 source, args, 5);
13089 Py_DECREF(descr);
13090
13091 return result;
13092 } else {
13093 PyObject *called_object = func(descr, source, (PyObject *)type);
13094 CHECK_OBJECT(called_object);
13095
13096 Py_DECREF(descr);
13097
13098 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13099 Py_DECREF(called_object);
13100 return result;
13101 }
13102 }
13103
13104 if (descr != NULL) {
13105 CHECK_OBJECT(descr);
13106
13107 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, descr, args);
13108 Py_DECREF(descr);
13109 return result;
13110 }
13111
13112#if PYTHON_VERSION < 0x300
13113 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13114 PyString_AS_STRING(attr_name));
13115#else
13116 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13117#endif
13118 return NULL;
13119 }
13120#if PYTHON_VERSION < 0x300
13121 else if (type == &PyInstance_Type) {
13122 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13123
13124 // The special cases have their own variant on the code generation level
13125 // as we are called with constants only.
13126 assert(attr_name != const_str_plain___dict__);
13127 assert(attr_name != const_str_plain___class__);
13128
13129 // Try the instance dict first.
13130 PyObject *called_object =
13131 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13132
13133 // Note: The "called_object" was found without taking a reference,
13134 // so we need not release it in this branch.
13135 if (called_object != NULL) {
13136 return CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13137 }
13138
13139 // Then check the class dictionaries.
13140 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13141
13142 // Note: The "called_object" was found without taking a reference,
13143 // so we need not release it in this branch.
13144 if (called_object != NULL) {
13145 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13146
13147 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13148 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13149 source, args, 5);
13150 } else if (descr_get != NULL) {
13151 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13152
13153 if (unlikely(method == NULL)) {
13154 return NULL;
13155 }
13156
13157 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, method, args);
13158 Py_DECREF(method);
13159 return result;
13160 } else {
13161 return CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13162 }
13163
13164 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13165 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13166 PyString_AS_STRING(source_instance->in_class->cl_name),
13167 PyString_AS_STRING(attr_name));
13168
13169 return NULL;
13170 } else {
13171 // Finally allow the "__getattr__" override to provide it or else
13172 // it's an error.
13173
13174 PyObject *args2[] = {source, attr_name};
13175
13176 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13177
13178 if (unlikely(called_object == NULL)) {
13179 return NULL;
13180 }
13181
13182 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13183 Py_DECREF(called_object);
13184 return result;
13185 }
13186 }
13187#endif
13188 else if (type->tp_getattro != NULL) {
13189 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13190
13191 if (unlikely(descr == NULL)) {
13192 return NULL;
13193 }
13194
13195 descrgetfunc func = NULL;
13196 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13197 func = Py_TYPE(descr)->tp_descr_get;
13198
13199 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13200 PyObject *called_object = func(descr, source, (PyObject *)type);
13201 Py_DECREF(descr);
13202
13203 if (unlikely(called_object == NULL)) {
13204 return NULL;
13205 }
13206
13207 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13208 Py_DECREF(called_object);
13209 return result;
13210 }
13211 }
13212
13213 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, descr, args);
13214 Py_DECREF(descr);
13215 return result;
13216 } else if (type->tp_getattr != NULL) {
13217 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13218
13219 if (unlikely(called_object == NULL)) {
13220 return NULL;
13221 }
13222
13223 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13224 Py_DECREF(called_object);
13225 return result;
13226 } else {
13227 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13228 Nuitka_String_AsString_Unchecked(attr_name));
13229
13230 return NULL;
13231 }
13232}
13233PyObject *CALL_METHOD_WITH_ARGS6(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13234 CHECK_OBJECT(source);
13235 CHECK_OBJECT(attr_name);
13236
13237 CHECK_OBJECTS(args, 6);
13238
13239 PyTypeObject *type = Py_TYPE(source);
13240
13241 if (hasTypeGenericGetAttr(type)) {
13242 // Unfortunately this is required, although of cause rarely necessary.
13243 if (unlikely(type->tp_dict == NULL)) {
13244 if (unlikely(PyType_Ready(type) < 0)) {
13245 return NULL;
13246 }
13247 }
13248
13249 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13250 descrgetfunc func = NULL;
13251
13252 if (descr != NULL) {
13253 Py_INCREF(descr);
13254
13255 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13256 func = Py_TYPE(descr)->tp_descr_get;
13257
13258 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13259 PyObject *called_object = func(descr, source, (PyObject *)type);
13260 Py_DECREF(descr);
13261
13262 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13263 Py_DECREF(called_object);
13264 return result;
13265 }
13266 }
13267 }
13268
13269 Py_ssize_t dictoffset = type->tp_dictoffset;
13270 PyObject *dict = NULL;
13271
13272 if (dictoffset != 0) {
13273 // Negative dictionary offsets have special meaning.
13274 if (dictoffset < 0) {
13275 Py_ssize_t tsize;
13276 size_t size;
13277
13278 tsize = ((PyVarObject *)source)->ob_size;
13279 if (tsize < 0) {
13280 tsize = -tsize;
13281 }
13282 size = _PyObject_VAR_SIZE(type, tsize);
13283
13284 dictoffset += (long)size;
13285 }
13286
13287 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13288 dict = *dictptr;
13289 }
13290
13291 if (dict != NULL) {
13292 CHECK_OBJECT(dict);
13293
13294 Py_INCREF(dict);
13295
13296 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13297
13298 if (called_object != NULL) {
13299 Py_XDECREF(descr);
13300 Py_DECREF(dict);
13301
13302 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13303 Py_DECREF(called_object);
13304 return result;
13305 }
13306
13307 Py_DECREF(dict);
13308 }
13309
13310 if (func != NULL) {
13311 if (func == Nuitka_Function_Type.tp_descr_get) {
13312 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13313 source, args, 6);
13314 Py_DECREF(descr);
13315
13316 return result;
13317 } else {
13318 PyObject *called_object = func(descr, source, (PyObject *)type);
13319 CHECK_OBJECT(called_object);
13320
13321 Py_DECREF(descr);
13322
13323 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13324 Py_DECREF(called_object);
13325 return result;
13326 }
13327 }
13328
13329 if (descr != NULL) {
13330 CHECK_OBJECT(descr);
13331
13332 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, descr, args);
13333 Py_DECREF(descr);
13334 return result;
13335 }
13336
13337#if PYTHON_VERSION < 0x300
13338 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13339 PyString_AS_STRING(attr_name));
13340#else
13341 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13342#endif
13343 return NULL;
13344 }
13345#if PYTHON_VERSION < 0x300
13346 else if (type == &PyInstance_Type) {
13347 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13348
13349 // The special cases have their own variant on the code generation level
13350 // as we are called with constants only.
13351 assert(attr_name != const_str_plain___dict__);
13352 assert(attr_name != const_str_plain___class__);
13353
13354 // Try the instance dict first.
13355 PyObject *called_object =
13356 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13357
13358 // Note: The "called_object" was found without taking a reference,
13359 // so we need not release it in this branch.
13360 if (called_object != NULL) {
13361 return CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13362 }
13363
13364 // Then check the class dictionaries.
13365 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13366
13367 // Note: The "called_object" was found without taking a reference,
13368 // so we need not release it in this branch.
13369 if (called_object != NULL) {
13370 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13371
13372 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13373 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13374 source, args, 6);
13375 } else if (descr_get != NULL) {
13376 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13377
13378 if (unlikely(method == NULL)) {
13379 return NULL;
13380 }
13381
13382 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, method, args);
13383 Py_DECREF(method);
13384 return result;
13385 } else {
13386 return CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13387 }
13388
13389 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13390 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13391 PyString_AS_STRING(source_instance->in_class->cl_name),
13392 PyString_AS_STRING(attr_name));
13393
13394 return NULL;
13395 } else {
13396 // Finally allow the "__getattr__" override to provide it or else
13397 // it's an error.
13398
13399 PyObject *args2[] = {source, attr_name};
13400
13401 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13402
13403 if (unlikely(called_object == NULL)) {
13404 return NULL;
13405 }
13406
13407 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13408 Py_DECREF(called_object);
13409 return result;
13410 }
13411 }
13412#endif
13413 else if (type->tp_getattro != NULL) {
13414 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13415
13416 if (unlikely(descr == NULL)) {
13417 return NULL;
13418 }
13419
13420 descrgetfunc func = NULL;
13421 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13422 func = Py_TYPE(descr)->tp_descr_get;
13423
13424 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13425 PyObject *called_object = func(descr, source, (PyObject *)type);
13426 Py_DECREF(descr);
13427
13428 if (unlikely(called_object == NULL)) {
13429 return NULL;
13430 }
13431
13432 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13433 Py_DECREF(called_object);
13434 return result;
13435 }
13436 }
13437
13438 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, descr, args);
13439 Py_DECREF(descr);
13440 return result;
13441 } else if (type->tp_getattr != NULL) {
13442 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13443
13444 if (unlikely(called_object == NULL)) {
13445 return NULL;
13446 }
13447
13448 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13449 Py_DECREF(called_object);
13450 return result;
13451 } else {
13452 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13453 Nuitka_String_AsString_Unchecked(attr_name));
13454
13455 return NULL;
13456 }
13457}
13458PyObject *CALL_METHOD_WITH_ARGS7(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13459 CHECK_OBJECT(source);
13460 CHECK_OBJECT(attr_name);
13461
13462 CHECK_OBJECTS(args, 7);
13463
13464 PyTypeObject *type = Py_TYPE(source);
13465
13466 if (hasTypeGenericGetAttr(type)) {
13467 // Unfortunately this is required, although of cause rarely necessary.
13468 if (unlikely(type->tp_dict == NULL)) {
13469 if (unlikely(PyType_Ready(type) < 0)) {
13470 return NULL;
13471 }
13472 }
13473
13474 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13475 descrgetfunc func = NULL;
13476
13477 if (descr != NULL) {
13478 Py_INCREF(descr);
13479
13480 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13481 func = Py_TYPE(descr)->tp_descr_get;
13482
13483 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13484 PyObject *called_object = func(descr, source, (PyObject *)type);
13485 Py_DECREF(descr);
13486
13487 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13488 Py_DECREF(called_object);
13489 return result;
13490 }
13491 }
13492 }
13493
13494 Py_ssize_t dictoffset = type->tp_dictoffset;
13495 PyObject *dict = NULL;
13496
13497 if (dictoffset != 0) {
13498 // Negative dictionary offsets have special meaning.
13499 if (dictoffset < 0) {
13500 Py_ssize_t tsize;
13501 size_t size;
13502
13503 tsize = ((PyVarObject *)source)->ob_size;
13504 if (tsize < 0) {
13505 tsize = -tsize;
13506 }
13507 size = _PyObject_VAR_SIZE(type, tsize);
13508
13509 dictoffset += (long)size;
13510 }
13511
13512 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13513 dict = *dictptr;
13514 }
13515
13516 if (dict != NULL) {
13517 CHECK_OBJECT(dict);
13518
13519 Py_INCREF(dict);
13520
13521 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13522
13523 if (called_object != NULL) {
13524 Py_XDECREF(descr);
13525 Py_DECREF(dict);
13526
13527 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13528 Py_DECREF(called_object);
13529 return result;
13530 }
13531
13532 Py_DECREF(dict);
13533 }
13534
13535 if (func != NULL) {
13536 if (func == Nuitka_Function_Type.tp_descr_get) {
13537 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13538 source, args, 7);
13539 Py_DECREF(descr);
13540
13541 return result;
13542 } else {
13543 PyObject *called_object = func(descr, source, (PyObject *)type);
13544 CHECK_OBJECT(called_object);
13545
13546 Py_DECREF(descr);
13547
13548 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13549 Py_DECREF(called_object);
13550 return result;
13551 }
13552 }
13553
13554 if (descr != NULL) {
13555 CHECK_OBJECT(descr);
13556
13557 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, descr, args);
13558 Py_DECREF(descr);
13559 return result;
13560 }
13561
13562#if PYTHON_VERSION < 0x300
13563 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13564 PyString_AS_STRING(attr_name));
13565#else
13566 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13567#endif
13568 return NULL;
13569 }
13570#if PYTHON_VERSION < 0x300
13571 else if (type == &PyInstance_Type) {
13572 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13573
13574 // The special cases have their own variant on the code generation level
13575 // as we are called with constants only.
13576 assert(attr_name != const_str_plain___dict__);
13577 assert(attr_name != const_str_plain___class__);
13578
13579 // Try the instance dict first.
13580 PyObject *called_object =
13581 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13582
13583 // Note: The "called_object" was found without taking a reference,
13584 // so we need not release it in this branch.
13585 if (called_object != NULL) {
13586 return CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13587 }
13588
13589 // Then check the class dictionaries.
13590 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13591
13592 // Note: The "called_object" was found without taking a reference,
13593 // so we need not release it in this branch.
13594 if (called_object != NULL) {
13595 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13596
13597 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13598 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13599 source, args, 7);
13600 } else if (descr_get != NULL) {
13601 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13602
13603 if (unlikely(method == NULL)) {
13604 return NULL;
13605 }
13606
13607 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, method, args);
13608 Py_DECREF(method);
13609 return result;
13610 } else {
13611 return CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13612 }
13613
13614 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13615 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13616 PyString_AS_STRING(source_instance->in_class->cl_name),
13617 PyString_AS_STRING(attr_name));
13618
13619 return NULL;
13620 } else {
13621 // Finally allow the "__getattr__" override to provide it or else
13622 // it's an error.
13623
13624 PyObject *args2[] = {source, attr_name};
13625
13626 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13627
13628 if (unlikely(called_object == NULL)) {
13629 return NULL;
13630 }
13631
13632 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13633 Py_DECREF(called_object);
13634 return result;
13635 }
13636 }
13637#endif
13638 else if (type->tp_getattro != NULL) {
13639 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13640
13641 if (unlikely(descr == NULL)) {
13642 return NULL;
13643 }
13644
13645 descrgetfunc func = NULL;
13646 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13647 func = Py_TYPE(descr)->tp_descr_get;
13648
13649 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13650 PyObject *called_object = func(descr, source, (PyObject *)type);
13651 Py_DECREF(descr);
13652
13653 if (unlikely(called_object == NULL)) {
13654 return NULL;
13655 }
13656
13657 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13658 Py_DECREF(called_object);
13659 return result;
13660 }
13661 }
13662
13663 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, descr, args);
13664 Py_DECREF(descr);
13665 return result;
13666 } else if (type->tp_getattr != NULL) {
13667 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13668
13669 if (unlikely(called_object == NULL)) {
13670 return NULL;
13671 }
13672
13673 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13674 Py_DECREF(called_object);
13675 return result;
13676 } else {
13677 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13678 Nuitka_String_AsString_Unchecked(attr_name));
13679
13680 return NULL;
13681 }
13682}
13683PyObject *CALL_METHOD_WITH_ARGS8(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13684 CHECK_OBJECT(source);
13685 CHECK_OBJECT(attr_name);
13686
13687 CHECK_OBJECTS(args, 8);
13688
13689 PyTypeObject *type = Py_TYPE(source);
13690
13691 if (hasTypeGenericGetAttr(type)) {
13692 // Unfortunately this is required, although of cause rarely necessary.
13693 if (unlikely(type->tp_dict == NULL)) {
13694 if (unlikely(PyType_Ready(type) < 0)) {
13695 return NULL;
13696 }
13697 }
13698
13699 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13700 descrgetfunc func = NULL;
13701
13702 if (descr != NULL) {
13703 Py_INCREF(descr);
13704
13705 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13706 func = Py_TYPE(descr)->tp_descr_get;
13707
13708 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13709 PyObject *called_object = func(descr, source, (PyObject *)type);
13710 Py_DECREF(descr);
13711
13712 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13713 Py_DECREF(called_object);
13714 return result;
13715 }
13716 }
13717 }
13718
13719 Py_ssize_t dictoffset = type->tp_dictoffset;
13720 PyObject *dict = NULL;
13721
13722 if (dictoffset != 0) {
13723 // Negative dictionary offsets have special meaning.
13724 if (dictoffset < 0) {
13725 Py_ssize_t tsize;
13726 size_t size;
13727
13728 tsize = ((PyVarObject *)source)->ob_size;
13729 if (tsize < 0) {
13730 tsize = -tsize;
13731 }
13732 size = _PyObject_VAR_SIZE(type, tsize);
13733
13734 dictoffset += (long)size;
13735 }
13736
13737 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13738 dict = *dictptr;
13739 }
13740
13741 if (dict != NULL) {
13742 CHECK_OBJECT(dict);
13743
13744 Py_INCREF(dict);
13745
13746 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13747
13748 if (called_object != NULL) {
13749 Py_XDECREF(descr);
13750 Py_DECREF(dict);
13751
13752 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13753 Py_DECREF(called_object);
13754 return result;
13755 }
13756
13757 Py_DECREF(dict);
13758 }
13759
13760 if (func != NULL) {
13761 if (func == Nuitka_Function_Type.tp_descr_get) {
13762 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13763 source, args, 8);
13764 Py_DECREF(descr);
13765
13766 return result;
13767 } else {
13768 PyObject *called_object = func(descr, source, (PyObject *)type);
13769 CHECK_OBJECT(called_object);
13770
13771 Py_DECREF(descr);
13772
13773 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13774 Py_DECREF(called_object);
13775 return result;
13776 }
13777 }
13778
13779 if (descr != NULL) {
13780 CHECK_OBJECT(descr);
13781
13782 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, descr, args);
13783 Py_DECREF(descr);
13784 return result;
13785 }
13786
13787#if PYTHON_VERSION < 0x300
13788 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13789 PyString_AS_STRING(attr_name));
13790#else
13791 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13792#endif
13793 return NULL;
13794 }
13795#if PYTHON_VERSION < 0x300
13796 else if (type == &PyInstance_Type) {
13797 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13798
13799 // The special cases have their own variant on the code generation level
13800 // as we are called with constants only.
13801 assert(attr_name != const_str_plain___dict__);
13802 assert(attr_name != const_str_plain___class__);
13803
13804 // Try the instance dict first.
13805 PyObject *called_object =
13806 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13807
13808 // Note: The "called_object" was found without taking a reference,
13809 // so we need not release it in this branch.
13810 if (called_object != NULL) {
13811 return CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13812 }
13813
13814 // Then check the class dictionaries.
13815 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13816
13817 // Note: The "called_object" was found without taking a reference,
13818 // so we need not release it in this branch.
13819 if (called_object != NULL) {
13820 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13821
13822 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13823 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13824 source, args, 8);
13825 } else if (descr_get != NULL) {
13826 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13827
13828 if (unlikely(method == NULL)) {
13829 return NULL;
13830 }
13831
13832 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, method, args);
13833 Py_DECREF(method);
13834 return result;
13835 } else {
13836 return CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13837 }
13838
13839 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13840 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13841 PyString_AS_STRING(source_instance->in_class->cl_name),
13842 PyString_AS_STRING(attr_name));
13843
13844 return NULL;
13845 } else {
13846 // Finally allow the "__getattr__" override to provide it or else
13847 // it's an error.
13848
13849 PyObject *args2[] = {source, attr_name};
13850
13851 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13852
13853 if (unlikely(called_object == NULL)) {
13854 return NULL;
13855 }
13856
13857 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13858 Py_DECREF(called_object);
13859 return result;
13860 }
13861 }
13862#endif
13863 else if (type->tp_getattro != NULL) {
13864 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13865
13866 if (unlikely(descr == NULL)) {
13867 return NULL;
13868 }
13869
13870 descrgetfunc func = NULL;
13871 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13872 func = Py_TYPE(descr)->tp_descr_get;
13873
13874 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13875 PyObject *called_object = func(descr, source, (PyObject *)type);
13876 Py_DECREF(descr);
13877
13878 if (unlikely(called_object == NULL)) {
13879 return NULL;
13880 }
13881
13882 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13883 Py_DECREF(called_object);
13884 return result;
13885 }
13886 }
13887
13888 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, descr, args);
13889 Py_DECREF(descr);
13890 return result;
13891 } else if (type->tp_getattr != NULL) {
13892 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13893
13894 if (unlikely(called_object == NULL)) {
13895 return NULL;
13896 }
13897
13898 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13899 Py_DECREF(called_object);
13900 return result;
13901 } else {
13902 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13903 Nuitka_String_AsString_Unchecked(attr_name));
13904
13905 return NULL;
13906 }
13907}
13908PyObject *CALL_METHOD_WITH_ARGS9(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13909 CHECK_OBJECT(source);
13910 CHECK_OBJECT(attr_name);
13911
13912 CHECK_OBJECTS(args, 9);
13913
13914 PyTypeObject *type = Py_TYPE(source);
13915
13916 if (hasTypeGenericGetAttr(type)) {
13917 // Unfortunately this is required, although of cause rarely necessary.
13918 if (unlikely(type->tp_dict == NULL)) {
13919 if (unlikely(PyType_Ready(type) < 0)) {
13920 return NULL;
13921 }
13922 }
13923
13924 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13925 descrgetfunc func = NULL;
13926
13927 if (descr != NULL) {
13928 Py_INCREF(descr);
13929
13930 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13931 func = Py_TYPE(descr)->tp_descr_get;
13932
13933 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13934 PyObject *called_object = func(descr, source, (PyObject *)type);
13935 Py_DECREF(descr);
13936
13937 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13938 Py_DECREF(called_object);
13939 return result;
13940 }
13941 }
13942 }
13943
13944 Py_ssize_t dictoffset = type->tp_dictoffset;
13945 PyObject *dict = NULL;
13946
13947 if (dictoffset != 0) {
13948 // Negative dictionary offsets have special meaning.
13949 if (dictoffset < 0) {
13950 Py_ssize_t tsize;
13951 size_t size;
13952
13953 tsize = ((PyVarObject *)source)->ob_size;
13954 if (tsize < 0) {
13955 tsize = -tsize;
13956 }
13957 size = _PyObject_VAR_SIZE(type, tsize);
13958
13959 dictoffset += (long)size;
13960 }
13961
13962 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13963 dict = *dictptr;
13964 }
13965
13966 if (dict != NULL) {
13967 CHECK_OBJECT(dict);
13968
13969 Py_INCREF(dict);
13970
13971 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13972
13973 if (called_object != NULL) {
13974 Py_XDECREF(descr);
13975 Py_DECREF(dict);
13976
13977 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13978 Py_DECREF(called_object);
13979 return result;
13980 }
13981
13982 Py_DECREF(dict);
13983 }
13984
13985 if (func != NULL) {
13986 if (func == Nuitka_Function_Type.tp_descr_get) {
13987 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13988 source, args, 9);
13989 Py_DECREF(descr);
13990
13991 return result;
13992 } else {
13993 PyObject *called_object = func(descr, source, (PyObject *)type);
13994 CHECK_OBJECT(called_object);
13995
13996 Py_DECREF(descr);
13997
13998 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13999 Py_DECREF(called_object);
14000 return result;
14001 }
14002 }
14003
14004 if (descr != NULL) {
14005 CHECK_OBJECT(descr);
14006
14007 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, descr, args);
14008 Py_DECREF(descr);
14009 return result;
14010 }
14011
14012#if PYTHON_VERSION < 0x300
14013 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14014 PyString_AS_STRING(attr_name));
14015#else
14016 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
14017#endif
14018 return NULL;
14019 }
14020#if PYTHON_VERSION < 0x300
14021 else if (type == &PyInstance_Type) {
14022 PyInstanceObject *source_instance = (PyInstanceObject *)source;
14023
14024 // The special cases have their own variant on the code generation level
14025 // as we are called with constants only.
14026 assert(attr_name != const_str_plain___dict__);
14027 assert(attr_name != const_str_plain___class__);
14028
14029 // Try the instance dict first.
14030 PyObject *called_object =
14031 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
14032
14033 // Note: The "called_object" was found without taking a reference,
14034 // so we need not release it in this branch.
14035 if (called_object != NULL) {
14036 return CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14037 }
14038
14039 // Then check the class dictionaries.
14040 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
14041
14042 // Note: The "called_object" was found without taking a reference,
14043 // so we need not release it in this branch.
14044 if (called_object != NULL) {
14045 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
14046
14047 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
14048 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
14049 source, args, 9);
14050 } else if (descr_get != NULL) {
14051 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
14052
14053 if (unlikely(method == NULL)) {
14054 return NULL;
14055 }
14056
14057 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, method, args);
14058 Py_DECREF(method);
14059 return result;
14060 } else {
14061 return CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14062 }
14063
14064 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
14065 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
14066 PyString_AS_STRING(source_instance->in_class->cl_name),
14067 PyString_AS_STRING(attr_name));
14068
14069 return NULL;
14070 } else {
14071 // Finally allow the "__getattr__" override to provide it or else
14072 // it's an error.
14073
14074 PyObject *args2[] = {source, attr_name};
14075
14076 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
14077
14078 if (unlikely(called_object == NULL)) {
14079 return NULL;
14080 }
14081
14082 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14083 Py_DECREF(called_object);
14084 return result;
14085 }
14086 }
14087#endif
14088 else if (type->tp_getattro != NULL) {
14089 PyObject *descr = (*type->tp_getattro)(source, attr_name);
14090
14091 if (unlikely(descr == NULL)) {
14092 return NULL;
14093 }
14094
14095 descrgetfunc func = NULL;
14096 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14097 func = Py_TYPE(descr)->tp_descr_get;
14098
14099 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14100 PyObject *called_object = func(descr, source, (PyObject *)type);
14101 Py_DECREF(descr);
14102
14103 if (unlikely(called_object == NULL)) {
14104 return NULL;
14105 }
14106
14107 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14108 Py_DECREF(called_object);
14109 return result;
14110 }
14111 }
14112
14113 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, descr, args);
14114 Py_DECREF(descr);
14115 return result;
14116 } else if (type->tp_getattr != NULL) {
14117 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
14118
14119 if (unlikely(called_object == NULL)) {
14120 return NULL;
14121 }
14122
14123 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14124 Py_DECREF(called_object);
14125 return result;
14126 } else {
14127 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14128 Nuitka_String_AsString_Unchecked(attr_name));
14129
14130 return NULL;
14131 }
14132}
14133PyObject *CALL_METHOD_WITH_ARGS10(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
14134 CHECK_OBJECT(source);
14135 CHECK_OBJECT(attr_name);
14136
14137 CHECK_OBJECTS(args, 10);
14138
14139 PyTypeObject *type = Py_TYPE(source);
14140
14141 if (hasTypeGenericGetAttr(type)) {
14142 // Unfortunately this is required, although of cause rarely necessary.
14143 if (unlikely(type->tp_dict == NULL)) {
14144 if (unlikely(PyType_Ready(type) < 0)) {
14145 return NULL;
14146 }
14147 }
14148
14149 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
14150 descrgetfunc func = NULL;
14151
14152 if (descr != NULL) {
14153 Py_INCREF(descr);
14154
14155 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14156 func = Py_TYPE(descr)->tp_descr_get;
14157
14158 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14159 PyObject *called_object = func(descr, source, (PyObject *)type);
14160 Py_DECREF(descr);
14161
14162 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14163 Py_DECREF(called_object);
14164 return result;
14165 }
14166 }
14167 }
14168
14169 Py_ssize_t dictoffset = type->tp_dictoffset;
14170 PyObject *dict = NULL;
14171
14172 if (dictoffset != 0) {
14173 // Negative dictionary offsets have special meaning.
14174 if (dictoffset < 0) {
14175 Py_ssize_t tsize;
14176 size_t size;
14177
14178 tsize = ((PyVarObject *)source)->ob_size;
14179 if (tsize < 0) {
14180 tsize = -tsize;
14181 }
14182 size = _PyObject_VAR_SIZE(type, tsize);
14183
14184 dictoffset += (long)size;
14185 }
14186
14187 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
14188 dict = *dictptr;
14189 }
14190
14191 if (dict != NULL) {
14192 CHECK_OBJECT(dict);
14193
14194 Py_INCREF(dict);
14195
14196 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
14197
14198 if (called_object != NULL) {
14199 Py_XDECREF(descr);
14200 Py_DECREF(dict);
14201
14202 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14203 Py_DECREF(called_object);
14204 return result;
14205 }
14206
14207 Py_DECREF(dict);
14208 }
14209
14210 if (func != NULL) {
14211 if (func == Nuitka_Function_Type.tp_descr_get) {
14212 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
14213 source, args, 10);
14214 Py_DECREF(descr);
14215
14216 return result;
14217 } else {
14218 PyObject *called_object = func(descr, source, (PyObject *)type);
14219 CHECK_OBJECT(called_object);
14220
14221 Py_DECREF(descr);
14222
14223 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14224 Py_DECREF(called_object);
14225 return result;
14226 }
14227 }
14228
14229 if (descr != NULL) {
14230 CHECK_OBJECT(descr);
14231
14232 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, descr, args);
14233 Py_DECREF(descr);
14234 return result;
14235 }
14236
14237#if PYTHON_VERSION < 0x300
14238 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14239 PyString_AS_STRING(attr_name));
14240#else
14241 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
14242#endif
14243 return NULL;
14244 }
14245#if PYTHON_VERSION < 0x300
14246 else if (type == &PyInstance_Type) {
14247 PyInstanceObject *source_instance = (PyInstanceObject *)source;
14248
14249 // The special cases have their own variant on the code generation level
14250 // as we are called with constants only.
14251 assert(attr_name != const_str_plain___dict__);
14252 assert(attr_name != const_str_plain___class__);
14253
14254 // Try the instance dict first.
14255 PyObject *called_object =
14256 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
14257
14258 // Note: The "called_object" was found without taking a reference,
14259 // so we need not release it in this branch.
14260 if (called_object != NULL) {
14261 return CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14262 }
14263
14264 // Then check the class dictionaries.
14265 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
14266
14267 // Note: The "called_object" was found without taking a reference,
14268 // so we need not release it in this branch.
14269 if (called_object != NULL) {
14270 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
14271
14272 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
14273 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
14274 source, args, 10);
14275 } else if (descr_get != NULL) {
14276 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
14277
14278 if (unlikely(method == NULL)) {
14279 return NULL;
14280 }
14281
14282 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, method, args);
14283 Py_DECREF(method);
14284 return result;
14285 } else {
14286 return CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14287 }
14288
14289 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
14290 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
14291 PyString_AS_STRING(source_instance->in_class->cl_name),
14292 PyString_AS_STRING(attr_name));
14293
14294 return NULL;
14295 } else {
14296 // Finally allow the "__getattr__" override to provide it or else
14297 // it's an error.
14298
14299 PyObject *args2[] = {source, attr_name};
14300
14301 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
14302
14303 if (unlikely(called_object == NULL)) {
14304 return NULL;
14305 }
14306
14307 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14308 Py_DECREF(called_object);
14309 return result;
14310 }
14311 }
14312#endif
14313 else if (type->tp_getattro != NULL) {
14314 PyObject *descr = (*type->tp_getattro)(source, attr_name);
14315
14316 if (unlikely(descr == NULL)) {
14317 return NULL;
14318 }
14319
14320 descrgetfunc func = NULL;
14321 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14322 func = Py_TYPE(descr)->tp_descr_get;
14323
14324 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14325 PyObject *called_object = func(descr, source, (PyObject *)type);
14326 Py_DECREF(descr);
14327
14328 if (unlikely(called_object == NULL)) {
14329 return NULL;
14330 }
14331
14332 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14333 Py_DECREF(called_object);
14334 return result;
14335 }
14336 }
14337
14338 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, descr, args);
14339 Py_DECREF(descr);
14340 return result;
14341 } else if (type->tp_getattr != NULL) {
14342 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
14343
14344 if (unlikely(called_object == NULL)) {
14345 return NULL;
14346 }
14347
14348 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14349 Py_DECREF(called_object);
14350 return result;
14351 } else {
14352 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14353 Nuitka_String_AsString_Unchecked(attr_name));
14354
14355 return NULL;
14356 }
14357}
14358#if defined(__clang__)
14359#pragma clang diagnostic pop
14360#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
14361#pragma GCC diagnostic pop
14362#endif
14363
14364// Part of "Nuitka", an optimizing Python compiler that is compatible and
14365// integrates with CPython, but also works on its own.
14366//
14367// Licensed under the Apache License, Version 2.0 (the "License");
14368// you may not use this file except in compliance with the License.
14369// You may obtain a copy of the License at
14370//
14371// http://www.apache.org/licenses/LICENSE-2.0
14372//
14373// Unless required by applicable law or agreed to in writing, software
14374// distributed under the License is distributed on an "AS IS" BASIS,
14375// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14376// See the License for the specific language governing permissions and
14377// limitations under the License.
Definition compiled_function.h:22
Definition compiled_method.h:16