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#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
18#pragma GCC diagnostic push
19#endif
20#pragma GCC diagnostic ignored "-Wparentheses"
21#endif
22
23PyObject *CALL_FUNCTION_NO_ARGS(PyThreadState *tstate, PyObject *called) {
24 CHECK_OBJECT(called);
25
26 if (Nuitka_Function_Check(called)) {
27 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
28 return NULL;
29 }
30
31 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
32 PyObject *result;
33
34 if (function->m_args_simple && 0 == function->m_args_positional_count) {
35 result = function->m_c_code(tstate, function, NULL);
36 } else if (function->m_args_simple && 0 + function->m_defaults_given == function->m_args_positional_count) {
37 PyObject **python_pars = &PyTuple_GET_ITEM(function->m_defaults, 0);
38
39 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
40 Py_INCREF(python_pars[i]);
41 }
42
43 result = function->m_c_code(tstate, function, python_pars);
44 } else {
45 result = Nuitka_CallFunctionNoArgs(tstate, function);
46 }
47
48 Py_LeaveRecursiveCall();
49
50 CHECK_OBJECT_X(result);
51
52 return result;
53 } else if (Nuitka_Method_Check(called)) {
54 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
55
56 if (method->m_object == NULL) {
57 PyErr_Format(
58 PyExc_TypeError,
59 "unbound compiled_method %s%s must be called with %s instance as first argument (got nothing instead)",
60 GET_CALLABLE_NAME((PyObject *)method->m_function), GET_CALLABLE_DESC((PyObject *)method->m_function),
61 GET_CLASS_NAME(method->m_class));
62 return NULL;
63 } else {
64 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
65 return NULL;
66 }
67
68 struct Nuitka_FunctionObject *function = method->m_function;
69
70 PyObject *result;
71
72 if (function->m_args_simple && 0 + 1 == function->m_args_positional_count) {
73 PyObject *python_pars[0 + 1];
74
75 python_pars[0] = method->m_object;
76 Py_INCREF(method->m_object);
77
78 result = function->m_c_code(tstate, function, python_pars);
79 } else if (function->m_args_simple &&
80 0 + 1 + function->m_defaults_given == function->m_args_positional_count) {
81 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
82
83 python_pars[0] = method->m_object;
84 Py_INCREF(method->m_object);
85
86 memcpy(python_pars + 1 + 0, &PyTuple_GET_ITEM(function->m_defaults, 0),
87 function->m_defaults_given * sizeof(PyObject *));
88
89 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
90 Py_INCREF(python_pars[i]);
91 }
92
93 result = function->m_c_code(tstate, function, python_pars);
94 } else {
95 result = Nuitka_CallMethodFunctionNoArgs(tstate, function, method->m_object);
96 }
97
98 Py_LeaveRecursiveCall();
99
100 CHECK_OBJECT_X(result);
101
102 return result;
103 }
104#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
105 } else if (PyCFunction_CheckExact(called)) {
106#if PYTHON_VERSION >= 0x380
107#ifdef _NUITKA_FULL_COMPAT
108 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
109 return NULL;
110 }
111#endif
112
113 int flags = PyCFunction_GET_FLAGS(called);
114
115 PyObject *result;
116
117 if (!(flags & METH_VARARGS)) {
118 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
119
120 assert(func != NULL);
121 result = func(called, NULL, 0, NULL);
122
123 CHECK_OBJECT_X(result);
124 } else {
125 PyCFunction method = PyCFunction_GET_FUNCTION(called);
126 PyObject *self = PyCFunction_GET_SELF(called);
127
128 PyObject *pos_args = const_tuple_empty;
129
130 if (flags & METH_KEYWORDS) {
131 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
132 } else {
133 result = (*method)(self, pos_args);
134 }
135 }
136
137#ifdef _NUITKA_FULL_COMPAT
138 Py_LeaveRecursiveCall();
139#endif
140 CHECK_OBJECT_X(result);
141
142 return Nuitka_CheckFunctionResult(tstate, called, result);
143#else
144 // Try to be fast about wrapping the arguments.
145 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
146
147 if (likely(flags & METH_NOARGS)) {
148 // Recursion guard is not strictly necessary, as we already have
149 // one on our way to here.
150#ifdef _NUITKA_FULL_COMPAT
151 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
152 return NULL;
153 }
154#endif
155 PyCFunction method = PyCFunction_GET_FUNCTION(called);
156 PyObject *self = PyCFunction_GET_SELF(called);
157
158 PyObject *result = (*method)(self, NULL);
159
160#ifdef _NUITKA_FULL_COMPAT
161 Py_LeaveRecursiveCall();
162#endif
163 CHECK_OBJECT_X(result);
164
165 return Nuitka_CheckFunctionResult(tstate, called, result);
166 } else if (unlikely(flags & METH_O)) {
167 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (0 given)",
168 ((PyCFunctionObject *)called)->m_ml->ml_name);
169 return NULL;
170 } else if (flags & METH_VARARGS) {
171 // Recursion guard is not strictly necessary, as we already have
172 // one on our way to here.
173#ifdef _NUITKA_FULL_COMPAT
174 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
175 return NULL;
176 }
177#endif
178 PyCFunction method = PyCFunction_GET_FUNCTION(called);
179 PyObject *self = PyCFunction_GET_SELF(called);
180
181 PyObject *result;
182
183#if PYTHON_VERSION < 0x360
184 PyObject *pos_args = const_tuple_empty;
185 if (flags & METH_KEYWORDS) {
186 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
187 } else {
188 result = (*method)(self, pos_args);
189 }
190
191#else
192 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
193 PyObject *pos_args = const_tuple_empty;
194 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
195 } else if (flags == METH_FASTCALL) {
196#if PYTHON_VERSION < 0x370
197 result = (*(_PyCFunctionFast)method)(self, NULL, 0, NULL);
198#else
199 PyObject *pos_args = const_tuple_empty;
200 result = (*(_PyCFunctionFast)method)(self, &pos_args, 0);
201#endif
202 } else {
203 PyObject *pos_args = const_tuple_empty;
204 result = (*method)(self, pos_args);
205 }
206#endif
207
208#ifdef _NUITKA_FULL_COMPAT
209 Py_LeaveRecursiveCall();
210#endif
211
212 CHECK_OBJECT_X(result);
213
214 return Nuitka_CheckFunctionResult(tstate, called, result);
215 }
216#endif
217#endif
218#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
219 } else if (PyFunction_Check(called)) {
220#if PYTHON_VERSION < 0x3b0
221 PyObject *result = callPythonFunctionNoArgs(called);
222#else
223 PyObject *result = _PyFunction_Vectorcall(called, NULL, 0, NULL);
224#endif
225 CHECK_OBJECT_X(result);
226
227 return result;
228#endif
229#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
230 } else if (PyType_Check(called)) {
231 PyTypeObject *type = Py_TYPE(called);
232
233 if (type->tp_call == PyType_Type.tp_call) {
234 PyTypeObject *called_type = (PyTypeObject *)(called);
235
236 if (unlikely(called_type->tp_new == NULL)) {
237 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
238 return NULL;
239 }
240
241 PyObject *pos_args = const_tuple_empty;
242 PyObject *obj;
243
244 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
245 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
246 formatCannotInstantiateAbstractClass(tstate, called_type);
247 return NULL;
248 }
249
250 obj = called_type->tp_alloc(called_type, 0);
251 CHECK_OBJECT(obj);
252 } else {
253 obj = called_type->tp_new(called_type, pos_args, NULL);
254 }
255
256 if (likely(obj != NULL)) {
257 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
258 return obj;
259 }
260
261 // Work on produced type.
262 type = Py_TYPE(obj);
263
264 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
265 if (type->tp_init == default_tp_init_wrapper) {
266
267 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
268
269 // Not really allowed, since we wouldn't have the default wrapper set.
270 assert(init_method != NULL);
271
272 bool is_compiled_function = false;
273 bool init_method_needs_release = false;
274
275 if (likely(init_method != NULL)) {
276 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
277
278 if (func == Nuitka_Function_Type.tp_descr_get) {
279 is_compiled_function = true;
280 } else if (func != NULL) {
281 init_method = func(init_method, obj, (PyObject *)(type));
282 init_method_needs_release = true;
283 }
284 }
285
286 if (unlikely(init_method == NULL)) {
287 if (!HAS_ERROR_OCCURRED(tstate)) {
288 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
289 const_str_plain___init__);
290 }
291
292 return NULL;
293 }
294
295 PyObject *result;
296 if (is_compiled_function) {
297 result = Nuitka_CallMethodFunctionNoArgs(
298 tstate, (struct Nuitka_FunctionObject const *)init_method, obj);
299 } else {
300 result = CALL_FUNCTION_NO_ARGS(tstate, init_method);
301
302 if (init_method_needs_release) {
303 Py_DECREF(init_method);
304 }
305 }
306
307 if (unlikely(result == NULL)) {
308 Py_DECREF(obj);
309 return NULL;
310 }
311
312 Py_DECREF(result);
313
314 if (unlikely(result != Py_None)) {
315 Py_DECREF(obj);
316
317 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
318 return NULL;
319 }
320 } else {
321
322 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
323 Py_DECREF(obj);
324 return NULL;
325 }
326 }
327 }
328 }
329
330 CHECK_OBJECT_X(obj);
331
332 return obj;
333 }
334#endif
335#if PYTHON_VERSION < 0x300
336 } else if (PyClass_Check(called)) {
337 PyObject *obj = PyInstance_NewRaw(called, NULL);
338
339 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
340
341 if ((init_method == NULL)) {
342 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
343 Py_DECREF(obj);
344 return NULL;
345 }
346
347 return obj;
348 }
349
350 bool is_compiled_function = false;
351
352 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
353
354 if (descr_get == NULL) {
355 Py_INCREF(init_method);
356 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
357 is_compiled_function = true;
358 } else if (descr_get != NULL) {
359 PyObject *descr_method = descr_get(init_method, obj, called);
360
361 if (unlikely(descr_method == NULL)) {
362 return NULL;
363 }
364
365 init_method = descr_method;
366 }
367
368 PyObject *result;
369 if (is_compiled_function) {
370 result = Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj);
371 } else {
372 result = CALL_FUNCTION_NO_ARGS(tstate, init_method);
373 Py_DECREF(init_method);
374 }
375 if (unlikely(result == NULL)) {
376 return NULL;
377 }
378
379 Py_DECREF(result);
380
381 if (unlikely(result != Py_None)) {
382 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
383 return NULL;
384 }
385
386 CHECK_OBJECT_X(obj);
387
388 return obj;
389#endif
390#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
391 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
392 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
393
394 if (likely(func != NULL)) {
395 PyObject *result = func(called, NULL, 0, NULL);
396
397 CHECK_OBJECT_X(result);
398
399 return Nuitka_CheckFunctionResult(tstate, called, result);
400 }
401#endif
402 }
403
404#if 0
405 PRINT_NEW_LINE();
406 PRINT_STRING("FALLBACK");
407 PRINT_ITEM(called);
408 PRINT_NEW_LINE();
409#endif
410
411 PyObject *result = CALL_FUNCTION(tstate, called, const_tuple_empty, NULL);
412
413 CHECK_OBJECT_X(result);
414
415 return result;
416}
417PyObject *CALL_FUNCTION_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg) {
418 PyObject *const *args = &arg; // For easier code compatibility.
419 CHECK_OBJECT(called);
420 CHECK_OBJECTS(args, 1);
421
422 if (Nuitka_Function_Check(called)) {
423 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
424 return NULL;
425 }
426
427 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
428 PyObject *result;
429
430 if (function->m_args_simple && 1 == function->m_args_positional_count) {
431 Py_INCREF(args[0]);
432 result = function->m_c_code(tstate, function, (PyObject **)args);
433 } else if (function->m_args_simple && 1 + function->m_defaults_given == function->m_args_positional_count) {
434 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
435
436 memcpy(python_pars, args, 1 * sizeof(PyObject *));
437 memcpy(python_pars + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
438 function->m_defaults_given * sizeof(PyObject *));
439
440 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
441 Py_INCREF(python_pars[i]);
442 }
443
444 result = function->m_c_code(tstate, function, python_pars);
445 } else {
446 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 1);
447 }
448
449 Py_LeaveRecursiveCall();
450
451 CHECK_OBJECT_X(result);
452
453 return result;
454 } else if (Nuitka_Method_Check(called)) {
455 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
456
457 if (method->m_object == NULL) {
458 PyObject *self = args[0];
459
460 int res = PyObject_IsInstance(self, method->m_class);
461
462 if (unlikely(res < 0)) {
463 return NULL;
464 } else if (unlikely(res == 0)) {
465 PyErr_Format(PyExc_TypeError,
466 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
467 "instance instead)",
468 GET_CALLABLE_NAME((PyObject *)method->m_function),
469 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
470 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
471
472 return NULL;
473 }
474
475 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 1);
476
477 CHECK_OBJECT_X(result);
478
479 return result;
480 } else {
481 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
482 return NULL;
483 }
484
485 struct Nuitka_FunctionObject *function = method->m_function;
486
487 PyObject *result;
488
489 if (function->m_args_simple && 1 + 1 == function->m_args_positional_count) {
490 PyObject *python_pars[1 + 1];
491
492 python_pars[0] = method->m_object;
493 Py_INCREF(method->m_object);
494
495 python_pars[1] = args[0];
496 Py_INCREF(args[0]);
497 result = function->m_c_code(tstate, function, python_pars);
498 } else if (function->m_args_simple &&
499 1 + 1 + function->m_defaults_given == function->m_args_positional_count) {
500 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
501
502 python_pars[0] = method->m_object;
503 Py_INCREF(method->m_object);
504
505 memcpy(python_pars + 1, args, 1 * sizeof(PyObject *));
506 memcpy(python_pars + 1 + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
507 function->m_defaults_given * sizeof(PyObject *));
508
509 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
510 Py_INCREF(python_pars[i]);
511 }
512
513 result = function->m_c_code(tstate, function, python_pars);
514 } else {
515 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 1);
516 }
517
518 Py_LeaveRecursiveCall();
519
520 CHECK_OBJECT_X(result);
521
522 return result;
523 }
524#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
525 } else if (PyCFunction_CheckExact(called)) {
526#if PYTHON_VERSION >= 0x380
527#ifdef _NUITKA_FULL_COMPAT
528 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
529 return NULL;
530 }
531#endif
532
533 int flags = PyCFunction_GET_FLAGS(called);
534
535 PyObject *result;
536
537 if (!(flags & METH_VARARGS)) {
538 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
539
540 assert(func != NULL);
541 result = func(called, args, 1, NULL);
542
543 CHECK_OBJECT_X(result);
544 } else {
545 PyCFunction method = PyCFunction_GET_FUNCTION(called);
546 PyObject *self = PyCFunction_GET_SELF(called);
547
548 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
549
550 if (flags & METH_KEYWORDS) {
551 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
552 } else {
553 result = (*method)(self, pos_args);
554 }
555
556 Py_DECREF(pos_args);
557 }
558
559#ifdef _NUITKA_FULL_COMPAT
560 Py_LeaveRecursiveCall();
561#endif
562 CHECK_OBJECT_X(result);
563
564 return Nuitka_CheckFunctionResult(tstate, called, result);
565#else
566 // Try to be fast about wrapping the arguments.
567 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
568
569 if (unlikely(flags & METH_NOARGS)) {
570 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (1 given)",
571 ((PyCFunctionObject *)called)->m_ml->ml_name);
572 return NULL;
573 } else if ((flags & METH_O)) {
574 // Recursion guard is not strictly necessary, as we already have
575 // one on our way to here.
576#ifdef _NUITKA_FULL_COMPAT
577 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
578 return NULL;
579 }
580#endif
581 PyCFunction method = PyCFunction_GET_FUNCTION(called);
582 PyObject *self = PyCFunction_GET_SELF(called);
583
584 PyObject *result = (*method)(self, args[0]);
585
586#ifdef _NUITKA_FULL_COMPAT
587 Py_LeaveRecursiveCall();
588#endif
589
590 CHECK_OBJECT_X(result);
591
592 return Nuitka_CheckFunctionResult(tstate, called, result);
593 } else if (flags & METH_VARARGS) {
594 // Recursion guard is not strictly necessary, as we already have
595 // one on our way to here.
596#ifdef _NUITKA_FULL_COMPAT
597 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
598 return NULL;
599 }
600#endif
601 PyCFunction method = PyCFunction_GET_FUNCTION(called);
602 PyObject *self = PyCFunction_GET_SELF(called);
603
604 PyObject *result;
605
606#if PYTHON_VERSION < 0x360
607 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
608 if (flags & METH_KEYWORDS) {
609 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
610 } else {
611 result = (*method)(self, pos_args);
612 }
613
614 Py_DECREF(pos_args);
615#else
616 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
617 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
618 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
619 Py_DECREF(pos_args);
620 } else if (flags == METH_FASTCALL) {
621#if PYTHON_VERSION < 0x370
622 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 1, NULL);
623#else
624 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
625 result = (*(_PyCFunctionFast)method)(self, &pos_args, 1);
626 Py_DECREF(pos_args);
627#endif
628 } else {
629 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
630 result = (*method)(self, pos_args);
631 Py_DECREF(pos_args);
632 }
633#endif
634
635#ifdef _NUITKA_FULL_COMPAT
636 Py_LeaveRecursiveCall();
637#endif
638
639 CHECK_OBJECT_X(result);
640
641 return Nuitka_CheckFunctionResult(tstate, called, result);
642 }
643#endif
644#endif
645#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
646 } else if (PyFunction_Check(called)) {
647#if PYTHON_VERSION < 0x3b0
648 PyObject *result = callPythonFunction(called, args, 1);
649#else
650 PyObject *result = _PyFunction_Vectorcall(called, args, 1, NULL);
651#endif
652 CHECK_OBJECT_X(result);
653
654 return result;
655#endif
656#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
657 } else if (PyType_Check(called)) {
658 PyTypeObject *type = Py_TYPE(called);
659
660 if (type->tp_call == PyType_Type.tp_call) {
661 PyTypeObject *called_type = (PyTypeObject *)(called);
662
663 if (unlikely(called == (PyObject *)&PyType_Type)) {
664 PyObject *result = (PyObject *)Py_TYPE(args[0]);
665 Py_INCREF(result);
666 return result;
667 }
668
669 if (unlikely(called_type->tp_new == NULL)) {
670 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
671 return NULL;
672 }
673
674 PyObject *pos_args = NULL;
675 PyObject *obj;
676
677 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
678 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
679 formatCannotInstantiateAbstractClass(tstate, called_type);
680 return NULL;
681 }
682
683 obj = called_type->tp_alloc(called_type, 0);
684 CHECK_OBJECT(obj);
685 } else {
686 pos_args = MAKE_TUPLE(tstate, args, 1);
687 obj = called_type->tp_new(called_type, pos_args, NULL);
688 }
689
690 if (likely(obj != NULL)) {
691 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
692 Py_DECREF(pos_args);
693 return obj;
694 }
695
696 // Work on produced type.
697 type = Py_TYPE(obj);
698
699 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
700 if (type->tp_init == default_tp_init_wrapper) {
701 Py_XDECREF(pos_args);
702 pos_args = NULL;
703
704 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
705
706 // Not really allowed, since we wouldn't have the default wrapper set.
707 assert(init_method != NULL);
708
709 bool is_compiled_function = false;
710 bool init_method_needs_release = false;
711
712 if (likely(init_method != NULL)) {
713 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
714
715 if (func == Nuitka_Function_Type.tp_descr_get) {
716 is_compiled_function = true;
717 } else if (func != NULL) {
718 init_method = func(init_method, obj, (PyObject *)(type));
719 init_method_needs_release = true;
720 }
721 }
722
723 if (unlikely(init_method == NULL)) {
724 if (!HAS_ERROR_OCCURRED(tstate)) {
725 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
726 const_str_plain___init__);
727 }
728
729 return NULL;
730 }
731
732 PyObject *result;
733 if (is_compiled_function) {
734 result = Nuitka_CallMethodFunctionPosArgs(
735 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 1);
736 } else {
737 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
738
739 if (init_method_needs_release) {
740 Py_DECREF(init_method);
741 }
742 }
743
744 if (unlikely(result == NULL)) {
745 Py_DECREF(obj);
746 return NULL;
747 }
748
749 Py_DECREF(result);
750
751 if (unlikely(result != Py_None)) {
752 Py_DECREF(obj);
753
754 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
755 return NULL;
756 }
757 } else {
758 if (pos_args == NULL) {
759 pos_args = MAKE_TUPLE(tstate, args, 1);
760 }
761
762 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
763 Py_DECREF(obj);
764 Py_XDECREF(pos_args);
765 return NULL;
766 }
767 }
768 }
769 }
770
771 Py_XDECREF(pos_args);
772
773 CHECK_OBJECT_X(obj);
774
775 return obj;
776 }
777#endif
778#if PYTHON_VERSION < 0x300
779 } else if (PyClass_Check(called)) {
780 PyObject *obj = PyInstance_NewRaw(called, NULL);
781
782 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
783
784 if (unlikely(init_method == NULL)) {
785 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
786 Py_DECREF(obj);
787 return NULL;
788 }
789
790 Py_DECREF(obj);
791
792 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
793 return NULL;
794 }
795
796 bool is_compiled_function = false;
797
798 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
799
800 if (descr_get == NULL) {
801 Py_INCREF(init_method);
802 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
803 is_compiled_function = true;
804 } else if (descr_get != NULL) {
805 PyObject *descr_method = descr_get(init_method, obj, called);
806
807 if (unlikely(descr_method == NULL)) {
808 return NULL;
809 }
810
811 init_method = descr_method;
812 }
813
814 PyObject *result;
815 if (is_compiled_function) {
816 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
817 args, 1);
818 } else {
819 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
820 Py_DECREF(init_method);
821 }
822 if (unlikely(result == NULL)) {
823 return NULL;
824 }
825
826 Py_DECREF(result);
827
828 if (unlikely(result != Py_None)) {
829 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
830 return NULL;
831 }
832
833 CHECK_OBJECT_X(obj);
834
835 return obj;
836#endif
837#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
838 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
839 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
840
841 if (likely(func != NULL)) {
842 PyObject *result = func(called, args, 1, NULL);
843
844 CHECK_OBJECT_X(result);
845
846 return Nuitka_CheckFunctionResult(tstate, called, result);
847 }
848#endif
849 }
850
851#if 0
852 PRINT_NEW_LINE();
853 PRINT_STRING("FALLBACK");
854 PRINT_ITEM(called);
855 PRINT_NEW_LINE();
856#endif
857
858 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
859
860 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
861
862 Py_DECREF(pos_args);
863
864 CHECK_OBJECT_X(result);
865
866 return result;
867}
868PyObject *CALL_FUNCTION_WITH_POS_ARGS1(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
869 assert(PyTuple_CheckExact(pos_args));
870 assert(PyTuple_GET_SIZE(pos_args) == 1);
871 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
872 CHECK_OBJECT(called);
873 CHECK_OBJECTS(args, 1);
874
875 if (Nuitka_Function_Check(called)) {
876 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
877 return NULL;
878 }
879
880 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
881 PyObject *result;
882
883 if (function->m_args_simple && 1 == function->m_args_positional_count) {
884 Py_INCREF(args[0]);
885 result = function->m_c_code(tstate, function, (PyObject **)args);
886 } else if (function->m_args_simple && 1 + function->m_defaults_given == function->m_args_positional_count) {
887 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
888
889 memcpy(python_pars, args, 1 * sizeof(PyObject *));
890 memcpy(python_pars + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
891 function->m_defaults_given * sizeof(PyObject *));
892
893 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
894 Py_INCREF(python_pars[i]);
895 }
896
897 result = function->m_c_code(tstate, function, python_pars);
898 } else {
899 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 1);
900 }
901
902 Py_LeaveRecursiveCall();
903
904 CHECK_OBJECT_X(result);
905
906 return result;
907 } else if (Nuitka_Method_Check(called)) {
908 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
909
910 if (method->m_object == NULL) {
911 PyObject *self = args[0];
912
913 int res = PyObject_IsInstance(self, method->m_class);
914
915 if (unlikely(res < 0)) {
916 return NULL;
917 } else if (unlikely(res == 0)) {
918 PyErr_Format(PyExc_TypeError,
919 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
920 "instance instead)",
921 GET_CALLABLE_NAME((PyObject *)method->m_function),
922 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
923 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
924
925 return NULL;
926 }
927
928 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 1);
929
930 CHECK_OBJECT_X(result);
931
932 return result;
933 } else {
934 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
935 return NULL;
936 }
937
938 struct Nuitka_FunctionObject *function = method->m_function;
939
940 PyObject *result;
941
942 if (function->m_args_simple && 1 + 1 == function->m_args_positional_count) {
943 PyObject *python_pars[1 + 1];
944
945 python_pars[0] = method->m_object;
946 Py_INCREF(method->m_object);
947
948 python_pars[1] = args[0];
949 Py_INCREF(args[0]);
950 result = function->m_c_code(tstate, function, python_pars);
951 } else if (function->m_args_simple &&
952 1 + 1 + function->m_defaults_given == function->m_args_positional_count) {
953 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
954
955 python_pars[0] = method->m_object;
956 Py_INCREF(method->m_object);
957
958 memcpy(python_pars + 1, args, 1 * sizeof(PyObject *));
959 memcpy(python_pars + 1 + 1, &PyTuple_GET_ITEM(function->m_defaults, 0),
960 function->m_defaults_given * sizeof(PyObject *));
961
962 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
963 Py_INCREF(python_pars[i]);
964 }
965
966 result = function->m_c_code(tstate, function, python_pars);
967 } else {
968 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 1);
969 }
970
971 Py_LeaveRecursiveCall();
972
973 CHECK_OBJECT_X(result);
974
975 return result;
976 }
977#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
978 } else if (PyCFunction_CheckExact(called)) {
979#if PYTHON_VERSION >= 0x380
980#ifdef _NUITKA_FULL_COMPAT
981 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
982 return NULL;
983 }
984#endif
985
986 int flags = PyCFunction_GET_FLAGS(called);
987
988 PyObject *result;
989
990 if (!(flags & METH_VARARGS)) {
991 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
992
993 assert(func != NULL);
994 result = func(called, args, 1, NULL);
995
996 CHECK_OBJECT_X(result);
997 } else {
998 PyCFunction method = PyCFunction_GET_FUNCTION(called);
999 PyObject *self = PyCFunction_GET_SELF(called);
1000
1001 if (flags & METH_KEYWORDS) {
1002 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1003 } else {
1004 result = (*method)(self, pos_args);
1005 }
1006 }
1007
1008#ifdef _NUITKA_FULL_COMPAT
1009 Py_LeaveRecursiveCall();
1010#endif
1011 CHECK_OBJECT_X(result);
1012
1013 return Nuitka_CheckFunctionResult(tstate, called, result);
1014#else
1015 // Try to be fast about wrapping the arguments.
1016 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1017
1018 if (unlikely(flags & METH_NOARGS)) {
1019 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (1 given)",
1020 ((PyCFunctionObject *)called)->m_ml->ml_name);
1021 return NULL;
1022 } else if ((flags & METH_O)) {
1023 // Recursion guard is not strictly necessary, as we already have
1024 // one on our way to here.
1025#ifdef _NUITKA_FULL_COMPAT
1026 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1027 return NULL;
1028 }
1029#endif
1030 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1031 PyObject *self = PyCFunction_GET_SELF(called);
1032
1033 PyObject *result = (*method)(self, args[0]);
1034
1035#ifdef _NUITKA_FULL_COMPAT
1036 Py_LeaveRecursiveCall();
1037#endif
1038
1039 CHECK_OBJECT_X(result);
1040
1041 return Nuitka_CheckFunctionResult(tstate, called, result);
1042 } else if (flags & METH_VARARGS) {
1043 // Recursion guard is not strictly necessary, as we already have
1044 // one on our way to here.
1045#ifdef _NUITKA_FULL_COMPAT
1046 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1047 return NULL;
1048 }
1049#endif
1050 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1051 PyObject *self = PyCFunction_GET_SELF(called);
1052
1053 PyObject *result;
1054
1055#if PYTHON_VERSION < 0x360
1056 if (flags & METH_KEYWORDS) {
1057 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1058 } else {
1059 result = (*method)(self, pos_args);
1060 }
1061
1062#else
1063 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1064 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1065 } else if (flags == METH_FASTCALL) {
1066#if PYTHON_VERSION < 0x370
1067 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 1, NULL);
1068#else
1069 result = (*(_PyCFunctionFast)method)(self, &pos_args, 1);
1070#endif
1071 } else {
1072 result = (*method)(self, pos_args);
1073 }
1074#endif
1075
1076#ifdef _NUITKA_FULL_COMPAT
1077 Py_LeaveRecursiveCall();
1078#endif
1079
1080 CHECK_OBJECT_X(result);
1081
1082 return Nuitka_CheckFunctionResult(tstate, called, result);
1083 }
1084#endif
1085#endif
1086#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1087 } else if (PyFunction_Check(called)) {
1088#if PYTHON_VERSION < 0x3b0
1089 PyObject *result = callPythonFunction(called, args, 1);
1090#else
1091 PyObject *result = _PyFunction_Vectorcall(called, args, 1, NULL);
1092#endif
1093 CHECK_OBJECT_X(result);
1094
1095 return result;
1096#endif
1097#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1098 } else if (PyType_Check(called)) {
1099 PyTypeObject *type = Py_TYPE(called);
1100
1101 if (type->tp_call == PyType_Type.tp_call) {
1102 PyTypeObject *called_type = (PyTypeObject *)(called);
1103
1104 if (unlikely(called == (PyObject *)&PyType_Type)) {
1105 PyObject *result = (PyObject *)Py_TYPE(args[0]);
1106 Py_INCREF(result);
1107 return result;
1108 }
1109
1110 if (unlikely(called_type->tp_new == NULL)) {
1111 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1112 return NULL;
1113 }
1114
1115 PyObject *obj;
1116
1117 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1118 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1119 formatCannotInstantiateAbstractClass(tstate, called_type);
1120 return NULL;
1121 }
1122
1123 obj = called_type->tp_alloc(called_type, 0);
1124 CHECK_OBJECT(obj);
1125 } else {
1126 obj = called_type->tp_new(called_type, pos_args, NULL);
1127 }
1128
1129 if (likely(obj != NULL)) {
1130 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1131 return obj;
1132 }
1133
1134 // Work on produced type.
1135 type = Py_TYPE(obj);
1136
1137 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1138 if (type->tp_init == default_tp_init_wrapper) {
1139
1140 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1141
1142 // Not really allowed, since we wouldn't have the default wrapper set.
1143 assert(init_method != NULL);
1144
1145 bool is_compiled_function = false;
1146 bool init_method_needs_release = false;
1147
1148 if (likely(init_method != NULL)) {
1149 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1150
1151 if (func == Nuitka_Function_Type.tp_descr_get) {
1152 is_compiled_function = true;
1153 } else if (func != NULL) {
1154 init_method = func(init_method, obj, (PyObject *)(type));
1155 init_method_needs_release = true;
1156 }
1157 }
1158
1159 if (unlikely(init_method == NULL)) {
1160 if (!HAS_ERROR_OCCURRED(tstate)) {
1161 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1162 const_str_plain___init__);
1163 }
1164
1165 return NULL;
1166 }
1167
1168 PyObject *result;
1169 if (is_compiled_function) {
1170 result = Nuitka_CallMethodFunctionPosArgs(
1171 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 1);
1172 } else {
1173 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
1174
1175 if (init_method_needs_release) {
1176 Py_DECREF(init_method);
1177 }
1178 }
1179
1180 if (unlikely(result == NULL)) {
1181 Py_DECREF(obj);
1182 return NULL;
1183 }
1184
1185 Py_DECREF(result);
1186
1187 if (unlikely(result != Py_None)) {
1188 Py_DECREF(obj);
1189
1190 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1191 return NULL;
1192 }
1193 } else {
1194
1195 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
1196 Py_DECREF(obj);
1197 return NULL;
1198 }
1199 }
1200 }
1201 }
1202
1203 CHECK_OBJECT_X(obj);
1204
1205 return obj;
1206 }
1207#endif
1208#if PYTHON_VERSION < 0x300
1209 } else if (PyClass_Check(called)) {
1210 PyObject *obj = PyInstance_NewRaw(called, NULL);
1211
1212 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
1213
1214 if (unlikely(init_method == NULL)) {
1215 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
1216 Py_DECREF(obj);
1217 return NULL;
1218 }
1219
1220 Py_DECREF(obj);
1221
1222 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
1223 return NULL;
1224 }
1225
1226 bool is_compiled_function = false;
1227
1228 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
1229
1230 if (descr_get == NULL) {
1231 Py_INCREF(init_method);
1232 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
1233 is_compiled_function = true;
1234 } else if (descr_get != NULL) {
1235 PyObject *descr_method = descr_get(init_method, obj, called);
1236
1237 if (unlikely(descr_method == NULL)) {
1238 return NULL;
1239 }
1240
1241 init_method = descr_method;
1242 }
1243
1244 PyObject *result;
1245 if (is_compiled_function) {
1246 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
1247 args, 1);
1248 } else {
1249 result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, init_method, args[0]);
1250 Py_DECREF(init_method);
1251 }
1252 if (unlikely(result == NULL)) {
1253 return NULL;
1254 }
1255
1256 Py_DECREF(result);
1257
1258 if (unlikely(result != Py_None)) {
1259 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1260 return NULL;
1261 }
1262
1263 CHECK_OBJECT_X(obj);
1264
1265 return obj;
1266#endif
1267#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
1268 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
1269 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1270
1271 if (likely(func != NULL)) {
1272 PyObject *result = func(called, args, 1, NULL);
1273
1274 CHECK_OBJECT_X(result);
1275
1276 return Nuitka_CheckFunctionResult(tstate, called, result);
1277 }
1278#endif
1279 }
1280
1281#if 0
1282 PRINT_NEW_LINE();
1283 PRINT_STRING("FALLBACK");
1284 PRINT_ITEM(called);
1285 PRINT_NEW_LINE();
1286#endif
1287
1288 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
1289
1290 CHECK_OBJECT_X(result);
1291
1292 return result;
1293}
1294PyObject *CALL_FUNCTION_WITH_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
1295 CHECK_OBJECT(called);
1296 CHECK_OBJECTS(args, 2);
1297
1298 if (Nuitka_Function_Check(called)) {
1299 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1300 return NULL;
1301 }
1302
1303 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
1304 PyObject *result;
1305
1306 if (function->m_args_simple && 2 == function->m_args_positional_count) {
1307 for (Py_ssize_t i = 0; i < 2; i++) {
1308 Py_INCREF(args[i]);
1309 }
1310 result = function->m_c_code(tstate, function, (PyObject **)args);
1311 } else if (function->m_args_simple && 2 + function->m_defaults_given == function->m_args_positional_count) {
1312 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1313
1314 memcpy(python_pars, args, 2 * sizeof(PyObject *));
1315 memcpy(python_pars + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1316 function->m_defaults_given * sizeof(PyObject *));
1317
1318 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
1319 Py_INCREF(python_pars[i]);
1320 }
1321
1322 result = function->m_c_code(tstate, function, python_pars);
1323 } else {
1324 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 2);
1325 }
1326
1327 Py_LeaveRecursiveCall();
1328
1329 CHECK_OBJECT_X(result);
1330
1331 return result;
1332 } else if (Nuitka_Method_Check(called)) {
1333 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
1334
1335 if (method->m_object == NULL) {
1336 PyObject *self = args[0];
1337
1338 int res = PyObject_IsInstance(self, method->m_class);
1339
1340 if (unlikely(res < 0)) {
1341 return NULL;
1342 } else if (unlikely(res == 0)) {
1343 PyErr_Format(PyExc_TypeError,
1344 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
1345 "instance instead)",
1346 GET_CALLABLE_NAME((PyObject *)method->m_function),
1347 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
1348 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
1349
1350 return NULL;
1351 }
1352
1353 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 2);
1354
1355 CHECK_OBJECT_X(result);
1356
1357 return result;
1358 } else {
1359 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1360 return NULL;
1361 }
1362
1363 struct Nuitka_FunctionObject *function = method->m_function;
1364
1365 PyObject *result;
1366
1367 if (function->m_args_simple && 2 + 1 == function->m_args_positional_count) {
1368 PyObject *python_pars[2 + 1];
1369
1370 python_pars[0] = method->m_object;
1371 Py_INCREF(method->m_object);
1372
1373 for (Py_ssize_t i = 0; i < 2; i++) {
1374 python_pars[i + 1] = args[i];
1375 Py_INCREF(args[i]);
1376 }
1377 result = function->m_c_code(tstate, function, python_pars);
1378 } else if (function->m_args_simple &&
1379 2 + 1 + function->m_defaults_given == function->m_args_positional_count) {
1380 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1381
1382 python_pars[0] = method->m_object;
1383 Py_INCREF(method->m_object);
1384
1385 memcpy(python_pars + 1, args, 2 * sizeof(PyObject *));
1386 memcpy(python_pars + 1 + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1387 function->m_defaults_given * sizeof(PyObject *));
1388
1389 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
1390 Py_INCREF(python_pars[i]);
1391 }
1392
1393 result = function->m_c_code(tstate, function, python_pars);
1394 } else {
1395 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 2);
1396 }
1397
1398 Py_LeaveRecursiveCall();
1399
1400 CHECK_OBJECT_X(result);
1401
1402 return result;
1403 }
1404#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
1405 } else if (PyCFunction_CheckExact(called)) {
1406#if PYTHON_VERSION >= 0x380
1407#ifdef _NUITKA_FULL_COMPAT
1408 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1409 return NULL;
1410 }
1411#endif
1412
1413 int flags = PyCFunction_GET_FLAGS(called);
1414
1415 PyObject *result;
1416
1417 if (!(flags & METH_VARARGS)) {
1418 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1419
1420 assert(func != NULL);
1421 result = func(called, args, 2, NULL);
1422
1423 CHECK_OBJECT_X(result);
1424 } else {
1425 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1426 PyObject *self = PyCFunction_GET_SELF(called);
1427
1428 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1429
1430 if (flags & METH_KEYWORDS) {
1431 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1432 } else {
1433 result = (*method)(self, pos_args);
1434 }
1435
1436 Py_DECREF(pos_args);
1437 }
1438
1439#ifdef _NUITKA_FULL_COMPAT
1440 Py_LeaveRecursiveCall();
1441#endif
1442 CHECK_OBJECT_X(result);
1443
1444 return Nuitka_CheckFunctionResult(tstate, called, result);
1445#else
1446 // Try to be fast about wrapping the arguments.
1447 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1448
1449 if (unlikely(flags & METH_NOARGS)) {
1450 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (2 given)",
1451 ((PyCFunctionObject *)called)->m_ml->ml_name);
1452 return NULL;
1453 } else if (unlikely(flags & METH_O)) {
1454 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (2 given)",
1455 ((PyCFunctionObject *)called)->m_ml->ml_name);
1456 return NULL;
1457 } else if (flags & METH_VARARGS) {
1458 // Recursion guard is not strictly necessary, as we already have
1459 // one on our way to here.
1460#ifdef _NUITKA_FULL_COMPAT
1461 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1462 return NULL;
1463 }
1464#endif
1465 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1466 PyObject *self = PyCFunction_GET_SELF(called);
1467
1468 PyObject *result;
1469
1470#if PYTHON_VERSION < 0x360
1471 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1472 if (flags & METH_KEYWORDS) {
1473 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1474 } else {
1475 result = (*method)(self, pos_args);
1476 }
1477
1478 Py_DECREF(pos_args);
1479#else
1480 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1481 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1482 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1483 Py_DECREF(pos_args);
1484 } else if (flags == METH_FASTCALL) {
1485#if PYTHON_VERSION < 0x370
1486 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 2, NULL);
1487#else
1488 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1489 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
1490 Py_DECREF(pos_args);
1491#endif
1492 } else {
1493 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1494 result = (*method)(self, pos_args);
1495 Py_DECREF(pos_args);
1496 }
1497#endif
1498
1499#ifdef _NUITKA_FULL_COMPAT
1500 Py_LeaveRecursiveCall();
1501#endif
1502
1503 CHECK_OBJECT_X(result);
1504
1505 return Nuitka_CheckFunctionResult(tstate, called, result);
1506 }
1507#endif
1508#endif
1509#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1510 } else if (PyFunction_Check(called)) {
1511#if PYTHON_VERSION < 0x3b0
1512 PyObject *result = callPythonFunction(called, args, 2);
1513#else
1514 PyObject *result = _PyFunction_Vectorcall(called, args, 2, NULL);
1515#endif
1516 CHECK_OBJECT_X(result);
1517
1518 return result;
1519#endif
1520#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1521 } else if (PyType_Check(called)) {
1522 PyTypeObject *type = Py_TYPE(called);
1523
1524 if (type->tp_call == PyType_Type.tp_call) {
1525 PyTypeObject *called_type = (PyTypeObject *)(called);
1526
1527 if (unlikely(called_type->tp_new == NULL)) {
1528 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1529 return NULL;
1530 }
1531
1532 PyObject *pos_args = NULL;
1533 PyObject *obj;
1534
1535 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1536 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1537 formatCannotInstantiateAbstractClass(tstate, called_type);
1538 return NULL;
1539 }
1540
1541 obj = called_type->tp_alloc(called_type, 0);
1542 CHECK_OBJECT(obj);
1543 } else {
1544 pos_args = MAKE_TUPLE(tstate, args, 2);
1545 obj = called_type->tp_new(called_type, pos_args, NULL);
1546 }
1547
1548 if (likely(obj != NULL)) {
1549 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1550 Py_DECREF(pos_args);
1551 return obj;
1552 }
1553
1554 // Work on produced type.
1555 type = Py_TYPE(obj);
1556
1557 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1558 if (type->tp_init == default_tp_init_wrapper) {
1559 Py_XDECREF(pos_args);
1560 pos_args = NULL;
1561
1562 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1563
1564 // Not really allowed, since we wouldn't have the default wrapper set.
1565 assert(init_method != NULL);
1566
1567 bool is_compiled_function = false;
1568 bool init_method_needs_release = false;
1569
1570 if (likely(init_method != NULL)) {
1571 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1572
1573 if (func == Nuitka_Function_Type.tp_descr_get) {
1574 is_compiled_function = true;
1575 } else if (func != NULL) {
1576 init_method = func(init_method, obj, (PyObject *)(type));
1577 init_method_needs_release = true;
1578 }
1579 }
1580
1581 if (unlikely(init_method == NULL)) {
1582 if (!HAS_ERROR_OCCURRED(tstate)) {
1583 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
1584 const_str_plain___init__);
1585 }
1586
1587 return NULL;
1588 }
1589
1590 PyObject *result;
1591 if (is_compiled_function) {
1592 result = Nuitka_CallMethodFunctionPosArgs(
1593 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 2);
1594 } else {
1595 result = CALL_FUNCTION_WITH_ARGS2(tstate, init_method, args);
1596 if (init_method_needs_release) {
1597 Py_DECREF(init_method);
1598 }
1599 }
1600
1601 if (unlikely(result == NULL)) {
1602 Py_DECREF(obj);
1603 return NULL;
1604 }
1605
1606 Py_DECREF(result);
1607
1608 if (unlikely(result != Py_None)) {
1609 Py_DECREF(obj);
1610
1611 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1612 return NULL;
1613 }
1614 } else {
1615 if (pos_args == NULL) {
1616 pos_args = MAKE_TUPLE(tstate, args, 2);
1617 }
1618
1619 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
1620 Py_DECREF(obj);
1621 Py_XDECREF(pos_args);
1622 return NULL;
1623 }
1624 }
1625 }
1626 }
1627
1628 Py_XDECREF(pos_args);
1629
1630 CHECK_OBJECT_X(obj);
1631
1632 return obj;
1633 }
1634#endif
1635#if PYTHON_VERSION < 0x300
1636 } else if (PyClass_Check(called)) {
1637 PyObject *obj = PyInstance_NewRaw(called, NULL);
1638
1639 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
1640
1641 if (unlikely(init_method == NULL)) {
1642 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
1643 Py_DECREF(obj);
1644 return NULL;
1645 }
1646
1647 Py_DECREF(obj);
1648
1649 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
1650 return NULL;
1651 }
1652
1653 bool is_compiled_function = false;
1654
1655 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
1656
1657 if (descr_get == NULL) {
1658 Py_INCREF(init_method);
1659 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
1660 is_compiled_function = true;
1661 } else if (descr_get != NULL) {
1662 PyObject *descr_method = descr_get(init_method, obj, called);
1663
1664 if (unlikely(descr_method == NULL)) {
1665 return NULL;
1666 }
1667
1668 init_method = descr_method;
1669 }
1670
1671 PyObject *result;
1672 if (is_compiled_function) {
1673 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
1674 args, 2);
1675 } else {
1676 result = CALL_FUNCTION_WITH_ARGS2(tstate, init_method, args);
1677 Py_DECREF(init_method);
1678 }
1679 if (unlikely(result == NULL)) {
1680 return NULL;
1681 }
1682
1683 Py_DECREF(result);
1684
1685 if (unlikely(result != Py_None)) {
1686 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
1687 return NULL;
1688 }
1689
1690 CHECK_OBJECT_X(obj);
1691
1692 return obj;
1693#endif
1694#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
1695 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
1696 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1697
1698 if (likely(func != NULL)) {
1699 PyObject *result = func(called, args, 2, NULL);
1700
1701 CHECK_OBJECT_X(result);
1702
1703 return Nuitka_CheckFunctionResult(tstate, called, result);
1704 }
1705#endif
1706 }
1707
1708#if 0
1709 PRINT_NEW_LINE();
1710 PRINT_STRING("FALLBACK");
1711 PRINT_ITEM(called);
1712 PRINT_NEW_LINE();
1713#endif
1714
1715 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
1716
1717 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
1718
1719 Py_DECREF(pos_args);
1720
1721 CHECK_OBJECT_X(result);
1722
1723 return result;
1724}
1725PyObject *CALL_FUNCTION_WITH_POS_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
1726 assert(PyTuple_CheckExact(pos_args));
1727 assert(PyTuple_GET_SIZE(pos_args) == 2);
1728 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
1729 CHECK_OBJECT(called);
1730 CHECK_OBJECTS(args, 2);
1731
1732 if (Nuitka_Function_Check(called)) {
1733 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1734 return NULL;
1735 }
1736
1737 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
1738 PyObject *result;
1739
1740 if (function->m_args_simple && 2 == function->m_args_positional_count) {
1741 for (Py_ssize_t i = 0; i < 2; i++) {
1742 Py_INCREF(args[i]);
1743 }
1744 result = function->m_c_code(tstate, function, (PyObject **)args);
1745 } else if (function->m_args_simple && 2 + function->m_defaults_given == function->m_args_positional_count) {
1746 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1747
1748 memcpy(python_pars, args, 2 * sizeof(PyObject *));
1749 memcpy(python_pars + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1750 function->m_defaults_given * sizeof(PyObject *));
1751
1752 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
1753 Py_INCREF(python_pars[i]);
1754 }
1755
1756 result = function->m_c_code(tstate, function, python_pars);
1757 } else {
1758 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 2);
1759 }
1760
1761 Py_LeaveRecursiveCall();
1762
1763 CHECK_OBJECT_X(result);
1764
1765 return result;
1766 } else if (Nuitka_Method_Check(called)) {
1767 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
1768
1769 if (method->m_object == NULL) {
1770 PyObject *self = args[0];
1771
1772 int res = PyObject_IsInstance(self, method->m_class);
1773
1774 if (unlikely(res < 0)) {
1775 return NULL;
1776 } else if (unlikely(res == 0)) {
1777 PyErr_Format(PyExc_TypeError,
1778 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
1779 "instance instead)",
1780 GET_CALLABLE_NAME((PyObject *)method->m_function),
1781 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
1782 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
1783
1784 return NULL;
1785 }
1786
1787 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 2);
1788
1789 CHECK_OBJECT_X(result);
1790
1791 return result;
1792 } else {
1793 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1794 return NULL;
1795 }
1796
1797 struct Nuitka_FunctionObject *function = method->m_function;
1798
1799 PyObject *result;
1800
1801 if (function->m_args_simple && 2 + 1 == function->m_args_positional_count) {
1802 PyObject *python_pars[2 + 1];
1803
1804 python_pars[0] = method->m_object;
1805 Py_INCREF(method->m_object);
1806
1807 for (Py_ssize_t i = 0; i < 2; i++) {
1808 python_pars[i + 1] = args[i];
1809 Py_INCREF(args[i]);
1810 }
1811 result = function->m_c_code(tstate, function, python_pars);
1812 } else if (function->m_args_simple &&
1813 2 + 1 + function->m_defaults_given == function->m_args_positional_count) {
1814 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
1815
1816 python_pars[0] = method->m_object;
1817 Py_INCREF(method->m_object);
1818
1819 memcpy(python_pars + 1, args, 2 * sizeof(PyObject *));
1820 memcpy(python_pars + 1 + 2, &PyTuple_GET_ITEM(function->m_defaults, 0),
1821 function->m_defaults_given * sizeof(PyObject *));
1822
1823 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
1824 Py_INCREF(python_pars[i]);
1825 }
1826
1827 result = function->m_c_code(tstate, function, python_pars);
1828 } else {
1829 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 2);
1830 }
1831
1832 Py_LeaveRecursiveCall();
1833
1834 CHECK_OBJECT_X(result);
1835
1836 return result;
1837 }
1838#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
1839 } else if (PyCFunction_CheckExact(called)) {
1840#if PYTHON_VERSION >= 0x380
1841#ifdef _NUITKA_FULL_COMPAT
1842 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1843 return NULL;
1844 }
1845#endif
1846
1847 int flags = PyCFunction_GET_FLAGS(called);
1848
1849 PyObject *result;
1850
1851 if (!(flags & METH_VARARGS)) {
1852 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
1853
1854 assert(func != NULL);
1855 result = func(called, args, 2, NULL);
1856
1857 CHECK_OBJECT_X(result);
1858 } else {
1859 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1860 PyObject *self = PyCFunction_GET_SELF(called);
1861
1862 if (flags & METH_KEYWORDS) {
1863 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
1864 } else {
1865 result = (*method)(self, pos_args);
1866 }
1867 }
1868
1869#ifdef _NUITKA_FULL_COMPAT
1870 Py_LeaveRecursiveCall();
1871#endif
1872 CHECK_OBJECT_X(result);
1873
1874 return Nuitka_CheckFunctionResult(tstate, called, result);
1875#else
1876 // Try to be fast about wrapping the arguments.
1877 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
1878
1879 if (unlikely(flags & METH_NOARGS)) {
1880 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (2 given)",
1881 ((PyCFunctionObject *)called)->m_ml->ml_name);
1882 return NULL;
1883 } else if (unlikely(flags & METH_O)) {
1884 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (2 given)",
1885 ((PyCFunctionObject *)called)->m_ml->ml_name);
1886 return NULL;
1887 } else if (flags & METH_VARARGS) {
1888 // Recursion guard is not strictly necessary, as we already have
1889 // one on our way to here.
1890#ifdef _NUITKA_FULL_COMPAT
1891 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
1892 return NULL;
1893 }
1894#endif
1895 PyCFunction method = PyCFunction_GET_FUNCTION(called);
1896 PyObject *self = PyCFunction_GET_SELF(called);
1897
1898 PyObject *result;
1899
1900#if PYTHON_VERSION < 0x360
1901 if (flags & METH_KEYWORDS) {
1902 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1903 } else {
1904 result = (*method)(self, pos_args);
1905 }
1906
1907#else
1908 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
1909 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
1910 } else if (flags == METH_FASTCALL) {
1911#if PYTHON_VERSION < 0x370
1912 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 2, NULL);
1913#else
1914 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
1915#endif
1916 } else {
1917 result = (*method)(self, pos_args);
1918 }
1919#endif
1920
1921#ifdef _NUITKA_FULL_COMPAT
1922 Py_LeaveRecursiveCall();
1923#endif
1924
1925 CHECK_OBJECT_X(result);
1926
1927 return Nuitka_CheckFunctionResult(tstate, called, result);
1928 }
1929#endif
1930#endif
1931#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
1932 } else if (PyFunction_Check(called)) {
1933#if PYTHON_VERSION < 0x3b0
1934 PyObject *result = callPythonFunction(called, args, 2);
1935#else
1936 PyObject *result = _PyFunction_Vectorcall(called, args, 2, NULL);
1937#endif
1938 CHECK_OBJECT_X(result);
1939
1940 return result;
1941#endif
1942#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
1943 } else if (PyType_Check(called)) {
1944 PyTypeObject *type = Py_TYPE(called);
1945
1946 if (type->tp_call == PyType_Type.tp_call) {
1947 PyTypeObject *called_type = (PyTypeObject *)(called);
1948
1949 if (unlikely(called_type->tp_new == NULL)) {
1950 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
1951 return NULL;
1952 }
1953
1954 PyObject *obj;
1955
1956 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
1957 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
1958 formatCannotInstantiateAbstractClass(tstate, called_type);
1959 return NULL;
1960 }
1961
1962 obj = called_type->tp_alloc(called_type, 0);
1963 CHECK_OBJECT(obj);
1964 } else {
1965 obj = called_type->tp_new(called_type, pos_args, NULL);
1966 }
1967
1968 if (likely(obj != NULL)) {
1969 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
1970 return obj;
1971 }
1972
1973 // Work on produced type.
1974 type = Py_TYPE(obj);
1975
1976 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
1977 if (type->tp_init == default_tp_init_wrapper) {
1978
1979 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
1980
1981 // Not really allowed, since we wouldn't have the default wrapper set.
1982 assert(init_method != NULL);
1983
1984 bool is_compiled_function = false;
1985 bool init_method_needs_release = false;
1986
1987 if (likely(init_method != NULL)) {
1988 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
1989
1990 if (func == Nuitka_Function_Type.tp_descr_get) {
1991 is_compiled_function = true;
1992 } else if (func != NULL) {
1993 init_method = func(init_method, obj, (PyObject *)(type));
1994 init_method_needs_release = true;
1995 }
1996 }
1997
1998 if (unlikely(init_method == NULL)) {
1999 if (!HAS_ERROR_OCCURRED(tstate)) {
2000 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2001 const_str_plain___init__);
2002 }
2003
2004 return NULL;
2005 }
2006
2007 PyObject *result;
2008 if (is_compiled_function) {
2009 result = Nuitka_CallMethodFunctionPosArgs(
2010 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 2);
2011 } else {
2012 result = CALL_FUNCTION_WITH_POS_ARGS2(tstate, init_method, pos_args);
2013 if (init_method_needs_release) {
2014 Py_DECREF(init_method);
2015 }
2016 }
2017
2018 if (unlikely(result == NULL)) {
2019 Py_DECREF(obj);
2020 return NULL;
2021 }
2022
2023 Py_DECREF(result);
2024
2025 if (unlikely(result != Py_None)) {
2026 Py_DECREF(obj);
2027
2028 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2029 return NULL;
2030 }
2031 } else {
2032
2033 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2034 Py_DECREF(obj);
2035 return NULL;
2036 }
2037 }
2038 }
2039 }
2040
2041 CHECK_OBJECT_X(obj);
2042
2043 return obj;
2044 }
2045#endif
2046#if PYTHON_VERSION < 0x300
2047 } else if (PyClass_Check(called)) {
2048 PyObject *obj = PyInstance_NewRaw(called, NULL);
2049
2050 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2051
2052 if (unlikely(init_method == NULL)) {
2053 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2054 Py_DECREF(obj);
2055 return NULL;
2056 }
2057
2058 Py_DECREF(obj);
2059
2060 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2061 return NULL;
2062 }
2063
2064 bool is_compiled_function = false;
2065
2066 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2067
2068 if (descr_get == NULL) {
2069 Py_INCREF(init_method);
2070 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2071 is_compiled_function = true;
2072 } else if (descr_get != NULL) {
2073 PyObject *descr_method = descr_get(init_method, obj, called);
2074
2075 if (unlikely(descr_method == NULL)) {
2076 return NULL;
2077 }
2078
2079 init_method = descr_method;
2080 }
2081
2082 PyObject *result;
2083 if (is_compiled_function) {
2084 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2085 args, 2);
2086 } else {
2087 result = CALL_FUNCTION_WITH_POS_ARGS2(tstate, init_method, pos_args);
2088 Py_DECREF(init_method);
2089 }
2090 if (unlikely(result == NULL)) {
2091 return NULL;
2092 }
2093
2094 Py_DECREF(result);
2095
2096 if (unlikely(result != Py_None)) {
2097 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2098 return NULL;
2099 }
2100
2101 CHECK_OBJECT_X(obj);
2102
2103 return obj;
2104#endif
2105#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2106 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2107 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2108
2109 if (likely(func != NULL)) {
2110 PyObject *result = func(called, args, 2, NULL);
2111
2112 CHECK_OBJECT_X(result);
2113
2114 return Nuitka_CheckFunctionResult(tstate, called, result);
2115 }
2116#endif
2117 }
2118
2119#if 0
2120 PRINT_NEW_LINE();
2121 PRINT_STRING("FALLBACK");
2122 PRINT_ITEM(called);
2123 PRINT_NEW_LINE();
2124#endif
2125
2126 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2127
2128 CHECK_OBJECT_X(result);
2129
2130 return result;
2131}
2132PyObject *CALL_FUNCTION_WITH_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
2133 CHECK_OBJECT(called);
2134 CHECK_OBJECTS(args, 3);
2135
2136 if (Nuitka_Function_Check(called)) {
2137 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2138 return NULL;
2139 }
2140
2141 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2142 PyObject *result;
2143
2144 if (function->m_args_simple && 3 == function->m_args_positional_count) {
2145 for (Py_ssize_t i = 0; i < 3; i++) {
2146 Py_INCREF(args[i]);
2147 }
2148 result = function->m_c_code(tstate, function, (PyObject **)args);
2149 } else if (function->m_args_simple && 3 + function->m_defaults_given == function->m_args_positional_count) {
2150 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2151
2152 memcpy(python_pars, args, 3 * sizeof(PyObject *));
2153 memcpy(python_pars + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2154 function->m_defaults_given * sizeof(PyObject *));
2155
2156 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2157 Py_INCREF(python_pars[i]);
2158 }
2159
2160 result = function->m_c_code(tstate, function, python_pars);
2161 } else {
2162 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 3);
2163 }
2164
2165 Py_LeaveRecursiveCall();
2166
2167 CHECK_OBJECT_X(result);
2168
2169 return result;
2170 } else if (Nuitka_Method_Check(called)) {
2171 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
2172
2173 if (method->m_object == NULL) {
2174 PyObject *self = args[0];
2175
2176 int res = PyObject_IsInstance(self, method->m_class);
2177
2178 if (unlikely(res < 0)) {
2179 return NULL;
2180 } else if (unlikely(res == 0)) {
2181 PyErr_Format(PyExc_TypeError,
2182 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
2183 "instance instead)",
2184 GET_CALLABLE_NAME((PyObject *)method->m_function),
2185 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
2186 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
2187
2188 return NULL;
2189 }
2190
2191 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 3);
2192
2193 CHECK_OBJECT_X(result);
2194
2195 return result;
2196 } else {
2197 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2198 return NULL;
2199 }
2200
2201 struct Nuitka_FunctionObject *function = method->m_function;
2202
2203 PyObject *result;
2204
2205 if (function->m_args_simple && 3 + 1 == function->m_args_positional_count) {
2206 PyObject *python_pars[3 + 1];
2207
2208 python_pars[0] = method->m_object;
2209 Py_INCREF(method->m_object);
2210
2211 for (Py_ssize_t i = 0; i < 3; i++) {
2212 python_pars[i + 1] = args[i];
2213 Py_INCREF(args[i]);
2214 }
2215 result = function->m_c_code(tstate, function, python_pars);
2216 } else if (function->m_args_simple &&
2217 3 + 1 + function->m_defaults_given == function->m_args_positional_count) {
2218 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2219
2220 python_pars[0] = method->m_object;
2221 Py_INCREF(method->m_object);
2222
2223 memcpy(python_pars + 1, args, 3 * sizeof(PyObject *));
2224 memcpy(python_pars + 1 + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2225 function->m_defaults_given * sizeof(PyObject *));
2226
2227 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
2228 Py_INCREF(python_pars[i]);
2229 }
2230
2231 result = function->m_c_code(tstate, function, python_pars);
2232 } else {
2233 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 3);
2234 }
2235
2236 Py_LeaveRecursiveCall();
2237
2238 CHECK_OBJECT_X(result);
2239
2240 return result;
2241 }
2242#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
2243 } else if (PyCFunction_CheckExact(called)) {
2244#if PYTHON_VERSION >= 0x380
2245#ifdef _NUITKA_FULL_COMPAT
2246 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2247 return NULL;
2248 }
2249#endif
2250
2251 int flags = PyCFunction_GET_FLAGS(called);
2252
2253 PyObject *result;
2254
2255 if (!(flags & METH_VARARGS)) {
2256 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2257
2258 assert(func != NULL);
2259 result = func(called, args, 3, NULL);
2260
2261 CHECK_OBJECT_X(result);
2262 } else {
2263 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2264 PyObject *self = PyCFunction_GET_SELF(called);
2265
2266 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2267
2268 if (flags & METH_KEYWORDS) {
2269 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
2270 } else {
2271 result = (*method)(self, pos_args);
2272 }
2273
2274 Py_DECREF(pos_args);
2275 }
2276
2277#ifdef _NUITKA_FULL_COMPAT
2278 Py_LeaveRecursiveCall();
2279#endif
2280 CHECK_OBJECT_X(result);
2281
2282 return Nuitka_CheckFunctionResult(tstate, called, result);
2283#else
2284 // Try to be fast about wrapping the arguments.
2285 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
2286
2287 if (unlikely(flags & METH_NOARGS)) {
2288 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (3 given)",
2289 ((PyCFunctionObject *)called)->m_ml->ml_name);
2290 return NULL;
2291 } else if (unlikely(flags & METH_O)) {
2292 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
2293 ((PyCFunctionObject *)called)->m_ml->ml_name);
2294 return NULL;
2295 } else if (flags & METH_VARARGS) {
2296 // Recursion guard is not strictly necessary, as we already have
2297 // one on our way to here.
2298#ifdef _NUITKA_FULL_COMPAT
2299 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2300 return NULL;
2301 }
2302#endif
2303 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2304 PyObject *self = PyCFunction_GET_SELF(called);
2305
2306 PyObject *result;
2307
2308#if PYTHON_VERSION < 0x360
2309 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2310 if (flags & METH_KEYWORDS) {
2311 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2312 } else {
2313 result = (*method)(self, pos_args);
2314 }
2315
2316 Py_DECREF(pos_args);
2317#else
2318 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
2319 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2320 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2321 Py_DECREF(pos_args);
2322 } else if (flags == METH_FASTCALL) {
2323#if PYTHON_VERSION < 0x370
2324 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 3, NULL);
2325#else
2326 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2327 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
2328 Py_DECREF(pos_args);
2329#endif
2330 } else {
2331 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2332 result = (*method)(self, pos_args);
2333 Py_DECREF(pos_args);
2334 }
2335#endif
2336
2337#ifdef _NUITKA_FULL_COMPAT
2338 Py_LeaveRecursiveCall();
2339#endif
2340
2341 CHECK_OBJECT_X(result);
2342
2343 return Nuitka_CheckFunctionResult(tstate, called, result);
2344 }
2345#endif
2346#endif
2347#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
2348 } else if (PyFunction_Check(called)) {
2349#if PYTHON_VERSION < 0x3b0
2350 PyObject *result = callPythonFunction(called, args, 3);
2351#else
2352 PyObject *result = _PyFunction_Vectorcall(called, args, 3, NULL);
2353#endif
2354 CHECK_OBJECT_X(result);
2355
2356 return result;
2357#endif
2358#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
2359 } else if (PyType_Check(called)) {
2360 PyTypeObject *type = Py_TYPE(called);
2361
2362 if (type->tp_call == PyType_Type.tp_call) {
2363 PyTypeObject *called_type = (PyTypeObject *)(called);
2364
2365 if (unlikely(called_type->tp_new == NULL)) {
2366 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
2367 return NULL;
2368 }
2369
2370 PyObject *pos_args = NULL;
2371 PyObject *obj;
2372
2373 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
2374 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
2375 formatCannotInstantiateAbstractClass(tstate, called_type);
2376 return NULL;
2377 }
2378
2379 obj = called_type->tp_alloc(called_type, 0);
2380 CHECK_OBJECT(obj);
2381 } else {
2382 pos_args = MAKE_TUPLE(tstate, args, 3);
2383 obj = called_type->tp_new(called_type, pos_args, NULL);
2384 }
2385
2386 if (likely(obj != NULL)) {
2387 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
2388 Py_DECREF(pos_args);
2389 return obj;
2390 }
2391
2392 // Work on produced type.
2393 type = Py_TYPE(obj);
2394
2395 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
2396 if (type->tp_init == default_tp_init_wrapper) {
2397 Py_XDECREF(pos_args);
2398 pos_args = NULL;
2399
2400 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
2401
2402 // Not really allowed, since we wouldn't have the default wrapper set.
2403 assert(init_method != NULL);
2404
2405 bool is_compiled_function = false;
2406 bool init_method_needs_release = false;
2407
2408 if (likely(init_method != NULL)) {
2409 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
2410
2411 if (func == Nuitka_Function_Type.tp_descr_get) {
2412 is_compiled_function = true;
2413 } else if (func != NULL) {
2414 init_method = func(init_method, obj, (PyObject *)(type));
2415 init_method_needs_release = true;
2416 }
2417 }
2418
2419 if (unlikely(init_method == NULL)) {
2420 if (!HAS_ERROR_OCCURRED(tstate)) {
2421 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2422 const_str_plain___init__);
2423 }
2424
2425 return NULL;
2426 }
2427
2428 PyObject *result;
2429 if (is_compiled_function) {
2430 result = Nuitka_CallMethodFunctionPosArgs(
2431 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 3);
2432 } else {
2433 result = CALL_FUNCTION_WITH_ARGS3(tstate, init_method, args);
2434 if (init_method_needs_release) {
2435 Py_DECREF(init_method);
2436 }
2437 }
2438
2439 if (unlikely(result == NULL)) {
2440 Py_DECREF(obj);
2441 return NULL;
2442 }
2443
2444 Py_DECREF(result);
2445
2446 if (unlikely(result != Py_None)) {
2447 Py_DECREF(obj);
2448
2449 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2450 return NULL;
2451 }
2452 } else {
2453 if (pos_args == NULL) {
2454 pos_args = MAKE_TUPLE(tstate, args, 3);
2455 }
2456
2457 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2458 Py_DECREF(obj);
2459 Py_XDECREF(pos_args);
2460 return NULL;
2461 }
2462 }
2463 }
2464 }
2465
2466 Py_XDECREF(pos_args);
2467
2468 CHECK_OBJECT_X(obj);
2469
2470 return obj;
2471 }
2472#endif
2473#if PYTHON_VERSION < 0x300
2474 } else if (PyClass_Check(called)) {
2475 PyObject *obj = PyInstance_NewRaw(called, NULL);
2476
2477 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2478
2479 if (unlikely(init_method == NULL)) {
2480 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2481 Py_DECREF(obj);
2482 return NULL;
2483 }
2484
2485 Py_DECREF(obj);
2486
2487 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2488 return NULL;
2489 }
2490
2491 bool is_compiled_function = false;
2492
2493 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2494
2495 if (descr_get == NULL) {
2496 Py_INCREF(init_method);
2497 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2498 is_compiled_function = true;
2499 } else if (descr_get != NULL) {
2500 PyObject *descr_method = descr_get(init_method, obj, called);
2501
2502 if (unlikely(descr_method == NULL)) {
2503 return NULL;
2504 }
2505
2506 init_method = descr_method;
2507 }
2508
2509 PyObject *result;
2510 if (is_compiled_function) {
2511 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2512 args, 3);
2513 } else {
2514 result = CALL_FUNCTION_WITH_ARGS3(tstate, init_method, args);
2515 Py_DECREF(init_method);
2516 }
2517 if (unlikely(result == NULL)) {
2518 return NULL;
2519 }
2520
2521 Py_DECREF(result);
2522
2523 if (unlikely(result != Py_None)) {
2524 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2525 return NULL;
2526 }
2527
2528 CHECK_OBJECT_X(obj);
2529
2530 return obj;
2531#endif
2532#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2533 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2534 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2535
2536 if (likely(func != NULL)) {
2537 PyObject *result = func(called, args, 3, NULL);
2538
2539 CHECK_OBJECT_X(result);
2540
2541 return Nuitka_CheckFunctionResult(tstate, called, result);
2542 }
2543#endif
2544 }
2545
2546#if 0
2547 PRINT_NEW_LINE();
2548 PRINT_STRING("FALLBACK");
2549 PRINT_ITEM(called);
2550 PRINT_NEW_LINE();
2551#endif
2552
2553 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
2554
2555 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2556
2557 Py_DECREF(pos_args);
2558
2559 CHECK_OBJECT_X(result);
2560
2561 return result;
2562}
2563PyObject *CALL_FUNCTION_WITH_POS_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
2564 assert(PyTuple_CheckExact(pos_args));
2565 assert(PyTuple_GET_SIZE(pos_args) == 3);
2566 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
2567 CHECK_OBJECT(called);
2568 CHECK_OBJECTS(args, 3);
2569
2570 if (Nuitka_Function_Check(called)) {
2571 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2572 return NULL;
2573 }
2574
2575 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2576 PyObject *result;
2577
2578 if (function->m_args_simple && 3 == function->m_args_positional_count) {
2579 for (Py_ssize_t i = 0; i < 3; i++) {
2580 Py_INCREF(args[i]);
2581 }
2582 result = function->m_c_code(tstate, function, (PyObject **)args);
2583 } else if (function->m_args_simple && 3 + function->m_defaults_given == function->m_args_positional_count) {
2584 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2585
2586 memcpy(python_pars, args, 3 * sizeof(PyObject *));
2587 memcpy(python_pars + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2588 function->m_defaults_given * sizeof(PyObject *));
2589
2590 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2591 Py_INCREF(python_pars[i]);
2592 }
2593
2594 result = function->m_c_code(tstate, function, python_pars);
2595 } else {
2596 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 3);
2597 }
2598
2599 Py_LeaveRecursiveCall();
2600
2601 CHECK_OBJECT_X(result);
2602
2603 return result;
2604 } else if (Nuitka_Method_Check(called)) {
2605 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
2606
2607 if (method->m_object == NULL) {
2608 PyObject *self = args[0];
2609
2610 int res = PyObject_IsInstance(self, method->m_class);
2611
2612 if (unlikely(res < 0)) {
2613 return NULL;
2614 } else if (unlikely(res == 0)) {
2615 PyErr_Format(PyExc_TypeError,
2616 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
2617 "instance instead)",
2618 GET_CALLABLE_NAME((PyObject *)method->m_function),
2619 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
2620 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
2621
2622 return NULL;
2623 }
2624
2625 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 3);
2626
2627 CHECK_OBJECT_X(result);
2628
2629 return result;
2630 } else {
2631 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2632 return NULL;
2633 }
2634
2635 struct Nuitka_FunctionObject *function = method->m_function;
2636
2637 PyObject *result;
2638
2639 if (function->m_args_simple && 3 + 1 == function->m_args_positional_count) {
2640 PyObject *python_pars[3 + 1];
2641
2642 python_pars[0] = method->m_object;
2643 Py_INCREF(method->m_object);
2644
2645 for (Py_ssize_t i = 0; i < 3; i++) {
2646 python_pars[i + 1] = args[i];
2647 Py_INCREF(args[i]);
2648 }
2649 result = function->m_c_code(tstate, function, python_pars);
2650 } else if (function->m_args_simple &&
2651 3 + 1 + function->m_defaults_given == function->m_args_positional_count) {
2652 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2653
2654 python_pars[0] = method->m_object;
2655 Py_INCREF(method->m_object);
2656
2657 memcpy(python_pars + 1, args, 3 * sizeof(PyObject *));
2658 memcpy(python_pars + 1 + 3, &PyTuple_GET_ITEM(function->m_defaults, 0),
2659 function->m_defaults_given * sizeof(PyObject *));
2660
2661 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
2662 Py_INCREF(python_pars[i]);
2663 }
2664
2665 result = function->m_c_code(tstate, function, python_pars);
2666 } else {
2667 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 3);
2668 }
2669
2670 Py_LeaveRecursiveCall();
2671
2672 CHECK_OBJECT_X(result);
2673
2674 return result;
2675 }
2676#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
2677 } else if (PyCFunction_CheckExact(called)) {
2678#if PYTHON_VERSION >= 0x380
2679#ifdef _NUITKA_FULL_COMPAT
2680 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2681 return NULL;
2682 }
2683#endif
2684
2685 int flags = PyCFunction_GET_FLAGS(called);
2686
2687 PyObject *result;
2688
2689 if (!(flags & METH_VARARGS)) {
2690 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2691
2692 assert(func != NULL);
2693 result = func(called, args, 3, NULL);
2694
2695 CHECK_OBJECT_X(result);
2696 } else {
2697 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2698 PyObject *self = PyCFunction_GET_SELF(called);
2699
2700 if (flags & METH_KEYWORDS) {
2701 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
2702 } else {
2703 result = (*method)(self, pos_args);
2704 }
2705 }
2706
2707#ifdef _NUITKA_FULL_COMPAT
2708 Py_LeaveRecursiveCall();
2709#endif
2710 CHECK_OBJECT_X(result);
2711
2712 return Nuitka_CheckFunctionResult(tstate, called, result);
2713#else
2714 // Try to be fast about wrapping the arguments.
2715 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
2716
2717 if (unlikely(flags & METH_NOARGS)) {
2718 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (3 given)",
2719 ((PyCFunctionObject *)called)->m_ml->ml_name);
2720 return NULL;
2721 } else if (unlikely(flags & METH_O)) {
2722 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
2723 ((PyCFunctionObject *)called)->m_ml->ml_name);
2724 return NULL;
2725 } else if (flags & METH_VARARGS) {
2726 // Recursion guard is not strictly necessary, as we already have
2727 // one on our way to here.
2728#ifdef _NUITKA_FULL_COMPAT
2729 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2730 return NULL;
2731 }
2732#endif
2733 PyCFunction method = PyCFunction_GET_FUNCTION(called);
2734 PyObject *self = PyCFunction_GET_SELF(called);
2735
2736 PyObject *result;
2737
2738#if PYTHON_VERSION < 0x360
2739 if (flags & METH_KEYWORDS) {
2740 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2741 } else {
2742 result = (*method)(self, pos_args);
2743 }
2744
2745#else
2746 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
2747 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
2748 } else if (flags == METH_FASTCALL) {
2749#if PYTHON_VERSION < 0x370
2750 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 3, NULL);
2751#else
2752 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
2753#endif
2754 } else {
2755 result = (*method)(self, pos_args);
2756 }
2757#endif
2758
2759#ifdef _NUITKA_FULL_COMPAT
2760 Py_LeaveRecursiveCall();
2761#endif
2762
2763 CHECK_OBJECT_X(result);
2764
2765 return Nuitka_CheckFunctionResult(tstate, called, result);
2766 }
2767#endif
2768#endif
2769#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
2770 } else if (PyFunction_Check(called)) {
2771#if PYTHON_VERSION < 0x3b0
2772 PyObject *result = callPythonFunction(called, args, 3);
2773#else
2774 PyObject *result = _PyFunction_Vectorcall(called, args, 3, NULL);
2775#endif
2776 CHECK_OBJECT_X(result);
2777
2778 return result;
2779#endif
2780#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
2781 } else if (PyType_Check(called)) {
2782 PyTypeObject *type = Py_TYPE(called);
2783
2784 if (type->tp_call == PyType_Type.tp_call) {
2785 PyTypeObject *called_type = (PyTypeObject *)(called);
2786
2787 if (unlikely(called_type->tp_new == NULL)) {
2788 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
2789 return NULL;
2790 }
2791
2792 PyObject *obj;
2793
2794 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
2795 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
2796 formatCannotInstantiateAbstractClass(tstate, called_type);
2797 return NULL;
2798 }
2799
2800 obj = called_type->tp_alloc(called_type, 0);
2801 CHECK_OBJECT(obj);
2802 } else {
2803 obj = called_type->tp_new(called_type, pos_args, NULL);
2804 }
2805
2806 if (likely(obj != NULL)) {
2807 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
2808 return obj;
2809 }
2810
2811 // Work on produced type.
2812 type = Py_TYPE(obj);
2813
2814 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
2815 if (type->tp_init == default_tp_init_wrapper) {
2816
2817 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
2818
2819 // Not really allowed, since we wouldn't have the default wrapper set.
2820 assert(init_method != NULL);
2821
2822 bool is_compiled_function = false;
2823 bool init_method_needs_release = false;
2824
2825 if (likely(init_method != NULL)) {
2826 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
2827
2828 if (func == Nuitka_Function_Type.tp_descr_get) {
2829 is_compiled_function = true;
2830 } else if (func != NULL) {
2831 init_method = func(init_method, obj, (PyObject *)(type));
2832 init_method_needs_release = true;
2833 }
2834 }
2835
2836 if (unlikely(init_method == NULL)) {
2837 if (!HAS_ERROR_OCCURRED(tstate)) {
2838 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
2839 const_str_plain___init__);
2840 }
2841
2842 return NULL;
2843 }
2844
2845 PyObject *result;
2846 if (is_compiled_function) {
2847 result = Nuitka_CallMethodFunctionPosArgs(
2848 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 3);
2849 } else {
2850 result = CALL_FUNCTION_WITH_POS_ARGS3(tstate, init_method, pos_args);
2851 if (init_method_needs_release) {
2852 Py_DECREF(init_method);
2853 }
2854 }
2855
2856 if (unlikely(result == NULL)) {
2857 Py_DECREF(obj);
2858 return NULL;
2859 }
2860
2861 Py_DECREF(result);
2862
2863 if (unlikely(result != Py_None)) {
2864 Py_DECREF(obj);
2865
2866 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2867 return NULL;
2868 }
2869 } else {
2870
2871 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
2872 Py_DECREF(obj);
2873 return NULL;
2874 }
2875 }
2876 }
2877 }
2878
2879 CHECK_OBJECT_X(obj);
2880
2881 return obj;
2882 }
2883#endif
2884#if PYTHON_VERSION < 0x300
2885 } else if (PyClass_Check(called)) {
2886 PyObject *obj = PyInstance_NewRaw(called, NULL);
2887
2888 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
2889
2890 if (unlikely(init_method == NULL)) {
2891 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
2892 Py_DECREF(obj);
2893 return NULL;
2894 }
2895
2896 Py_DECREF(obj);
2897
2898 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
2899 return NULL;
2900 }
2901
2902 bool is_compiled_function = false;
2903
2904 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
2905
2906 if (descr_get == NULL) {
2907 Py_INCREF(init_method);
2908 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
2909 is_compiled_function = true;
2910 } else if (descr_get != NULL) {
2911 PyObject *descr_method = descr_get(init_method, obj, called);
2912
2913 if (unlikely(descr_method == NULL)) {
2914 return NULL;
2915 }
2916
2917 init_method = descr_method;
2918 }
2919
2920 PyObject *result;
2921 if (is_compiled_function) {
2922 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
2923 args, 3);
2924 } else {
2925 result = CALL_FUNCTION_WITH_POS_ARGS3(tstate, init_method, pos_args);
2926 Py_DECREF(init_method);
2927 }
2928 if (unlikely(result == NULL)) {
2929 return NULL;
2930 }
2931
2932 Py_DECREF(result);
2933
2934 if (unlikely(result != Py_None)) {
2935 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
2936 return NULL;
2937 }
2938
2939 CHECK_OBJECT_X(obj);
2940
2941 return obj;
2942#endif
2943#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
2944 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
2945 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
2946
2947 if (likely(func != NULL)) {
2948 PyObject *result = func(called, args, 3, NULL);
2949
2950 CHECK_OBJECT_X(result);
2951
2952 return Nuitka_CheckFunctionResult(tstate, called, result);
2953 }
2954#endif
2955 }
2956
2957#if 0
2958 PRINT_NEW_LINE();
2959 PRINT_STRING("FALLBACK");
2960 PRINT_ITEM(called);
2961 PRINT_NEW_LINE();
2962#endif
2963
2964 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
2965
2966 CHECK_OBJECT_X(result);
2967
2968 return result;
2969}
2970PyObject *CALL_FUNCTION_WITH_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
2971 CHECK_OBJECT(called);
2972 CHECK_OBJECTS(args, 4);
2973
2974 if (Nuitka_Function_Check(called)) {
2975 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
2976 return NULL;
2977 }
2978
2979 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
2980 PyObject *result;
2981
2982 if (function->m_args_simple && 4 == function->m_args_positional_count) {
2983 for (Py_ssize_t i = 0; i < 4; i++) {
2984 Py_INCREF(args[i]);
2985 }
2986 result = function->m_c_code(tstate, function, (PyObject **)args);
2987 } else if (function->m_args_simple && 4 + function->m_defaults_given == function->m_args_positional_count) {
2988 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
2989
2990 memcpy(python_pars, args, 4 * sizeof(PyObject *));
2991 memcpy(python_pars + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
2992 function->m_defaults_given * sizeof(PyObject *));
2993
2994 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
2995 Py_INCREF(python_pars[i]);
2996 }
2997
2998 result = function->m_c_code(tstate, function, python_pars);
2999 } else {
3000 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 4);
3001 }
3002
3003 Py_LeaveRecursiveCall();
3004
3005 CHECK_OBJECT_X(result);
3006
3007 return result;
3008 } else if (Nuitka_Method_Check(called)) {
3009 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3010
3011 if (method->m_object == NULL) {
3012 PyObject *self = args[0];
3013
3014 int res = PyObject_IsInstance(self, method->m_class);
3015
3016 if (unlikely(res < 0)) {
3017 return NULL;
3018 } else if (unlikely(res == 0)) {
3019 PyErr_Format(PyExc_TypeError,
3020 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3021 "instance instead)",
3022 GET_CALLABLE_NAME((PyObject *)method->m_function),
3023 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3024 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3025
3026 return NULL;
3027 }
3028
3029 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 4);
3030
3031 CHECK_OBJECT_X(result);
3032
3033 return result;
3034 } else {
3035 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3036 return NULL;
3037 }
3038
3039 struct Nuitka_FunctionObject *function = method->m_function;
3040
3041 PyObject *result;
3042
3043 if (function->m_args_simple && 4 + 1 == function->m_args_positional_count) {
3044 PyObject *python_pars[4 + 1];
3045
3046 python_pars[0] = method->m_object;
3047 Py_INCREF(method->m_object);
3048
3049 for (Py_ssize_t i = 0; i < 4; i++) {
3050 python_pars[i + 1] = args[i];
3051 Py_INCREF(args[i]);
3052 }
3053 result = function->m_c_code(tstate, function, python_pars);
3054 } else if (function->m_args_simple &&
3055 4 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3056 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3057
3058 python_pars[0] = method->m_object;
3059 Py_INCREF(method->m_object);
3060
3061 memcpy(python_pars + 1, args, 4 * sizeof(PyObject *));
3062 memcpy(python_pars + 1 + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3063 function->m_defaults_given * sizeof(PyObject *));
3064
3065 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3066 Py_INCREF(python_pars[i]);
3067 }
3068
3069 result = function->m_c_code(tstate, function, python_pars);
3070 } else {
3071 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 4);
3072 }
3073
3074 Py_LeaveRecursiveCall();
3075
3076 CHECK_OBJECT_X(result);
3077
3078 return result;
3079 }
3080#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3081 } else if (PyCFunction_CheckExact(called)) {
3082#if PYTHON_VERSION >= 0x380
3083#ifdef _NUITKA_FULL_COMPAT
3084 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3085 return NULL;
3086 }
3087#endif
3088
3089 int flags = PyCFunction_GET_FLAGS(called);
3090
3091 PyObject *result;
3092
3093 if (!(flags & METH_VARARGS)) {
3094 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3095
3096 assert(func != NULL);
3097 result = func(called, args, 4, NULL);
3098
3099 CHECK_OBJECT_X(result);
3100 } else {
3101 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3102 PyObject *self = PyCFunction_GET_SELF(called);
3103
3104 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3105
3106 if (flags & METH_KEYWORDS) {
3107 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3108 } else {
3109 result = (*method)(self, pos_args);
3110 }
3111
3112 Py_DECREF(pos_args);
3113 }
3114
3115#ifdef _NUITKA_FULL_COMPAT
3116 Py_LeaveRecursiveCall();
3117#endif
3118 CHECK_OBJECT_X(result);
3119
3120 return Nuitka_CheckFunctionResult(tstate, called, result);
3121#else
3122 // Try to be fast about wrapping the arguments.
3123 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3124
3125 if (unlikely(flags & METH_NOARGS)) {
3126 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (4 given)",
3127 ((PyCFunctionObject *)called)->m_ml->ml_name);
3128 return NULL;
3129 } else if (unlikely(flags & METH_O)) {
3130 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
3131 ((PyCFunctionObject *)called)->m_ml->ml_name);
3132 return NULL;
3133 } else if (flags & METH_VARARGS) {
3134 // Recursion guard is not strictly necessary, as we already have
3135 // one on our way to here.
3136#ifdef _NUITKA_FULL_COMPAT
3137 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3138 return NULL;
3139 }
3140#endif
3141 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3142 PyObject *self = PyCFunction_GET_SELF(called);
3143
3144 PyObject *result;
3145
3146#if PYTHON_VERSION < 0x360
3147 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3148 if (flags & METH_KEYWORDS) {
3149 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3150 } else {
3151 result = (*method)(self, pos_args);
3152 }
3153
3154 Py_DECREF(pos_args);
3155#else
3156 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3157 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3158 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3159 Py_DECREF(pos_args);
3160 } else if (flags == METH_FASTCALL) {
3161#if PYTHON_VERSION < 0x370
3162 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 4, NULL);
3163#else
3164 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3165 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
3166 Py_DECREF(pos_args);
3167#endif
3168 } else {
3169 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3170 result = (*method)(self, pos_args);
3171 Py_DECREF(pos_args);
3172 }
3173#endif
3174
3175#ifdef _NUITKA_FULL_COMPAT
3176 Py_LeaveRecursiveCall();
3177#endif
3178
3179 CHECK_OBJECT_X(result);
3180
3181 return Nuitka_CheckFunctionResult(tstate, called, result);
3182 }
3183#endif
3184#endif
3185#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
3186 } else if (PyFunction_Check(called)) {
3187#if PYTHON_VERSION < 0x3b0
3188 PyObject *result = callPythonFunction(called, args, 4);
3189#else
3190 PyObject *result = _PyFunction_Vectorcall(called, args, 4, NULL);
3191#endif
3192 CHECK_OBJECT_X(result);
3193
3194 return result;
3195#endif
3196#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
3197 } else if (PyType_Check(called)) {
3198 PyTypeObject *type = Py_TYPE(called);
3199
3200 if (type->tp_call == PyType_Type.tp_call) {
3201 PyTypeObject *called_type = (PyTypeObject *)(called);
3202
3203 if (unlikely(called_type->tp_new == NULL)) {
3204 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
3205 return NULL;
3206 }
3207
3208 PyObject *pos_args = NULL;
3209 PyObject *obj;
3210
3211 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
3212 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
3213 formatCannotInstantiateAbstractClass(tstate, called_type);
3214 return NULL;
3215 }
3216
3217 obj = called_type->tp_alloc(called_type, 0);
3218 CHECK_OBJECT(obj);
3219 } else {
3220 pos_args = MAKE_TUPLE(tstate, args, 4);
3221 obj = called_type->tp_new(called_type, pos_args, NULL);
3222 }
3223
3224 if (likely(obj != NULL)) {
3225 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
3226 Py_DECREF(pos_args);
3227 return obj;
3228 }
3229
3230 // Work on produced type.
3231 type = Py_TYPE(obj);
3232
3233 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
3234 if (type->tp_init == default_tp_init_wrapper) {
3235 Py_XDECREF(pos_args);
3236 pos_args = NULL;
3237
3238 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
3239
3240 // Not really allowed, since we wouldn't have the default wrapper set.
3241 assert(init_method != NULL);
3242
3243 bool is_compiled_function = false;
3244 bool init_method_needs_release = false;
3245
3246 if (likely(init_method != NULL)) {
3247 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
3248
3249 if (func == Nuitka_Function_Type.tp_descr_get) {
3250 is_compiled_function = true;
3251 } else if (func != NULL) {
3252 init_method = func(init_method, obj, (PyObject *)(type));
3253 init_method_needs_release = true;
3254 }
3255 }
3256
3257 if (unlikely(init_method == NULL)) {
3258 if (!HAS_ERROR_OCCURRED(tstate)) {
3259 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
3260 const_str_plain___init__);
3261 }
3262
3263 return NULL;
3264 }
3265
3266 PyObject *result;
3267 if (is_compiled_function) {
3268 result = Nuitka_CallMethodFunctionPosArgs(
3269 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 4);
3270 } else {
3271 result = CALL_FUNCTION_WITH_ARGS4(tstate, init_method, args);
3272 if (init_method_needs_release) {
3273 Py_DECREF(init_method);
3274 }
3275 }
3276
3277 if (unlikely(result == NULL)) {
3278 Py_DECREF(obj);
3279 return NULL;
3280 }
3281
3282 Py_DECREF(result);
3283
3284 if (unlikely(result != Py_None)) {
3285 Py_DECREF(obj);
3286
3287 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3288 return NULL;
3289 }
3290 } else {
3291 if (pos_args == NULL) {
3292 pos_args = MAKE_TUPLE(tstate, args, 4);
3293 }
3294
3295 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
3296 Py_DECREF(obj);
3297 Py_XDECREF(pos_args);
3298 return NULL;
3299 }
3300 }
3301 }
3302 }
3303
3304 Py_XDECREF(pos_args);
3305
3306 CHECK_OBJECT_X(obj);
3307
3308 return obj;
3309 }
3310#endif
3311#if PYTHON_VERSION < 0x300
3312 } else if (PyClass_Check(called)) {
3313 PyObject *obj = PyInstance_NewRaw(called, NULL);
3314
3315 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
3316
3317 if (unlikely(init_method == NULL)) {
3318 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
3319 Py_DECREF(obj);
3320 return NULL;
3321 }
3322
3323 Py_DECREF(obj);
3324
3325 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
3326 return NULL;
3327 }
3328
3329 bool is_compiled_function = false;
3330
3331 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
3332
3333 if (descr_get == NULL) {
3334 Py_INCREF(init_method);
3335 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
3336 is_compiled_function = true;
3337 } else if (descr_get != NULL) {
3338 PyObject *descr_method = descr_get(init_method, obj, called);
3339
3340 if (unlikely(descr_method == NULL)) {
3341 return NULL;
3342 }
3343
3344 init_method = descr_method;
3345 }
3346
3347 PyObject *result;
3348 if (is_compiled_function) {
3349 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
3350 args, 4);
3351 } else {
3352 result = CALL_FUNCTION_WITH_ARGS4(tstate, init_method, args);
3353 Py_DECREF(init_method);
3354 }
3355 if (unlikely(result == NULL)) {
3356 return NULL;
3357 }
3358
3359 Py_DECREF(result);
3360
3361 if (unlikely(result != Py_None)) {
3362 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3363 return NULL;
3364 }
3365
3366 CHECK_OBJECT_X(obj);
3367
3368 return obj;
3369#endif
3370#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
3371 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
3372 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3373
3374 if (likely(func != NULL)) {
3375 PyObject *result = func(called, args, 4, NULL);
3376
3377 CHECK_OBJECT_X(result);
3378
3379 return Nuitka_CheckFunctionResult(tstate, called, result);
3380 }
3381#endif
3382 }
3383
3384#if 0
3385 PRINT_NEW_LINE();
3386 PRINT_STRING("FALLBACK");
3387 PRINT_ITEM(called);
3388 PRINT_NEW_LINE();
3389#endif
3390
3391 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
3392
3393 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
3394
3395 Py_DECREF(pos_args);
3396
3397 CHECK_OBJECT_X(result);
3398
3399 return result;
3400}
3401PyObject *CALL_FUNCTION_WITH_POS_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
3402 assert(PyTuple_CheckExact(pos_args));
3403 assert(PyTuple_GET_SIZE(pos_args) == 4);
3404 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
3405 CHECK_OBJECT(called);
3406 CHECK_OBJECTS(args, 4);
3407
3408 if (Nuitka_Function_Check(called)) {
3409 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3410 return NULL;
3411 }
3412
3413 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
3414 PyObject *result;
3415
3416 if (function->m_args_simple && 4 == function->m_args_positional_count) {
3417 for (Py_ssize_t i = 0; i < 4; i++) {
3418 Py_INCREF(args[i]);
3419 }
3420 result = function->m_c_code(tstate, function, (PyObject **)args);
3421 } else if (function->m_args_simple && 4 + function->m_defaults_given == function->m_args_positional_count) {
3422 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3423
3424 memcpy(python_pars, args, 4 * sizeof(PyObject *));
3425 memcpy(python_pars + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3426 function->m_defaults_given * sizeof(PyObject *));
3427
3428 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
3429 Py_INCREF(python_pars[i]);
3430 }
3431
3432 result = function->m_c_code(tstate, function, python_pars);
3433 } else {
3434 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 4);
3435 }
3436
3437 Py_LeaveRecursiveCall();
3438
3439 CHECK_OBJECT_X(result);
3440
3441 return result;
3442 } else if (Nuitka_Method_Check(called)) {
3443 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3444
3445 if (method->m_object == NULL) {
3446 PyObject *self = args[0];
3447
3448 int res = PyObject_IsInstance(self, method->m_class);
3449
3450 if (unlikely(res < 0)) {
3451 return NULL;
3452 } else if (unlikely(res == 0)) {
3453 PyErr_Format(PyExc_TypeError,
3454 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3455 "instance instead)",
3456 GET_CALLABLE_NAME((PyObject *)method->m_function),
3457 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3458 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3459
3460 return NULL;
3461 }
3462
3463 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 4);
3464
3465 CHECK_OBJECT_X(result);
3466
3467 return result;
3468 } else {
3469 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3470 return NULL;
3471 }
3472
3473 struct Nuitka_FunctionObject *function = method->m_function;
3474
3475 PyObject *result;
3476
3477 if (function->m_args_simple && 4 + 1 == function->m_args_positional_count) {
3478 PyObject *python_pars[4 + 1];
3479
3480 python_pars[0] = method->m_object;
3481 Py_INCREF(method->m_object);
3482
3483 for (Py_ssize_t i = 0; i < 4; i++) {
3484 python_pars[i + 1] = args[i];
3485 Py_INCREF(args[i]);
3486 }
3487 result = function->m_c_code(tstate, function, python_pars);
3488 } else if (function->m_args_simple &&
3489 4 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3490 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3491
3492 python_pars[0] = method->m_object;
3493 Py_INCREF(method->m_object);
3494
3495 memcpy(python_pars + 1, args, 4 * sizeof(PyObject *));
3496 memcpy(python_pars + 1 + 4, &PyTuple_GET_ITEM(function->m_defaults, 0),
3497 function->m_defaults_given * sizeof(PyObject *));
3498
3499 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3500 Py_INCREF(python_pars[i]);
3501 }
3502
3503 result = function->m_c_code(tstate, function, python_pars);
3504 } else {
3505 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 4);
3506 }
3507
3508 Py_LeaveRecursiveCall();
3509
3510 CHECK_OBJECT_X(result);
3511
3512 return result;
3513 }
3514#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3515 } else if (PyCFunction_CheckExact(called)) {
3516#if PYTHON_VERSION >= 0x380
3517#ifdef _NUITKA_FULL_COMPAT
3518 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3519 return NULL;
3520 }
3521#endif
3522
3523 int flags = PyCFunction_GET_FLAGS(called);
3524
3525 PyObject *result;
3526
3527 if (!(flags & METH_VARARGS)) {
3528 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3529
3530 assert(func != NULL);
3531 result = func(called, args, 4, NULL);
3532
3533 CHECK_OBJECT_X(result);
3534 } else {
3535 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3536 PyObject *self = PyCFunction_GET_SELF(called);
3537
3538 if (flags & METH_KEYWORDS) {
3539 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3540 } else {
3541 result = (*method)(self, pos_args);
3542 }
3543 }
3544
3545#ifdef _NUITKA_FULL_COMPAT
3546 Py_LeaveRecursiveCall();
3547#endif
3548 CHECK_OBJECT_X(result);
3549
3550 return Nuitka_CheckFunctionResult(tstate, called, result);
3551#else
3552 // Try to be fast about wrapping the arguments.
3553 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3554
3555 if (unlikely(flags & METH_NOARGS)) {
3556 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (4 given)",
3557 ((PyCFunctionObject *)called)->m_ml->ml_name);
3558 return NULL;
3559 } else if (unlikely(flags & METH_O)) {
3560 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
3561 ((PyCFunctionObject *)called)->m_ml->ml_name);
3562 return NULL;
3563 } else if (flags & METH_VARARGS) {
3564 // Recursion guard is not strictly necessary, as we already have
3565 // one on our way to here.
3566#ifdef _NUITKA_FULL_COMPAT
3567 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3568 return NULL;
3569 }
3570#endif
3571 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3572 PyObject *self = PyCFunction_GET_SELF(called);
3573
3574 PyObject *result;
3575
3576#if PYTHON_VERSION < 0x360
3577 if (flags & METH_KEYWORDS) {
3578 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3579 } else {
3580 result = (*method)(self, pos_args);
3581 }
3582
3583#else
3584 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3585 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3586 } else if (flags == METH_FASTCALL) {
3587#if PYTHON_VERSION < 0x370
3588 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 4, NULL);
3589#else
3590 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
3591#endif
3592 } else {
3593 result = (*method)(self, pos_args);
3594 }
3595#endif
3596
3597#ifdef _NUITKA_FULL_COMPAT
3598 Py_LeaveRecursiveCall();
3599#endif
3600
3601 CHECK_OBJECT_X(result);
3602
3603 return Nuitka_CheckFunctionResult(tstate, called, result);
3604 }
3605#endif
3606#endif
3607#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
3608 } else if (PyFunction_Check(called)) {
3609#if PYTHON_VERSION < 0x3b0
3610 PyObject *result = callPythonFunction(called, args, 4);
3611#else
3612 PyObject *result = _PyFunction_Vectorcall(called, args, 4, NULL);
3613#endif
3614 CHECK_OBJECT_X(result);
3615
3616 return result;
3617#endif
3618#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
3619 } else if (PyType_Check(called)) {
3620 PyTypeObject *type = Py_TYPE(called);
3621
3622 if (type->tp_call == PyType_Type.tp_call) {
3623 PyTypeObject *called_type = (PyTypeObject *)(called);
3624
3625 if (unlikely(called_type->tp_new == NULL)) {
3626 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
3627 return NULL;
3628 }
3629
3630 PyObject *obj;
3631
3632 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
3633 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
3634 formatCannotInstantiateAbstractClass(tstate, called_type);
3635 return NULL;
3636 }
3637
3638 obj = called_type->tp_alloc(called_type, 0);
3639 CHECK_OBJECT(obj);
3640 } else {
3641 obj = called_type->tp_new(called_type, pos_args, NULL);
3642 }
3643
3644 if (likely(obj != NULL)) {
3645 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
3646 return obj;
3647 }
3648
3649 // Work on produced type.
3650 type = Py_TYPE(obj);
3651
3652 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
3653 if (type->tp_init == default_tp_init_wrapper) {
3654
3655 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
3656
3657 // Not really allowed, since we wouldn't have the default wrapper set.
3658 assert(init_method != NULL);
3659
3660 bool is_compiled_function = false;
3661 bool init_method_needs_release = false;
3662
3663 if (likely(init_method != NULL)) {
3664 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
3665
3666 if (func == Nuitka_Function_Type.tp_descr_get) {
3667 is_compiled_function = true;
3668 } else if (func != NULL) {
3669 init_method = func(init_method, obj, (PyObject *)(type));
3670 init_method_needs_release = true;
3671 }
3672 }
3673
3674 if (unlikely(init_method == NULL)) {
3675 if (!HAS_ERROR_OCCURRED(tstate)) {
3676 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
3677 const_str_plain___init__);
3678 }
3679
3680 return NULL;
3681 }
3682
3683 PyObject *result;
3684 if (is_compiled_function) {
3685 result = Nuitka_CallMethodFunctionPosArgs(
3686 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 4);
3687 } else {
3688 result = CALL_FUNCTION_WITH_POS_ARGS4(tstate, init_method, pos_args);
3689 if (init_method_needs_release) {
3690 Py_DECREF(init_method);
3691 }
3692 }
3693
3694 if (unlikely(result == NULL)) {
3695 Py_DECREF(obj);
3696 return NULL;
3697 }
3698
3699 Py_DECREF(result);
3700
3701 if (unlikely(result != Py_None)) {
3702 Py_DECREF(obj);
3703
3704 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3705 return NULL;
3706 }
3707 } else {
3708
3709 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
3710 Py_DECREF(obj);
3711 return NULL;
3712 }
3713 }
3714 }
3715 }
3716
3717 CHECK_OBJECT_X(obj);
3718
3719 return obj;
3720 }
3721#endif
3722#if PYTHON_VERSION < 0x300
3723 } else if (PyClass_Check(called)) {
3724 PyObject *obj = PyInstance_NewRaw(called, NULL);
3725
3726 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
3727
3728 if (unlikely(init_method == NULL)) {
3729 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
3730 Py_DECREF(obj);
3731 return NULL;
3732 }
3733
3734 Py_DECREF(obj);
3735
3736 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
3737 return NULL;
3738 }
3739
3740 bool is_compiled_function = false;
3741
3742 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
3743
3744 if (descr_get == NULL) {
3745 Py_INCREF(init_method);
3746 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
3747 is_compiled_function = true;
3748 } else if (descr_get != NULL) {
3749 PyObject *descr_method = descr_get(init_method, obj, called);
3750
3751 if (unlikely(descr_method == NULL)) {
3752 return NULL;
3753 }
3754
3755 init_method = descr_method;
3756 }
3757
3758 PyObject *result;
3759 if (is_compiled_function) {
3760 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
3761 args, 4);
3762 } else {
3763 result = CALL_FUNCTION_WITH_POS_ARGS4(tstate, init_method, pos_args);
3764 Py_DECREF(init_method);
3765 }
3766 if (unlikely(result == NULL)) {
3767 return NULL;
3768 }
3769
3770 Py_DECREF(result);
3771
3772 if (unlikely(result != Py_None)) {
3773 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
3774 return NULL;
3775 }
3776
3777 CHECK_OBJECT_X(obj);
3778
3779 return obj;
3780#endif
3781#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
3782 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
3783 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3784
3785 if (likely(func != NULL)) {
3786 PyObject *result = func(called, args, 4, NULL);
3787
3788 CHECK_OBJECT_X(result);
3789
3790 return Nuitka_CheckFunctionResult(tstate, called, result);
3791 }
3792#endif
3793 }
3794
3795#if 0
3796 PRINT_NEW_LINE();
3797 PRINT_STRING("FALLBACK");
3798 PRINT_ITEM(called);
3799 PRINT_NEW_LINE();
3800#endif
3801
3802 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
3803
3804 CHECK_OBJECT_X(result);
3805
3806 return result;
3807}
3808PyObject *CALL_FUNCTION_WITH_ARGS5(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
3809 CHECK_OBJECT(called);
3810 CHECK_OBJECTS(args, 5);
3811
3812 if (Nuitka_Function_Check(called)) {
3813 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3814 return NULL;
3815 }
3816
3817 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
3818 PyObject *result;
3819
3820 if (function->m_args_simple && 5 == function->m_args_positional_count) {
3821 for (Py_ssize_t i = 0; i < 5; i++) {
3822 Py_INCREF(args[i]);
3823 }
3824 result = function->m_c_code(tstate, function, (PyObject **)args);
3825 } else if (function->m_args_simple && 5 + function->m_defaults_given == function->m_args_positional_count) {
3826 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3827
3828 memcpy(python_pars, args, 5 * sizeof(PyObject *));
3829 memcpy(python_pars + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
3830 function->m_defaults_given * sizeof(PyObject *));
3831
3832 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
3833 Py_INCREF(python_pars[i]);
3834 }
3835
3836 result = function->m_c_code(tstate, function, python_pars);
3837 } else {
3838 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 5);
3839 }
3840
3841 Py_LeaveRecursiveCall();
3842
3843 CHECK_OBJECT_X(result);
3844
3845 return result;
3846 } else if (Nuitka_Method_Check(called)) {
3847 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
3848
3849 if (method->m_object == NULL) {
3850 PyObject *self = args[0];
3851
3852 int res = PyObject_IsInstance(self, method->m_class);
3853
3854 if (unlikely(res < 0)) {
3855 return NULL;
3856 } else if (unlikely(res == 0)) {
3857 PyErr_Format(PyExc_TypeError,
3858 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
3859 "instance instead)",
3860 GET_CALLABLE_NAME((PyObject *)method->m_function),
3861 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
3862 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
3863
3864 return NULL;
3865 }
3866
3867 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 5);
3868
3869 CHECK_OBJECT_X(result);
3870
3871 return result;
3872 } else {
3873 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3874 return NULL;
3875 }
3876
3877 struct Nuitka_FunctionObject *function = method->m_function;
3878
3879 PyObject *result;
3880
3881 if (function->m_args_simple && 5 + 1 == function->m_args_positional_count) {
3882 PyObject *python_pars[5 + 1];
3883
3884 python_pars[0] = method->m_object;
3885 Py_INCREF(method->m_object);
3886
3887 for (Py_ssize_t i = 0; i < 5; i++) {
3888 python_pars[i + 1] = args[i];
3889 Py_INCREF(args[i]);
3890 }
3891 result = function->m_c_code(tstate, function, python_pars);
3892 } else if (function->m_args_simple &&
3893 5 + 1 + function->m_defaults_given == function->m_args_positional_count) {
3894 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
3895
3896 python_pars[0] = method->m_object;
3897 Py_INCREF(method->m_object);
3898
3899 memcpy(python_pars + 1, args, 5 * sizeof(PyObject *));
3900 memcpy(python_pars + 1 + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
3901 function->m_defaults_given * sizeof(PyObject *));
3902
3903 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
3904 Py_INCREF(python_pars[i]);
3905 }
3906
3907 result = function->m_c_code(tstate, function, python_pars);
3908 } else {
3909 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 5);
3910 }
3911
3912 Py_LeaveRecursiveCall();
3913
3914 CHECK_OBJECT_X(result);
3915
3916 return result;
3917 }
3918#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
3919 } else if (PyCFunction_CheckExact(called)) {
3920#if PYTHON_VERSION >= 0x380
3921#ifdef _NUITKA_FULL_COMPAT
3922 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3923 return NULL;
3924 }
3925#endif
3926
3927 int flags = PyCFunction_GET_FLAGS(called);
3928
3929 PyObject *result;
3930
3931 if (!(flags & METH_VARARGS)) {
3932 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
3933
3934 assert(func != NULL);
3935 result = func(called, args, 5, NULL);
3936
3937 CHECK_OBJECT_X(result);
3938 } else {
3939 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3940 PyObject *self = PyCFunction_GET_SELF(called);
3941
3942 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3943
3944 if (flags & METH_KEYWORDS) {
3945 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
3946 } else {
3947 result = (*method)(self, pos_args);
3948 }
3949
3950 Py_DECREF(pos_args);
3951 }
3952
3953#ifdef _NUITKA_FULL_COMPAT
3954 Py_LeaveRecursiveCall();
3955#endif
3956 CHECK_OBJECT_X(result);
3957
3958 return Nuitka_CheckFunctionResult(tstate, called, result);
3959#else
3960 // Try to be fast about wrapping the arguments.
3961 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
3962
3963 if (unlikely(flags & METH_NOARGS)) {
3964 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (5 given)",
3965 ((PyCFunctionObject *)called)->m_ml->ml_name);
3966 return NULL;
3967 } else if (unlikely(flags & METH_O)) {
3968 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (5 given)",
3969 ((PyCFunctionObject *)called)->m_ml->ml_name);
3970 return NULL;
3971 } else if (flags & METH_VARARGS) {
3972 // Recursion guard is not strictly necessary, as we already have
3973 // one on our way to here.
3974#ifdef _NUITKA_FULL_COMPAT
3975 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
3976 return NULL;
3977 }
3978#endif
3979 PyCFunction method = PyCFunction_GET_FUNCTION(called);
3980 PyObject *self = PyCFunction_GET_SELF(called);
3981
3982 PyObject *result;
3983
3984#if PYTHON_VERSION < 0x360
3985 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3986 if (flags & METH_KEYWORDS) {
3987 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3988 } else {
3989 result = (*method)(self, pos_args);
3990 }
3991
3992 Py_DECREF(pos_args);
3993#else
3994 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
3995 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
3996 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
3997 Py_DECREF(pos_args);
3998 } else if (flags == METH_FASTCALL) {
3999#if PYTHON_VERSION < 0x370
4000 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 5, NULL);
4001#else
4002 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4003 result = (*(_PyCFunctionFast)method)(self, &pos_args, 5);
4004 Py_DECREF(pos_args);
4005#endif
4006 } else {
4007 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4008 result = (*method)(self, pos_args);
4009 Py_DECREF(pos_args);
4010 }
4011#endif
4012
4013#ifdef _NUITKA_FULL_COMPAT
4014 Py_LeaveRecursiveCall();
4015#endif
4016
4017 CHECK_OBJECT_X(result);
4018
4019 return Nuitka_CheckFunctionResult(tstate, called, result);
4020 }
4021#endif
4022#endif
4023#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4024 } else if (PyFunction_Check(called)) {
4025#if PYTHON_VERSION < 0x3b0
4026 PyObject *result = callPythonFunction(called, args, 5);
4027#else
4028 PyObject *result = _PyFunction_Vectorcall(called, args, 5, NULL);
4029#endif
4030 CHECK_OBJECT_X(result);
4031
4032 return result;
4033#endif
4034#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4035 } else if (PyType_Check(called)) {
4036 PyTypeObject *type = Py_TYPE(called);
4037
4038 if (type->tp_call == PyType_Type.tp_call) {
4039 PyTypeObject *called_type = (PyTypeObject *)(called);
4040
4041 if (unlikely(called_type->tp_new == NULL)) {
4042 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4043 return NULL;
4044 }
4045
4046 PyObject *pos_args = NULL;
4047 PyObject *obj;
4048
4049 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4050 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4051 formatCannotInstantiateAbstractClass(tstate, called_type);
4052 return NULL;
4053 }
4054
4055 obj = called_type->tp_alloc(called_type, 0);
4056 CHECK_OBJECT(obj);
4057 } else {
4058 pos_args = MAKE_TUPLE(tstate, args, 5);
4059 obj = called_type->tp_new(called_type, pos_args, NULL);
4060 }
4061
4062 if (likely(obj != NULL)) {
4063 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4064 Py_DECREF(pos_args);
4065 return obj;
4066 }
4067
4068 // Work on produced type.
4069 type = Py_TYPE(obj);
4070
4071 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4072 if (type->tp_init == default_tp_init_wrapper) {
4073 Py_XDECREF(pos_args);
4074 pos_args = NULL;
4075
4076 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4077
4078 // Not really allowed, since we wouldn't have the default wrapper set.
4079 assert(init_method != NULL);
4080
4081 bool is_compiled_function = false;
4082 bool init_method_needs_release = false;
4083
4084 if (likely(init_method != NULL)) {
4085 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4086
4087 if (func == Nuitka_Function_Type.tp_descr_get) {
4088 is_compiled_function = true;
4089 } else if (func != NULL) {
4090 init_method = func(init_method, obj, (PyObject *)(type));
4091 init_method_needs_release = true;
4092 }
4093 }
4094
4095 if (unlikely(init_method == NULL)) {
4096 if (!HAS_ERROR_OCCURRED(tstate)) {
4097 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4098 const_str_plain___init__);
4099 }
4100
4101 return NULL;
4102 }
4103
4104 PyObject *result;
4105 if (is_compiled_function) {
4106 result = Nuitka_CallMethodFunctionPosArgs(
4107 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 5);
4108 } else {
4109 result = CALL_FUNCTION_WITH_ARGS5(tstate, init_method, args);
4110 if (init_method_needs_release) {
4111 Py_DECREF(init_method);
4112 }
4113 }
4114
4115 if (unlikely(result == NULL)) {
4116 Py_DECREF(obj);
4117 return NULL;
4118 }
4119
4120 Py_DECREF(result);
4121
4122 if (unlikely(result != Py_None)) {
4123 Py_DECREF(obj);
4124
4125 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4126 return NULL;
4127 }
4128 } else {
4129 if (pos_args == NULL) {
4130 pos_args = MAKE_TUPLE(tstate, args, 5);
4131 }
4132
4133 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4134 Py_DECREF(obj);
4135 Py_XDECREF(pos_args);
4136 return NULL;
4137 }
4138 }
4139 }
4140 }
4141
4142 Py_XDECREF(pos_args);
4143
4144 CHECK_OBJECT_X(obj);
4145
4146 return obj;
4147 }
4148#endif
4149#if PYTHON_VERSION < 0x300
4150 } else if (PyClass_Check(called)) {
4151 PyObject *obj = PyInstance_NewRaw(called, NULL);
4152
4153 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4154
4155 if (unlikely(init_method == NULL)) {
4156 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4157 Py_DECREF(obj);
4158 return NULL;
4159 }
4160
4161 Py_DECREF(obj);
4162
4163 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4164 return NULL;
4165 }
4166
4167 bool is_compiled_function = false;
4168
4169 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4170
4171 if (descr_get == NULL) {
4172 Py_INCREF(init_method);
4173 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
4174 is_compiled_function = true;
4175 } else if (descr_get != NULL) {
4176 PyObject *descr_method = descr_get(init_method, obj, called);
4177
4178 if (unlikely(descr_method == NULL)) {
4179 return NULL;
4180 }
4181
4182 init_method = descr_method;
4183 }
4184
4185 PyObject *result;
4186 if (is_compiled_function) {
4187 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
4188 args, 5);
4189 } else {
4190 result = CALL_FUNCTION_WITH_ARGS5(tstate, init_method, args);
4191 Py_DECREF(init_method);
4192 }
4193 if (unlikely(result == NULL)) {
4194 return NULL;
4195 }
4196
4197 Py_DECREF(result);
4198
4199 if (unlikely(result != Py_None)) {
4200 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4201 return NULL;
4202 }
4203
4204 CHECK_OBJECT_X(obj);
4205
4206 return obj;
4207#endif
4208#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
4209 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
4210 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4211
4212 if (likely(func != NULL)) {
4213 PyObject *result = func(called, args, 5, NULL);
4214
4215 CHECK_OBJECT_X(result);
4216
4217 return Nuitka_CheckFunctionResult(tstate, called, result);
4218 }
4219#endif
4220 }
4221
4222#if 0
4223 PRINT_NEW_LINE();
4224 PRINT_STRING("FALLBACK");
4225 PRINT_ITEM(called);
4226 PRINT_NEW_LINE();
4227#endif
4228
4229 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
4230
4231 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
4232
4233 Py_DECREF(pos_args);
4234
4235 CHECK_OBJECT_X(result);
4236
4237 return result;
4238}
4239PyObject *CALL_FUNCTION_WITH_POS_ARGS5(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
4240 assert(PyTuple_CheckExact(pos_args));
4241 assert(PyTuple_GET_SIZE(pos_args) == 5);
4242 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
4243 CHECK_OBJECT(called);
4244 CHECK_OBJECTS(args, 5);
4245
4246 if (Nuitka_Function_Check(called)) {
4247 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4248 return NULL;
4249 }
4250
4251 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
4252 PyObject *result;
4253
4254 if (function->m_args_simple && 5 == function->m_args_positional_count) {
4255 for (Py_ssize_t i = 0; i < 5; i++) {
4256 Py_INCREF(args[i]);
4257 }
4258 result = function->m_c_code(tstate, function, (PyObject **)args);
4259 } else if (function->m_args_simple && 5 + function->m_defaults_given == function->m_args_positional_count) {
4260 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4261
4262 memcpy(python_pars, args, 5 * sizeof(PyObject *));
4263 memcpy(python_pars + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
4264 function->m_defaults_given * sizeof(PyObject *));
4265
4266 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
4267 Py_INCREF(python_pars[i]);
4268 }
4269
4270 result = function->m_c_code(tstate, function, python_pars);
4271 } else {
4272 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 5);
4273 }
4274
4275 Py_LeaveRecursiveCall();
4276
4277 CHECK_OBJECT_X(result);
4278
4279 return result;
4280 } else if (Nuitka_Method_Check(called)) {
4281 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
4282
4283 if (method->m_object == NULL) {
4284 PyObject *self = args[0];
4285
4286 int res = PyObject_IsInstance(self, method->m_class);
4287
4288 if (unlikely(res < 0)) {
4289 return NULL;
4290 } else if (unlikely(res == 0)) {
4291 PyErr_Format(PyExc_TypeError,
4292 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
4293 "instance instead)",
4294 GET_CALLABLE_NAME((PyObject *)method->m_function),
4295 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
4296 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
4297
4298 return NULL;
4299 }
4300
4301 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 5);
4302
4303 CHECK_OBJECT_X(result);
4304
4305 return result;
4306 } else {
4307 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4308 return NULL;
4309 }
4310
4311 struct Nuitka_FunctionObject *function = method->m_function;
4312
4313 PyObject *result;
4314
4315 if (function->m_args_simple && 5 + 1 == function->m_args_positional_count) {
4316 PyObject *python_pars[5 + 1];
4317
4318 python_pars[0] = method->m_object;
4319 Py_INCREF(method->m_object);
4320
4321 for (Py_ssize_t i = 0; i < 5; i++) {
4322 python_pars[i + 1] = args[i];
4323 Py_INCREF(args[i]);
4324 }
4325 result = function->m_c_code(tstate, function, python_pars);
4326 } else if (function->m_args_simple &&
4327 5 + 1 + function->m_defaults_given == function->m_args_positional_count) {
4328 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4329
4330 python_pars[0] = method->m_object;
4331 Py_INCREF(method->m_object);
4332
4333 memcpy(python_pars + 1, args, 5 * sizeof(PyObject *));
4334 memcpy(python_pars + 1 + 5, &PyTuple_GET_ITEM(function->m_defaults, 0),
4335 function->m_defaults_given * sizeof(PyObject *));
4336
4337 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
4338 Py_INCREF(python_pars[i]);
4339 }
4340
4341 result = function->m_c_code(tstate, function, python_pars);
4342 } else {
4343 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 5);
4344 }
4345
4346 Py_LeaveRecursiveCall();
4347
4348 CHECK_OBJECT_X(result);
4349
4350 return result;
4351 }
4352#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
4353 } else if (PyCFunction_CheckExact(called)) {
4354#if PYTHON_VERSION >= 0x380
4355#ifdef _NUITKA_FULL_COMPAT
4356 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4357 return NULL;
4358 }
4359#endif
4360
4361 int flags = PyCFunction_GET_FLAGS(called);
4362
4363 PyObject *result;
4364
4365 if (!(flags & METH_VARARGS)) {
4366 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4367
4368 assert(func != NULL);
4369 result = func(called, args, 5, NULL);
4370
4371 CHECK_OBJECT_X(result);
4372 } else {
4373 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4374 PyObject *self = PyCFunction_GET_SELF(called);
4375
4376 if (flags & METH_KEYWORDS) {
4377 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
4378 } else {
4379 result = (*method)(self, pos_args);
4380 }
4381 }
4382
4383#ifdef _NUITKA_FULL_COMPAT
4384 Py_LeaveRecursiveCall();
4385#endif
4386 CHECK_OBJECT_X(result);
4387
4388 return Nuitka_CheckFunctionResult(tstate, called, result);
4389#else
4390 // Try to be fast about wrapping the arguments.
4391 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
4392
4393 if (unlikely(flags & METH_NOARGS)) {
4394 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (5 given)",
4395 ((PyCFunctionObject *)called)->m_ml->ml_name);
4396 return NULL;
4397 } else if (unlikely(flags & METH_O)) {
4398 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (5 given)",
4399 ((PyCFunctionObject *)called)->m_ml->ml_name);
4400 return NULL;
4401 } else if (flags & METH_VARARGS) {
4402 // Recursion guard is not strictly necessary, as we already have
4403 // one on our way to here.
4404#ifdef _NUITKA_FULL_COMPAT
4405 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4406 return NULL;
4407 }
4408#endif
4409 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4410 PyObject *self = PyCFunction_GET_SELF(called);
4411
4412 PyObject *result;
4413
4414#if PYTHON_VERSION < 0x360
4415 if (flags & METH_KEYWORDS) {
4416 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4417 } else {
4418 result = (*method)(self, pos_args);
4419 }
4420
4421#else
4422 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
4423 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4424 } else if (flags == METH_FASTCALL) {
4425#if PYTHON_VERSION < 0x370
4426 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 5, NULL);
4427#else
4428 result = (*(_PyCFunctionFast)method)(self, &pos_args, 5);
4429#endif
4430 } else {
4431 result = (*method)(self, pos_args);
4432 }
4433#endif
4434
4435#ifdef _NUITKA_FULL_COMPAT
4436 Py_LeaveRecursiveCall();
4437#endif
4438
4439 CHECK_OBJECT_X(result);
4440
4441 return Nuitka_CheckFunctionResult(tstate, called, result);
4442 }
4443#endif
4444#endif
4445#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4446 } else if (PyFunction_Check(called)) {
4447#if PYTHON_VERSION < 0x3b0
4448 PyObject *result = callPythonFunction(called, args, 5);
4449#else
4450 PyObject *result = _PyFunction_Vectorcall(called, args, 5, NULL);
4451#endif
4452 CHECK_OBJECT_X(result);
4453
4454 return result;
4455#endif
4456#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4457 } else if (PyType_Check(called)) {
4458 PyTypeObject *type = Py_TYPE(called);
4459
4460 if (type->tp_call == PyType_Type.tp_call) {
4461 PyTypeObject *called_type = (PyTypeObject *)(called);
4462
4463 if (unlikely(called_type->tp_new == NULL)) {
4464 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4465 return NULL;
4466 }
4467
4468 PyObject *obj;
4469
4470 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4471 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4472 formatCannotInstantiateAbstractClass(tstate, called_type);
4473 return NULL;
4474 }
4475
4476 obj = called_type->tp_alloc(called_type, 0);
4477 CHECK_OBJECT(obj);
4478 } else {
4479 obj = called_type->tp_new(called_type, pos_args, NULL);
4480 }
4481
4482 if (likely(obj != NULL)) {
4483 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4484 return obj;
4485 }
4486
4487 // Work on produced type.
4488 type = Py_TYPE(obj);
4489
4490 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4491 if (type->tp_init == default_tp_init_wrapper) {
4492
4493 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4494
4495 // Not really allowed, since we wouldn't have the default wrapper set.
4496 assert(init_method != NULL);
4497
4498 bool is_compiled_function = false;
4499 bool init_method_needs_release = false;
4500
4501 if (likely(init_method != NULL)) {
4502 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4503
4504 if (func == Nuitka_Function_Type.tp_descr_get) {
4505 is_compiled_function = true;
4506 } else if (func != NULL) {
4507 init_method = func(init_method, obj, (PyObject *)(type));
4508 init_method_needs_release = true;
4509 }
4510 }
4511
4512 if (unlikely(init_method == NULL)) {
4513 if (!HAS_ERROR_OCCURRED(tstate)) {
4514 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4515 const_str_plain___init__);
4516 }
4517
4518 return NULL;
4519 }
4520
4521 PyObject *result;
4522 if (is_compiled_function) {
4523 result = Nuitka_CallMethodFunctionPosArgs(
4524 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 5);
4525 } else {
4526 result = CALL_FUNCTION_WITH_POS_ARGS5(tstate, init_method, pos_args);
4527 if (init_method_needs_release) {
4528 Py_DECREF(init_method);
4529 }
4530 }
4531
4532 if (unlikely(result == NULL)) {
4533 Py_DECREF(obj);
4534 return NULL;
4535 }
4536
4537 Py_DECREF(result);
4538
4539 if (unlikely(result != Py_None)) {
4540 Py_DECREF(obj);
4541
4542 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4543 return NULL;
4544 }
4545 } else {
4546
4547 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4548 Py_DECREF(obj);
4549 return NULL;
4550 }
4551 }
4552 }
4553 }
4554
4555 CHECK_OBJECT_X(obj);
4556
4557 return obj;
4558 }
4559#endif
4560#if PYTHON_VERSION < 0x300
4561 } else if (PyClass_Check(called)) {
4562 PyObject *obj = PyInstance_NewRaw(called, NULL);
4563
4564 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4565
4566 if (unlikely(init_method == NULL)) {
4567 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4568 Py_DECREF(obj);
4569 return NULL;
4570 }
4571
4572 Py_DECREF(obj);
4573
4574 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
4575 return NULL;
4576 }
4577
4578 bool is_compiled_function = false;
4579
4580 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
4581
4582 if (descr_get == NULL) {
4583 Py_INCREF(init_method);
4584 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
4585 is_compiled_function = true;
4586 } else if (descr_get != NULL) {
4587 PyObject *descr_method = descr_get(init_method, obj, called);
4588
4589 if (unlikely(descr_method == NULL)) {
4590 return NULL;
4591 }
4592
4593 init_method = descr_method;
4594 }
4595
4596 PyObject *result;
4597 if (is_compiled_function) {
4598 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
4599 args, 5);
4600 } else {
4601 result = CALL_FUNCTION_WITH_POS_ARGS5(tstate, init_method, pos_args);
4602 Py_DECREF(init_method);
4603 }
4604 if (unlikely(result == NULL)) {
4605 return NULL;
4606 }
4607
4608 Py_DECREF(result);
4609
4610 if (unlikely(result != Py_None)) {
4611 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4612 return NULL;
4613 }
4614
4615 CHECK_OBJECT_X(obj);
4616
4617 return obj;
4618#endif
4619#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
4620 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
4621 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4622
4623 if (likely(func != NULL)) {
4624 PyObject *result = func(called, args, 5, NULL);
4625
4626 CHECK_OBJECT_X(result);
4627
4628 return Nuitka_CheckFunctionResult(tstate, called, result);
4629 }
4630#endif
4631 }
4632
4633#if 0
4634 PRINT_NEW_LINE();
4635 PRINT_STRING("FALLBACK");
4636 PRINT_ITEM(called);
4637 PRINT_NEW_LINE();
4638#endif
4639
4640 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
4641
4642 CHECK_OBJECT_X(result);
4643
4644 return result;
4645}
4646PyObject *CALL_FUNCTION_WITH_ARGS6(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
4647 CHECK_OBJECT(called);
4648 CHECK_OBJECTS(args, 6);
4649
4650 if (Nuitka_Function_Check(called)) {
4651 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4652 return NULL;
4653 }
4654
4655 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
4656 PyObject *result;
4657
4658 if (function->m_args_simple && 6 == function->m_args_positional_count) {
4659 for (Py_ssize_t i = 0; i < 6; i++) {
4660 Py_INCREF(args[i]);
4661 }
4662 result = function->m_c_code(tstate, function, (PyObject **)args);
4663 } else if (function->m_args_simple && 6 + function->m_defaults_given == function->m_args_positional_count) {
4664 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4665
4666 memcpy(python_pars, args, 6 * sizeof(PyObject *));
4667 memcpy(python_pars + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
4668 function->m_defaults_given * sizeof(PyObject *));
4669
4670 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
4671 Py_INCREF(python_pars[i]);
4672 }
4673
4674 result = function->m_c_code(tstate, function, python_pars);
4675 } else {
4676 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 6);
4677 }
4678
4679 Py_LeaveRecursiveCall();
4680
4681 CHECK_OBJECT_X(result);
4682
4683 return result;
4684 } else if (Nuitka_Method_Check(called)) {
4685 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
4686
4687 if (method->m_object == NULL) {
4688 PyObject *self = args[0];
4689
4690 int res = PyObject_IsInstance(self, method->m_class);
4691
4692 if (unlikely(res < 0)) {
4693 return NULL;
4694 } else if (unlikely(res == 0)) {
4695 PyErr_Format(PyExc_TypeError,
4696 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
4697 "instance instead)",
4698 GET_CALLABLE_NAME((PyObject *)method->m_function),
4699 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
4700 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
4701
4702 return NULL;
4703 }
4704
4705 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 6);
4706
4707 CHECK_OBJECT_X(result);
4708
4709 return result;
4710 } else {
4711 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4712 return NULL;
4713 }
4714
4715 struct Nuitka_FunctionObject *function = method->m_function;
4716
4717 PyObject *result;
4718
4719 if (function->m_args_simple && 6 + 1 == function->m_args_positional_count) {
4720 PyObject *python_pars[6 + 1];
4721
4722 python_pars[0] = method->m_object;
4723 Py_INCREF(method->m_object);
4724
4725 for (Py_ssize_t i = 0; i < 6; i++) {
4726 python_pars[i + 1] = args[i];
4727 Py_INCREF(args[i]);
4728 }
4729 result = function->m_c_code(tstate, function, python_pars);
4730 } else if (function->m_args_simple &&
4731 6 + 1 + function->m_defaults_given == function->m_args_positional_count) {
4732 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
4733
4734 python_pars[0] = method->m_object;
4735 Py_INCREF(method->m_object);
4736
4737 memcpy(python_pars + 1, args, 6 * sizeof(PyObject *));
4738 memcpy(python_pars + 1 + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
4739 function->m_defaults_given * sizeof(PyObject *));
4740
4741 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
4742 Py_INCREF(python_pars[i]);
4743 }
4744
4745 result = function->m_c_code(tstate, function, python_pars);
4746 } else {
4747 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 6);
4748 }
4749
4750 Py_LeaveRecursiveCall();
4751
4752 CHECK_OBJECT_X(result);
4753
4754 return result;
4755 }
4756#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
4757 } else if (PyCFunction_CheckExact(called)) {
4758#if PYTHON_VERSION >= 0x380
4759#ifdef _NUITKA_FULL_COMPAT
4760 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4761 return NULL;
4762 }
4763#endif
4764
4765 int flags = PyCFunction_GET_FLAGS(called);
4766
4767 PyObject *result;
4768
4769 if (!(flags & METH_VARARGS)) {
4770 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
4771
4772 assert(func != NULL);
4773 result = func(called, args, 6, NULL);
4774
4775 CHECK_OBJECT_X(result);
4776 } else {
4777 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4778 PyObject *self = PyCFunction_GET_SELF(called);
4779
4780 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4781
4782 if (flags & METH_KEYWORDS) {
4783 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
4784 } else {
4785 result = (*method)(self, pos_args);
4786 }
4787
4788 Py_DECREF(pos_args);
4789 }
4790
4791#ifdef _NUITKA_FULL_COMPAT
4792 Py_LeaveRecursiveCall();
4793#endif
4794 CHECK_OBJECT_X(result);
4795
4796 return Nuitka_CheckFunctionResult(tstate, called, result);
4797#else
4798 // Try to be fast about wrapping the arguments.
4799 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
4800
4801 if (unlikely(flags & METH_NOARGS)) {
4802 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (6 given)",
4803 ((PyCFunctionObject *)called)->m_ml->ml_name);
4804 return NULL;
4805 } else if (unlikely(flags & METH_O)) {
4806 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (6 given)",
4807 ((PyCFunctionObject *)called)->m_ml->ml_name);
4808 return NULL;
4809 } else if (flags & METH_VARARGS) {
4810 // Recursion guard is not strictly necessary, as we already have
4811 // one on our way to here.
4812#ifdef _NUITKA_FULL_COMPAT
4813 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
4814 return NULL;
4815 }
4816#endif
4817 PyCFunction method = PyCFunction_GET_FUNCTION(called);
4818 PyObject *self = PyCFunction_GET_SELF(called);
4819
4820 PyObject *result;
4821
4822#if PYTHON_VERSION < 0x360
4823 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4824 if (flags & METH_KEYWORDS) {
4825 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4826 } else {
4827 result = (*method)(self, pos_args);
4828 }
4829
4830 Py_DECREF(pos_args);
4831#else
4832 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
4833 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4834 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
4835 Py_DECREF(pos_args);
4836 } else if (flags == METH_FASTCALL) {
4837#if PYTHON_VERSION < 0x370
4838 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 6, NULL);
4839#else
4840 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4841 result = (*(_PyCFunctionFast)method)(self, &pos_args, 6);
4842 Py_DECREF(pos_args);
4843#endif
4844 } else {
4845 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
4846 result = (*method)(self, pos_args);
4847 Py_DECREF(pos_args);
4848 }
4849#endif
4850
4851#ifdef _NUITKA_FULL_COMPAT
4852 Py_LeaveRecursiveCall();
4853#endif
4854
4855 CHECK_OBJECT_X(result);
4856
4857 return Nuitka_CheckFunctionResult(tstate, called, result);
4858 }
4859#endif
4860#endif
4861#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
4862 } else if (PyFunction_Check(called)) {
4863#if PYTHON_VERSION < 0x3b0
4864 PyObject *result = callPythonFunction(called, args, 6);
4865#else
4866 PyObject *result = _PyFunction_Vectorcall(called, args, 6, NULL);
4867#endif
4868 CHECK_OBJECT_X(result);
4869
4870 return result;
4871#endif
4872#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
4873 } else if (PyType_Check(called)) {
4874 PyTypeObject *type = Py_TYPE(called);
4875
4876 if (type->tp_call == PyType_Type.tp_call) {
4877 PyTypeObject *called_type = (PyTypeObject *)(called);
4878
4879 if (unlikely(called_type->tp_new == NULL)) {
4880 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
4881 return NULL;
4882 }
4883
4884 PyObject *pos_args = NULL;
4885 PyObject *obj;
4886
4887 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
4888 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
4889 formatCannotInstantiateAbstractClass(tstate, called_type);
4890 return NULL;
4891 }
4892
4893 obj = called_type->tp_alloc(called_type, 0);
4894 CHECK_OBJECT(obj);
4895 } else {
4896 pos_args = MAKE_TUPLE(tstate, args, 6);
4897 obj = called_type->tp_new(called_type, pos_args, NULL);
4898 }
4899
4900 if (likely(obj != NULL)) {
4901 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
4902 Py_DECREF(pos_args);
4903 return obj;
4904 }
4905
4906 // Work on produced type.
4907 type = Py_TYPE(obj);
4908
4909 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
4910 if (type->tp_init == default_tp_init_wrapper) {
4911 Py_XDECREF(pos_args);
4912 pos_args = NULL;
4913
4914 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
4915
4916 // Not really allowed, since we wouldn't have the default wrapper set.
4917 assert(init_method != NULL);
4918
4919 bool is_compiled_function = false;
4920 bool init_method_needs_release = false;
4921
4922 if (likely(init_method != NULL)) {
4923 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
4924
4925 if (func == Nuitka_Function_Type.tp_descr_get) {
4926 is_compiled_function = true;
4927 } else if (func != NULL) {
4928 init_method = func(init_method, obj, (PyObject *)(type));
4929 init_method_needs_release = true;
4930 }
4931 }
4932
4933 if (unlikely(init_method == NULL)) {
4934 if (!HAS_ERROR_OCCURRED(tstate)) {
4935 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
4936 const_str_plain___init__);
4937 }
4938
4939 return NULL;
4940 }
4941
4942 PyObject *result;
4943 if (is_compiled_function) {
4944 result = Nuitka_CallMethodFunctionPosArgs(
4945 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 6);
4946 } else {
4947 result = CALL_FUNCTION_WITH_ARGS6(tstate, init_method, args);
4948 if (init_method_needs_release) {
4949 Py_DECREF(init_method);
4950 }
4951 }
4952
4953 if (unlikely(result == NULL)) {
4954 Py_DECREF(obj);
4955 return NULL;
4956 }
4957
4958 Py_DECREF(result);
4959
4960 if (unlikely(result != Py_None)) {
4961 Py_DECREF(obj);
4962
4963 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
4964 return NULL;
4965 }
4966 } else {
4967 if (pos_args == NULL) {
4968 pos_args = MAKE_TUPLE(tstate, args, 6);
4969 }
4970
4971 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
4972 Py_DECREF(obj);
4973 Py_XDECREF(pos_args);
4974 return NULL;
4975 }
4976 }
4977 }
4978 }
4979
4980 Py_XDECREF(pos_args);
4981
4982 CHECK_OBJECT_X(obj);
4983
4984 return obj;
4985 }
4986#endif
4987#if PYTHON_VERSION < 0x300
4988 } else if (PyClass_Check(called)) {
4989 PyObject *obj = PyInstance_NewRaw(called, NULL);
4990
4991 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
4992
4993 if (unlikely(init_method == NULL)) {
4994 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
4995 Py_DECREF(obj);
4996 return NULL;
4997 }
4998
4999 Py_DECREF(obj);
5000
5001 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5002 return NULL;
5003 }
5004
5005 bool is_compiled_function = false;
5006
5007 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5008
5009 if (descr_get == NULL) {
5010 Py_INCREF(init_method);
5011 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5012 is_compiled_function = true;
5013 } else if (descr_get != NULL) {
5014 PyObject *descr_method = descr_get(init_method, obj, called);
5015
5016 if (unlikely(descr_method == NULL)) {
5017 return NULL;
5018 }
5019
5020 init_method = descr_method;
5021 }
5022
5023 PyObject *result;
5024 if (is_compiled_function) {
5025 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5026 args, 6);
5027 } else {
5028 result = CALL_FUNCTION_WITH_ARGS6(tstate, init_method, args);
5029 Py_DECREF(init_method);
5030 }
5031 if (unlikely(result == NULL)) {
5032 return NULL;
5033 }
5034
5035 Py_DECREF(result);
5036
5037 if (unlikely(result != Py_None)) {
5038 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5039 return NULL;
5040 }
5041
5042 CHECK_OBJECT_X(obj);
5043
5044 return obj;
5045#endif
5046#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5047 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5048 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5049
5050 if (likely(func != NULL)) {
5051 PyObject *result = func(called, args, 6, NULL);
5052
5053 CHECK_OBJECT_X(result);
5054
5055 return Nuitka_CheckFunctionResult(tstate, called, result);
5056 }
5057#endif
5058 }
5059
5060#if 0
5061 PRINT_NEW_LINE();
5062 PRINT_STRING("FALLBACK");
5063 PRINT_ITEM(called);
5064 PRINT_NEW_LINE();
5065#endif
5066
5067 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
5068
5069 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5070
5071 Py_DECREF(pos_args);
5072
5073 CHECK_OBJECT_X(result);
5074
5075 return result;
5076}
5077PyObject *CALL_FUNCTION_WITH_POS_ARGS6(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
5078 assert(PyTuple_CheckExact(pos_args));
5079 assert(PyTuple_GET_SIZE(pos_args) == 6);
5080 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
5081 CHECK_OBJECT(called);
5082 CHECK_OBJECTS(args, 6);
5083
5084 if (Nuitka_Function_Check(called)) {
5085 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5086 return NULL;
5087 }
5088
5089 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5090 PyObject *result;
5091
5092 if (function->m_args_simple && 6 == function->m_args_positional_count) {
5093 for (Py_ssize_t i = 0; i < 6; i++) {
5094 Py_INCREF(args[i]);
5095 }
5096 result = function->m_c_code(tstate, function, (PyObject **)args);
5097 } else if (function->m_args_simple && 6 + function->m_defaults_given == function->m_args_positional_count) {
5098 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5099
5100 memcpy(python_pars, args, 6 * sizeof(PyObject *));
5101 memcpy(python_pars + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
5102 function->m_defaults_given * sizeof(PyObject *));
5103
5104 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5105 Py_INCREF(python_pars[i]);
5106 }
5107
5108 result = function->m_c_code(tstate, function, python_pars);
5109 } else {
5110 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 6);
5111 }
5112
5113 Py_LeaveRecursiveCall();
5114
5115 CHECK_OBJECT_X(result);
5116
5117 return result;
5118 } else if (Nuitka_Method_Check(called)) {
5119 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5120
5121 if (method->m_object == NULL) {
5122 PyObject *self = args[0];
5123
5124 int res = PyObject_IsInstance(self, method->m_class);
5125
5126 if (unlikely(res < 0)) {
5127 return NULL;
5128 } else if (unlikely(res == 0)) {
5129 PyErr_Format(PyExc_TypeError,
5130 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5131 "instance instead)",
5132 GET_CALLABLE_NAME((PyObject *)method->m_function),
5133 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5134 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5135
5136 return NULL;
5137 }
5138
5139 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 6);
5140
5141 CHECK_OBJECT_X(result);
5142
5143 return result;
5144 } else {
5145 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5146 return NULL;
5147 }
5148
5149 struct Nuitka_FunctionObject *function = method->m_function;
5150
5151 PyObject *result;
5152
5153 if (function->m_args_simple && 6 + 1 == function->m_args_positional_count) {
5154 PyObject *python_pars[6 + 1];
5155
5156 python_pars[0] = method->m_object;
5157 Py_INCREF(method->m_object);
5158
5159 for (Py_ssize_t i = 0; i < 6; i++) {
5160 python_pars[i + 1] = args[i];
5161 Py_INCREF(args[i]);
5162 }
5163 result = function->m_c_code(tstate, function, python_pars);
5164 } else if (function->m_args_simple &&
5165 6 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5166 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5167
5168 python_pars[0] = method->m_object;
5169 Py_INCREF(method->m_object);
5170
5171 memcpy(python_pars + 1, args, 6 * sizeof(PyObject *));
5172 memcpy(python_pars + 1 + 6, &PyTuple_GET_ITEM(function->m_defaults, 0),
5173 function->m_defaults_given * sizeof(PyObject *));
5174
5175 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
5176 Py_INCREF(python_pars[i]);
5177 }
5178
5179 result = function->m_c_code(tstate, function, python_pars);
5180 } else {
5181 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 6);
5182 }
5183
5184 Py_LeaveRecursiveCall();
5185
5186 CHECK_OBJECT_X(result);
5187
5188 return result;
5189 }
5190#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
5191 } else if (PyCFunction_CheckExact(called)) {
5192#if PYTHON_VERSION >= 0x380
5193#ifdef _NUITKA_FULL_COMPAT
5194 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5195 return NULL;
5196 }
5197#endif
5198
5199 int flags = PyCFunction_GET_FLAGS(called);
5200
5201 PyObject *result;
5202
5203 if (!(flags & METH_VARARGS)) {
5204 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5205
5206 assert(func != NULL);
5207 result = func(called, args, 6, NULL);
5208
5209 CHECK_OBJECT_X(result);
5210 } else {
5211 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5212 PyObject *self = PyCFunction_GET_SELF(called);
5213
5214 if (flags & METH_KEYWORDS) {
5215 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
5216 } else {
5217 result = (*method)(self, pos_args);
5218 }
5219 }
5220
5221#ifdef _NUITKA_FULL_COMPAT
5222 Py_LeaveRecursiveCall();
5223#endif
5224 CHECK_OBJECT_X(result);
5225
5226 return Nuitka_CheckFunctionResult(tstate, called, result);
5227#else
5228 // Try to be fast about wrapping the arguments.
5229 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
5230
5231 if (unlikely(flags & METH_NOARGS)) {
5232 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (6 given)",
5233 ((PyCFunctionObject *)called)->m_ml->ml_name);
5234 return NULL;
5235 } else if (unlikely(flags & METH_O)) {
5236 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (6 given)",
5237 ((PyCFunctionObject *)called)->m_ml->ml_name);
5238 return NULL;
5239 } else if (flags & METH_VARARGS) {
5240 // Recursion guard is not strictly necessary, as we already have
5241 // one on our way to here.
5242#ifdef _NUITKA_FULL_COMPAT
5243 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5244 return NULL;
5245 }
5246#endif
5247 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5248 PyObject *self = PyCFunction_GET_SELF(called);
5249
5250 PyObject *result;
5251
5252#if PYTHON_VERSION < 0x360
5253 if (flags & METH_KEYWORDS) {
5254 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5255 } else {
5256 result = (*method)(self, pos_args);
5257 }
5258
5259#else
5260 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
5261 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5262 } else if (flags == METH_FASTCALL) {
5263#if PYTHON_VERSION < 0x370
5264 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 6, NULL);
5265#else
5266 result = (*(_PyCFunctionFast)method)(self, &pos_args, 6);
5267#endif
5268 } else {
5269 result = (*method)(self, pos_args);
5270 }
5271#endif
5272
5273#ifdef _NUITKA_FULL_COMPAT
5274 Py_LeaveRecursiveCall();
5275#endif
5276
5277 CHECK_OBJECT_X(result);
5278
5279 return Nuitka_CheckFunctionResult(tstate, called, result);
5280 }
5281#endif
5282#endif
5283#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
5284 } else if (PyFunction_Check(called)) {
5285#if PYTHON_VERSION < 0x3b0
5286 PyObject *result = callPythonFunction(called, args, 6);
5287#else
5288 PyObject *result = _PyFunction_Vectorcall(called, args, 6, NULL);
5289#endif
5290 CHECK_OBJECT_X(result);
5291
5292 return result;
5293#endif
5294#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
5295 } else if (PyType_Check(called)) {
5296 PyTypeObject *type = Py_TYPE(called);
5297
5298 if (type->tp_call == PyType_Type.tp_call) {
5299 PyTypeObject *called_type = (PyTypeObject *)(called);
5300
5301 if (unlikely(called_type->tp_new == NULL)) {
5302 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
5303 return NULL;
5304 }
5305
5306 PyObject *obj;
5307
5308 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
5309 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
5310 formatCannotInstantiateAbstractClass(tstate, called_type);
5311 return NULL;
5312 }
5313
5314 obj = called_type->tp_alloc(called_type, 0);
5315 CHECK_OBJECT(obj);
5316 } else {
5317 obj = called_type->tp_new(called_type, pos_args, NULL);
5318 }
5319
5320 if (likely(obj != NULL)) {
5321 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
5322 return obj;
5323 }
5324
5325 // Work on produced type.
5326 type = Py_TYPE(obj);
5327
5328 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
5329 if (type->tp_init == default_tp_init_wrapper) {
5330
5331 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
5332
5333 // Not really allowed, since we wouldn't have the default wrapper set.
5334 assert(init_method != NULL);
5335
5336 bool is_compiled_function = false;
5337 bool init_method_needs_release = false;
5338
5339 if (likely(init_method != NULL)) {
5340 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
5341
5342 if (func == Nuitka_Function_Type.tp_descr_get) {
5343 is_compiled_function = true;
5344 } else if (func != NULL) {
5345 init_method = func(init_method, obj, (PyObject *)(type));
5346 init_method_needs_release = true;
5347 }
5348 }
5349
5350 if (unlikely(init_method == NULL)) {
5351 if (!HAS_ERROR_OCCURRED(tstate)) {
5352 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
5353 const_str_plain___init__);
5354 }
5355
5356 return NULL;
5357 }
5358
5359 PyObject *result;
5360 if (is_compiled_function) {
5361 result = Nuitka_CallMethodFunctionPosArgs(
5362 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 6);
5363 } else {
5364 result = CALL_FUNCTION_WITH_POS_ARGS6(tstate, init_method, pos_args);
5365 if (init_method_needs_release) {
5366 Py_DECREF(init_method);
5367 }
5368 }
5369
5370 if (unlikely(result == NULL)) {
5371 Py_DECREF(obj);
5372 return NULL;
5373 }
5374
5375 Py_DECREF(result);
5376
5377 if (unlikely(result != Py_None)) {
5378 Py_DECREF(obj);
5379
5380 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5381 return NULL;
5382 }
5383 } else {
5384
5385 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
5386 Py_DECREF(obj);
5387 return NULL;
5388 }
5389 }
5390 }
5391 }
5392
5393 CHECK_OBJECT_X(obj);
5394
5395 return obj;
5396 }
5397#endif
5398#if PYTHON_VERSION < 0x300
5399 } else if (PyClass_Check(called)) {
5400 PyObject *obj = PyInstance_NewRaw(called, NULL);
5401
5402 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
5403
5404 if (unlikely(init_method == NULL)) {
5405 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
5406 Py_DECREF(obj);
5407 return NULL;
5408 }
5409
5410 Py_DECREF(obj);
5411
5412 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5413 return NULL;
5414 }
5415
5416 bool is_compiled_function = false;
5417
5418 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5419
5420 if (descr_get == NULL) {
5421 Py_INCREF(init_method);
5422 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5423 is_compiled_function = true;
5424 } else if (descr_get != NULL) {
5425 PyObject *descr_method = descr_get(init_method, obj, called);
5426
5427 if (unlikely(descr_method == NULL)) {
5428 return NULL;
5429 }
5430
5431 init_method = descr_method;
5432 }
5433
5434 PyObject *result;
5435 if (is_compiled_function) {
5436 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5437 args, 6);
5438 } else {
5439 result = CALL_FUNCTION_WITH_POS_ARGS6(tstate, init_method, pos_args);
5440 Py_DECREF(init_method);
5441 }
5442 if (unlikely(result == NULL)) {
5443 return NULL;
5444 }
5445
5446 Py_DECREF(result);
5447
5448 if (unlikely(result != Py_None)) {
5449 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5450 return NULL;
5451 }
5452
5453 CHECK_OBJECT_X(obj);
5454
5455 return obj;
5456#endif
5457#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5458 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5459 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5460
5461 if (likely(func != NULL)) {
5462 PyObject *result = func(called, args, 6, NULL);
5463
5464 CHECK_OBJECT_X(result);
5465
5466 return Nuitka_CheckFunctionResult(tstate, called, result);
5467 }
5468#endif
5469 }
5470
5471#if 0
5472 PRINT_NEW_LINE();
5473 PRINT_STRING("FALLBACK");
5474 PRINT_ITEM(called);
5475 PRINT_NEW_LINE();
5476#endif
5477
5478 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5479
5480 CHECK_OBJECT_X(result);
5481
5482 return result;
5483}
5484PyObject *CALL_FUNCTION_WITH_ARGS7(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
5485 CHECK_OBJECT(called);
5486 CHECK_OBJECTS(args, 7);
5487
5488 if (Nuitka_Function_Check(called)) {
5489 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5490 return NULL;
5491 }
5492
5493 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5494 PyObject *result;
5495
5496 if (function->m_args_simple && 7 == function->m_args_positional_count) {
5497 for (Py_ssize_t i = 0; i < 7; i++) {
5498 Py_INCREF(args[i]);
5499 }
5500 result = function->m_c_code(tstate, function, (PyObject **)args);
5501 } else if (function->m_args_simple && 7 + function->m_defaults_given == function->m_args_positional_count) {
5502 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5503
5504 memcpy(python_pars, args, 7 * sizeof(PyObject *));
5505 memcpy(python_pars + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5506 function->m_defaults_given * sizeof(PyObject *));
5507
5508 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5509 Py_INCREF(python_pars[i]);
5510 }
5511
5512 result = function->m_c_code(tstate, function, python_pars);
5513 } else {
5514 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 7);
5515 }
5516
5517 Py_LeaveRecursiveCall();
5518
5519 CHECK_OBJECT_X(result);
5520
5521 return result;
5522 } else if (Nuitka_Method_Check(called)) {
5523 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5524
5525 if (method->m_object == NULL) {
5526 PyObject *self = args[0];
5527
5528 int res = PyObject_IsInstance(self, method->m_class);
5529
5530 if (unlikely(res < 0)) {
5531 return NULL;
5532 } else if (unlikely(res == 0)) {
5533 PyErr_Format(PyExc_TypeError,
5534 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5535 "instance instead)",
5536 GET_CALLABLE_NAME((PyObject *)method->m_function),
5537 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5538 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5539
5540 return NULL;
5541 }
5542
5543 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 7);
5544
5545 CHECK_OBJECT_X(result);
5546
5547 return result;
5548 } else {
5549 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5550 return NULL;
5551 }
5552
5553 struct Nuitka_FunctionObject *function = method->m_function;
5554
5555 PyObject *result;
5556
5557 if (function->m_args_simple && 7 + 1 == function->m_args_positional_count) {
5558 PyObject *python_pars[7 + 1];
5559
5560 python_pars[0] = method->m_object;
5561 Py_INCREF(method->m_object);
5562
5563 for (Py_ssize_t i = 0; i < 7; i++) {
5564 python_pars[i + 1] = args[i];
5565 Py_INCREF(args[i]);
5566 }
5567 result = function->m_c_code(tstate, function, python_pars);
5568 } else if (function->m_args_simple &&
5569 7 + 1 + function->m_defaults_given == function->m_args_positional_count) {
5570 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5571
5572 python_pars[0] = method->m_object;
5573 Py_INCREF(method->m_object);
5574
5575 memcpy(python_pars + 1, args, 7 * sizeof(PyObject *));
5576 memcpy(python_pars + 1 + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5577 function->m_defaults_given * sizeof(PyObject *));
5578
5579 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
5580 Py_INCREF(python_pars[i]);
5581 }
5582
5583 result = function->m_c_code(tstate, function, python_pars);
5584 } else {
5585 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 7);
5586 }
5587
5588 Py_LeaveRecursiveCall();
5589
5590 CHECK_OBJECT_X(result);
5591
5592 return result;
5593 }
5594#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
5595 } else if (PyCFunction_CheckExact(called)) {
5596#if PYTHON_VERSION >= 0x380
5597#ifdef _NUITKA_FULL_COMPAT
5598 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5599 return NULL;
5600 }
5601#endif
5602
5603 int flags = PyCFunction_GET_FLAGS(called);
5604
5605 PyObject *result;
5606
5607 if (!(flags & METH_VARARGS)) {
5608 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5609
5610 assert(func != NULL);
5611 result = func(called, args, 7, NULL);
5612
5613 CHECK_OBJECT_X(result);
5614 } else {
5615 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5616 PyObject *self = PyCFunction_GET_SELF(called);
5617
5618 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5619
5620 if (flags & METH_KEYWORDS) {
5621 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
5622 } else {
5623 result = (*method)(self, pos_args);
5624 }
5625
5626 Py_DECREF(pos_args);
5627 }
5628
5629#ifdef _NUITKA_FULL_COMPAT
5630 Py_LeaveRecursiveCall();
5631#endif
5632 CHECK_OBJECT_X(result);
5633
5634 return Nuitka_CheckFunctionResult(tstate, called, result);
5635#else
5636 // Try to be fast about wrapping the arguments.
5637 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
5638
5639 if (unlikely(flags & METH_NOARGS)) {
5640 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (7 given)",
5641 ((PyCFunctionObject *)called)->m_ml->ml_name);
5642 return NULL;
5643 } else if (unlikely(flags & METH_O)) {
5644 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (7 given)",
5645 ((PyCFunctionObject *)called)->m_ml->ml_name);
5646 return NULL;
5647 } else if (flags & METH_VARARGS) {
5648 // Recursion guard is not strictly necessary, as we already have
5649 // one on our way to here.
5650#ifdef _NUITKA_FULL_COMPAT
5651 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5652 return NULL;
5653 }
5654#endif
5655 PyCFunction method = PyCFunction_GET_FUNCTION(called);
5656 PyObject *self = PyCFunction_GET_SELF(called);
5657
5658 PyObject *result;
5659
5660#if PYTHON_VERSION < 0x360
5661 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5662 if (flags & METH_KEYWORDS) {
5663 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5664 } else {
5665 result = (*method)(self, pos_args);
5666 }
5667
5668 Py_DECREF(pos_args);
5669#else
5670 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
5671 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5672 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
5673 Py_DECREF(pos_args);
5674 } else if (flags == METH_FASTCALL) {
5675#if PYTHON_VERSION < 0x370
5676 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 7, NULL);
5677#else
5678 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5679 result = (*(_PyCFunctionFast)method)(self, &pos_args, 7);
5680 Py_DECREF(pos_args);
5681#endif
5682 } else {
5683 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5684 result = (*method)(self, pos_args);
5685 Py_DECREF(pos_args);
5686 }
5687#endif
5688
5689#ifdef _NUITKA_FULL_COMPAT
5690 Py_LeaveRecursiveCall();
5691#endif
5692
5693 CHECK_OBJECT_X(result);
5694
5695 return Nuitka_CheckFunctionResult(tstate, called, result);
5696 }
5697#endif
5698#endif
5699#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
5700 } else if (PyFunction_Check(called)) {
5701#if PYTHON_VERSION < 0x3b0
5702 PyObject *result = callPythonFunction(called, args, 7);
5703#else
5704 PyObject *result = _PyFunction_Vectorcall(called, args, 7, NULL);
5705#endif
5706 CHECK_OBJECT_X(result);
5707
5708 return result;
5709#endif
5710#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
5711 } else if (PyType_Check(called)) {
5712 PyTypeObject *type = Py_TYPE(called);
5713
5714 if (type->tp_call == PyType_Type.tp_call) {
5715 PyTypeObject *called_type = (PyTypeObject *)(called);
5716
5717 if (unlikely(called_type->tp_new == NULL)) {
5718 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
5719 return NULL;
5720 }
5721
5722 PyObject *pos_args = NULL;
5723 PyObject *obj;
5724
5725 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
5726 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
5727 formatCannotInstantiateAbstractClass(tstate, called_type);
5728 return NULL;
5729 }
5730
5731 obj = called_type->tp_alloc(called_type, 0);
5732 CHECK_OBJECT(obj);
5733 } else {
5734 pos_args = MAKE_TUPLE(tstate, args, 7);
5735 obj = called_type->tp_new(called_type, pos_args, NULL);
5736 }
5737
5738 if (likely(obj != NULL)) {
5739 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
5740 Py_DECREF(pos_args);
5741 return obj;
5742 }
5743
5744 // Work on produced type.
5745 type = Py_TYPE(obj);
5746
5747 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
5748 if (type->tp_init == default_tp_init_wrapper) {
5749 Py_XDECREF(pos_args);
5750 pos_args = NULL;
5751
5752 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
5753
5754 // Not really allowed, since we wouldn't have the default wrapper set.
5755 assert(init_method != NULL);
5756
5757 bool is_compiled_function = false;
5758 bool init_method_needs_release = false;
5759
5760 if (likely(init_method != NULL)) {
5761 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
5762
5763 if (func == Nuitka_Function_Type.tp_descr_get) {
5764 is_compiled_function = true;
5765 } else if (func != NULL) {
5766 init_method = func(init_method, obj, (PyObject *)(type));
5767 init_method_needs_release = true;
5768 }
5769 }
5770
5771 if (unlikely(init_method == NULL)) {
5772 if (!HAS_ERROR_OCCURRED(tstate)) {
5773 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
5774 const_str_plain___init__);
5775 }
5776
5777 return NULL;
5778 }
5779
5780 PyObject *result;
5781 if (is_compiled_function) {
5782 result = Nuitka_CallMethodFunctionPosArgs(
5783 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 7);
5784 } else {
5785 result = CALL_FUNCTION_WITH_ARGS7(tstate, init_method, args);
5786 if (init_method_needs_release) {
5787 Py_DECREF(init_method);
5788 }
5789 }
5790
5791 if (unlikely(result == NULL)) {
5792 Py_DECREF(obj);
5793 return NULL;
5794 }
5795
5796 Py_DECREF(result);
5797
5798 if (unlikely(result != Py_None)) {
5799 Py_DECREF(obj);
5800
5801 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5802 return NULL;
5803 }
5804 } else {
5805 if (pos_args == NULL) {
5806 pos_args = MAKE_TUPLE(tstate, args, 7);
5807 }
5808
5809 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
5810 Py_DECREF(obj);
5811 Py_XDECREF(pos_args);
5812 return NULL;
5813 }
5814 }
5815 }
5816 }
5817
5818 Py_XDECREF(pos_args);
5819
5820 CHECK_OBJECT_X(obj);
5821
5822 return obj;
5823 }
5824#endif
5825#if PYTHON_VERSION < 0x300
5826 } else if (PyClass_Check(called)) {
5827 PyObject *obj = PyInstance_NewRaw(called, NULL);
5828
5829 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
5830
5831 if (unlikely(init_method == NULL)) {
5832 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
5833 Py_DECREF(obj);
5834 return NULL;
5835 }
5836
5837 Py_DECREF(obj);
5838
5839 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
5840 return NULL;
5841 }
5842
5843 bool is_compiled_function = false;
5844
5845 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
5846
5847 if (descr_get == NULL) {
5848 Py_INCREF(init_method);
5849 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
5850 is_compiled_function = true;
5851 } else if (descr_get != NULL) {
5852 PyObject *descr_method = descr_get(init_method, obj, called);
5853
5854 if (unlikely(descr_method == NULL)) {
5855 return NULL;
5856 }
5857
5858 init_method = descr_method;
5859 }
5860
5861 PyObject *result;
5862 if (is_compiled_function) {
5863 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
5864 args, 7);
5865 } else {
5866 result = CALL_FUNCTION_WITH_ARGS7(tstate, init_method, args);
5867 Py_DECREF(init_method);
5868 }
5869 if (unlikely(result == NULL)) {
5870 return NULL;
5871 }
5872
5873 Py_DECREF(result);
5874
5875 if (unlikely(result != Py_None)) {
5876 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
5877 return NULL;
5878 }
5879
5880 CHECK_OBJECT_X(obj);
5881
5882 return obj;
5883#endif
5884#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
5885 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
5886 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
5887
5888 if (likely(func != NULL)) {
5889 PyObject *result = func(called, args, 7, NULL);
5890
5891 CHECK_OBJECT_X(result);
5892
5893 return Nuitka_CheckFunctionResult(tstate, called, result);
5894 }
5895#endif
5896 }
5897
5898#if 0
5899 PRINT_NEW_LINE();
5900 PRINT_STRING("FALLBACK");
5901 PRINT_ITEM(called);
5902 PRINT_NEW_LINE();
5903#endif
5904
5905 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
5906
5907 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
5908
5909 Py_DECREF(pos_args);
5910
5911 CHECK_OBJECT_X(result);
5912
5913 return result;
5914}
5915PyObject *CALL_FUNCTION_WITH_POS_ARGS7(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
5916 assert(PyTuple_CheckExact(pos_args));
5917 assert(PyTuple_GET_SIZE(pos_args) == 7);
5918 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
5919 CHECK_OBJECT(called);
5920 CHECK_OBJECTS(args, 7);
5921
5922 if (Nuitka_Function_Check(called)) {
5923 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5924 return NULL;
5925 }
5926
5927 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
5928 PyObject *result;
5929
5930 if (function->m_args_simple && 7 == function->m_args_positional_count) {
5931 for (Py_ssize_t i = 0; i < 7; i++) {
5932 Py_INCREF(args[i]);
5933 }
5934 result = function->m_c_code(tstate, function, (PyObject **)args);
5935 } else if (function->m_args_simple && 7 + function->m_defaults_given == function->m_args_positional_count) {
5936 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
5937
5938 memcpy(python_pars, args, 7 * sizeof(PyObject *));
5939 memcpy(python_pars + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
5940 function->m_defaults_given * sizeof(PyObject *));
5941
5942 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
5943 Py_INCREF(python_pars[i]);
5944 }
5945
5946 result = function->m_c_code(tstate, function, python_pars);
5947 } else {
5948 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 7);
5949 }
5950
5951 Py_LeaveRecursiveCall();
5952
5953 CHECK_OBJECT_X(result);
5954
5955 return result;
5956 } else if (Nuitka_Method_Check(called)) {
5957 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
5958
5959 if (method->m_object == NULL) {
5960 PyObject *self = args[0];
5961
5962 int res = PyObject_IsInstance(self, method->m_class);
5963
5964 if (unlikely(res < 0)) {
5965 return NULL;
5966 } else if (unlikely(res == 0)) {
5967 PyErr_Format(PyExc_TypeError,
5968 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
5969 "instance instead)",
5970 GET_CALLABLE_NAME((PyObject *)method->m_function),
5971 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
5972 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
5973
5974 return NULL;
5975 }
5976
5977 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 7);
5978
5979 CHECK_OBJECT_X(result);
5980
5981 return result;
5982 } else {
5983 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
5984 return NULL;
5985 }
5986
5987 struct Nuitka_FunctionObject *function = method->m_function;
5988
5989 PyObject *result;
5990
5991 if (function->m_args_simple && 7 + 1 == function->m_args_positional_count) {
5992 PyObject *python_pars[7 + 1];
5993
5994 python_pars[0] = method->m_object;
5995 Py_INCREF(method->m_object);
5996
5997 for (Py_ssize_t i = 0; i < 7; i++) {
5998 python_pars[i + 1] = args[i];
5999 Py_INCREF(args[i]);
6000 }
6001 result = function->m_c_code(tstate, function, python_pars);
6002 } else if (function->m_args_simple &&
6003 7 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6004 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6005
6006 python_pars[0] = method->m_object;
6007 Py_INCREF(method->m_object);
6008
6009 memcpy(python_pars + 1, args, 7 * sizeof(PyObject *));
6010 memcpy(python_pars + 1 + 7, &PyTuple_GET_ITEM(function->m_defaults, 0),
6011 function->m_defaults_given * sizeof(PyObject *));
6012
6013 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6014 Py_INCREF(python_pars[i]);
6015 }
6016
6017 result = function->m_c_code(tstate, function, python_pars);
6018 } else {
6019 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 7);
6020 }
6021
6022 Py_LeaveRecursiveCall();
6023
6024 CHECK_OBJECT_X(result);
6025
6026 return result;
6027 }
6028#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6029 } else if (PyCFunction_CheckExact(called)) {
6030#if PYTHON_VERSION >= 0x380
6031#ifdef _NUITKA_FULL_COMPAT
6032 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6033 return NULL;
6034 }
6035#endif
6036
6037 int flags = PyCFunction_GET_FLAGS(called);
6038
6039 PyObject *result;
6040
6041 if (!(flags & METH_VARARGS)) {
6042 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6043
6044 assert(func != NULL);
6045 result = func(called, args, 7, NULL);
6046
6047 CHECK_OBJECT_X(result);
6048 } else {
6049 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6050 PyObject *self = PyCFunction_GET_SELF(called);
6051
6052 if (flags & METH_KEYWORDS) {
6053 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6054 } else {
6055 result = (*method)(self, pos_args);
6056 }
6057 }
6058
6059#ifdef _NUITKA_FULL_COMPAT
6060 Py_LeaveRecursiveCall();
6061#endif
6062 CHECK_OBJECT_X(result);
6063
6064 return Nuitka_CheckFunctionResult(tstate, called, result);
6065#else
6066 // Try to be fast about wrapping the arguments.
6067 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6068
6069 if (unlikely(flags & METH_NOARGS)) {
6070 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (7 given)",
6071 ((PyCFunctionObject *)called)->m_ml->ml_name);
6072 return NULL;
6073 } else if (unlikely(flags & METH_O)) {
6074 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (7 given)",
6075 ((PyCFunctionObject *)called)->m_ml->ml_name);
6076 return NULL;
6077 } else if (flags & METH_VARARGS) {
6078 // Recursion guard is not strictly necessary, as we already have
6079 // one on our way to here.
6080#ifdef _NUITKA_FULL_COMPAT
6081 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6082 return NULL;
6083 }
6084#endif
6085 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6086 PyObject *self = PyCFunction_GET_SELF(called);
6087
6088 PyObject *result;
6089
6090#if PYTHON_VERSION < 0x360
6091 if (flags & METH_KEYWORDS) {
6092 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6093 } else {
6094 result = (*method)(self, pos_args);
6095 }
6096
6097#else
6098 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6099 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6100 } else if (flags == METH_FASTCALL) {
6101#if PYTHON_VERSION < 0x370
6102 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 7, NULL);
6103#else
6104 result = (*(_PyCFunctionFast)method)(self, &pos_args, 7);
6105#endif
6106 } else {
6107 result = (*method)(self, pos_args);
6108 }
6109#endif
6110
6111#ifdef _NUITKA_FULL_COMPAT
6112 Py_LeaveRecursiveCall();
6113#endif
6114
6115 CHECK_OBJECT_X(result);
6116
6117 return Nuitka_CheckFunctionResult(tstate, called, result);
6118 }
6119#endif
6120#endif
6121#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6122 } else if (PyFunction_Check(called)) {
6123#if PYTHON_VERSION < 0x3b0
6124 PyObject *result = callPythonFunction(called, args, 7);
6125#else
6126 PyObject *result = _PyFunction_Vectorcall(called, args, 7, NULL);
6127#endif
6128 CHECK_OBJECT_X(result);
6129
6130 return result;
6131#endif
6132#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6133 } else if (PyType_Check(called)) {
6134 PyTypeObject *type = Py_TYPE(called);
6135
6136 if (type->tp_call == PyType_Type.tp_call) {
6137 PyTypeObject *called_type = (PyTypeObject *)(called);
6138
6139 if (unlikely(called_type->tp_new == NULL)) {
6140 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6141 return NULL;
6142 }
6143
6144 PyObject *obj;
6145
6146 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6147 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6148 formatCannotInstantiateAbstractClass(tstate, called_type);
6149 return NULL;
6150 }
6151
6152 obj = called_type->tp_alloc(called_type, 0);
6153 CHECK_OBJECT(obj);
6154 } else {
6155 obj = called_type->tp_new(called_type, pos_args, NULL);
6156 }
6157
6158 if (likely(obj != NULL)) {
6159 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6160 return obj;
6161 }
6162
6163 // Work on produced type.
6164 type = Py_TYPE(obj);
6165
6166 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6167 if (type->tp_init == default_tp_init_wrapper) {
6168
6169 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6170
6171 // Not really allowed, since we wouldn't have the default wrapper set.
6172 assert(init_method != NULL);
6173
6174 bool is_compiled_function = false;
6175 bool init_method_needs_release = false;
6176
6177 if (likely(init_method != NULL)) {
6178 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
6179
6180 if (func == Nuitka_Function_Type.tp_descr_get) {
6181 is_compiled_function = true;
6182 } else if (func != NULL) {
6183 init_method = func(init_method, obj, (PyObject *)(type));
6184 init_method_needs_release = true;
6185 }
6186 }
6187
6188 if (unlikely(init_method == NULL)) {
6189 if (!HAS_ERROR_OCCURRED(tstate)) {
6190 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
6191 const_str_plain___init__);
6192 }
6193
6194 return NULL;
6195 }
6196
6197 PyObject *result;
6198 if (is_compiled_function) {
6199 result = Nuitka_CallMethodFunctionPosArgs(
6200 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 7);
6201 } else {
6202 result = CALL_FUNCTION_WITH_POS_ARGS7(tstate, init_method, pos_args);
6203 if (init_method_needs_release) {
6204 Py_DECREF(init_method);
6205 }
6206 }
6207
6208 if (unlikely(result == NULL)) {
6209 Py_DECREF(obj);
6210 return NULL;
6211 }
6212
6213 Py_DECREF(result);
6214
6215 if (unlikely(result != Py_None)) {
6216 Py_DECREF(obj);
6217
6218 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6219 return NULL;
6220 }
6221 } else {
6222
6223 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
6224 Py_DECREF(obj);
6225 return NULL;
6226 }
6227 }
6228 }
6229 }
6230
6231 CHECK_OBJECT_X(obj);
6232
6233 return obj;
6234 }
6235#endif
6236#if PYTHON_VERSION < 0x300
6237 } else if (PyClass_Check(called)) {
6238 PyObject *obj = PyInstance_NewRaw(called, NULL);
6239
6240 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
6241
6242 if (unlikely(init_method == NULL)) {
6243 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
6244 Py_DECREF(obj);
6245 return NULL;
6246 }
6247
6248 Py_DECREF(obj);
6249
6250 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
6251 return NULL;
6252 }
6253
6254 bool is_compiled_function = false;
6255
6256 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
6257
6258 if (descr_get == NULL) {
6259 Py_INCREF(init_method);
6260 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
6261 is_compiled_function = true;
6262 } else if (descr_get != NULL) {
6263 PyObject *descr_method = descr_get(init_method, obj, called);
6264
6265 if (unlikely(descr_method == NULL)) {
6266 return NULL;
6267 }
6268
6269 init_method = descr_method;
6270 }
6271
6272 PyObject *result;
6273 if (is_compiled_function) {
6274 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
6275 args, 7);
6276 } else {
6277 result = CALL_FUNCTION_WITH_POS_ARGS7(tstate, init_method, pos_args);
6278 Py_DECREF(init_method);
6279 }
6280 if (unlikely(result == NULL)) {
6281 return NULL;
6282 }
6283
6284 Py_DECREF(result);
6285
6286 if (unlikely(result != Py_None)) {
6287 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6288 return NULL;
6289 }
6290
6291 CHECK_OBJECT_X(obj);
6292
6293 return obj;
6294#endif
6295#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
6296 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
6297 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6298
6299 if (likely(func != NULL)) {
6300 PyObject *result = func(called, args, 7, NULL);
6301
6302 CHECK_OBJECT_X(result);
6303
6304 return Nuitka_CheckFunctionResult(tstate, called, result);
6305 }
6306#endif
6307 }
6308
6309#if 0
6310 PRINT_NEW_LINE();
6311 PRINT_STRING("FALLBACK");
6312 PRINT_ITEM(called);
6313 PRINT_NEW_LINE();
6314#endif
6315
6316 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
6317
6318 CHECK_OBJECT_X(result);
6319
6320 return result;
6321}
6322PyObject *CALL_FUNCTION_WITH_ARGS8(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
6323 CHECK_OBJECT(called);
6324 CHECK_OBJECTS(args, 8);
6325
6326 if (Nuitka_Function_Check(called)) {
6327 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6328 return NULL;
6329 }
6330
6331 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
6332 PyObject *result;
6333
6334 if (function->m_args_simple && 8 == function->m_args_positional_count) {
6335 for (Py_ssize_t i = 0; i < 8; i++) {
6336 Py_INCREF(args[i]);
6337 }
6338 result = function->m_c_code(tstate, function, (PyObject **)args);
6339 } else if (function->m_args_simple && 8 + function->m_defaults_given == function->m_args_positional_count) {
6340 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6341
6342 memcpy(python_pars, args, 8 * sizeof(PyObject *));
6343 memcpy(python_pars + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6344 function->m_defaults_given * sizeof(PyObject *));
6345
6346 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
6347 Py_INCREF(python_pars[i]);
6348 }
6349
6350 result = function->m_c_code(tstate, function, python_pars);
6351 } else {
6352 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 8);
6353 }
6354
6355 Py_LeaveRecursiveCall();
6356
6357 CHECK_OBJECT_X(result);
6358
6359 return result;
6360 } else if (Nuitka_Method_Check(called)) {
6361 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
6362
6363 if (method->m_object == NULL) {
6364 PyObject *self = args[0];
6365
6366 int res = PyObject_IsInstance(self, method->m_class);
6367
6368 if (unlikely(res < 0)) {
6369 return NULL;
6370 } else if (unlikely(res == 0)) {
6371 PyErr_Format(PyExc_TypeError,
6372 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
6373 "instance instead)",
6374 GET_CALLABLE_NAME((PyObject *)method->m_function),
6375 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
6376 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
6377
6378 return NULL;
6379 }
6380
6381 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 8);
6382
6383 CHECK_OBJECT_X(result);
6384
6385 return result;
6386 } else {
6387 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6388 return NULL;
6389 }
6390
6391 struct Nuitka_FunctionObject *function = method->m_function;
6392
6393 PyObject *result;
6394
6395 if (function->m_args_simple && 8 + 1 == function->m_args_positional_count) {
6396 PyObject *python_pars[8 + 1];
6397
6398 python_pars[0] = method->m_object;
6399 Py_INCREF(method->m_object);
6400
6401 for (Py_ssize_t i = 0; i < 8; i++) {
6402 python_pars[i + 1] = args[i];
6403 Py_INCREF(args[i]);
6404 }
6405 result = function->m_c_code(tstate, function, python_pars);
6406 } else if (function->m_args_simple &&
6407 8 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6408 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6409
6410 python_pars[0] = method->m_object;
6411 Py_INCREF(method->m_object);
6412
6413 memcpy(python_pars + 1, args, 8 * sizeof(PyObject *));
6414 memcpy(python_pars + 1 + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6415 function->m_defaults_given * sizeof(PyObject *));
6416
6417 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6418 Py_INCREF(python_pars[i]);
6419 }
6420
6421 result = function->m_c_code(tstate, function, python_pars);
6422 } else {
6423 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 8);
6424 }
6425
6426 Py_LeaveRecursiveCall();
6427
6428 CHECK_OBJECT_X(result);
6429
6430 return result;
6431 }
6432#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6433 } else if (PyCFunction_CheckExact(called)) {
6434#if PYTHON_VERSION >= 0x380
6435#ifdef _NUITKA_FULL_COMPAT
6436 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6437 return NULL;
6438 }
6439#endif
6440
6441 int flags = PyCFunction_GET_FLAGS(called);
6442
6443 PyObject *result;
6444
6445 if (!(flags & METH_VARARGS)) {
6446 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6447
6448 assert(func != NULL);
6449 result = func(called, args, 8, NULL);
6450
6451 CHECK_OBJECT_X(result);
6452 } else {
6453 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6454 PyObject *self = PyCFunction_GET_SELF(called);
6455
6456 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6457
6458 if (flags & METH_KEYWORDS) {
6459 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6460 } else {
6461 result = (*method)(self, pos_args);
6462 }
6463
6464 Py_DECREF(pos_args);
6465 }
6466
6467#ifdef _NUITKA_FULL_COMPAT
6468 Py_LeaveRecursiveCall();
6469#endif
6470 CHECK_OBJECT_X(result);
6471
6472 return Nuitka_CheckFunctionResult(tstate, called, result);
6473#else
6474 // Try to be fast about wrapping the arguments.
6475 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6476
6477 if (unlikely(flags & METH_NOARGS)) {
6478 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (8 given)",
6479 ((PyCFunctionObject *)called)->m_ml->ml_name);
6480 return NULL;
6481 } else if (unlikely(flags & METH_O)) {
6482 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (8 given)",
6483 ((PyCFunctionObject *)called)->m_ml->ml_name);
6484 return NULL;
6485 } else if (flags & METH_VARARGS) {
6486 // Recursion guard is not strictly necessary, as we already have
6487 // one on our way to here.
6488#ifdef _NUITKA_FULL_COMPAT
6489 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6490 return NULL;
6491 }
6492#endif
6493 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6494 PyObject *self = PyCFunction_GET_SELF(called);
6495
6496 PyObject *result;
6497
6498#if PYTHON_VERSION < 0x360
6499 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6500 if (flags & METH_KEYWORDS) {
6501 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6502 } else {
6503 result = (*method)(self, pos_args);
6504 }
6505
6506 Py_DECREF(pos_args);
6507#else
6508 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6509 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6510 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6511 Py_DECREF(pos_args);
6512 } else if (flags == METH_FASTCALL) {
6513#if PYTHON_VERSION < 0x370
6514 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 8, NULL);
6515#else
6516 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6517 result = (*(_PyCFunctionFast)method)(self, &pos_args, 8);
6518 Py_DECREF(pos_args);
6519#endif
6520 } else {
6521 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6522 result = (*method)(self, pos_args);
6523 Py_DECREF(pos_args);
6524 }
6525#endif
6526
6527#ifdef _NUITKA_FULL_COMPAT
6528 Py_LeaveRecursiveCall();
6529#endif
6530
6531 CHECK_OBJECT_X(result);
6532
6533 return Nuitka_CheckFunctionResult(tstate, called, result);
6534 }
6535#endif
6536#endif
6537#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6538 } else if (PyFunction_Check(called)) {
6539#if PYTHON_VERSION < 0x3b0
6540 PyObject *result = callPythonFunction(called, args, 8);
6541#else
6542 PyObject *result = _PyFunction_Vectorcall(called, args, 8, NULL);
6543#endif
6544 CHECK_OBJECT_X(result);
6545
6546 return result;
6547#endif
6548#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6549 } else if (PyType_Check(called)) {
6550 PyTypeObject *type = Py_TYPE(called);
6551
6552 if (type->tp_call == PyType_Type.tp_call) {
6553 PyTypeObject *called_type = (PyTypeObject *)(called);
6554
6555 if (unlikely(called_type->tp_new == NULL)) {
6556 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6557 return NULL;
6558 }
6559
6560 PyObject *pos_args = NULL;
6561 PyObject *obj;
6562
6563 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6564 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6565 formatCannotInstantiateAbstractClass(tstate, called_type);
6566 return NULL;
6567 }
6568
6569 obj = called_type->tp_alloc(called_type, 0);
6570 CHECK_OBJECT(obj);
6571 } else {
6572 pos_args = MAKE_TUPLE(tstate, args, 8);
6573 obj = called_type->tp_new(called_type, pos_args, NULL);
6574 }
6575
6576 if (likely(obj != NULL)) {
6577 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6578 Py_DECREF(pos_args);
6579 return obj;
6580 }
6581
6582 // Work on produced type.
6583 type = Py_TYPE(obj);
6584
6585 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
6586 if (type->tp_init == default_tp_init_wrapper) {
6587 Py_XDECREF(pos_args);
6588 pos_args = NULL;
6589
6590 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
6591
6592 // Not really allowed, since we wouldn't have the default wrapper set.
6593 assert(init_method != NULL);
6594
6595 bool is_compiled_function = false;
6596 bool init_method_needs_release = false;
6597
6598 if (likely(init_method != NULL)) {
6599 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
6600
6601 if (func == Nuitka_Function_Type.tp_descr_get) {
6602 is_compiled_function = true;
6603 } else if (func != NULL) {
6604 init_method = func(init_method, obj, (PyObject *)(type));
6605 init_method_needs_release = true;
6606 }
6607 }
6608
6609 if (unlikely(init_method == NULL)) {
6610 if (!HAS_ERROR_OCCURRED(tstate)) {
6611 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
6612 const_str_plain___init__);
6613 }
6614
6615 return NULL;
6616 }
6617
6618 PyObject *result;
6619 if (is_compiled_function) {
6620 result = Nuitka_CallMethodFunctionPosArgs(
6621 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 8);
6622 } else {
6623 result = CALL_FUNCTION_WITH_ARGS8(tstate, init_method, args);
6624 if (init_method_needs_release) {
6625 Py_DECREF(init_method);
6626 }
6627 }
6628
6629 if (unlikely(result == NULL)) {
6630 Py_DECREF(obj);
6631 return NULL;
6632 }
6633
6634 Py_DECREF(result);
6635
6636 if (unlikely(result != Py_None)) {
6637 Py_DECREF(obj);
6638
6639 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6640 return NULL;
6641 }
6642 } else {
6643 if (pos_args == NULL) {
6644 pos_args = MAKE_TUPLE(tstate, args, 8);
6645 }
6646
6647 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
6648 Py_DECREF(obj);
6649 Py_XDECREF(pos_args);
6650 return NULL;
6651 }
6652 }
6653 }
6654 }
6655
6656 Py_XDECREF(pos_args);
6657
6658 CHECK_OBJECT_X(obj);
6659
6660 return obj;
6661 }
6662#endif
6663#if PYTHON_VERSION < 0x300
6664 } else if (PyClass_Check(called)) {
6665 PyObject *obj = PyInstance_NewRaw(called, NULL);
6666
6667 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
6668
6669 if (unlikely(init_method == NULL)) {
6670 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
6671 Py_DECREF(obj);
6672 return NULL;
6673 }
6674
6675 Py_DECREF(obj);
6676
6677 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
6678 return NULL;
6679 }
6680
6681 bool is_compiled_function = false;
6682
6683 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
6684
6685 if (descr_get == NULL) {
6686 Py_INCREF(init_method);
6687 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
6688 is_compiled_function = true;
6689 } else if (descr_get != NULL) {
6690 PyObject *descr_method = descr_get(init_method, obj, called);
6691
6692 if (unlikely(descr_method == NULL)) {
6693 return NULL;
6694 }
6695
6696 init_method = descr_method;
6697 }
6698
6699 PyObject *result;
6700 if (is_compiled_function) {
6701 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
6702 args, 8);
6703 } else {
6704 result = CALL_FUNCTION_WITH_ARGS8(tstate, init_method, args);
6705 Py_DECREF(init_method);
6706 }
6707 if (unlikely(result == NULL)) {
6708 return NULL;
6709 }
6710
6711 Py_DECREF(result);
6712
6713 if (unlikely(result != Py_None)) {
6714 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
6715 return NULL;
6716 }
6717
6718 CHECK_OBJECT_X(obj);
6719
6720 return obj;
6721#endif
6722#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
6723 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
6724 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6725
6726 if (likely(func != NULL)) {
6727 PyObject *result = func(called, args, 8, NULL);
6728
6729 CHECK_OBJECT_X(result);
6730
6731 return Nuitka_CheckFunctionResult(tstate, called, result);
6732 }
6733#endif
6734 }
6735
6736#if 0
6737 PRINT_NEW_LINE();
6738 PRINT_STRING("FALLBACK");
6739 PRINT_ITEM(called);
6740 PRINT_NEW_LINE();
6741#endif
6742
6743 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
6744
6745 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
6746
6747 Py_DECREF(pos_args);
6748
6749 CHECK_OBJECT_X(result);
6750
6751 return result;
6752}
6753PyObject *CALL_FUNCTION_WITH_POS_ARGS8(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
6754 assert(PyTuple_CheckExact(pos_args));
6755 assert(PyTuple_GET_SIZE(pos_args) == 8);
6756 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
6757 CHECK_OBJECT(called);
6758 CHECK_OBJECTS(args, 8);
6759
6760 if (Nuitka_Function_Check(called)) {
6761 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6762 return NULL;
6763 }
6764
6765 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
6766 PyObject *result;
6767
6768 if (function->m_args_simple && 8 == function->m_args_positional_count) {
6769 for (Py_ssize_t i = 0; i < 8; i++) {
6770 Py_INCREF(args[i]);
6771 }
6772 result = function->m_c_code(tstate, function, (PyObject **)args);
6773 } else if (function->m_args_simple && 8 + function->m_defaults_given == function->m_args_positional_count) {
6774 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6775
6776 memcpy(python_pars, args, 8 * sizeof(PyObject *));
6777 memcpy(python_pars + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6778 function->m_defaults_given * sizeof(PyObject *));
6779
6780 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
6781 Py_INCREF(python_pars[i]);
6782 }
6783
6784 result = function->m_c_code(tstate, function, python_pars);
6785 } else {
6786 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 8);
6787 }
6788
6789 Py_LeaveRecursiveCall();
6790
6791 CHECK_OBJECT_X(result);
6792
6793 return result;
6794 } else if (Nuitka_Method_Check(called)) {
6795 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
6796
6797 if (method->m_object == NULL) {
6798 PyObject *self = args[0];
6799
6800 int res = PyObject_IsInstance(self, method->m_class);
6801
6802 if (unlikely(res < 0)) {
6803 return NULL;
6804 } else if (unlikely(res == 0)) {
6805 PyErr_Format(PyExc_TypeError,
6806 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
6807 "instance instead)",
6808 GET_CALLABLE_NAME((PyObject *)method->m_function),
6809 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
6810 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
6811
6812 return NULL;
6813 }
6814
6815 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 8);
6816
6817 CHECK_OBJECT_X(result);
6818
6819 return result;
6820 } else {
6821 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6822 return NULL;
6823 }
6824
6825 struct Nuitka_FunctionObject *function = method->m_function;
6826
6827 PyObject *result;
6828
6829 if (function->m_args_simple && 8 + 1 == function->m_args_positional_count) {
6830 PyObject *python_pars[8 + 1];
6831
6832 python_pars[0] = method->m_object;
6833 Py_INCREF(method->m_object);
6834
6835 for (Py_ssize_t i = 0; i < 8; i++) {
6836 python_pars[i + 1] = args[i];
6837 Py_INCREF(args[i]);
6838 }
6839 result = function->m_c_code(tstate, function, python_pars);
6840 } else if (function->m_args_simple &&
6841 8 + 1 + function->m_defaults_given == function->m_args_positional_count) {
6842 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
6843
6844 python_pars[0] = method->m_object;
6845 Py_INCREF(method->m_object);
6846
6847 memcpy(python_pars + 1, args, 8 * sizeof(PyObject *));
6848 memcpy(python_pars + 1 + 8, &PyTuple_GET_ITEM(function->m_defaults, 0),
6849 function->m_defaults_given * sizeof(PyObject *));
6850
6851 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
6852 Py_INCREF(python_pars[i]);
6853 }
6854
6855 result = function->m_c_code(tstate, function, python_pars);
6856 } else {
6857 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 8);
6858 }
6859
6860 Py_LeaveRecursiveCall();
6861
6862 CHECK_OBJECT_X(result);
6863
6864 return result;
6865 }
6866#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
6867 } else if (PyCFunction_CheckExact(called)) {
6868#if PYTHON_VERSION >= 0x380
6869#ifdef _NUITKA_FULL_COMPAT
6870 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6871 return NULL;
6872 }
6873#endif
6874
6875 int flags = PyCFunction_GET_FLAGS(called);
6876
6877 PyObject *result;
6878
6879 if (!(flags & METH_VARARGS)) {
6880 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
6881
6882 assert(func != NULL);
6883 result = func(called, args, 8, NULL);
6884
6885 CHECK_OBJECT_X(result);
6886 } else {
6887 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6888 PyObject *self = PyCFunction_GET_SELF(called);
6889
6890 if (flags & METH_KEYWORDS) {
6891 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
6892 } else {
6893 result = (*method)(self, pos_args);
6894 }
6895 }
6896
6897#ifdef _NUITKA_FULL_COMPAT
6898 Py_LeaveRecursiveCall();
6899#endif
6900 CHECK_OBJECT_X(result);
6901
6902 return Nuitka_CheckFunctionResult(tstate, called, result);
6903#else
6904 // Try to be fast about wrapping the arguments.
6905 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
6906
6907 if (unlikely(flags & METH_NOARGS)) {
6908 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (8 given)",
6909 ((PyCFunctionObject *)called)->m_ml->ml_name);
6910 return NULL;
6911 } else if (unlikely(flags & METH_O)) {
6912 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (8 given)",
6913 ((PyCFunctionObject *)called)->m_ml->ml_name);
6914 return NULL;
6915 } else if (flags & METH_VARARGS) {
6916 // Recursion guard is not strictly necessary, as we already have
6917 // one on our way to here.
6918#ifdef _NUITKA_FULL_COMPAT
6919 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
6920 return NULL;
6921 }
6922#endif
6923 PyCFunction method = PyCFunction_GET_FUNCTION(called);
6924 PyObject *self = PyCFunction_GET_SELF(called);
6925
6926 PyObject *result;
6927
6928#if PYTHON_VERSION < 0x360
6929 if (flags & METH_KEYWORDS) {
6930 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6931 } else {
6932 result = (*method)(self, pos_args);
6933 }
6934
6935#else
6936 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
6937 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
6938 } else if (flags == METH_FASTCALL) {
6939#if PYTHON_VERSION < 0x370
6940 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 8, NULL);
6941#else
6942 result = (*(_PyCFunctionFast)method)(self, &pos_args, 8);
6943#endif
6944 } else {
6945 result = (*method)(self, pos_args);
6946 }
6947#endif
6948
6949#ifdef _NUITKA_FULL_COMPAT
6950 Py_LeaveRecursiveCall();
6951#endif
6952
6953 CHECK_OBJECT_X(result);
6954
6955 return Nuitka_CheckFunctionResult(tstate, called, result);
6956 }
6957#endif
6958#endif
6959#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
6960 } else if (PyFunction_Check(called)) {
6961#if PYTHON_VERSION < 0x3b0
6962 PyObject *result = callPythonFunction(called, args, 8);
6963#else
6964 PyObject *result = _PyFunction_Vectorcall(called, args, 8, NULL);
6965#endif
6966 CHECK_OBJECT_X(result);
6967
6968 return result;
6969#endif
6970#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
6971 } else if (PyType_Check(called)) {
6972 PyTypeObject *type = Py_TYPE(called);
6973
6974 if (type->tp_call == PyType_Type.tp_call) {
6975 PyTypeObject *called_type = (PyTypeObject *)(called);
6976
6977 if (unlikely(called_type->tp_new == NULL)) {
6978 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
6979 return NULL;
6980 }
6981
6982 PyObject *obj;
6983
6984 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
6985 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
6986 formatCannotInstantiateAbstractClass(tstate, called_type);
6987 return NULL;
6988 }
6989
6990 obj = called_type->tp_alloc(called_type, 0);
6991 CHECK_OBJECT(obj);
6992 } else {
6993 obj = called_type->tp_new(called_type, pos_args, NULL);
6994 }
6995
6996 if (likely(obj != NULL)) {
6997 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
6998 return obj;
6999 }
7000
7001 // Work on produced type.
7002 type = Py_TYPE(obj);
7003
7004 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7005 if (type->tp_init == default_tp_init_wrapper) {
7006
7007 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7008
7009 // Not really allowed, since we wouldn't have the default wrapper set.
7010 assert(init_method != NULL);
7011
7012 bool is_compiled_function = false;
7013 bool init_method_needs_release = false;
7014
7015 if (likely(init_method != NULL)) {
7016 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7017
7018 if (func == Nuitka_Function_Type.tp_descr_get) {
7019 is_compiled_function = true;
7020 } else if (func != NULL) {
7021 init_method = func(init_method, obj, (PyObject *)(type));
7022 init_method_needs_release = true;
7023 }
7024 }
7025
7026 if (unlikely(init_method == NULL)) {
7027 if (!HAS_ERROR_OCCURRED(tstate)) {
7028 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7029 const_str_plain___init__);
7030 }
7031
7032 return NULL;
7033 }
7034
7035 PyObject *result;
7036 if (is_compiled_function) {
7037 result = Nuitka_CallMethodFunctionPosArgs(
7038 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 8);
7039 } else {
7040 result = CALL_FUNCTION_WITH_POS_ARGS8(tstate, init_method, pos_args);
7041 if (init_method_needs_release) {
7042 Py_DECREF(init_method);
7043 }
7044 }
7045
7046 if (unlikely(result == NULL)) {
7047 Py_DECREF(obj);
7048 return NULL;
7049 }
7050
7051 Py_DECREF(result);
7052
7053 if (unlikely(result != Py_None)) {
7054 Py_DECREF(obj);
7055
7056 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7057 return NULL;
7058 }
7059 } else {
7060
7061 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7062 Py_DECREF(obj);
7063 return NULL;
7064 }
7065 }
7066 }
7067 }
7068
7069 CHECK_OBJECT_X(obj);
7070
7071 return obj;
7072 }
7073#endif
7074#if PYTHON_VERSION < 0x300
7075 } else if (PyClass_Check(called)) {
7076 PyObject *obj = PyInstance_NewRaw(called, NULL);
7077
7078 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7079
7080 if (unlikely(init_method == NULL)) {
7081 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7082 Py_DECREF(obj);
7083 return NULL;
7084 }
7085
7086 Py_DECREF(obj);
7087
7088 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7089 return NULL;
7090 }
7091
7092 bool is_compiled_function = false;
7093
7094 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7095
7096 if (descr_get == NULL) {
7097 Py_INCREF(init_method);
7098 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7099 is_compiled_function = true;
7100 } else if (descr_get != NULL) {
7101 PyObject *descr_method = descr_get(init_method, obj, called);
7102
7103 if (unlikely(descr_method == NULL)) {
7104 return NULL;
7105 }
7106
7107 init_method = descr_method;
7108 }
7109
7110 PyObject *result;
7111 if (is_compiled_function) {
7112 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7113 args, 8);
7114 } else {
7115 result = CALL_FUNCTION_WITH_POS_ARGS8(tstate, init_method, pos_args);
7116 Py_DECREF(init_method);
7117 }
7118 if (unlikely(result == NULL)) {
7119 return NULL;
7120 }
7121
7122 Py_DECREF(result);
7123
7124 if (unlikely(result != Py_None)) {
7125 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7126 return NULL;
7127 }
7128
7129 CHECK_OBJECT_X(obj);
7130
7131 return obj;
7132#endif
7133#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7134 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7135 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7136
7137 if (likely(func != NULL)) {
7138 PyObject *result = func(called, args, 8, NULL);
7139
7140 CHECK_OBJECT_X(result);
7141
7142 return Nuitka_CheckFunctionResult(tstate, called, result);
7143 }
7144#endif
7145 }
7146
7147#if 0
7148 PRINT_NEW_LINE();
7149 PRINT_STRING("FALLBACK");
7150 PRINT_ITEM(called);
7151 PRINT_NEW_LINE();
7152#endif
7153
7154 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7155
7156 CHECK_OBJECT_X(result);
7157
7158 return result;
7159}
7160PyObject *CALL_FUNCTION_WITH_ARGS9(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
7161 CHECK_OBJECT(called);
7162 CHECK_OBJECTS(args, 9);
7163
7164 if (Nuitka_Function_Check(called)) {
7165 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7166 return NULL;
7167 }
7168
7169 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7170 PyObject *result;
7171
7172 if (function->m_args_simple && 9 == function->m_args_positional_count) {
7173 for (Py_ssize_t i = 0; i < 9; i++) {
7174 Py_INCREF(args[i]);
7175 }
7176 result = function->m_c_code(tstate, function, (PyObject **)args);
7177 } else if (function->m_args_simple && 9 + function->m_defaults_given == function->m_args_positional_count) {
7178 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7179
7180 memcpy(python_pars, args, 9 * sizeof(PyObject *));
7181 memcpy(python_pars + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7182 function->m_defaults_given * sizeof(PyObject *));
7183
7184 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
7185 Py_INCREF(python_pars[i]);
7186 }
7187
7188 result = function->m_c_code(tstate, function, python_pars);
7189 } else {
7190 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 9);
7191 }
7192
7193 Py_LeaveRecursiveCall();
7194
7195 CHECK_OBJECT_X(result);
7196
7197 return result;
7198 } else if (Nuitka_Method_Check(called)) {
7199 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
7200
7201 if (method->m_object == NULL) {
7202 PyObject *self = args[0];
7203
7204 int res = PyObject_IsInstance(self, method->m_class);
7205
7206 if (unlikely(res < 0)) {
7207 return NULL;
7208 } else if (unlikely(res == 0)) {
7209 PyErr_Format(PyExc_TypeError,
7210 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
7211 "instance instead)",
7212 GET_CALLABLE_NAME((PyObject *)method->m_function),
7213 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
7214 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
7215
7216 return NULL;
7217 }
7218
7219 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 9);
7220
7221 CHECK_OBJECT_X(result);
7222
7223 return result;
7224 } else {
7225 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7226 return NULL;
7227 }
7228
7229 struct Nuitka_FunctionObject *function = method->m_function;
7230
7231 PyObject *result;
7232
7233 if (function->m_args_simple && 9 + 1 == function->m_args_positional_count) {
7234 PyObject *python_pars[9 + 1];
7235
7236 python_pars[0] = method->m_object;
7237 Py_INCREF(method->m_object);
7238
7239 for (Py_ssize_t i = 0; i < 9; i++) {
7240 python_pars[i + 1] = args[i];
7241 Py_INCREF(args[i]);
7242 }
7243 result = function->m_c_code(tstate, function, python_pars);
7244 } else if (function->m_args_simple &&
7245 9 + 1 + function->m_defaults_given == function->m_args_positional_count) {
7246 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7247
7248 python_pars[0] = method->m_object;
7249 Py_INCREF(method->m_object);
7250
7251 memcpy(python_pars + 1, args, 9 * sizeof(PyObject *));
7252 memcpy(python_pars + 1 + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7253 function->m_defaults_given * sizeof(PyObject *));
7254
7255 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
7256 Py_INCREF(python_pars[i]);
7257 }
7258
7259 result = function->m_c_code(tstate, function, python_pars);
7260 } else {
7261 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 9);
7262 }
7263
7264 Py_LeaveRecursiveCall();
7265
7266 CHECK_OBJECT_X(result);
7267
7268 return result;
7269 }
7270#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
7271 } else if (PyCFunction_CheckExact(called)) {
7272#if PYTHON_VERSION >= 0x380
7273#ifdef _NUITKA_FULL_COMPAT
7274 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7275 return NULL;
7276 }
7277#endif
7278
7279 int flags = PyCFunction_GET_FLAGS(called);
7280
7281 PyObject *result;
7282
7283 if (!(flags & METH_VARARGS)) {
7284 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7285
7286 assert(func != NULL);
7287 result = func(called, args, 9, NULL);
7288
7289 CHECK_OBJECT_X(result);
7290 } else {
7291 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7292 PyObject *self = PyCFunction_GET_SELF(called);
7293
7294 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7295
7296 if (flags & METH_KEYWORDS) {
7297 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
7298 } else {
7299 result = (*method)(self, pos_args);
7300 }
7301
7302 Py_DECREF(pos_args);
7303 }
7304
7305#ifdef _NUITKA_FULL_COMPAT
7306 Py_LeaveRecursiveCall();
7307#endif
7308 CHECK_OBJECT_X(result);
7309
7310 return Nuitka_CheckFunctionResult(tstate, called, result);
7311#else
7312 // Try to be fast about wrapping the arguments.
7313 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
7314
7315 if (unlikely(flags & METH_NOARGS)) {
7316 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (9 given)",
7317 ((PyCFunctionObject *)called)->m_ml->ml_name);
7318 return NULL;
7319 } else if (unlikely(flags & METH_O)) {
7320 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (9 given)",
7321 ((PyCFunctionObject *)called)->m_ml->ml_name);
7322 return NULL;
7323 } else if (flags & METH_VARARGS) {
7324 // Recursion guard is not strictly necessary, as we already have
7325 // one on our way to here.
7326#ifdef _NUITKA_FULL_COMPAT
7327 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7328 return NULL;
7329 }
7330#endif
7331 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7332 PyObject *self = PyCFunction_GET_SELF(called);
7333
7334 PyObject *result;
7335
7336#if PYTHON_VERSION < 0x360
7337 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7338 if (flags & METH_KEYWORDS) {
7339 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7340 } else {
7341 result = (*method)(self, pos_args);
7342 }
7343
7344 Py_DECREF(pos_args);
7345#else
7346 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
7347 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7348 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7349 Py_DECREF(pos_args);
7350 } else if (flags == METH_FASTCALL) {
7351#if PYTHON_VERSION < 0x370
7352 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 9, NULL);
7353#else
7354 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7355 result = (*(_PyCFunctionFast)method)(self, &pos_args, 9);
7356 Py_DECREF(pos_args);
7357#endif
7358 } else {
7359 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7360 result = (*method)(self, pos_args);
7361 Py_DECREF(pos_args);
7362 }
7363#endif
7364
7365#ifdef _NUITKA_FULL_COMPAT
7366 Py_LeaveRecursiveCall();
7367#endif
7368
7369 CHECK_OBJECT_X(result);
7370
7371 return Nuitka_CheckFunctionResult(tstate, called, result);
7372 }
7373#endif
7374#endif
7375#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
7376 } else if (PyFunction_Check(called)) {
7377#if PYTHON_VERSION < 0x3b0
7378 PyObject *result = callPythonFunction(called, args, 9);
7379#else
7380 PyObject *result = _PyFunction_Vectorcall(called, args, 9, NULL);
7381#endif
7382 CHECK_OBJECT_X(result);
7383
7384 return result;
7385#endif
7386#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
7387 } else if (PyType_Check(called)) {
7388 PyTypeObject *type = Py_TYPE(called);
7389
7390 if (type->tp_call == PyType_Type.tp_call) {
7391 PyTypeObject *called_type = (PyTypeObject *)(called);
7392
7393 if (unlikely(called_type->tp_new == NULL)) {
7394 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
7395 return NULL;
7396 }
7397
7398 PyObject *pos_args = NULL;
7399 PyObject *obj;
7400
7401 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
7402 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
7403 formatCannotInstantiateAbstractClass(tstate, called_type);
7404 return NULL;
7405 }
7406
7407 obj = called_type->tp_alloc(called_type, 0);
7408 CHECK_OBJECT(obj);
7409 } else {
7410 pos_args = MAKE_TUPLE(tstate, args, 9);
7411 obj = called_type->tp_new(called_type, pos_args, NULL);
7412 }
7413
7414 if (likely(obj != NULL)) {
7415 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
7416 Py_DECREF(pos_args);
7417 return obj;
7418 }
7419
7420 // Work on produced type.
7421 type = Py_TYPE(obj);
7422
7423 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7424 if (type->tp_init == default_tp_init_wrapper) {
7425 Py_XDECREF(pos_args);
7426 pos_args = NULL;
7427
7428 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7429
7430 // Not really allowed, since we wouldn't have the default wrapper set.
7431 assert(init_method != NULL);
7432
7433 bool is_compiled_function = false;
7434 bool init_method_needs_release = false;
7435
7436 if (likely(init_method != NULL)) {
7437 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7438
7439 if (func == Nuitka_Function_Type.tp_descr_get) {
7440 is_compiled_function = true;
7441 } else if (func != NULL) {
7442 init_method = func(init_method, obj, (PyObject *)(type));
7443 init_method_needs_release = true;
7444 }
7445 }
7446
7447 if (unlikely(init_method == NULL)) {
7448 if (!HAS_ERROR_OCCURRED(tstate)) {
7449 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7450 const_str_plain___init__);
7451 }
7452
7453 return NULL;
7454 }
7455
7456 PyObject *result;
7457 if (is_compiled_function) {
7458 result = Nuitka_CallMethodFunctionPosArgs(
7459 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 9);
7460 } else {
7461 result = CALL_FUNCTION_WITH_ARGS9(tstate, init_method, args);
7462 if (init_method_needs_release) {
7463 Py_DECREF(init_method);
7464 }
7465 }
7466
7467 if (unlikely(result == NULL)) {
7468 Py_DECREF(obj);
7469 return NULL;
7470 }
7471
7472 Py_DECREF(result);
7473
7474 if (unlikely(result != Py_None)) {
7475 Py_DECREF(obj);
7476
7477 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7478 return NULL;
7479 }
7480 } else {
7481 if (pos_args == NULL) {
7482 pos_args = MAKE_TUPLE(tstate, args, 9);
7483 }
7484
7485 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7486 Py_DECREF(obj);
7487 Py_XDECREF(pos_args);
7488 return NULL;
7489 }
7490 }
7491 }
7492 }
7493
7494 Py_XDECREF(pos_args);
7495
7496 CHECK_OBJECT_X(obj);
7497
7498 return obj;
7499 }
7500#endif
7501#if PYTHON_VERSION < 0x300
7502 } else if (PyClass_Check(called)) {
7503 PyObject *obj = PyInstance_NewRaw(called, NULL);
7504
7505 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7506
7507 if (unlikely(init_method == NULL)) {
7508 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7509 Py_DECREF(obj);
7510 return NULL;
7511 }
7512
7513 Py_DECREF(obj);
7514
7515 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7516 return NULL;
7517 }
7518
7519 bool is_compiled_function = false;
7520
7521 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7522
7523 if (descr_get == NULL) {
7524 Py_INCREF(init_method);
7525 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7526 is_compiled_function = true;
7527 } else if (descr_get != NULL) {
7528 PyObject *descr_method = descr_get(init_method, obj, called);
7529
7530 if (unlikely(descr_method == NULL)) {
7531 return NULL;
7532 }
7533
7534 init_method = descr_method;
7535 }
7536
7537 PyObject *result;
7538 if (is_compiled_function) {
7539 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7540 args, 9);
7541 } else {
7542 result = CALL_FUNCTION_WITH_ARGS9(tstate, init_method, args);
7543 Py_DECREF(init_method);
7544 }
7545 if (unlikely(result == NULL)) {
7546 return NULL;
7547 }
7548
7549 Py_DECREF(result);
7550
7551 if (unlikely(result != Py_None)) {
7552 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7553 return NULL;
7554 }
7555
7556 CHECK_OBJECT_X(obj);
7557
7558 return obj;
7559#endif
7560#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7561 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7562 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7563
7564 if (likely(func != NULL)) {
7565 PyObject *result = func(called, args, 9, NULL);
7566
7567 CHECK_OBJECT_X(result);
7568
7569 return Nuitka_CheckFunctionResult(tstate, called, result);
7570 }
7571#endif
7572 }
7573
7574#if 0
7575 PRINT_NEW_LINE();
7576 PRINT_STRING("FALLBACK");
7577 PRINT_ITEM(called);
7578 PRINT_NEW_LINE();
7579#endif
7580
7581 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
7582
7583 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7584
7585 Py_DECREF(pos_args);
7586
7587 CHECK_OBJECT_X(result);
7588
7589 return result;
7590}
7591PyObject *CALL_FUNCTION_WITH_POS_ARGS9(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
7592 assert(PyTuple_CheckExact(pos_args));
7593 assert(PyTuple_GET_SIZE(pos_args) == 9);
7594 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
7595 CHECK_OBJECT(called);
7596 CHECK_OBJECTS(args, 9);
7597
7598 if (Nuitka_Function_Check(called)) {
7599 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7600 return NULL;
7601 }
7602
7603 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
7604 PyObject *result;
7605
7606 if (function->m_args_simple && 9 == function->m_args_positional_count) {
7607 for (Py_ssize_t i = 0; i < 9; i++) {
7608 Py_INCREF(args[i]);
7609 }
7610 result = function->m_c_code(tstate, function, (PyObject **)args);
7611 } else if (function->m_args_simple && 9 + function->m_defaults_given == function->m_args_positional_count) {
7612 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7613
7614 memcpy(python_pars, args, 9 * sizeof(PyObject *));
7615 memcpy(python_pars + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7616 function->m_defaults_given * sizeof(PyObject *));
7617
7618 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
7619 Py_INCREF(python_pars[i]);
7620 }
7621
7622 result = function->m_c_code(tstate, function, python_pars);
7623 } else {
7624 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 9);
7625 }
7626
7627 Py_LeaveRecursiveCall();
7628
7629 CHECK_OBJECT_X(result);
7630
7631 return result;
7632 } else if (Nuitka_Method_Check(called)) {
7633 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
7634
7635 if (method->m_object == NULL) {
7636 PyObject *self = args[0];
7637
7638 int res = PyObject_IsInstance(self, method->m_class);
7639
7640 if (unlikely(res < 0)) {
7641 return NULL;
7642 } else if (unlikely(res == 0)) {
7643 PyErr_Format(PyExc_TypeError,
7644 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
7645 "instance instead)",
7646 GET_CALLABLE_NAME((PyObject *)method->m_function),
7647 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
7648 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
7649
7650 return NULL;
7651 }
7652
7653 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 9);
7654
7655 CHECK_OBJECT_X(result);
7656
7657 return result;
7658 } else {
7659 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7660 return NULL;
7661 }
7662
7663 struct Nuitka_FunctionObject *function = method->m_function;
7664
7665 PyObject *result;
7666
7667 if (function->m_args_simple && 9 + 1 == function->m_args_positional_count) {
7668 PyObject *python_pars[9 + 1];
7669
7670 python_pars[0] = method->m_object;
7671 Py_INCREF(method->m_object);
7672
7673 for (Py_ssize_t i = 0; i < 9; i++) {
7674 python_pars[i + 1] = args[i];
7675 Py_INCREF(args[i]);
7676 }
7677 result = function->m_c_code(tstate, function, python_pars);
7678 } else if (function->m_args_simple &&
7679 9 + 1 + function->m_defaults_given == function->m_args_positional_count) {
7680 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
7681
7682 python_pars[0] = method->m_object;
7683 Py_INCREF(method->m_object);
7684
7685 memcpy(python_pars + 1, args, 9 * sizeof(PyObject *));
7686 memcpy(python_pars + 1 + 9, &PyTuple_GET_ITEM(function->m_defaults, 0),
7687 function->m_defaults_given * sizeof(PyObject *));
7688
7689 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
7690 Py_INCREF(python_pars[i]);
7691 }
7692
7693 result = function->m_c_code(tstate, function, python_pars);
7694 } else {
7695 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 9);
7696 }
7697
7698 Py_LeaveRecursiveCall();
7699
7700 CHECK_OBJECT_X(result);
7701
7702 return result;
7703 }
7704#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
7705 } else if (PyCFunction_CheckExact(called)) {
7706#if PYTHON_VERSION >= 0x380
7707#ifdef _NUITKA_FULL_COMPAT
7708 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7709 return NULL;
7710 }
7711#endif
7712
7713 int flags = PyCFunction_GET_FLAGS(called);
7714
7715 PyObject *result;
7716
7717 if (!(flags & METH_VARARGS)) {
7718 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7719
7720 assert(func != NULL);
7721 result = func(called, args, 9, NULL);
7722
7723 CHECK_OBJECT_X(result);
7724 } else {
7725 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7726 PyObject *self = PyCFunction_GET_SELF(called);
7727
7728 if (flags & METH_KEYWORDS) {
7729 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
7730 } else {
7731 result = (*method)(self, pos_args);
7732 }
7733 }
7734
7735#ifdef _NUITKA_FULL_COMPAT
7736 Py_LeaveRecursiveCall();
7737#endif
7738 CHECK_OBJECT_X(result);
7739
7740 return Nuitka_CheckFunctionResult(tstate, called, result);
7741#else
7742 // Try to be fast about wrapping the arguments.
7743 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
7744
7745 if (unlikely(flags & METH_NOARGS)) {
7746 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (9 given)",
7747 ((PyCFunctionObject *)called)->m_ml->ml_name);
7748 return NULL;
7749 } else if (unlikely(flags & METH_O)) {
7750 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (9 given)",
7751 ((PyCFunctionObject *)called)->m_ml->ml_name);
7752 return NULL;
7753 } else if (flags & METH_VARARGS) {
7754 // Recursion guard is not strictly necessary, as we already have
7755 // one on our way to here.
7756#ifdef _NUITKA_FULL_COMPAT
7757 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
7758 return NULL;
7759 }
7760#endif
7761 PyCFunction method = PyCFunction_GET_FUNCTION(called);
7762 PyObject *self = PyCFunction_GET_SELF(called);
7763
7764 PyObject *result;
7765
7766#if PYTHON_VERSION < 0x360
7767 if (flags & METH_KEYWORDS) {
7768 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7769 } else {
7770 result = (*method)(self, pos_args);
7771 }
7772
7773#else
7774 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
7775 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
7776 } else if (flags == METH_FASTCALL) {
7777#if PYTHON_VERSION < 0x370
7778 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 9, NULL);
7779#else
7780 result = (*(_PyCFunctionFast)method)(self, &pos_args, 9);
7781#endif
7782 } else {
7783 result = (*method)(self, pos_args);
7784 }
7785#endif
7786
7787#ifdef _NUITKA_FULL_COMPAT
7788 Py_LeaveRecursiveCall();
7789#endif
7790
7791 CHECK_OBJECT_X(result);
7792
7793 return Nuitka_CheckFunctionResult(tstate, called, result);
7794 }
7795#endif
7796#endif
7797#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
7798 } else if (PyFunction_Check(called)) {
7799#if PYTHON_VERSION < 0x3b0
7800 PyObject *result = callPythonFunction(called, args, 9);
7801#else
7802 PyObject *result = _PyFunction_Vectorcall(called, args, 9, NULL);
7803#endif
7804 CHECK_OBJECT_X(result);
7805
7806 return result;
7807#endif
7808#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
7809 } else if (PyType_Check(called)) {
7810 PyTypeObject *type = Py_TYPE(called);
7811
7812 if (type->tp_call == PyType_Type.tp_call) {
7813 PyTypeObject *called_type = (PyTypeObject *)(called);
7814
7815 if (unlikely(called_type->tp_new == NULL)) {
7816 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
7817 return NULL;
7818 }
7819
7820 PyObject *obj;
7821
7822 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
7823 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
7824 formatCannotInstantiateAbstractClass(tstate, called_type);
7825 return NULL;
7826 }
7827
7828 obj = called_type->tp_alloc(called_type, 0);
7829 CHECK_OBJECT(obj);
7830 } else {
7831 obj = called_type->tp_new(called_type, pos_args, NULL);
7832 }
7833
7834 if (likely(obj != NULL)) {
7835 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
7836 return obj;
7837 }
7838
7839 // Work on produced type.
7840 type = Py_TYPE(obj);
7841
7842 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
7843 if (type->tp_init == default_tp_init_wrapper) {
7844
7845 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
7846
7847 // Not really allowed, since we wouldn't have the default wrapper set.
7848 assert(init_method != NULL);
7849
7850 bool is_compiled_function = false;
7851 bool init_method_needs_release = false;
7852
7853 if (likely(init_method != NULL)) {
7854 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
7855
7856 if (func == Nuitka_Function_Type.tp_descr_get) {
7857 is_compiled_function = true;
7858 } else if (func != NULL) {
7859 init_method = func(init_method, obj, (PyObject *)(type));
7860 init_method_needs_release = true;
7861 }
7862 }
7863
7864 if (unlikely(init_method == NULL)) {
7865 if (!HAS_ERROR_OCCURRED(tstate)) {
7866 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
7867 const_str_plain___init__);
7868 }
7869
7870 return NULL;
7871 }
7872
7873 PyObject *result;
7874 if (is_compiled_function) {
7875 result = Nuitka_CallMethodFunctionPosArgs(
7876 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 9);
7877 } else {
7878 result = CALL_FUNCTION_WITH_POS_ARGS9(tstate, init_method, pos_args);
7879 if (init_method_needs_release) {
7880 Py_DECREF(init_method);
7881 }
7882 }
7883
7884 if (unlikely(result == NULL)) {
7885 Py_DECREF(obj);
7886 return NULL;
7887 }
7888
7889 Py_DECREF(result);
7890
7891 if (unlikely(result != Py_None)) {
7892 Py_DECREF(obj);
7893
7894 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7895 return NULL;
7896 }
7897 } else {
7898
7899 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
7900 Py_DECREF(obj);
7901 return NULL;
7902 }
7903 }
7904 }
7905 }
7906
7907 CHECK_OBJECT_X(obj);
7908
7909 return obj;
7910 }
7911#endif
7912#if PYTHON_VERSION < 0x300
7913 } else if (PyClass_Check(called)) {
7914 PyObject *obj = PyInstance_NewRaw(called, NULL);
7915
7916 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
7917
7918 if (unlikely(init_method == NULL)) {
7919 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
7920 Py_DECREF(obj);
7921 return NULL;
7922 }
7923
7924 Py_DECREF(obj);
7925
7926 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
7927 return NULL;
7928 }
7929
7930 bool is_compiled_function = false;
7931
7932 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
7933
7934 if (descr_get == NULL) {
7935 Py_INCREF(init_method);
7936 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
7937 is_compiled_function = true;
7938 } else if (descr_get != NULL) {
7939 PyObject *descr_method = descr_get(init_method, obj, called);
7940
7941 if (unlikely(descr_method == NULL)) {
7942 return NULL;
7943 }
7944
7945 init_method = descr_method;
7946 }
7947
7948 PyObject *result;
7949 if (is_compiled_function) {
7950 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
7951 args, 9);
7952 } else {
7953 result = CALL_FUNCTION_WITH_POS_ARGS9(tstate, init_method, pos_args);
7954 Py_DECREF(init_method);
7955 }
7956 if (unlikely(result == NULL)) {
7957 return NULL;
7958 }
7959
7960 Py_DECREF(result);
7961
7962 if (unlikely(result != Py_None)) {
7963 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
7964 return NULL;
7965 }
7966
7967 CHECK_OBJECT_X(obj);
7968
7969 return obj;
7970#endif
7971#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
7972 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
7973 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
7974
7975 if (likely(func != NULL)) {
7976 PyObject *result = func(called, args, 9, NULL);
7977
7978 CHECK_OBJECT_X(result);
7979
7980 return Nuitka_CheckFunctionResult(tstate, called, result);
7981 }
7982#endif
7983 }
7984
7985#if 0
7986 PRINT_NEW_LINE();
7987 PRINT_STRING("FALLBACK");
7988 PRINT_ITEM(called);
7989 PRINT_NEW_LINE();
7990#endif
7991
7992 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
7993
7994 CHECK_OBJECT_X(result);
7995
7996 return result;
7997}
7998PyObject *CALL_FUNCTION_WITH_ARGS10(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
7999 CHECK_OBJECT(called);
8000 CHECK_OBJECTS(args, 10);
8001
8002 if (Nuitka_Function_Check(called)) {
8003 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8004 return NULL;
8005 }
8006
8007 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8008 PyObject *result;
8009
8010 if (function->m_args_simple && 10 == function->m_args_positional_count) {
8011 for (Py_ssize_t i = 0; i < 10; i++) {
8012 Py_INCREF(args[i]);
8013 }
8014 result = function->m_c_code(tstate, function, (PyObject **)args);
8015 } else if (function->m_args_simple && 10 + function->m_defaults_given == function->m_args_positional_count) {
8016 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8017
8018 memcpy(python_pars, args, 10 * sizeof(PyObject *));
8019 memcpy(python_pars + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8020 function->m_defaults_given * sizeof(PyObject *));
8021
8022 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
8023 Py_INCREF(python_pars[i]);
8024 }
8025
8026 result = function->m_c_code(tstate, function, python_pars);
8027 } else {
8028 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 10);
8029 }
8030
8031 Py_LeaveRecursiveCall();
8032
8033 CHECK_OBJECT_X(result);
8034
8035 return result;
8036 } else if (Nuitka_Method_Check(called)) {
8037 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
8038
8039 if (method->m_object == NULL) {
8040 PyObject *self = args[0];
8041
8042 int res = PyObject_IsInstance(self, method->m_class);
8043
8044 if (unlikely(res < 0)) {
8045 return NULL;
8046 } else if (unlikely(res == 0)) {
8047 PyErr_Format(PyExc_TypeError,
8048 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
8049 "instance instead)",
8050 GET_CALLABLE_NAME((PyObject *)method->m_function),
8051 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
8052 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
8053
8054 return NULL;
8055 }
8056
8057 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 10);
8058
8059 CHECK_OBJECT_X(result);
8060
8061 return result;
8062 } else {
8063 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8064 return NULL;
8065 }
8066
8067 struct Nuitka_FunctionObject *function = method->m_function;
8068
8069 PyObject *result;
8070
8071 if (function->m_args_simple && 10 + 1 == function->m_args_positional_count) {
8072 PyObject *python_pars[10 + 1];
8073
8074 python_pars[0] = method->m_object;
8075 Py_INCREF(method->m_object);
8076
8077 for (Py_ssize_t i = 0; i < 10; i++) {
8078 python_pars[i + 1] = args[i];
8079 Py_INCREF(args[i]);
8080 }
8081 result = function->m_c_code(tstate, function, python_pars);
8082 } else if (function->m_args_simple &&
8083 10 + 1 + function->m_defaults_given == function->m_args_positional_count) {
8084 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8085
8086 python_pars[0] = method->m_object;
8087 Py_INCREF(method->m_object);
8088
8089 memcpy(python_pars + 1, args, 10 * sizeof(PyObject *));
8090 memcpy(python_pars + 1 + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8091 function->m_defaults_given * sizeof(PyObject *));
8092
8093 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
8094 Py_INCREF(python_pars[i]);
8095 }
8096
8097 result = function->m_c_code(tstate, function, python_pars);
8098 } else {
8099 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 10);
8100 }
8101
8102 Py_LeaveRecursiveCall();
8103
8104 CHECK_OBJECT_X(result);
8105
8106 return result;
8107 }
8108#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
8109 } else if (PyCFunction_CheckExact(called)) {
8110#if PYTHON_VERSION >= 0x380
8111#ifdef _NUITKA_FULL_COMPAT
8112 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8113 return NULL;
8114 }
8115#endif
8116
8117 int flags = PyCFunction_GET_FLAGS(called);
8118
8119 PyObject *result;
8120
8121 if (!(flags & METH_VARARGS)) {
8122 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8123
8124 assert(func != NULL);
8125 result = func(called, args, 10, NULL);
8126
8127 CHECK_OBJECT_X(result);
8128 } else {
8129 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8130 PyObject *self = PyCFunction_GET_SELF(called);
8131
8132 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8133
8134 if (flags & METH_KEYWORDS) {
8135 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
8136 } else {
8137 result = (*method)(self, pos_args);
8138 }
8139
8140 Py_DECREF(pos_args);
8141 }
8142
8143#ifdef _NUITKA_FULL_COMPAT
8144 Py_LeaveRecursiveCall();
8145#endif
8146 CHECK_OBJECT_X(result);
8147
8148 return Nuitka_CheckFunctionResult(tstate, called, result);
8149#else
8150 // Try to be fast about wrapping the arguments.
8151 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
8152
8153 if (unlikely(flags & METH_NOARGS)) {
8154 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (10 given)",
8155 ((PyCFunctionObject *)called)->m_ml->ml_name);
8156 return NULL;
8157 } else if (unlikely(flags & METH_O)) {
8158 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (10 given)",
8159 ((PyCFunctionObject *)called)->m_ml->ml_name);
8160 return NULL;
8161 } else if (flags & METH_VARARGS) {
8162 // Recursion guard is not strictly necessary, as we already have
8163 // one on our way to here.
8164#ifdef _NUITKA_FULL_COMPAT
8165 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8166 return NULL;
8167 }
8168#endif
8169 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8170 PyObject *self = PyCFunction_GET_SELF(called);
8171
8172 PyObject *result;
8173
8174#if PYTHON_VERSION < 0x360
8175 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8176 if (flags & METH_KEYWORDS) {
8177 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8178 } else {
8179 result = (*method)(self, pos_args);
8180 }
8181
8182 Py_DECREF(pos_args);
8183#else
8184 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
8185 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8186 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8187 Py_DECREF(pos_args);
8188 } else if (flags == METH_FASTCALL) {
8189#if PYTHON_VERSION < 0x370
8190 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 10, NULL);
8191#else
8192 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8193 result = (*(_PyCFunctionFast)method)(self, &pos_args, 10);
8194 Py_DECREF(pos_args);
8195#endif
8196 } else {
8197 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8198 result = (*method)(self, pos_args);
8199 Py_DECREF(pos_args);
8200 }
8201#endif
8202
8203#ifdef _NUITKA_FULL_COMPAT
8204 Py_LeaveRecursiveCall();
8205#endif
8206
8207 CHECK_OBJECT_X(result);
8208
8209 return Nuitka_CheckFunctionResult(tstate, called, result);
8210 }
8211#endif
8212#endif
8213#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
8214 } else if (PyFunction_Check(called)) {
8215#if PYTHON_VERSION < 0x3b0
8216 PyObject *result = callPythonFunction(called, args, 10);
8217#else
8218 PyObject *result = _PyFunction_Vectorcall(called, args, 10, NULL);
8219#endif
8220 CHECK_OBJECT_X(result);
8221
8222 return result;
8223#endif
8224#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
8225 } else if (PyType_Check(called)) {
8226 PyTypeObject *type = Py_TYPE(called);
8227
8228 if (type->tp_call == PyType_Type.tp_call) {
8229 PyTypeObject *called_type = (PyTypeObject *)(called);
8230
8231 if (unlikely(called_type->tp_new == NULL)) {
8232 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
8233 return NULL;
8234 }
8235
8236 PyObject *pos_args = NULL;
8237 PyObject *obj;
8238
8239 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
8240 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
8241 formatCannotInstantiateAbstractClass(tstate, called_type);
8242 return NULL;
8243 }
8244
8245 obj = called_type->tp_alloc(called_type, 0);
8246 CHECK_OBJECT(obj);
8247 } else {
8248 pos_args = MAKE_TUPLE(tstate, args, 10);
8249 obj = called_type->tp_new(called_type, pos_args, NULL);
8250 }
8251
8252 if (likely(obj != NULL)) {
8253 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
8254 Py_DECREF(pos_args);
8255 return obj;
8256 }
8257
8258 // Work on produced type.
8259 type = Py_TYPE(obj);
8260
8261 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
8262 if (type->tp_init == default_tp_init_wrapper) {
8263 Py_XDECREF(pos_args);
8264 pos_args = NULL;
8265
8266 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
8267
8268 // Not really allowed, since we wouldn't have the default wrapper set.
8269 assert(init_method != NULL);
8270
8271 bool is_compiled_function = false;
8272 bool init_method_needs_release = false;
8273
8274 if (likely(init_method != NULL)) {
8275 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
8276
8277 if (func == Nuitka_Function_Type.tp_descr_get) {
8278 is_compiled_function = true;
8279 } else if (func != NULL) {
8280 init_method = func(init_method, obj, (PyObject *)(type));
8281 init_method_needs_release = true;
8282 }
8283 }
8284
8285 if (unlikely(init_method == NULL)) {
8286 if (!HAS_ERROR_OCCURRED(tstate)) {
8287 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
8288 const_str_plain___init__);
8289 }
8290
8291 return NULL;
8292 }
8293
8294 PyObject *result;
8295 if (is_compiled_function) {
8296 result = Nuitka_CallMethodFunctionPosArgs(
8297 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 10);
8298 } else {
8299 result = CALL_FUNCTION_WITH_ARGS10(tstate, init_method, args);
8300 if (init_method_needs_release) {
8301 Py_DECREF(init_method);
8302 }
8303 }
8304
8305 if (unlikely(result == NULL)) {
8306 Py_DECREF(obj);
8307 return NULL;
8308 }
8309
8310 Py_DECREF(result);
8311
8312 if (unlikely(result != Py_None)) {
8313 Py_DECREF(obj);
8314
8315 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8316 return NULL;
8317 }
8318 } else {
8319 if (pos_args == NULL) {
8320 pos_args = MAKE_TUPLE(tstate, args, 10);
8321 }
8322
8323 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
8324 Py_DECREF(obj);
8325 Py_XDECREF(pos_args);
8326 return NULL;
8327 }
8328 }
8329 }
8330 }
8331
8332 Py_XDECREF(pos_args);
8333
8334 CHECK_OBJECT_X(obj);
8335
8336 return obj;
8337 }
8338#endif
8339#if PYTHON_VERSION < 0x300
8340 } else if (PyClass_Check(called)) {
8341 PyObject *obj = PyInstance_NewRaw(called, NULL);
8342
8343 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
8344
8345 if (unlikely(init_method == NULL)) {
8346 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
8347 Py_DECREF(obj);
8348 return NULL;
8349 }
8350
8351 Py_DECREF(obj);
8352
8353 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
8354 return NULL;
8355 }
8356
8357 bool is_compiled_function = false;
8358
8359 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
8360
8361 if (descr_get == NULL) {
8362 Py_INCREF(init_method);
8363 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
8364 is_compiled_function = true;
8365 } else if (descr_get != NULL) {
8366 PyObject *descr_method = descr_get(init_method, obj, called);
8367
8368 if (unlikely(descr_method == NULL)) {
8369 return NULL;
8370 }
8371
8372 init_method = descr_method;
8373 }
8374
8375 PyObject *result;
8376 if (is_compiled_function) {
8377 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
8378 args, 10);
8379 } else {
8380 result = CALL_FUNCTION_WITH_ARGS10(tstate, init_method, args);
8381 Py_DECREF(init_method);
8382 }
8383 if (unlikely(result == NULL)) {
8384 return NULL;
8385 }
8386
8387 Py_DECREF(result);
8388
8389 if (unlikely(result != Py_None)) {
8390 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8391 return NULL;
8392 }
8393
8394 CHECK_OBJECT_X(obj);
8395
8396 return obj;
8397#endif
8398#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8399 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8400 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8401
8402 if (likely(func != NULL)) {
8403 PyObject *result = func(called, args, 10, NULL);
8404
8405 CHECK_OBJECT_X(result);
8406
8407 return Nuitka_CheckFunctionResult(tstate, called, result);
8408 }
8409#endif
8410 }
8411
8412#if 0
8413 PRINT_NEW_LINE();
8414 PRINT_STRING("FALLBACK");
8415 PRINT_ITEM(called);
8416 PRINT_NEW_LINE();
8417#endif
8418
8419 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
8420
8421 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
8422
8423 Py_DECREF(pos_args);
8424
8425 CHECK_OBJECT_X(result);
8426
8427 return result;
8428}
8429PyObject *CALL_FUNCTION_WITH_POS_ARGS10(PyThreadState *tstate, PyObject *called, PyObject *pos_args) {
8430 assert(PyTuple_CheckExact(pos_args));
8431 assert(PyTuple_GET_SIZE(pos_args) == 10);
8432 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
8433 CHECK_OBJECT(called);
8434 CHECK_OBJECTS(args, 10);
8435
8436 if (Nuitka_Function_Check(called)) {
8437 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8438 return NULL;
8439 }
8440
8441 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8442 PyObject *result;
8443
8444 if (function->m_args_simple && 10 == function->m_args_positional_count) {
8445 for (Py_ssize_t i = 0; i < 10; i++) {
8446 Py_INCREF(args[i]);
8447 }
8448 result = function->m_c_code(tstate, function, (PyObject **)args);
8449 } else if (function->m_args_simple && 10 + function->m_defaults_given == function->m_args_positional_count) {
8450 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8451
8452 memcpy(python_pars, args, 10 * sizeof(PyObject *));
8453 memcpy(python_pars + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8454 function->m_defaults_given * sizeof(PyObject *));
8455
8456 for (Py_ssize_t i = 0; i < function->m_args_positional_count; i++) {
8457 Py_INCREF(python_pars[i]);
8458 }
8459
8460 result = function->m_c_code(tstate, function, python_pars);
8461 } else {
8462 result = Nuitka_CallFunctionPosArgs(tstate, function, args, 10);
8463 }
8464
8465 Py_LeaveRecursiveCall();
8466
8467 CHECK_OBJECT_X(result);
8468
8469 return result;
8470 } else if (Nuitka_Method_Check(called)) {
8471 struct Nuitka_MethodObject *method = (struct Nuitka_MethodObject *)called;
8472
8473 if (method->m_object == NULL) {
8474 PyObject *self = args[0];
8475
8476 int res = PyObject_IsInstance(self, method->m_class);
8477
8478 if (unlikely(res < 0)) {
8479 return NULL;
8480 } else if (unlikely(res == 0)) {
8481 PyErr_Format(PyExc_TypeError,
8482 "unbound compiled_method %s%s must be called with %s instance as first argument (got %s "
8483 "instance instead)",
8484 GET_CALLABLE_NAME((PyObject *)method->m_function),
8485 GET_CALLABLE_DESC((PyObject *)method->m_function), GET_CLASS_NAME(method->m_class),
8486 GET_INSTANCE_CLASS_NAME(tstate, (PyObject *)self));
8487
8488 return NULL;
8489 }
8490
8491 PyObject *result = Nuitka_CallFunctionPosArgs(tstate, method->m_function, args, 10);
8492
8493 CHECK_OBJECT_X(result);
8494
8495 return result;
8496 } else {
8497 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8498 return NULL;
8499 }
8500
8501 struct Nuitka_FunctionObject *function = method->m_function;
8502
8503 PyObject *result;
8504
8505 if (function->m_args_simple && 10 + 1 == function->m_args_positional_count) {
8506 PyObject *python_pars[10 + 1];
8507
8508 python_pars[0] = method->m_object;
8509 Py_INCREF(method->m_object);
8510
8511 for (Py_ssize_t i = 0; i < 10; i++) {
8512 python_pars[i + 1] = args[i];
8513 Py_INCREF(args[i]);
8514 }
8515 result = function->m_c_code(tstate, function, python_pars);
8516 } else if (function->m_args_simple &&
8517 10 + 1 + function->m_defaults_given == function->m_args_positional_count) {
8518 NUITKA_DYNAMIC_ARRAY_DECL(python_pars, PyObject *, function->m_args_positional_count);
8519
8520 python_pars[0] = method->m_object;
8521 Py_INCREF(method->m_object);
8522
8523 memcpy(python_pars + 1, args, 10 * sizeof(PyObject *));
8524 memcpy(python_pars + 1 + 10, &PyTuple_GET_ITEM(function->m_defaults, 0),
8525 function->m_defaults_given * sizeof(PyObject *));
8526
8527 for (Py_ssize_t i = 1; i < function->m_args_overall_count; i++) {
8528 Py_INCREF(python_pars[i]);
8529 }
8530
8531 result = function->m_c_code(tstate, function, python_pars);
8532 } else {
8533 result = Nuitka_CallMethodFunctionPosArgs(tstate, function, method->m_object, args, 10);
8534 }
8535
8536 Py_LeaveRecursiveCall();
8537
8538 CHECK_OBJECT_X(result);
8539
8540 return result;
8541 }
8542#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_CFUNCTION_CALL_OPT)
8543 } else if (PyCFunction_CheckExact(called)) {
8544#if PYTHON_VERSION >= 0x380
8545#ifdef _NUITKA_FULL_COMPAT
8546 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8547 return NULL;
8548 }
8549#endif
8550
8551 int flags = PyCFunction_GET_FLAGS(called);
8552
8553 PyObject *result;
8554
8555 if (!(flags & METH_VARARGS)) {
8556 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8557
8558 assert(func != NULL);
8559 result = func(called, args, 10, NULL);
8560
8561 CHECK_OBJECT_X(result);
8562 } else {
8563 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8564 PyObject *self = PyCFunction_GET_SELF(called);
8565
8566 if (flags & METH_KEYWORDS) {
8567 result = (*(PyCFunctionWithKeywords)(void (*)(void))method)(self, pos_args, NULL);
8568 } else {
8569 result = (*method)(self, pos_args);
8570 }
8571 }
8572
8573#ifdef _NUITKA_FULL_COMPAT
8574 Py_LeaveRecursiveCall();
8575#endif
8576 CHECK_OBJECT_X(result);
8577
8578 return Nuitka_CheckFunctionResult(tstate, called, result);
8579#else
8580 // Try to be fast about wrapping the arguments.
8581 int flags = PyCFunction_GET_FLAGS(called) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
8582
8583 if (unlikely(flags & METH_NOARGS)) {
8584 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes no arguments (10 given)",
8585 ((PyCFunctionObject *)called)->m_ml->ml_name);
8586 return NULL;
8587 } else if (unlikely(flags & METH_O)) {
8588 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (10 given)",
8589 ((PyCFunctionObject *)called)->m_ml->ml_name);
8590 return NULL;
8591 } else if (flags & METH_VARARGS) {
8592 // Recursion guard is not strictly necessary, as we already have
8593 // one on our way to here.
8594#ifdef _NUITKA_FULL_COMPAT
8595 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8596 return NULL;
8597 }
8598#endif
8599 PyCFunction method = PyCFunction_GET_FUNCTION(called);
8600 PyObject *self = PyCFunction_GET_SELF(called);
8601
8602 PyObject *result;
8603
8604#if PYTHON_VERSION < 0x360
8605 if (flags & METH_KEYWORDS) {
8606 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8607 } else {
8608 result = (*method)(self, pos_args);
8609 }
8610
8611#else
8612 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
8613 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
8614 } else if (flags == METH_FASTCALL) {
8615#if PYTHON_VERSION < 0x370
8616 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args, 10, NULL);
8617#else
8618 result = (*(_PyCFunctionFast)method)(self, &pos_args, 10);
8619#endif
8620 } else {
8621 result = (*method)(self, pos_args);
8622 }
8623#endif
8624
8625#ifdef _NUITKA_FULL_COMPAT
8626 Py_LeaveRecursiveCall();
8627#endif
8628
8629 CHECK_OBJECT_X(result);
8630
8631 return Nuitka_CheckFunctionResult(tstate, called, result);
8632 }
8633#endif
8634#endif
8635#if PYTHON_VERSION < 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_UNCOMPILED_FUNCTION_CALL_OPT)
8636 } else if (PyFunction_Check(called)) {
8637#if PYTHON_VERSION < 0x3b0
8638 PyObject *result = callPythonFunction(called, args, 10);
8639#else
8640 PyObject *result = _PyFunction_Vectorcall(called, args, 10, NULL);
8641#endif
8642 CHECK_OBJECT_X(result);
8643
8644 return result;
8645#endif
8646#if !defined(_NUITKA_EXPERIMENTAL_DISABLE_TYPE_CREATION_OPT)
8647 } else if (PyType_Check(called)) {
8648 PyTypeObject *type = Py_TYPE(called);
8649
8650 if (type->tp_call == PyType_Type.tp_call) {
8651 PyTypeObject *called_type = (PyTypeObject *)(called);
8652
8653 if (unlikely(called_type->tp_new == NULL)) {
8654 PyErr_Format(PyExc_TypeError, "cannot create '%s' instances", called_type->tp_name);
8655 return NULL;
8656 }
8657
8658 PyObject *obj;
8659
8660 if (called_type->tp_new == PyBaseObject_Type.tp_new) {
8661 if (unlikely(called_type->tp_flags & Py_TPFLAGS_IS_ABSTRACT)) {
8662 formatCannotInstantiateAbstractClass(tstate, called_type);
8663 return NULL;
8664 }
8665
8666 obj = called_type->tp_alloc(called_type, 0);
8667 CHECK_OBJECT(obj);
8668 } else {
8669 obj = called_type->tp_new(called_type, pos_args, NULL);
8670 }
8671
8672 if (likely(obj != NULL)) {
8673 if (!Nuitka_Type_IsSubtype(obj->ob_type, called_type)) {
8674 return obj;
8675 }
8676
8677 // Work on produced type.
8678 type = Py_TYPE(obj);
8679
8680 if (NuitkaType_HasFeatureClass(type) && type->tp_init != NULL) {
8681 if (type->tp_init == default_tp_init_wrapper) {
8682
8683 PyObject *init_method = Nuitka_TypeLookup(type, const_str_plain___init__);
8684
8685 // Not really allowed, since we wouldn't have the default wrapper set.
8686 assert(init_method != NULL);
8687
8688 bool is_compiled_function = false;
8689 bool init_method_needs_release = false;
8690
8691 if (likely(init_method != NULL)) {
8692 descrgetfunc func = Py_TYPE(init_method)->tp_descr_get;
8693
8694 if (func == Nuitka_Function_Type.tp_descr_get) {
8695 is_compiled_function = true;
8696 } else if (func != NULL) {
8697 init_method = func(init_method, obj, (PyObject *)(type));
8698 init_method_needs_release = true;
8699 }
8700 }
8701
8702 if (unlikely(init_method == NULL)) {
8703 if (!HAS_ERROR_OCCURRED(tstate)) {
8704 SET_CURRENT_EXCEPTION_TYPE0_VALUE0(tstate, PyExc_AttributeError,
8705 const_str_plain___init__);
8706 }
8707
8708 return NULL;
8709 }
8710
8711 PyObject *result;
8712 if (is_compiled_function) {
8713 result = Nuitka_CallMethodFunctionPosArgs(
8714 tstate, (struct Nuitka_FunctionObject const *)init_method, obj, args, 10);
8715 } else {
8716 result = CALL_FUNCTION_WITH_POS_ARGS10(tstate, init_method, pos_args);
8717 if (init_method_needs_release) {
8718 Py_DECREF(init_method);
8719 }
8720 }
8721
8722 if (unlikely(result == NULL)) {
8723 Py_DECREF(obj);
8724 return NULL;
8725 }
8726
8727 Py_DECREF(result);
8728
8729 if (unlikely(result != Py_None)) {
8730 Py_DECREF(obj);
8731
8732 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8733 return NULL;
8734 }
8735 } else {
8736
8737 if (unlikely(type->tp_init(obj, pos_args, NULL) < 0)) {
8738 Py_DECREF(obj);
8739 return NULL;
8740 }
8741 }
8742 }
8743 }
8744
8745 CHECK_OBJECT_X(obj);
8746
8747 return obj;
8748 }
8749#endif
8750#if PYTHON_VERSION < 0x300
8751 } else if (PyClass_Check(called)) {
8752 PyObject *obj = PyInstance_NewRaw(called, NULL);
8753
8754 PyObject *init_method = FIND_ATTRIBUTE_IN_CLASS((PyClassObject *)called, const_str_plain___init__);
8755
8756 if (unlikely(init_method == NULL)) {
8757 if (unlikely(HAS_ERROR_OCCURRED(tstate))) {
8758 Py_DECREF(obj);
8759 return NULL;
8760 }
8761
8762 Py_DECREF(obj);
8763
8764 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_TypeError, "this constructor takes no arguments");
8765 return NULL;
8766 }
8767
8768 bool is_compiled_function = false;
8769
8770 descrgetfunc descr_get = Py_TYPE(init_method)->tp_descr_get;
8771
8772 if (descr_get == NULL) {
8773 Py_INCREF(init_method);
8774 } else if (descr_get == Nuitka_Function_Type.tp_descr_get) {
8775 is_compiled_function = true;
8776 } else if (descr_get != NULL) {
8777 PyObject *descr_method = descr_get(init_method, obj, called);
8778
8779 if (unlikely(descr_method == NULL)) {
8780 return NULL;
8781 }
8782
8783 init_method = descr_method;
8784 }
8785
8786 PyObject *result;
8787 if (is_compiled_function) {
8788 result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)init_method, obj,
8789 args, 10);
8790 } else {
8791 result = CALL_FUNCTION_WITH_POS_ARGS10(tstate, init_method, pos_args);
8792 Py_DECREF(init_method);
8793 }
8794 if (unlikely(result == NULL)) {
8795 return NULL;
8796 }
8797
8798 Py_DECREF(result);
8799
8800 if (unlikely(result != Py_None)) {
8801 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("__init__() should return None, not '%s'", result);
8802 return NULL;
8803 }
8804
8805 CHECK_OBJECT_X(obj);
8806
8807 return obj;
8808#endif
8809#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8810 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8811 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8812
8813 if (likely(func != NULL)) {
8814 PyObject *result = func(called, args, 10, NULL);
8815
8816 CHECK_OBJECT_X(result);
8817
8818 return Nuitka_CheckFunctionResult(tstate, called, result);
8819 }
8820#endif
8821 }
8822
8823#if 0
8824 PRINT_NEW_LINE();
8825 PRINT_STRING("FALLBACK");
8826 PRINT_ITEM(called);
8827 PRINT_NEW_LINE();
8828#endif
8829
8830 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
8831
8832 CHECK_OBJECT_X(result);
8833
8834 return result;
8835}
8836PyObject *CALL_FUNCTION_WITH_NO_ARGS_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *kw_values,
8837 PyObject *kw_names) {
8838
8839 CHECK_OBJECT(kw_names);
8840 assert(PyTuple_CheckExact(kw_names));
8841 CHECK_OBJECT(called);
8842
8843 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
8844
8845 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
8846
8847 if (Nuitka_Function_Check(called)) {
8848 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8849 return NULL;
8850 }
8851
8852 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8853
8854 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, NULL, 0, kw_values, kw_names);
8855
8856 Py_LeaveRecursiveCall();
8857
8858 CHECK_OBJECT_X(result);
8859
8860 return result;
8861#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8862 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8863 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8864
8865 if (likely(func != NULL)) {
8866 PyObject *result = func(called, kw_values, 0, kw_names);
8867
8868 CHECK_OBJECT_X(result);
8869
8870 return Nuitka_CheckFunctionResult(tstate, called, result);
8871 }
8872#endif
8873 }
8874
8875#if 0
8876 PRINT_STRING("FALLBACK");
8877 PRINT_ITEM(called);
8878 PRINT_NEW_LINE();
8879#endif
8880
8881 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
8882
8883 if (unlikely(call_slot == NULL)) {
8884 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
8885
8886 return NULL;
8887 }
8888
8889 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8890 return NULL;
8891 }
8892
8893 PyObject *pos_args = const_tuple_empty;
8894
8895 PyObject *named_args = _PyDict_NewPresized(nkwargs);
8896
8897 for (Py_ssize_t i = 0; i < nkwargs; i++) {
8898 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
8899
8900 PyObject *value = kw_values[i];
8901
8902 CHECK_OBJECT(key);
8903 CHECK_OBJECT(value);
8904
8905 DICT_SET_ITEM(named_args, key, value);
8906 }
8907
8908 PyObject *result = (*call_slot)(called, pos_args, named_args);
8909
8910 Py_DECREF(named_args);
8911
8912 Py_LeaveRecursiveCall();
8913
8914 CHECK_OBJECT_X(result);
8915
8916 return Nuitka_CheckFunctionResult(tstate, called, result);
8917}
8918PyObject *CALL_FUNCTION_WITH_ARGS1_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
8919 PyObject *kw_names) {
8920 CHECK_OBJECTS(args, 1);
8921 CHECK_OBJECT(kw_names);
8922 assert(PyTuple_CheckExact(kw_names));
8923 CHECK_OBJECT(called);
8924
8925 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
8926
8927 CHECK_OBJECTS(&args[1], nkwargs);
8928
8929 if (Nuitka_Function_Check(called)) {
8930 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8931 return NULL;
8932 }
8933
8934 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
8935
8936 PyObject *result =
8937 Nuitka_CallFunctionVectorcall(tstate, function, args, 1, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
8938
8939 Py_LeaveRecursiveCall();
8940
8941 CHECK_OBJECT_X(result);
8942
8943 return result;
8944#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
8945 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
8946 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
8947
8948 if (likely(func != NULL)) {
8949 PyObject *result = func(called, args, 1, kw_names);
8950
8951 CHECK_OBJECT_X(result);
8952
8953 return Nuitka_CheckFunctionResult(tstate, called, result);
8954 }
8955#endif
8956 }
8957
8958#if 0
8959 PRINT_STRING("FALLBACK");
8960 PRINT_ITEM(called);
8961 PRINT_NEW_LINE();
8962#endif
8963
8964 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
8965
8966 if (unlikely(call_slot == NULL)) {
8967 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
8968
8969 return NULL;
8970 }
8971
8972 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
8973 return NULL;
8974 }
8975
8976 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
8977
8978 PyObject *named_args = _PyDict_NewPresized(nkwargs);
8979
8980 for (Py_ssize_t i = 0; i < nkwargs; i++) {
8981 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
8982
8983 PyObject *value = args[1 + i];
8984
8985 CHECK_OBJECT(key);
8986 CHECK_OBJECT(value);
8987
8988 DICT_SET_ITEM(named_args, key, value);
8989 }
8990
8991 PyObject *result = (*call_slot)(called, pos_args, named_args);
8992
8993 Py_DECREF(pos_args);
8994 Py_DECREF(named_args);
8995
8996 Py_LeaveRecursiveCall();
8997
8998 CHECK_OBJECT_X(result);
8999
9000 return Nuitka_CheckFunctionResult(tstate, called, result);
9001}
9002PyObject *CALL_FUNCTION_WITH_ARGS1_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9003 PyObject *const *kw_values, PyObject *kw_names) {
9004 CHECK_OBJECTS(args, 1);
9005 CHECK_OBJECT(kw_names);
9006 assert(PyTuple_CheckExact(kw_names));
9007 CHECK_OBJECT(called);
9008
9009 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9010
9011 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9012
9013 if (Nuitka_Function_Check(called)) {
9014 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9015 return NULL;
9016 }
9017
9018 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9019
9020 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 1, kw_values, kw_names);
9021
9022 Py_LeaveRecursiveCall();
9023
9024 CHECK_OBJECT_X(result);
9025
9026 return result;
9027#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9028 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9029 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9030
9031 if (likely(func != NULL)) {
9032 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 1 + nkwargs);
9033
9034 memcpy(vectorcall_args, args, 1 * sizeof(PyObject *));
9035 memcpy(&vectorcall_args[1], kw_values, nkwargs * sizeof(PyObject *));
9036
9037 PyObject *result = func(called, vectorcall_args, 1, kw_names);
9038
9039 CHECK_OBJECT_X(result);
9040
9041 return Nuitka_CheckFunctionResult(tstate, called, result);
9042 }
9043#endif
9044 }
9045
9046#if 0
9047 PRINT_STRING("FALLBACK");
9048 PRINT_ITEM(called);
9049 PRINT_NEW_LINE();
9050#endif
9051
9052 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9053
9054 if (unlikely(call_slot == NULL)) {
9055 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9056
9057 return NULL;
9058 }
9059
9060 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9061 return NULL;
9062 }
9063
9064 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
9065
9066 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9067
9068 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9069 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9070
9071 PyObject *value = kw_values[i];
9072
9073 CHECK_OBJECT(key);
9074 CHECK_OBJECT(value);
9075
9076 DICT_SET_ITEM(named_args, key, value);
9077 }
9078
9079 PyObject *result = (*call_slot)(called, pos_args, named_args);
9080
9081 Py_DECREF(pos_args);
9082 Py_DECREF(named_args);
9083
9084 Py_LeaveRecursiveCall();
9085
9086 CHECK_OBJECT_X(result);
9087
9088 return Nuitka_CheckFunctionResult(tstate, called, result);
9089}
9090PyObject *CALL_FUNCTION_WITH_POS_ARGS1_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9091 PyObject *const *kw_values, PyObject *kw_names) {
9092 assert(PyTuple_CheckExact(pos_args));
9093 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9094 CHECK_OBJECTS(args, 1);
9095 CHECK_OBJECT(kw_names);
9096 assert(PyTuple_CheckExact(kw_names));
9097 CHECK_OBJECT(called);
9098
9099 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9100
9101 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9102
9103 if (Nuitka_Function_Check(called)) {
9104 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9105 return NULL;
9106 }
9107
9108 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9109
9110 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 1, kw_values, kw_names);
9111
9112 Py_LeaveRecursiveCall();
9113
9114 CHECK_OBJECT_X(result);
9115
9116 return result;
9117#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9118 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9119 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9120
9121 if (likely(func != NULL)) {
9122 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 1 + nkwargs);
9123
9124 memcpy(vectorcall_args, args, 1 * sizeof(PyObject *));
9125 memcpy(&vectorcall_args[1], kw_values, nkwargs * sizeof(PyObject *));
9126
9127 PyObject *result = func(called, vectorcall_args, 1, kw_names);
9128
9129 CHECK_OBJECT_X(result);
9130
9131 return Nuitka_CheckFunctionResult(tstate, called, result);
9132 }
9133#endif
9134 }
9135
9136#if 0
9137 PRINT_STRING("FALLBACK");
9138 PRINT_ITEM(called);
9139 PRINT_NEW_LINE();
9140#endif
9141
9142 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9143
9144 if (unlikely(call_slot == NULL)) {
9145 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9146
9147 return NULL;
9148 }
9149
9150 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9151 return NULL;
9152 }
9153
9154 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9155
9156 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9157 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9158
9159 PyObject *value = kw_values[i];
9160
9161 CHECK_OBJECT(key);
9162 CHECK_OBJECT(value);
9163
9164 DICT_SET_ITEM(named_args, key, value);
9165 }
9166
9167 PyObject *result = (*call_slot)(called, pos_args, named_args);
9168
9169 Py_DECREF(named_args);
9170
9171 Py_LeaveRecursiveCall();
9172
9173 CHECK_OBJECT_X(result);
9174
9175 return Nuitka_CheckFunctionResult(tstate, called, result);
9176}
9177PyObject *CALL_FUNCTION_WITH_ARGS2_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9178 PyObject *kw_names) {
9179 CHECK_OBJECTS(args, 2);
9180 CHECK_OBJECT(kw_names);
9181 assert(PyTuple_CheckExact(kw_names));
9182 CHECK_OBJECT(called);
9183
9184 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9185
9186 CHECK_OBJECTS(&args[2], nkwargs);
9187
9188 if (Nuitka_Function_Check(called)) {
9189 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9190 return NULL;
9191 }
9192
9193 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9194
9195 PyObject *result =
9196 Nuitka_CallFunctionVectorcall(tstate, function, args, 2, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9197
9198 Py_LeaveRecursiveCall();
9199
9200 CHECK_OBJECT_X(result);
9201
9202 return result;
9203#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9204 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9205 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9206
9207 if (likely(func != NULL)) {
9208 PyObject *result = func(called, args, 2, kw_names);
9209
9210 CHECK_OBJECT_X(result);
9211
9212 return Nuitka_CheckFunctionResult(tstate, called, result);
9213 }
9214#endif
9215 }
9216
9217#if 0
9218 PRINT_STRING("FALLBACK");
9219 PRINT_ITEM(called);
9220 PRINT_NEW_LINE();
9221#endif
9222
9223 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9224
9225 if (unlikely(call_slot == NULL)) {
9226 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9227
9228 return NULL;
9229 }
9230
9231 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9232 return NULL;
9233 }
9234
9235 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
9236
9237 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9238
9239 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9240 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9241
9242 PyObject *value = args[2 + i];
9243
9244 CHECK_OBJECT(key);
9245 CHECK_OBJECT(value);
9246
9247 DICT_SET_ITEM(named_args, key, value);
9248 }
9249
9250 PyObject *result = (*call_slot)(called, pos_args, named_args);
9251
9252 Py_DECREF(pos_args);
9253 Py_DECREF(named_args);
9254
9255 Py_LeaveRecursiveCall();
9256
9257 CHECK_OBJECT_X(result);
9258
9259 return Nuitka_CheckFunctionResult(tstate, called, result);
9260}
9261PyObject *CALL_FUNCTION_WITH_ARGS2_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9262 PyObject *const *kw_values, PyObject *kw_names) {
9263 CHECK_OBJECTS(args, 2);
9264 CHECK_OBJECT(kw_names);
9265 assert(PyTuple_CheckExact(kw_names));
9266 CHECK_OBJECT(called);
9267
9268 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9269
9270 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9271
9272 if (Nuitka_Function_Check(called)) {
9273 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9274 return NULL;
9275 }
9276
9277 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9278
9279 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 2, kw_values, kw_names);
9280
9281 Py_LeaveRecursiveCall();
9282
9283 CHECK_OBJECT_X(result);
9284
9285 return result;
9286#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9287 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9288 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9289
9290 if (likely(func != NULL)) {
9291 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 2 + nkwargs);
9292
9293 memcpy(vectorcall_args, args, 2 * sizeof(PyObject *));
9294 memcpy(&vectorcall_args[2], kw_values, nkwargs * sizeof(PyObject *));
9295
9296 PyObject *result = func(called, vectorcall_args, 2, kw_names);
9297
9298 CHECK_OBJECT_X(result);
9299
9300 return Nuitka_CheckFunctionResult(tstate, called, result);
9301 }
9302#endif
9303 }
9304
9305#if 0
9306 PRINT_STRING("FALLBACK");
9307 PRINT_ITEM(called);
9308 PRINT_NEW_LINE();
9309#endif
9310
9311 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9312
9313 if (unlikely(call_slot == NULL)) {
9314 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9315
9316 return NULL;
9317 }
9318
9319 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9320 return NULL;
9321 }
9322
9323 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
9324
9325 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9326
9327 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9328 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9329
9330 PyObject *value = kw_values[i];
9331
9332 CHECK_OBJECT(key);
9333 CHECK_OBJECT(value);
9334
9335 DICT_SET_ITEM(named_args, key, value);
9336 }
9337
9338 PyObject *result = (*call_slot)(called, pos_args, named_args);
9339
9340 Py_DECREF(pos_args);
9341 Py_DECREF(named_args);
9342
9343 Py_LeaveRecursiveCall();
9344
9345 CHECK_OBJECT_X(result);
9346
9347 return Nuitka_CheckFunctionResult(tstate, called, result);
9348}
9349PyObject *CALL_FUNCTION_WITH_POS_ARGS2_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9350 PyObject *const *kw_values, PyObject *kw_names) {
9351 assert(PyTuple_CheckExact(pos_args));
9352 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9353 CHECK_OBJECTS(args, 2);
9354 CHECK_OBJECT(kw_names);
9355 assert(PyTuple_CheckExact(kw_names));
9356 CHECK_OBJECT(called);
9357
9358 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9359
9360 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9361
9362 if (Nuitka_Function_Check(called)) {
9363 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9364 return NULL;
9365 }
9366
9367 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9368
9369 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 2, kw_values, kw_names);
9370
9371 Py_LeaveRecursiveCall();
9372
9373 CHECK_OBJECT_X(result);
9374
9375 return result;
9376#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9377 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9378 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9379
9380 if (likely(func != NULL)) {
9381 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 2 + nkwargs);
9382
9383 memcpy(vectorcall_args, args, 2 * sizeof(PyObject *));
9384 memcpy(&vectorcall_args[2], kw_values, nkwargs * sizeof(PyObject *));
9385
9386 PyObject *result = func(called, vectorcall_args, 2, kw_names);
9387
9388 CHECK_OBJECT_X(result);
9389
9390 return Nuitka_CheckFunctionResult(tstate, called, result);
9391 }
9392#endif
9393 }
9394
9395#if 0
9396 PRINT_STRING("FALLBACK");
9397 PRINT_ITEM(called);
9398 PRINT_NEW_LINE();
9399#endif
9400
9401 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9402
9403 if (unlikely(call_slot == NULL)) {
9404 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9405
9406 return NULL;
9407 }
9408
9409 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9410 return NULL;
9411 }
9412
9413 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9414
9415 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9416 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9417
9418 PyObject *value = kw_values[i];
9419
9420 CHECK_OBJECT(key);
9421 CHECK_OBJECT(value);
9422
9423 DICT_SET_ITEM(named_args, key, value);
9424 }
9425
9426 PyObject *result = (*call_slot)(called, pos_args, named_args);
9427
9428 Py_DECREF(named_args);
9429
9430 Py_LeaveRecursiveCall();
9431
9432 CHECK_OBJECT_X(result);
9433
9434 return Nuitka_CheckFunctionResult(tstate, called, result);
9435}
9436PyObject *CALL_FUNCTION_WITH_ARGS3_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9437 PyObject *kw_names) {
9438 CHECK_OBJECTS(args, 3);
9439 CHECK_OBJECT(kw_names);
9440 assert(PyTuple_CheckExact(kw_names));
9441 CHECK_OBJECT(called);
9442
9443 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9444
9445 CHECK_OBJECTS(&args[3], nkwargs);
9446
9447 if (Nuitka_Function_Check(called)) {
9448 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9449 return NULL;
9450 }
9451
9452 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9453
9454 PyObject *result =
9455 Nuitka_CallFunctionVectorcall(tstate, function, args, 3, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9456
9457 Py_LeaveRecursiveCall();
9458
9459 CHECK_OBJECT_X(result);
9460
9461 return result;
9462#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9463 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9464 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9465
9466 if (likely(func != NULL)) {
9467 PyObject *result = func(called, args, 3, kw_names);
9468
9469 CHECK_OBJECT_X(result);
9470
9471 return Nuitka_CheckFunctionResult(tstate, called, result);
9472 }
9473#endif
9474 }
9475
9476#if 0
9477 PRINT_STRING("FALLBACK");
9478 PRINT_ITEM(called);
9479 PRINT_NEW_LINE();
9480#endif
9481
9482 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9483
9484 if (unlikely(call_slot == NULL)) {
9485 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9486
9487 return NULL;
9488 }
9489
9490 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9491 return NULL;
9492 }
9493
9494 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
9495
9496 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9497
9498 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9499 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9500
9501 PyObject *value = args[3 + i];
9502
9503 CHECK_OBJECT(key);
9504 CHECK_OBJECT(value);
9505
9506 DICT_SET_ITEM(named_args, key, value);
9507 }
9508
9509 PyObject *result = (*call_slot)(called, pos_args, named_args);
9510
9511 Py_DECREF(pos_args);
9512 Py_DECREF(named_args);
9513
9514 Py_LeaveRecursiveCall();
9515
9516 CHECK_OBJECT_X(result);
9517
9518 return Nuitka_CheckFunctionResult(tstate, called, result);
9519}
9520PyObject *CALL_FUNCTION_WITH_ARGS3_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9521 PyObject *const *kw_values, PyObject *kw_names) {
9522 CHECK_OBJECTS(args, 3);
9523 CHECK_OBJECT(kw_names);
9524 assert(PyTuple_CheckExact(kw_names));
9525 CHECK_OBJECT(called);
9526
9527 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9528
9529 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9530
9531 if (Nuitka_Function_Check(called)) {
9532 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9533 return NULL;
9534 }
9535
9536 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9537
9538 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 3, kw_values, kw_names);
9539
9540 Py_LeaveRecursiveCall();
9541
9542 CHECK_OBJECT_X(result);
9543
9544 return result;
9545#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9546 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9547 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9548
9549 if (likely(func != NULL)) {
9550 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 3 + nkwargs);
9551
9552 memcpy(vectorcall_args, args, 3 * sizeof(PyObject *));
9553 memcpy(&vectorcall_args[3], kw_values, nkwargs * sizeof(PyObject *));
9554
9555 PyObject *result = func(called, vectorcall_args, 3, kw_names);
9556
9557 CHECK_OBJECT_X(result);
9558
9559 return Nuitka_CheckFunctionResult(tstate, called, result);
9560 }
9561#endif
9562 }
9563
9564#if 0
9565 PRINT_STRING("FALLBACK");
9566 PRINT_ITEM(called);
9567 PRINT_NEW_LINE();
9568#endif
9569
9570 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9571
9572 if (unlikely(call_slot == NULL)) {
9573 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9574
9575 return NULL;
9576 }
9577
9578 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9579 return NULL;
9580 }
9581
9582 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
9583
9584 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9585
9586 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9587 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9588
9589 PyObject *value = kw_values[i];
9590
9591 CHECK_OBJECT(key);
9592 CHECK_OBJECT(value);
9593
9594 DICT_SET_ITEM(named_args, key, value);
9595 }
9596
9597 PyObject *result = (*call_slot)(called, pos_args, named_args);
9598
9599 Py_DECREF(pos_args);
9600 Py_DECREF(named_args);
9601
9602 Py_LeaveRecursiveCall();
9603
9604 CHECK_OBJECT_X(result);
9605
9606 return Nuitka_CheckFunctionResult(tstate, called, result);
9607}
9608PyObject *CALL_FUNCTION_WITH_POS_ARGS3_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9609 PyObject *const *kw_values, PyObject *kw_names) {
9610 assert(PyTuple_CheckExact(pos_args));
9611 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9612 CHECK_OBJECTS(args, 3);
9613 CHECK_OBJECT(kw_names);
9614 assert(PyTuple_CheckExact(kw_names));
9615 CHECK_OBJECT(called);
9616
9617 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9618
9619 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9620
9621 if (Nuitka_Function_Check(called)) {
9622 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9623 return NULL;
9624 }
9625
9626 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9627
9628 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 3, kw_values, kw_names);
9629
9630 Py_LeaveRecursiveCall();
9631
9632 CHECK_OBJECT_X(result);
9633
9634 return result;
9635#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9636 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9637 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9638
9639 if (likely(func != NULL)) {
9640 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 3 + nkwargs);
9641
9642 memcpy(vectorcall_args, args, 3 * sizeof(PyObject *));
9643 memcpy(&vectorcall_args[3], kw_values, nkwargs * sizeof(PyObject *));
9644
9645 PyObject *result = func(called, vectorcall_args, 3, kw_names);
9646
9647 CHECK_OBJECT_X(result);
9648
9649 return Nuitka_CheckFunctionResult(tstate, called, result);
9650 }
9651#endif
9652 }
9653
9654#if 0
9655 PRINT_STRING("FALLBACK");
9656 PRINT_ITEM(called);
9657 PRINT_NEW_LINE();
9658#endif
9659
9660 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9661
9662 if (unlikely(call_slot == NULL)) {
9663 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9664
9665 return NULL;
9666 }
9667
9668 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9669 return NULL;
9670 }
9671
9672 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9673
9674 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9675 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9676
9677 PyObject *value = kw_values[i];
9678
9679 CHECK_OBJECT(key);
9680 CHECK_OBJECT(value);
9681
9682 DICT_SET_ITEM(named_args, key, value);
9683 }
9684
9685 PyObject *result = (*call_slot)(called, pos_args, named_args);
9686
9687 Py_DECREF(named_args);
9688
9689 Py_LeaveRecursiveCall();
9690
9691 CHECK_OBJECT_X(result);
9692
9693 return Nuitka_CheckFunctionResult(tstate, called, result);
9694}
9695PyObject *CALL_FUNCTION_WITH_ARGS4_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9696 PyObject *kw_names) {
9697 CHECK_OBJECTS(args, 4);
9698 CHECK_OBJECT(kw_names);
9699 assert(PyTuple_CheckExact(kw_names));
9700 CHECK_OBJECT(called);
9701
9702 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9703
9704 CHECK_OBJECTS(&args[4], nkwargs);
9705
9706 if (Nuitka_Function_Check(called)) {
9707 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9708 return NULL;
9709 }
9710
9711 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9712
9713 PyObject *result =
9714 Nuitka_CallFunctionVectorcall(tstate, function, args, 4, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9715
9716 Py_LeaveRecursiveCall();
9717
9718 CHECK_OBJECT_X(result);
9719
9720 return result;
9721#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9722 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9723 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9724
9725 if (likely(func != NULL)) {
9726 PyObject *result = func(called, args, 4, kw_names);
9727
9728 CHECK_OBJECT_X(result);
9729
9730 return Nuitka_CheckFunctionResult(tstate, called, result);
9731 }
9732#endif
9733 }
9734
9735#if 0
9736 PRINT_STRING("FALLBACK");
9737 PRINT_ITEM(called);
9738 PRINT_NEW_LINE();
9739#endif
9740
9741 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9742
9743 if (unlikely(call_slot == NULL)) {
9744 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9745
9746 return NULL;
9747 }
9748
9749 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9750 return NULL;
9751 }
9752
9753 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
9754
9755 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9756
9757 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9758 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9759
9760 PyObject *value = args[4 + i];
9761
9762 CHECK_OBJECT(key);
9763 CHECK_OBJECT(value);
9764
9765 DICT_SET_ITEM(named_args, key, value);
9766 }
9767
9768 PyObject *result = (*call_slot)(called, pos_args, named_args);
9769
9770 Py_DECREF(pos_args);
9771 Py_DECREF(named_args);
9772
9773 Py_LeaveRecursiveCall();
9774
9775 CHECK_OBJECT_X(result);
9776
9777 return Nuitka_CheckFunctionResult(tstate, called, result);
9778}
9779PyObject *CALL_FUNCTION_WITH_ARGS4_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9780 PyObject *const *kw_values, PyObject *kw_names) {
9781 CHECK_OBJECTS(args, 4);
9782 CHECK_OBJECT(kw_names);
9783 assert(PyTuple_CheckExact(kw_names));
9784 CHECK_OBJECT(called);
9785
9786 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9787
9788 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9789
9790 if (Nuitka_Function_Check(called)) {
9791 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9792 return NULL;
9793 }
9794
9795 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9796
9797 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 4, kw_values, kw_names);
9798
9799 Py_LeaveRecursiveCall();
9800
9801 CHECK_OBJECT_X(result);
9802
9803 return result;
9804#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9805 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9806 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9807
9808 if (likely(func != NULL)) {
9809 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 4 + nkwargs);
9810
9811 memcpy(vectorcall_args, args, 4 * sizeof(PyObject *));
9812 memcpy(&vectorcall_args[4], kw_values, nkwargs * sizeof(PyObject *));
9813
9814 PyObject *result = func(called, vectorcall_args, 4, kw_names);
9815
9816 CHECK_OBJECT_X(result);
9817
9818 return Nuitka_CheckFunctionResult(tstate, called, result);
9819 }
9820#endif
9821 }
9822
9823#if 0
9824 PRINT_STRING("FALLBACK");
9825 PRINT_ITEM(called);
9826 PRINT_NEW_LINE();
9827#endif
9828
9829 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9830
9831 if (unlikely(call_slot == NULL)) {
9832 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9833
9834 return NULL;
9835 }
9836
9837 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9838 return NULL;
9839 }
9840
9841 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
9842
9843 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9844
9845 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9846 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9847
9848 PyObject *value = kw_values[i];
9849
9850 CHECK_OBJECT(key);
9851 CHECK_OBJECT(value);
9852
9853 DICT_SET_ITEM(named_args, key, value);
9854 }
9855
9856 PyObject *result = (*call_slot)(called, pos_args, named_args);
9857
9858 Py_DECREF(pos_args);
9859 Py_DECREF(named_args);
9860
9861 Py_LeaveRecursiveCall();
9862
9863 CHECK_OBJECT_X(result);
9864
9865 return Nuitka_CheckFunctionResult(tstate, called, result);
9866}
9867PyObject *CALL_FUNCTION_WITH_POS_ARGS4_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
9868 PyObject *const *kw_values, PyObject *kw_names) {
9869 assert(PyTuple_CheckExact(pos_args));
9870 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
9871 CHECK_OBJECTS(args, 4);
9872 CHECK_OBJECT(kw_names);
9873 assert(PyTuple_CheckExact(kw_names));
9874 CHECK_OBJECT(called);
9875
9876 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9877
9878 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
9879
9880 if (Nuitka_Function_Check(called)) {
9881 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9882 return NULL;
9883 }
9884
9885 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9886
9887 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 4, kw_values, kw_names);
9888
9889 Py_LeaveRecursiveCall();
9890
9891 CHECK_OBJECT_X(result);
9892
9893 return result;
9894#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9895 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9896 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9897
9898 if (likely(func != NULL)) {
9899 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 4 + nkwargs);
9900
9901 memcpy(vectorcall_args, args, 4 * sizeof(PyObject *));
9902 memcpy(&vectorcall_args[4], kw_values, nkwargs * sizeof(PyObject *));
9903
9904 PyObject *result = func(called, vectorcall_args, 4, kw_names);
9905
9906 CHECK_OBJECT_X(result);
9907
9908 return Nuitka_CheckFunctionResult(tstate, called, result);
9909 }
9910#endif
9911 }
9912
9913#if 0
9914 PRINT_STRING("FALLBACK");
9915 PRINT_ITEM(called);
9916 PRINT_NEW_LINE();
9917#endif
9918
9919 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
9920
9921 if (unlikely(call_slot == NULL)) {
9922 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
9923
9924 return NULL;
9925 }
9926
9927 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9928 return NULL;
9929 }
9930
9931 PyObject *named_args = _PyDict_NewPresized(nkwargs);
9932
9933 for (Py_ssize_t i = 0; i < nkwargs; i++) {
9934 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
9935
9936 PyObject *value = kw_values[i];
9937
9938 CHECK_OBJECT(key);
9939 CHECK_OBJECT(value);
9940
9941 DICT_SET_ITEM(named_args, key, value);
9942 }
9943
9944 PyObject *result = (*call_slot)(called, pos_args, named_args);
9945
9946 Py_DECREF(named_args);
9947
9948 Py_LeaveRecursiveCall();
9949
9950 CHECK_OBJECT_X(result);
9951
9952 return Nuitka_CheckFunctionResult(tstate, called, result);
9953}
9954PyObject *CALL_FUNCTION_WITH_ARGS5_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
9955 PyObject *kw_names) {
9956 CHECK_OBJECTS(args, 5);
9957 CHECK_OBJECT(kw_names);
9958 assert(PyTuple_CheckExact(kw_names));
9959 CHECK_OBJECT(called);
9960
9961 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
9962
9963 CHECK_OBJECTS(&args[5], nkwargs);
9964
9965 if (Nuitka_Function_Check(called)) {
9966 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
9967 return NULL;
9968 }
9969
9970 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
9971
9972 PyObject *result =
9973 Nuitka_CallFunctionVectorcall(tstate, function, args, 5, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
9974
9975 Py_LeaveRecursiveCall();
9976
9977 CHECK_OBJECT_X(result);
9978
9979 return result;
9980#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
9981 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
9982 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
9983
9984 if (likely(func != NULL)) {
9985 PyObject *result = func(called, args, 5, kw_names);
9986
9987 CHECK_OBJECT_X(result);
9988
9989 return Nuitka_CheckFunctionResult(tstate, called, result);
9990 }
9991#endif
9992 }
9993
9994#if 0
9995 PRINT_STRING("FALLBACK");
9996 PRINT_ITEM(called);
9997 PRINT_NEW_LINE();
9998#endif
9999
10000 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10001
10002 if (unlikely(call_slot == NULL)) {
10003 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10004
10005 return NULL;
10006 }
10007
10008 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10009 return NULL;
10010 }
10011
10012 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
10013
10014 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10015
10016 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10017 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10018
10019 PyObject *value = args[5 + i];
10020
10021 CHECK_OBJECT(key);
10022 CHECK_OBJECT(value);
10023
10024 DICT_SET_ITEM(named_args, key, value);
10025 }
10026
10027 PyObject *result = (*call_slot)(called, pos_args, named_args);
10028
10029 Py_DECREF(pos_args);
10030 Py_DECREF(named_args);
10031
10032 Py_LeaveRecursiveCall();
10033
10034 CHECK_OBJECT_X(result);
10035
10036 return Nuitka_CheckFunctionResult(tstate, called, result);
10037}
10038PyObject *CALL_FUNCTION_WITH_ARGS5_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10039 PyObject *const *kw_values, PyObject *kw_names) {
10040 CHECK_OBJECTS(args, 5);
10041 CHECK_OBJECT(kw_names);
10042 assert(PyTuple_CheckExact(kw_names));
10043 CHECK_OBJECT(called);
10044
10045 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10046
10047 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10048
10049 if (Nuitka_Function_Check(called)) {
10050 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10051 return NULL;
10052 }
10053
10054 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10055
10056 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 5, kw_values, kw_names);
10057
10058 Py_LeaveRecursiveCall();
10059
10060 CHECK_OBJECT_X(result);
10061
10062 return result;
10063#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10064 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10065 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10066
10067 if (likely(func != NULL)) {
10068 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 5 + nkwargs);
10069
10070 memcpy(vectorcall_args, args, 5 * sizeof(PyObject *));
10071 memcpy(&vectorcall_args[5], kw_values, nkwargs * sizeof(PyObject *));
10072
10073 PyObject *result = func(called, vectorcall_args, 5, kw_names);
10074
10075 CHECK_OBJECT_X(result);
10076
10077 return Nuitka_CheckFunctionResult(tstate, called, result);
10078 }
10079#endif
10080 }
10081
10082#if 0
10083 PRINT_STRING("FALLBACK");
10084 PRINT_ITEM(called);
10085 PRINT_NEW_LINE();
10086#endif
10087
10088 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10089
10090 if (unlikely(call_slot == NULL)) {
10091 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10092
10093 return NULL;
10094 }
10095
10096 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10097 return NULL;
10098 }
10099
10100 PyObject *pos_args = MAKE_TUPLE(tstate, args, 5);
10101
10102 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10103
10104 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10105 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10106
10107 PyObject *value = kw_values[i];
10108
10109 CHECK_OBJECT(key);
10110 CHECK_OBJECT(value);
10111
10112 DICT_SET_ITEM(named_args, key, value);
10113 }
10114
10115 PyObject *result = (*call_slot)(called, pos_args, named_args);
10116
10117 Py_DECREF(pos_args);
10118 Py_DECREF(named_args);
10119
10120 Py_LeaveRecursiveCall();
10121
10122 CHECK_OBJECT_X(result);
10123
10124 return Nuitka_CheckFunctionResult(tstate, called, result);
10125}
10126PyObject *CALL_FUNCTION_WITH_POS_ARGS5_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10127 PyObject *const *kw_values, PyObject *kw_names) {
10128 assert(PyTuple_CheckExact(pos_args));
10129 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10130 CHECK_OBJECTS(args, 5);
10131 CHECK_OBJECT(kw_names);
10132 assert(PyTuple_CheckExact(kw_names));
10133 CHECK_OBJECT(called);
10134
10135 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10136
10137 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10138
10139 if (Nuitka_Function_Check(called)) {
10140 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10141 return NULL;
10142 }
10143
10144 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10145
10146 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 5, kw_values, kw_names);
10147
10148 Py_LeaveRecursiveCall();
10149
10150 CHECK_OBJECT_X(result);
10151
10152 return result;
10153#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10154 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10155 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10156
10157 if (likely(func != NULL)) {
10158 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 5 + nkwargs);
10159
10160 memcpy(vectorcall_args, args, 5 * sizeof(PyObject *));
10161 memcpy(&vectorcall_args[5], kw_values, nkwargs * sizeof(PyObject *));
10162
10163 PyObject *result = func(called, vectorcall_args, 5, kw_names);
10164
10165 CHECK_OBJECT_X(result);
10166
10167 return Nuitka_CheckFunctionResult(tstate, called, result);
10168 }
10169#endif
10170 }
10171
10172#if 0
10173 PRINT_STRING("FALLBACK");
10174 PRINT_ITEM(called);
10175 PRINT_NEW_LINE();
10176#endif
10177
10178 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10179
10180 if (unlikely(call_slot == NULL)) {
10181 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10182
10183 return NULL;
10184 }
10185
10186 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10187 return NULL;
10188 }
10189
10190 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10191
10192 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10193 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10194
10195 PyObject *value = kw_values[i];
10196
10197 CHECK_OBJECT(key);
10198 CHECK_OBJECT(value);
10199
10200 DICT_SET_ITEM(named_args, key, value);
10201 }
10202
10203 PyObject *result = (*call_slot)(called, pos_args, named_args);
10204
10205 Py_DECREF(named_args);
10206
10207 Py_LeaveRecursiveCall();
10208
10209 CHECK_OBJECT_X(result);
10210
10211 return Nuitka_CheckFunctionResult(tstate, called, result);
10212}
10213PyObject *CALL_FUNCTION_WITH_ARGS6_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10214 PyObject *kw_names) {
10215 CHECK_OBJECTS(args, 6);
10216 CHECK_OBJECT(kw_names);
10217 assert(PyTuple_CheckExact(kw_names));
10218 CHECK_OBJECT(called);
10219
10220 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10221
10222 CHECK_OBJECTS(&args[6], nkwargs);
10223
10224 if (Nuitka_Function_Check(called)) {
10225 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10226 return NULL;
10227 }
10228
10229 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10230
10231 PyObject *result =
10232 Nuitka_CallFunctionVectorcall(tstate, function, args, 6, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
10233
10234 Py_LeaveRecursiveCall();
10235
10236 CHECK_OBJECT_X(result);
10237
10238 return result;
10239#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10240 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10241 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10242
10243 if (likely(func != NULL)) {
10244 PyObject *result = func(called, args, 6, kw_names);
10245
10246 CHECK_OBJECT_X(result);
10247
10248 return Nuitka_CheckFunctionResult(tstate, called, result);
10249 }
10250#endif
10251 }
10252
10253#if 0
10254 PRINT_STRING("FALLBACK");
10255 PRINT_ITEM(called);
10256 PRINT_NEW_LINE();
10257#endif
10258
10259 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10260
10261 if (unlikely(call_slot == NULL)) {
10262 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10263
10264 return NULL;
10265 }
10266
10267 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10268 return NULL;
10269 }
10270
10271 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
10272
10273 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10274
10275 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10276 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10277
10278 PyObject *value = args[6 + i];
10279
10280 CHECK_OBJECT(key);
10281 CHECK_OBJECT(value);
10282
10283 DICT_SET_ITEM(named_args, key, value);
10284 }
10285
10286 PyObject *result = (*call_slot)(called, pos_args, named_args);
10287
10288 Py_DECREF(pos_args);
10289 Py_DECREF(named_args);
10290
10291 Py_LeaveRecursiveCall();
10292
10293 CHECK_OBJECT_X(result);
10294
10295 return Nuitka_CheckFunctionResult(tstate, called, result);
10296}
10297PyObject *CALL_FUNCTION_WITH_ARGS6_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10298 PyObject *const *kw_values, PyObject *kw_names) {
10299 CHECK_OBJECTS(args, 6);
10300 CHECK_OBJECT(kw_names);
10301 assert(PyTuple_CheckExact(kw_names));
10302 CHECK_OBJECT(called);
10303
10304 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10305
10306 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10307
10308 if (Nuitka_Function_Check(called)) {
10309 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10310 return NULL;
10311 }
10312
10313 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10314
10315 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 6, kw_values, kw_names);
10316
10317 Py_LeaveRecursiveCall();
10318
10319 CHECK_OBJECT_X(result);
10320
10321 return result;
10322#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10323 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10324 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10325
10326 if (likely(func != NULL)) {
10327 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 6 + nkwargs);
10328
10329 memcpy(vectorcall_args, args, 6 * sizeof(PyObject *));
10330 memcpy(&vectorcall_args[6], kw_values, nkwargs * sizeof(PyObject *));
10331
10332 PyObject *result = func(called, vectorcall_args, 6, kw_names);
10333
10334 CHECK_OBJECT_X(result);
10335
10336 return Nuitka_CheckFunctionResult(tstate, called, result);
10337 }
10338#endif
10339 }
10340
10341#if 0
10342 PRINT_STRING("FALLBACK");
10343 PRINT_ITEM(called);
10344 PRINT_NEW_LINE();
10345#endif
10346
10347 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10348
10349 if (unlikely(call_slot == NULL)) {
10350 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10351
10352 return NULL;
10353 }
10354
10355 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10356 return NULL;
10357 }
10358
10359 PyObject *pos_args = MAKE_TUPLE(tstate, args, 6);
10360
10361 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10362
10363 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10364 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10365
10366 PyObject *value = kw_values[i];
10367
10368 CHECK_OBJECT(key);
10369 CHECK_OBJECT(value);
10370
10371 DICT_SET_ITEM(named_args, key, value);
10372 }
10373
10374 PyObject *result = (*call_slot)(called, pos_args, named_args);
10375
10376 Py_DECREF(pos_args);
10377 Py_DECREF(named_args);
10378
10379 Py_LeaveRecursiveCall();
10380
10381 CHECK_OBJECT_X(result);
10382
10383 return Nuitka_CheckFunctionResult(tstate, called, result);
10384}
10385PyObject *CALL_FUNCTION_WITH_POS_ARGS6_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10386 PyObject *const *kw_values, PyObject *kw_names) {
10387 assert(PyTuple_CheckExact(pos_args));
10388 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10389 CHECK_OBJECTS(args, 6);
10390 CHECK_OBJECT(kw_names);
10391 assert(PyTuple_CheckExact(kw_names));
10392 CHECK_OBJECT(called);
10393
10394 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10395
10396 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10397
10398 if (Nuitka_Function_Check(called)) {
10399 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10400 return NULL;
10401 }
10402
10403 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10404
10405 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 6, kw_values, kw_names);
10406
10407 Py_LeaveRecursiveCall();
10408
10409 CHECK_OBJECT_X(result);
10410
10411 return result;
10412#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10413 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10414 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10415
10416 if (likely(func != NULL)) {
10417 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 6 + nkwargs);
10418
10419 memcpy(vectorcall_args, args, 6 * sizeof(PyObject *));
10420 memcpy(&vectorcall_args[6], kw_values, nkwargs * sizeof(PyObject *));
10421
10422 PyObject *result = func(called, vectorcall_args, 6, kw_names);
10423
10424 CHECK_OBJECT_X(result);
10425
10426 return Nuitka_CheckFunctionResult(tstate, called, result);
10427 }
10428#endif
10429 }
10430
10431#if 0
10432 PRINT_STRING("FALLBACK");
10433 PRINT_ITEM(called);
10434 PRINT_NEW_LINE();
10435#endif
10436
10437 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10438
10439 if (unlikely(call_slot == NULL)) {
10440 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10441
10442 return NULL;
10443 }
10444
10445 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10446 return NULL;
10447 }
10448
10449 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10450
10451 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10452 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10453
10454 PyObject *value = kw_values[i];
10455
10456 CHECK_OBJECT(key);
10457 CHECK_OBJECT(value);
10458
10459 DICT_SET_ITEM(named_args, key, value);
10460 }
10461
10462 PyObject *result = (*call_slot)(called, pos_args, named_args);
10463
10464 Py_DECREF(named_args);
10465
10466 Py_LeaveRecursiveCall();
10467
10468 CHECK_OBJECT_X(result);
10469
10470 return Nuitka_CheckFunctionResult(tstate, called, result);
10471}
10472PyObject *CALL_FUNCTION_WITH_ARGS7_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10473 PyObject *kw_names) {
10474 CHECK_OBJECTS(args, 7);
10475 CHECK_OBJECT(kw_names);
10476 assert(PyTuple_CheckExact(kw_names));
10477 CHECK_OBJECT(called);
10478
10479 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10480
10481 CHECK_OBJECTS(&args[7], nkwargs);
10482
10483 if (Nuitka_Function_Check(called)) {
10484 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10485 return NULL;
10486 }
10487
10488 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10489
10490 PyObject *result =
10491 Nuitka_CallFunctionVectorcall(tstate, function, args, 7, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
10492
10493 Py_LeaveRecursiveCall();
10494
10495 CHECK_OBJECT_X(result);
10496
10497 return result;
10498#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10499 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10500 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10501
10502 if (likely(func != NULL)) {
10503 PyObject *result = func(called, args, 7, kw_names);
10504
10505 CHECK_OBJECT_X(result);
10506
10507 return Nuitka_CheckFunctionResult(tstate, called, result);
10508 }
10509#endif
10510 }
10511
10512#if 0
10513 PRINT_STRING("FALLBACK");
10514 PRINT_ITEM(called);
10515 PRINT_NEW_LINE();
10516#endif
10517
10518 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10519
10520 if (unlikely(call_slot == NULL)) {
10521 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10522
10523 return NULL;
10524 }
10525
10526 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10527 return NULL;
10528 }
10529
10530 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
10531
10532 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10533
10534 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10535 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10536
10537 PyObject *value = args[7 + i];
10538
10539 CHECK_OBJECT(key);
10540 CHECK_OBJECT(value);
10541
10542 DICT_SET_ITEM(named_args, key, value);
10543 }
10544
10545 PyObject *result = (*call_slot)(called, pos_args, named_args);
10546
10547 Py_DECREF(pos_args);
10548 Py_DECREF(named_args);
10549
10550 Py_LeaveRecursiveCall();
10551
10552 CHECK_OBJECT_X(result);
10553
10554 return Nuitka_CheckFunctionResult(tstate, called, result);
10555}
10556PyObject *CALL_FUNCTION_WITH_ARGS7_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10557 PyObject *const *kw_values, PyObject *kw_names) {
10558 CHECK_OBJECTS(args, 7);
10559 CHECK_OBJECT(kw_names);
10560 assert(PyTuple_CheckExact(kw_names));
10561 CHECK_OBJECT(called);
10562
10563 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10564
10565 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10566
10567 if (Nuitka_Function_Check(called)) {
10568 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10569 return NULL;
10570 }
10571
10572 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10573
10574 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 7, kw_values, kw_names);
10575
10576 Py_LeaveRecursiveCall();
10577
10578 CHECK_OBJECT_X(result);
10579
10580 return result;
10581#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10582 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10583 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10584
10585 if (likely(func != NULL)) {
10586 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 7 + nkwargs);
10587
10588 memcpy(vectorcall_args, args, 7 * sizeof(PyObject *));
10589 memcpy(&vectorcall_args[7], kw_values, nkwargs * sizeof(PyObject *));
10590
10591 PyObject *result = func(called, vectorcall_args, 7, kw_names);
10592
10593 CHECK_OBJECT_X(result);
10594
10595 return Nuitka_CheckFunctionResult(tstate, called, result);
10596 }
10597#endif
10598 }
10599
10600#if 0
10601 PRINT_STRING("FALLBACK");
10602 PRINT_ITEM(called);
10603 PRINT_NEW_LINE();
10604#endif
10605
10606 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10607
10608 if (unlikely(call_slot == NULL)) {
10609 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10610
10611 return NULL;
10612 }
10613
10614 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10615 return NULL;
10616 }
10617
10618 PyObject *pos_args = MAKE_TUPLE(tstate, args, 7);
10619
10620 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10621
10622 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10623 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10624
10625 PyObject *value = kw_values[i];
10626
10627 CHECK_OBJECT(key);
10628 CHECK_OBJECT(value);
10629
10630 DICT_SET_ITEM(named_args, key, value);
10631 }
10632
10633 PyObject *result = (*call_slot)(called, pos_args, named_args);
10634
10635 Py_DECREF(pos_args);
10636 Py_DECREF(named_args);
10637
10638 Py_LeaveRecursiveCall();
10639
10640 CHECK_OBJECT_X(result);
10641
10642 return Nuitka_CheckFunctionResult(tstate, called, result);
10643}
10644PyObject *CALL_FUNCTION_WITH_POS_ARGS7_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10645 PyObject *const *kw_values, PyObject *kw_names) {
10646 assert(PyTuple_CheckExact(pos_args));
10647 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10648 CHECK_OBJECTS(args, 7);
10649 CHECK_OBJECT(kw_names);
10650 assert(PyTuple_CheckExact(kw_names));
10651 CHECK_OBJECT(called);
10652
10653 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10654
10655 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10656
10657 if (Nuitka_Function_Check(called)) {
10658 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10659 return NULL;
10660 }
10661
10662 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10663
10664 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 7, kw_values, kw_names);
10665
10666 Py_LeaveRecursiveCall();
10667
10668 CHECK_OBJECT_X(result);
10669
10670 return result;
10671#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10672 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10673 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10674
10675 if (likely(func != NULL)) {
10676 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 7 + nkwargs);
10677
10678 memcpy(vectorcall_args, args, 7 * sizeof(PyObject *));
10679 memcpy(&vectorcall_args[7], kw_values, nkwargs * sizeof(PyObject *));
10680
10681 PyObject *result = func(called, vectorcall_args, 7, kw_names);
10682
10683 CHECK_OBJECT_X(result);
10684
10685 return Nuitka_CheckFunctionResult(tstate, called, result);
10686 }
10687#endif
10688 }
10689
10690#if 0
10691 PRINT_STRING("FALLBACK");
10692 PRINT_ITEM(called);
10693 PRINT_NEW_LINE();
10694#endif
10695
10696 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10697
10698 if (unlikely(call_slot == NULL)) {
10699 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10700
10701 return NULL;
10702 }
10703
10704 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10705 return NULL;
10706 }
10707
10708 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10709
10710 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10711 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10712
10713 PyObject *value = kw_values[i];
10714
10715 CHECK_OBJECT(key);
10716 CHECK_OBJECT(value);
10717
10718 DICT_SET_ITEM(named_args, key, value);
10719 }
10720
10721 PyObject *result = (*call_slot)(called, pos_args, named_args);
10722
10723 Py_DECREF(named_args);
10724
10725 Py_LeaveRecursiveCall();
10726
10727 CHECK_OBJECT_X(result);
10728
10729 return Nuitka_CheckFunctionResult(tstate, called, result);
10730}
10731PyObject *CALL_FUNCTION_WITH_ARGS8_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10732 PyObject *kw_names) {
10733 CHECK_OBJECTS(args, 8);
10734 CHECK_OBJECT(kw_names);
10735 assert(PyTuple_CheckExact(kw_names));
10736 CHECK_OBJECT(called);
10737
10738 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10739
10740 CHECK_OBJECTS(&args[8], nkwargs);
10741
10742 if (Nuitka_Function_Check(called)) {
10743 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10744 return NULL;
10745 }
10746
10747 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10748
10749 PyObject *result =
10750 Nuitka_CallFunctionVectorcall(tstate, function, args, 8, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
10751
10752 Py_LeaveRecursiveCall();
10753
10754 CHECK_OBJECT_X(result);
10755
10756 return result;
10757#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10758 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10759 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10760
10761 if (likely(func != NULL)) {
10762 PyObject *result = func(called, args, 8, kw_names);
10763
10764 CHECK_OBJECT_X(result);
10765
10766 return Nuitka_CheckFunctionResult(tstate, called, result);
10767 }
10768#endif
10769 }
10770
10771#if 0
10772 PRINT_STRING("FALLBACK");
10773 PRINT_ITEM(called);
10774 PRINT_NEW_LINE();
10775#endif
10776
10777 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10778
10779 if (unlikely(call_slot == NULL)) {
10780 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10781
10782 return NULL;
10783 }
10784
10785 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10786 return NULL;
10787 }
10788
10789 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
10790
10791 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10792
10793 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10794 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10795
10796 PyObject *value = args[8 + i];
10797
10798 CHECK_OBJECT(key);
10799 CHECK_OBJECT(value);
10800
10801 DICT_SET_ITEM(named_args, key, value);
10802 }
10803
10804 PyObject *result = (*call_slot)(called, pos_args, named_args);
10805
10806 Py_DECREF(pos_args);
10807 Py_DECREF(named_args);
10808
10809 Py_LeaveRecursiveCall();
10810
10811 CHECK_OBJECT_X(result);
10812
10813 return Nuitka_CheckFunctionResult(tstate, called, result);
10814}
10815PyObject *CALL_FUNCTION_WITH_ARGS8_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10816 PyObject *const *kw_values, PyObject *kw_names) {
10817 CHECK_OBJECTS(args, 8);
10818 CHECK_OBJECT(kw_names);
10819 assert(PyTuple_CheckExact(kw_names));
10820 CHECK_OBJECT(called);
10821
10822 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10823
10824 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10825
10826 if (Nuitka_Function_Check(called)) {
10827 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10828 return NULL;
10829 }
10830
10831 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10832
10833 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 8, kw_values, kw_names);
10834
10835 Py_LeaveRecursiveCall();
10836
10837 CHECK_OBJECT_X(result);
10838
10839 return result;
10840#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10841 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10842 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10843
10844 if (likely(func != NULL)) {
10845 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 8 + nkwargs);
10846
10847 memcpy(vectorcall_args, args, 8 * sizeof(PyObject *));
10848 memcpy(&vectorcall_args[8], kw_values, nkwargs * sizeof(PyObject *));
10849
10850 PyObject *result = func(called, vectorcall_args, 8, kw_names);
10851
10852 CHECK_OBJECT_X(result);
10853
10854 return Nuitka_CheckFunctionResult(tstate, called, result);
10855 }
10856#endif
10857 }
10858
10859#if 0
10860 PRINT_STRING("FALLBACK");
10861 PRINT_ITEM(called);
10862 PRINT_NEW_LINE();
10863#endif
10864
10865 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10866
10867 if (unlikely(call_slot == NULL)) {
10868 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10869
10870 return NULL;
10871 }
10872
10873 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10874 return NULL;
10875 }
10876
10877 PyObject *pos_args = MAKE_TUPLE(tstate, args, 8);
10878
10879 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10880
10881 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10882 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10883
10884 PyObject *value = kw_values[i];
10885
10886 CHECK_OBJECT(key);
10887 CHECK_OBJECT(value);
10888
10889 DICT_SET_ITEM(named_args, key, value);
10890 }
10891
10892 PyObject *result = (*call_slot)(called, pos_args, named_args);
10893
10894 Py_DECREF(pos_args);
10895 Py_DECREF(named_args);
10896
10897 Py_LeaveRecursiveCall();
10898
10899 CHECK_OBJECT_X(result);
10900
10901 return Nuitka_CheckFunctionResult(tstate, called, result);
10902}
10903PyObject *CALL_FUNCTION_WITH_POS_ARGS8_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
10904 PyObject *const *kw_values, PyObject *kw_names) {
10905 assert(PyTuple_CheckExact(pos_args));
10906 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
10907 CHECK_OBJECTS(args, 8);
10908 CHECK_OBJECT(kw_names);
10909 assert(PyTuple_CheckExact(kw_names));
10910 CHECK_OBJECT(called);
10911
10912 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10913
10914 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
10915
10916 if (Nuitka_Function_Check(called)) {
10917 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10918 return NULL;
10919 }
10920
10921 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
10922
10923 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 8, kw_values, kw_names);
10924
10925 Py_LeaveRecursiveCall();
10926
10927 CHECK_OBJECT_X(result);
10928
10929 return result;
10930#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
10931 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
10932 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
10933
10934 if (likely(func != NULL)) {
10935 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 8 + nkwargs);
10936
10937 memcpy(vectorcall_args, args, 8 * sizeof(PyObject *));
10938 memcpy(&vectorcall_args[8], kw_values, nkwargs * sizeof(PyObject *));
10939
10940 PyObject *result = func(called, vectorcall_args, 8, kw_names);
10941
10942 CHECK_OBJECT_X(result);
10943
10944 return Nuitka_CheckFunctionResult(tstate, called, result);
10945 }
10946#endif
10947 }
10948
10949#if 0
10950 PRINT_STRING("FALLBACK");
10951 PRINT_ITEM(called);
10952 PRINT_NEW_LINE();
10953#endif
10954
10955 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
10956
10957 if (unlikely(call_slot == NULL)) {
10958 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
10959
10960 return NULL;
10961 }
10962
10963 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
10964 return NULL;
10965 }
10966
10967 PyObject *named_args = _PyDict_NewPresized(nkwargs);
10968
10969 for (Py_ssize_t i = 0; i < nkwargs; i++) {
10970 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
10971
10972 PyObject *value = kw_values[i];
10973
10974 CHECK_OBJECT(key);
10975 CHECK_OBJECT(value);
10976
10977 DICT_SET_ITEM(named_args, key, value);
10978 }
10979
10980 PyObject *result = (*call_slot)(called, pos_args, named_args);
10981
10982 Py_DECREF(named_args);
10983
10984 Py_LeaveRecursiveCall();
10985
10986 CHECK_OBJECT_X(result);
10987
10988 return Nuitka_CheckFunctionResult(tstate, called, result);
10989}
10990PyObject *CALL_FUNCTION_WITH_ARGS9_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
10991 PyObject *kw_names) {
10992 CHECK_OBJECTS(args, 9);
10993 CHECK_OBJECT(kw_names);
10994 assert(PyTuple_CheckExact(kw_names));
10995 CHECK_OBJECT(called);
10996
10997 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
10998
10999 CHECK_OBJECTS(&args[9], nkwargs);
11000
11001 if (Nuitka_Function_Check(called)) {
11002 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11003 return NULL;
11004 }
11005
11006 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11007
11008 PyObject *result =
11009 Nuitka_CallFunctionVectorcall(tstate, function, args, 9, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
11010
11011 Py_LeaveRecursiveCall();
11012
11013 CHECK_OBJECT_X(result);
11014
11015 return result;
11016#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11017 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11018 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11019
11020 if (likely(func != NULL)) {
11021 PyObject *result = func(called, args, 9, kw_names);
11022
11023 CHECK_OBJECT_X(result);
11024
11025 return Nuitka_CheckFunctionResult(tstate, called, result);
11026 }
11027#endif
11028 }
11029
11030#if 0
11031 PRINT_STRING("FALLBACK");
11032 PRINT_ITEM(called);
11033 PRINT_NEW_LINE();
11034#endif
11035
11036 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11037
11038 if (unlikely(call_slot == NULL)) {
11039 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11040
11041 return NULL;
11042 }
11043
11044 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11045 return NULL;
11046 }
11047
11048 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
11049
11050 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11051
11052 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11053 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11054
11055 PyObject *value = args[9 + i];
11056
11057 CHECK_OBJECT(key);
11058 CHECK_OBJECT(value);
11059
11060 DICT_SET_ITEM(named_args, key, value);
11061 }
11062
11063 PyObject *result = (*call_slot)(called, pos_args, named_args);
11064
11065 Py_DECREF(pos_args);
11066 Py_DECREF(named_args);
11067
11068 Py_LeaveRecursiveCall();
11069
11070 CHECK_OBJECT_X(result);
11071
11072 return Nuitka_CheckFunctionResult(tstate, called, result);
11073}
11074PyObject *CALL_FUNCTION_WITH_ARGS9_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11075 PyObject *const *kw_values, PyObject *kw_names) {
11076 CHECK_OBJECTS(args, 9);
11077 CHECK_OBJECT(kw_names);
11078 assert(PyTuple_CheckExact(kw_names));
11079 CHECK_OBJECT(called);
11080
11081 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11082
11083 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11084
11085 if (Nuitka_Function_Check(called)) {
11086 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11087 return NULL;
11088 }
11089
11090 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11091
11092 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 9, kw_values, kw_names);
11093
11094 Py_LeaveRecursiveCall();
11095
11096 CHECK_OBJECT_X(result);
11097
11098 return result;
11099#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11100 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11101 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11102
11103 if (likely(func != NULL)) {
11104 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 9 + nkwargs);
11105
11106 memcpy(vectorcall_args, args, 9 * sizeof(PyObject *));
11107 memcpy(&vectorcall_args[9], kw_values, nkwargs * sizeof(PyObject *));
11108
11109 PyObject *result = func(called, vectorcall_args, 9, kw_names);
11110
11111 CHECK_OBJECT_X(result);
11112
11113 return Nuitka_CheckFunctionResult(tstate, called, result);
11114 }
11115#endif
11116 }
11117
11118#if 0
11119 PRINT_STRING("FALLBACK");
11120 PRINT_ITEM(called);
11121 PRINT_NEW_LINE();
11122#endif
11123
11124 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11125
11126 if (unlikely(call_slot == NULL)) {
11127 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11128
11129 return NULL;
11130 }
11131
11132 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11133 return NULL;
11134 }
11135
11136 PyObject *pos_args = MAKE_TUPLE(tstate, args, 9);
11137
11138 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11139
11140 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11141 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11142
11143 PyObject *value = kw_values[i];
11144
11145 CHECK_OBJECT(key);
11146 CHECK_OBJECT(value);
11147
11148 DICT_SET_ITEM(named_args, key, value);
11149 }
11150
11151 PyObject *result = (*call_slot)(called, pos_args, named_args);
11152
11153 Py_DECREF(pos_args);
11154 Py_DECREF(named_args);
11155
11156 Py_LeaveRecursiveCall();
11157
11158 CHECK_OBJECT_X(result);
11159
11160 return Nuitka_CheckFunctionResult(tstate, called, result);
11161}
11162PyObject *CALL_FUNCTION_WITH_POS_ARGS9_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
11163 PyObject *const *kw_values, PyObject *kw_names) {
11164 assert(PyTuple_CheckExact(pos_args));
11165 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
11166 CHECK_OBJECTS(args, 9);
11167 CHECK_OBJECT(kw_names);
11168 assert(PyTuple_CheckExact(kw_names));
11169 CHECK_OBJECT(called);
11170
11171 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11172
11173 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11174
11175 if (Nuitka_Function_Check(called)) {
11176 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11177 return NULL;
11178 }
11179
11180 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11181
11182 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 9, kw_values, kw_names);
11183
11184 Py_LeaveRecursiveCall();
11185
11186 CHECK_OBJECT_X(result);
11187
11188 return result;
11189#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11190 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11191 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11192
11193 if (likely(func != NULL)) {
11194 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 9 + nkwargs);
11195
11196 memcpy(vectorcall_args, args, 9 * sizeof(PyObject *));
11197 memcpy(&vectorcall_args[9], kw_values, nkwargs * sizeof(PyObject *));
11198
11199 PyObject *result = func(called, vectorcall_args, 9, kw_names);
11200
11201 CHECK_OBJECT_X(result);
11202
11203 return Nuitka_CheckFunctionResult(tstate, called, result);
11204 }
11205#endif
11206 }
11207
11208#if 0
11209 PRINT_STRING("FALLBACK");
11210 PRINT_ITEM(called);
11211 PRINT_NEW_LINE();
11212#endif
11213
11214 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11215
11216 if (unlikely(call_slot == NULL)) {
11217 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11218
11219 return NULL;
11220 }
11221
11222 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11223 return NULL;
11224 }
11225
11226 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11227
11228 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11229 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11230
11231 PyObject *value = kw_values[i];
11232
11233 CHECK_OBJECT(key);
11234 CHECK_OBJECT(value);
11235
11236 DICT_SET_ITEM(named_args, key, value);
11237 }
11238
11239 PyObject *result = (*call_slot)(called, pos_args, named_args);
11240
11241 Py_DECREF(named_args);
11242
11243 Py_LeaveRecursiveCall();
11244
11245 CHECK_OBJECT_X(result);
11246
11247 return Nuitka_CheckFunctionResult(tstate, called, result);
11248}
11249PyObject *CALL_FUNCTION_WITH_ARGS10_VECTORCALL(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11250 PyObject *kw_names) {
11251 CHECK_OBJECTS(args, 10);
11252 CHECK_OBJECT(kw_names);
11253 assert(PyTuple_CheckExact(kw_names));
11254 CHECK_OBJECT(called);
11255
11256 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11257
11258 CHECK_OBJECTS(&args[10], nkwargs);
11259
11260 if (Nuitka_Function_Check(called)) {
11261 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11262 return NULL;
11263 }
11264
11265 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11266
11267 PyObject *result =
11268 Nuitka_CallFunctionVectorcall(tstate, function, args, 10, &PyTuple_GET_ITEM(kw_names, 0), nkwargs);
11269
11270 Py_LeaveRecursiveCall();
11271
11272 CHECK_OBJECT_X(result);
11273
11274 return result;
11275#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11276 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11277 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11278
11279 if (likely(func != NULL)) {
11280 PyObject *result = func(called, args, 10, kw_names);
11281
11282 CHECK_OBJECT_X(result);
11283
11284 return Nuitka_CheckFunctionResult(tstate, called, result);
11285 }
11286#endif
11287 }
11288
11289#if 0
11290 PRINT_STRING("FALLBACK");
11291 PRINT_ITEM(called);
11292 PRINT_NEW_LINE();
11293#endif
11294
11295 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11296
11297 if (unlikely(call_slot == NULL)) {
11298 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11299
11300 return NULL;
11301 }
11302
11303 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11304 return NULL;
11305 }
11306
11307 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
11308
11309 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11310
11311 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11312 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11313
11314 PyObject *value = args[10 + i];
11315
11316 CHECK_OBJECT(key);
11317 CHECK_OBJECT(value);
11318
11319 DICT_SET_ITEM(named_args, key, value);
11320 }
11321
11322 PyObject *result = (*call_slot)(called, pos_args, named_args);
11323
11324 Py_DECREF(pos_args);
11325 Py_DECREF(named_args);
11326
11327 Py_LeaveRecursiveCall();
11328
11329 CHECK_OBJECT_X(result);
11330
11331 return Nuitka_CheckFunctionResult(tstate, called, result);
11332}
11333PyObject *CALL_FUNCTION_WITH_ARGS10_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *const *args,
11334 PyObject *const *kw_values, PyObject *kw_names) {
11335 CHECK_OBJECTS(args, 10);
11336 CHECK_OBJECT(kw_names);
11337 assert(PyTuple_CheckExact(kw_names));
11338 CHECK_OBJECT(called);
11339
11340 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11341
11342 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11343
11344 if (Nuitka_Function_Check(called)) {
11345 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11346 return NULL;
11347 }
11348
11349 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11350
11351 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 10, kw_values, kw_names);
11352
11353 Py_LeaveRecursiveCall();
11354
11355 CHECK_OBJECT_X(result);
11356
11357 return result;
11358#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11359 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11360 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11361
11362 if (likely(func != NULL)) {
11363 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 10 + nkwargs);
11364
11365 memcpy(vectorcall_args, args, 10 * sizeof(PyObject *));
11366 memcpy(&vectorcall_args[10], kw_values, nkwargs * sizeof(PyObject *));
11367
11368 PyObject *result = func(called, vectorcall_args, 10, kw_names);
11369
11370 CHECK_OBJECT_X(result);
11371
11372 return Nuitka_CheckFunctionResult(tstate, called, result);
11373 }
11374#endif
11375 }
11376
11377#if 0
11378 PRINT_STRING("FALLBACK");
11379 PRINT_ITEM(called);
11380 PRINT_NEW_LINE();
11381#endif
11382
11383 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11384
11385 if (unlikely(call_slot == NULL)) {
11386 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11387
11388 return NULL;
11389 }
11390
11391 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11392 return NULL;
11393 }
11394
11395 PyObject *pos_args = MAKE_TUPLE(tstate, args, 10);
11396
11397 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11398
11399 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11400 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11401
11402 PyObject *value = kw_values[i];
11403
11404 CHECK_OBJECT(key);
11405 CHECK_OBJECT(value);
11406
11407 DICT_SET_ITEM(named_args, key, value);
11408 }
11409
11410 PyObject *result = (*call_slot)(called, pos_args, named_args);
11411
11412 Py_DECREF(pos_args);
11413 Py_DECREF(named_args);
11414
11415 Py_LeaveRecursiveCall();
11416
11417 CHECK_OBJECT_X(result);
11418
11419 return Nuitka_CheckFunctionResult(tstate, called, result);
11420}
11421PyObject *CALL_FUNCTION_WITH_POS_ARGS10_KW_SPLIT(PyThreadState *tstate, PyObject *called, PyObject *pos_args,
11422 PyObject *const *kw_values, PyObject *kw_names) {
11423 assert(PyTuple_CheckExact(pos_args));
11424 PyObject *const *args = &PyTuple_GET_ITEM(pos_args, 0);
11425 CHECK_OBJECTS(args, 10);
11426 CHECK_OBJECT(kw_names);
11427 assert(PyTuple_CheckExact(kw_names));
11428 CHECK_OBJECT(called);
11429
11430 Py_ssize_t nkwargs = PyTuple_GET_SIZE(kw_names);
11431
11432 CHECK_OBJECTS(kw_values, PyTuple_GET_SIZE(kw_names));
11433
11434 if (Nuitka_Function_Check(called)) {
11435 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11436 return NULL;
11437 }
11438
11439 struct Nuitka_FunctionObject *function = (struct Nuitka_FunctionObject *)called;
11440
11441 PyObject *result = Nuitka_CallFunctionPosArgsKwSplit(tstate, function, args, 10, kw_values, kw_names);
11442
11443 Py_LeaveRecursiveCall();
11444
11445 CHECK_OBJECT_X(result);
11446
11447 return result;
11448#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11449 } else if (PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL)) {
11450 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11451
11452 if (likely(func != NULL)) {
11453 NUITKA_DYNAMIC_ARRAY_DECL(vectorcall_args, PyObject *, 10 + nkwargs);
11454
11455 memcpy(vectorcall_args, args, 10 * sizeof(PyObject *));
11456 memcpy(&vectorcall_args[10], kw_values, nkwargs * sizeof(PyObject *));
11457
11458 PyObject *result = func(called, vectorcall_args, 10, kw_names);
11459
11460 CHECK_OBJECT_X(result);
11461
11462 return Nuitka_CheckFunctionResult(tstate, called, result);
11463 }
11464#endif
11465 }
11466
11467#if 0
11468 PRINT_STRING("FALLBACK");
11469 PRINT_ITEM(called);
11470 PRINT_NEW_LINE();
11471#endif
11472
11473 ternaryfunc call_slot = Py_TYPE(called)->tp_call;
11474
11475 if (unlikely(call_slot == NULL)) {
11476 SET_CURRENT_EXCEPTION_TYPE_COMPLAINT("'%s' object is not callable", called);
11477
11478 return NULL;
11479 }
11480
11481 if (unlikely(Py_EnterRecursiveCall((char *)" while calling a Python object"))) {
11482 return NULL;
11483 }
11484
11485 PyObject *named_args = _PyDict_NewPresized(nkwargs);
11486
11487 for (Py_ssize_t i = 0; i < nkwargs; i++) {
11488 PyObject *key = PyTuple_GET_ITEM(kw_names, i);
11489
11490 PyObject *value = kw_values[i];
11491
11492 CHECK_OBJECT(key);
11493 CHECK_OBJECT(value);
11494
11495 DICT_SET_ITEM(named_args, key, value);
11496 }
11497
11498 PyObject *result = (*call_slot)(called, pos_args, named_args);
11499
11500 Py_DECREF(named_args);
11501
11502 Py_LeaveRecursiveCall();
11503
11504 CHECK_OBJECT_X(result);
11505
11506 return Nuitka_CheckFunctionResult(tstate, called, result);
11507}
11508PyObject *CALL_METHODDESCR_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *called, PyObject *arg) {
11509 PyObject *const *args = &arg; // For easier code compatibility.
11510 CHECK_OBJECT(called);
11511 CHECK_OBJECTS(args, 1);
11512
11513#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11514 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11515 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11516 assert(func != NULL);
11517 PyObject *result = func(called, args, 1, NULL);
11518
11519#ifndef __NUITKA_NO_ASSERT__
11520 return Nuitka_CheckFunctionResult(tstate, called, result);
11521#else
11522 return result;
11523#endif
11524#else
11525 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11526 PyMethodDef *method_def = called_descr->d_method;
11527
11528 // Try to be fast about wrapping the arguments.
11529 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11530
11531 if (likely(flags & METH_NOARGS)) {
11532 PyCFunction method = method_def->ml_meth;
11533 PyObject *self = args[0];
11534
11535 PyObject *result = (*method)(self, NULL);
11536
11537#ifndef __NUITKA_NO_ASSERT__
11538 return Nuitka_CheckFunctionResult(tstate, called, result);
11539#else
11540 return result;
11541#endif
11542 } else if ((flags & METH_O)) {
11543 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (1 given)",
11544 method_def->ml_name);
11545 return NULL;
11546 } else if (flags & METH_VARARGS) {
11547 PyCFunction method = method_def->ml_meth;
11548 PyObject *self = args[0];
11549
11550 PyObject *result;
11551
11552#if PYTHON_VERSION < 0x360
11553 if (flags & METH_KEYWORDS) {
11554 result = (*(PyCFunctionWithKeywords)method)(self, const_tuple_empty, NULL);
11555 } else {
11556 result = (*method)(self, const_tuple_empty);
11557 }
11558#else
11559 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11560 result = (*(PyCFunctionWithKeywords)method)(self, const_tuple_empty, NULL);
11561 } else if (flags == METH_FASTCALL) {
11562#if PYTHON_VERSION < 0x370
11563 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 0, NULL);
11564#else
11565 result = (*(_PyCFunctionFast)method)(self, &const_tuple_empty, 1);
11566#endif
11567 } else {
11568 result = (*method)(self, const_tuple_empty);
11569 }
11570#endif
11571#ifndef __NUITKA_NO_ASSERT__
11572 return Nuitka_CheckFunctionResult(tstate, called, result);
11573#else
11574 return result;
11575#endif
11576 }
11577
11578#if 0
11579 PRINT_NEW_LINE();
11580 PRINT_STRING("FALLBACK");
11581 PRINT_ITEM(called);
11582 PRINT_NEW_LINE();
11583#endif
11584
11585 PyObject *pos_args = MAKE_TUPLE(tstate, args, 1);
11586
11587 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11588
11589 Py_DECREF(pos_args);
11590
11591 return result;
11592#endif
11593}
11594PyObject *CALL_METHODDESCR_WITH_ARGS2(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11595 CHECK_OBJECT(called);
11596 CHECK_OBJECTS(args, 2);
11597
11598#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11599 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11600 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11601 assert(func != NULL);
11602 PyObject *result = func(called, args, 2, NULL);
11603
11604#ifndef __NUITKA_NO_ASSERT__
11605 return Nuitka_CheckFunctionResult(tstate, called, result);
11606#else
11607 return result;
11608#endif
11609#else
11610 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11611 PyMethodDef *method_def = called_descr->d_method;
11612
11613 // Try to be fast about wrapping the arguments.
11614 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11615
11616 if (unlikely(flags & METH_NOARGS)) {
11617 PyCFunction method = method_def->ml_meth;
11618 PyObject *self = args[0];
11619
11620 PyObject *result = (*method)(self, NULL);
11621
11622#ifndef __NUITKA_NO_ASSERT__
11623 return Nuitka_CheckFunctionResult(tstate, called, result);
11624#else
11625 return result;
11626#endif
11627 } else if (unlikely(flags & METH_O)) {
11628 PyCFunction method = method_def->ml_meth;
11629 PyObject *self = args[0];
11630
11631 PyObject *result = (*method)(self, args[1]);
11632
11633#ifndef __NUITKA_NO_ASSERT__
11634 return Nuitka_CheckFunctionResult(tstate, called, result);
11635#else
11636 return result;
11637#endif
11638 } else if (flags & METH_VARARGS) {
11639 PyCFunction method = method_def->ml_meth;
11640 PyObject *self = args[0];
11641
11642 PyObject *result;
11643
11644#if PYTHON_VERSION < 0x360
11645 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11646
11647 if (flags & METH_KEYWORDS) {
11648 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11649 } else {
11650 result = (*method)(self, pos_args);
11651 }
11652
11653 Py_DECREF(pos_args);
11654#else
11655 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11656 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11657 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11658 Py_DECREF(pos_args);
11659 } else if (flags == METH_FASTCALL) {
11660#if PYTHON_VERSION < 0x370
11661 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 1, NULL);
11662#else
11663 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11664 result = (*(_PyCFunctionFast)method)(self, &pos_args, 2);
11665 Py_DECREF(pos_args);
11666#endif
11667 } else {
11668 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 1);
11669 result = (*method)(self, pos_args);
11670 Py_DECREF(pos_args);
11671 }
11672#endif
11673#ifndef __NUITKA_NO_ASSERT__
11674 return Nuitka_CheckFunctionResult(tstate, called, result);
11675#else
11676 return result;
11677#endif
11678 }
11679
11680#if 0
11681 PRINT_NEW_LINE();
11682 PRINT_STRING("FALLBACK");
11683 PRINT_ITEM(called);
11684 PRINT_NEW_LINE();
11685#endif
11686
11687 PyObject *pos_args = MAKE_TUPLE(tstate, args, 2);
11688
11689 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11690
11691 Py_DECREF(pos_args);
11692
11693 return result;
11694#endif
11695}
11696PyObject *CALL_METHODDESCR_WITH_ARGS3(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11697 CHECK_OBJECT(called);
11698 CHECK_OBJECTS(args, 3);
11699
11700#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11701 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11702 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11703 assert(func != NULL);
11704 PyObject *result = func(called, args, 3, NULL);
11705
11706#ifndef __NUITKA_NO_ASSERT__
11707 return Nuitka_CheckFunctionResult(tstate, called, result);
11708#else
11709 return result;
11710#endif
11711#else
11712 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11713 PyMethodDef *method_def = called_descr->d_method;
11714
11715 // Try to be fast about wrapping the arguments.
11716 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11717
11718 if (unlikely(flags & METH_NOARGS)) {
11719 PyCFunction method = method_def->ml_meth;
11720 PyObject *self = args[0];
11721
11722 PyObject *result = (*method)(self, NULL);
11723
11724#ifndef __NUITKA_NO_ASSERT__
11725 return Nuitka_CheckFunctionResult(tstate, called, result);
11726#else
11727 return result;
11728#endif
11729 } else if (unlikely(flags & METH_O)) {
11730 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (3 given)",
11731 method_def->ml_name);
11732 return NULL;
11733 } else if (flags & METH_VARARGS) {
11734 PyCFunction method = method_def->ml_meth;
11735 PyObject *self = args[0];
11736
11737 PyObject *result;
11738
11739#if PYTHON_VERSION < 0x360
11740 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11741
11742 if (flags & METH_KEYWORDS) {
11743 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11744 } else {
11745 result = (*method)(self, pos_args);
11746 }
11747
11748 Py_DECREF(pos_args);
11749#else
11750 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11751 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11752 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11753 Py_DECREF(pos_args);
11754 } else if (flags == METH_FASTCALL) {
11755#if PYTHON_VERSION < 0x370
11756 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 2, NULL);
11757#else
11758 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11759 result = (*(_PyCFunctionFast)method)(self, &pos_args, 3);
11760 Py_DECREF(pos_args);
11761#endif
11762 } else {
11763 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 2);
11764 result = (*method)(self, pos_args);
11765 Py_DECREF(pos_args);
11766 }
11767#endif
11768#ifndef __NUITKA_NO_ASSERT__
11769 return Nuitka_CheckFunctionResult(tstate, called, result);
11770#else
11771 return result;
11772#endif
11773 }
11774
11775#if 0
11776 PRINT_NEW_LINE();
11777 PRINT_STRING("FALLBACK");
11778 PRINT_ITEM(called);
11779 PRINT_NEW_LINE();
11780#endif
11781
11782 PyObject *pos_args = MAKE_TUPLE(tstate, args, 3);
11783
11784 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11785
11786 Py_DECREF(pos_args);
11787
11788 return result;
11789#endif
11790}
11791PyObject *CALL_METHODDESCR_WITH_ARGS4(PyThreadState *tstate, PyObject *called, PyObject *const *args) {
11792 CHECK_OBJECT(called);
11793 CHECK_OBJECTS(args, 4);
11794
11795#if PYTHON_VERSION >= 0x380 && !defined(_NUITKA_EXPERIMENTAL_DISABLE_VECTORCALL_USAGE)
11796 assert(PyType_HasFeature(Py_TYPE(called), _Py_TPFLAGS_HAVE_VECTORCALL));
11797 vectorcallfunc func = *((vectorcallfunc *)(((char *)called) + Py_TYPE(called)->tp_vectorcall_offset));
11798 assert(func != NULL);
11799 PyObject *result = func(called, args, 4, NULL);
11800
11801#ifndef __NUITKA_NO_ASSERT__
11802 return Nuitka_CheckFunctionResult(tstate, called, result);
11803#else
11804 return result;
11805#endif
11806#else
11807 PyMethodDescrObject *called_descr = (PyMethodDescrObject *)called;
11808 PyMethodDef *method_def = called_descr->d_method;
11809
11810 // Try to be fast about wrapping the arguments.
11811 int flags = method_def->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
11812
11813 if (unlikely(flags & METH_NOARGS)) {
11814 PyCFunction method = method_def->ml_meth;
11815 PyObject *self = args[0];
11816
11817 PyObject *result = (*method)(self, NULL);
11818
11819#ifndef __NUITKA_NO_ASSERT__
11820 return Nuitka_CheckFunctionResult(tstate, called, result);
11821#else
11822 return result;
11823#endif
11824 } else if (unlikely(flags & METH_O)) {
11825 SET_CURRENT_EXCEPTION_TYPE0_FORMAT1(PyExc_TypeError, "%s() takes exactly one argument (4 given)",
11826 method_def->ml_name);
11827 return NULL;
11828 } else if (flags & METH_VARARGS) {
11829 PyCFunction method = method_def->ml_meth;
11830 PyObject *self = args[0];
11831
11832 PyObject *result;
11833
11834#if PYTHON_VERSION < 0x360
11835 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11836
11837 if (flags & METH_KEYWORDS) {
11838 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11839 } else {
11840 result = (*method)(self, pos_args);
11841 }
11842
11843 Py_DECREF(pos_args);
11844#else
11845 if (flags == (METH_VARARGS | METH_KEYWORDS)) {
11846 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11847 result = (*(PyCFunctionWithKeywords)method)(self, pos_args, NULL);
11848 Py_DECREF(pos_args);
11849 } else if (flags == METH_FASTCALL) {
11850#if PYTHON_VERSION < 0x370
11851 result = (*(_PyCFunctionFast)method)(self, (PyObject **)args + 1, 3, NULL);
11852#else
11853 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11854 result = (*(_PyCFunctionFast)method)(self, &pos_args, 4);
11855 Py_DECREF(pos_args);
11856#endif
11857 } else {
11858 PyObject *pos_args = MAKE_TUPLE(tstate, args + 1, 3);
11859 result = (*method)(self, pos_args);
11860 Py_DECREF(pos_args);
11861 }
11862#endif
11863#ifndef __NUITKA_NO_ASSERT__
11864 return Nuitka_CheckFunctionResult(tstate, called, result);
11865#else
11866 return result;
11867#endif
11868 }
11869
11870#if 0
11871 PRINT_NEW_LINE();
11872 PRINT_STRING("FALLBACK");
11873 PRINT_ITEM(called);
11874 PRINT_NEW_LINE();
11875#endif
11876
11877 PyObject *pos_args = MAKE_TUPLE(tstate, args, 4);
11878
11879 PyObject *result = CALL_FUNCTION(tstate, called, pos_args, NULL);
11880
11881 Py_DECREF(pos_args);
11882
11883 return result;
11884#endif
11885}
11886PyObject *CALL_METHOD_NO_ARGS(PyThreadState *tstate, PyObject *source, PyObject *attr_name) {
11887 CHECK_OBJECT(source);
11888 CHECK_OBJECT(attr_name);
11889
11890 PyTypeObject *type = Py_TYPE(source);
11891
11892 if (hasTypeGenericGetAttr(type)) {
11893 // Unfortunately this is required, although of cause rarely necessary.
11894 if (unlikely(type->tp_dict == NULL)) {
11895 if (unlikely(PyType_Ready(type) < 0)) {
11896 return NULL;
11897 }
11898 }
11899
11900 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
11901 descrgetfunc func = NULL;
11902
11903 if (descr != NULL) {
11904 Py_INCREF(descr);
11905
11906 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
11907 func = Py_TYPE(descr)->tp_descr_get;
11908
11909 if (func != NULL && Nuitka_Descr_IsData(descr)) {
11910 PyObject *called_object = func(descr, source, (PyObject *)type);
11911 Py_DECREF(descr);
11912
11913 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11914 Py_DECREF(called_object);
11915 return result;
11916 }
11917 }
11918 }
11919
11920 Py_ssize_t dictoffset = type->tp_dictoffset;
11921 PyObject *dict = NULL;
11922
11923 if (dictoffset != 0) {
11924 // Negative dictionary offsets have special meaning.
11925 if (dictoffset < 0) {
11926 Py_ssize_t tsize;
11927 size_t size;
11928
11929 tsize = ((PyVarObject *)source)->ob_size;
11930 if (tsize < 0) {
11931 tsize = -tsize;
11932 }
11933 size = _PyObject_VAR_SIZE(type, tsize);
11934
11935 dictoffset += (long)size;
11936 }
11937
11938 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
11939 dict = *dictptr;
11940 }
11941
11942 if (dict != NULL) {
11943 CHECK_OBJECT(dict);
11944
11945 Py_INCREF(dict);
11946
11947 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
11948
11949 if (called_object != NULL) {
11950 Py_XDECREF(descr);
11951 Py_DECREF(dict);
11952
11953 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11954 Py_DECREF(called_object);
11955 return result;
11956 }
11957
11958 Py_DECREF(dict);
11959 }
11960
11961 if (func != NULL) {
11962 if (func == Nuitka_Function_Type.tp_descr_get) {
11963 PyObject *result =
11964 Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)descr, source);
11965 Py_DECREF(descr);
11966
11967 return result;
11968 } else {
11969 PyObject *called_object = func(descr, source, (PyObject *)type);
11970 CHECK_OBJECT(called_object);
11971
11972 Py_DECREF(descr);
11973
11974 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
11975 Py_DECREF(called_object);
11976 return result;
11977 }
11978 }
11979
11980 if (descr != NULL) {
11981 CHECK_OBJECT(descr);
11982
11983 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, descr);
11984 Py_DECREF(descr);
11985 return result;
11986 }
11987
11988#if PYTHON_VERSION < 0x300
11989 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
11990 PyString_AS_STRING(attr_name));
11991#else
11992 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
11993#endif
11994 return NULL;
11995 }
11996#if PYTHON_VERSION < 0x300
11997 else if (type == &PyInstance_Type) {
11998 PyInstanceObject *source_instance = (PyInstanceObject *)source;
11999
12000 // The special cases have their own variant on the code generation level
12001 // as we are called with constants only.
12002 assert(attr_name != const_str_plain___dict__);
12003 assert(attr_name != const_str_plain___class__);
12004
12005 // Try the instance dict first.
12006 PyObject *called_object =
12007 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12008
12009 // Note: The "called_object" was found without taking a reference,
12010 // so we need not release it in this branch.
12011 if (called_object != NULL) {
12012 return CALL_FUNCTION_NO_ARGS(tstate, called_object);
12013 }
12014
12015 // Then check the class dictionaries.
12016 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12017
12018 // Note: The "called_object" was found without taking a reference,
12019 // so we need not release it in this branch.
12020 if (called_object != NULL) {
12021 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12022
12023 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12024 return Nuitka_CallMethodFunctionNoArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12025 source);
12026 } else if (descr_get != NULL) {
12027 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12028
12029 if (unlikely(method == NULL)) {
12030 return NULL;
12031 }
12032
12033 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, method);
12034 Py_DECREF(method);
12035 return result;
12036 } else {
12037 return CALL_FUNCTION_NO_ARGS(tstate, called_object);
12038 }
12039
12040 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12041 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12042 PyString_AS_STRING(source_instance->in_class->cl_name),
12043 PyString_AS_STRING(attr_name));
12044
12045 return NULL;
12046 } else {
12047 // Finally allow the "__getattr__" override to provide it or else
12048 // it's an error.
12049
12050 PyObject *args2[] = {source, attr_name};
12051
12052 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12053
12054 if (unlikely(called_object == NULL)) {
12055 return NULL;
12056 }
12057
12058 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12059 Py_DECREF(called_object);
12060 return result;
12061 }
12062 }
12063#endif
12064 else if (type->tp_getattro != NULL) {
12065 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12066
12067 if (unlikely(descr == NULL)) {
12068 return NULL;
12069 }
12070
12071 descrgetfunc func = NULL;
12072 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12073 func = Py_TYPE(descr)->tp_descr_get;
12074
12075 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12076 PyObject *called_object = func(descr, source, (PyObject *)type);
12077 Py_DECREF(descr);
12078
12079 if (unlikely(called_object == NULL)) {
12080 return NULL;
12081 }
12082
12083 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12084 Py_DECREF(called_object);
12085 return result;
12086 }
12087 }
12088
12089 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, descr);
12090 Py_DECREF(descr);
12091 return result;
12092 } else if (type->tp_getattr != NULL) {
12093 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12094
12095 if (unlikely(called_object == NULL)) {
12096 return NULL;
12097 }
12098
12099 PyObject *result = CALL_FUNCTION_NO_ARGS(tstate, called_object);
12100 Py_DECREF(called_object);
12101 return result;
12102 } else {
12103 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12104 Nuitka_String_AsString_Unchecked(attr_name));
12105
12106 return NULL;
12107 }
12108}
12109PyObject *CALL_METHOD_WITH_SINGLE_ARG(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *arg) {
12110 PyObject *const *args = &arg; // For easier code compatibility.
12111 CHECK_OBJECT(source);
12112 CHECK_OBJECT(attr_name);
12113
12114 CHECK_OBJECTS(args, 1);
12115
12116 PyTypeObject *type = Py_TYPE(source);
12117
12118 if (hasTypeGenericGetAttr(type)) {
12119 // Unfortunately this is required, although of cause rarely necessary.
12120 if (unlikely(type->tp_dict == NULL)) {
12121 if (unlikely(PyType_Ready(type) < 0)) {
12122 return NULL;
12123 }
12124 }
12125
12126 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12127 descrgetfunc func = NULL;
12128
12129 if (descr != NULL) {
12130 Py_INCREF(descr);
12131
12132 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12133 func = Py_TYPE(descr)->tp_descr_get;
12134
12135 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12136 PyObject *called_object = func(descr, source, (PyObject *)type);
12137 Py_DECREF(descr);
12138
12139 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12140 Py_DECREF(called_object);
12141 return result;
12142 }
12143 }
12144 }
12145
12146 Py_ssize_t dictoffset = type->tp_dictoffset;
12147 PyObject *dict = NULL;
12148
12149 if (dictoffset != 0) {
12150 // Negative dictionary offsets have special meaning.
12151 if (dictoffset < 0) {
12152 Py_ssize_t tsize;
12153 size_t size;
12154
12155 tsize = ((PyVarObject *)source)->ob_size;
12156 if (tsize < 0) {
12157 tsize = -tsize;
12158 }
12159 size = _PyObject_VAR_SIZE(type, tsize);
12160
12161 dictoffset += (long)size;
12162 }
12163
12164 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12165 dict = *dictptr;
12166 }
12167
12168 if (dict != NULL) {
12169 CHECK_OBJECT(dict);
12170
12171 Py_INCREF(dict);
12172
12173 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12174
12175 if (called_object != NULL) {
12176 Py_XDECREF(descr);
12177 Py_DECREF(dict);
12178
12179 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12180 Py_DECREF(called_object);
12181 return result;
12182 }
12183
12184 Py_DECREF(dict);
12185 }
12186
12187 if (func != NULL) {
12188 if (func == Nuitka_Function_Type.tp_descr_get) {
12189 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12190 source, args, 1);
12191 Py_DECREF(descr);
12192
12193 return result;
12194 } else {
12195 PyObject *called_object = func(descr, source, (PyObject *)type);
12196 CHECK_OBJECT(called_object);
12197
12198 Py_DECREF(descr);
12199
12200 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12201 Py_DECREF(called_object);
12202 return result;
12203 }
12204 }
12205
12206 if (descr != NULL) {
12207 CHECK_OBJECT(descr);
12208
12209 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, descr, args[0]);
12210 Py_DECREF(descr);
12211 return result;
12212 }
12213
12214#if PYTHON_VERSION < 0x300
12215 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12216 PyString_AS_STRING(attr_name));
12217#else
12218 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12219#endif
12220 return NULL;
12221 }
12222#if PYTHON_VERSION < 0x300
12223 else if (type == &PyInstance_Type) {
12224 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12225
12226 // The special cases have their own variant on the code generation level
12227 // as we are called with constants only.
12228 assert(attr_name != const_str_plain___dict__);
12229 assert(attr_name != const_str_plain___class__);
12230
12231 // Try the instance dict first.
12232 PyObject *called_object =
12233 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12234
12235 // Note: The "called_object" was found without taking a reference,
12236 // so we need not release it in this branch.
12237 if (called_object != NULL) {
12238 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12239 }
12240
12241 // Then check the class dictionaries.
12242 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12243
12244 // Note: The "called_object" was found without taking a reference,
12245 // so we need not release it in this branch.
12246 if (called_object != NULL) {
12247 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12248
12249 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12250 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12251 source, args, 1);
12252 } else if (descr_get != NULL) {
12253 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12254
12255 if (unlikely(method == NULL)) {
12256 return NULL;
12257 }
12258
12259 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, method, args[0]);
12260 Py_DECREF(method);
12261 return result;
12262 } else {
12263 return CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12264 }
12265
12266 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12267 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12268 PyString_AS_STRING(source_instance->in_class->cl_name),
12269 PyString_AS_STRING(attr_name));
12270
12271 return NULL;
12272 } else {
12273 // Finally allow the "__getattr__" override to provide it or else
12274 // it's an error.
12275
12276 PyObject *args2[] = {source, attr_name};
12277
12278 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12279
12280 if (unlikely(called_object == NULL)) {
12281 return NULL;
12282 }
12283
12284 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12285 Py_DECREF(called_object);
12286 return result;
12287 }
12288 }
12289#endif
12290 else if (type->tp_getattro != NULL) {
12291 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12292
12293 if (unlikely(descr == NULL)) {
12294 return NULL;
12295 }
12296
12297 descrgetfunc func = NULL;
12298 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12299 func = Py_TYPE(descr)->tp_descr_get;
12300
12301 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12302 PyObject *called_object = func(descr, source, (PyObject *)type);
12303 Py_DECREF(descr);
12304
12305 if (unlikely(called_object == NULL)) {
12306 return NULL;
12307 }
12308
12309 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12310 Py_DECREF(called_object);
12311 return result;
12312 }
12313 }
12314
12315 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, descr, args[0]);
12316 Py_DECREF(descr);
12317 return result;
12318 } else if (type->tp_getattr != NULL) {
12319 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12320
12321 if (unlikely(called_object == NULL)) {
12322 return NULL;
12323 }
12324
12325 PyObject *result = CALL_FUNCTION_WITH_SINGLE_ARG(tstate, called_object, args[0]);
12326 Py_DECREF(called_object);
12327 return result;
12328 } else {
12329 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12330 Nuitka_String_AsString_Unchecked(attr_name));
12331
12332 return NULL;
12333 }
12334}
12335PyObject *CALL_METHOD_WITH_ARGS2(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12336 CHECK_OBJECT(source);
12337 CHECK_OBJECT(attr_name);
12338
12339 CHECK_OBJECTS(args, 2);
12340
12341 PyTypeObject *type = Py_TYPE(source);
12342
12343 if (hasTypeGenericGetAttr(type)) {
12344 // Unfortunately this is required, although of cause rarely necessary.
12345 if (unlikely(type->tp_dict == NULL)) {
12346 if (unlikely(PyType_Ready(type) < 0)) {
12347 return NULL;
12348 }
12349 }
12350
12351 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12352 descrgetfunc func = NULL;
12353
12354 if (descr != NULL) {
12355 Py_INCREF(descr);
12356
12357 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12358 func = Py_TYPE(descr)->tp_descr_get;
12359
12360 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12361 PyObject *called_object = func(descr, source, (PyObject *)type);
12362 Py_DECREF(descr);
12363
12364 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12365 Py_DECREF(called_object);
12366 return result;
12367 }
12368 }
12369 }
12370
12371 Py_ssize_t dictoffset = type->tp_dictoffset;
12372 PyObject *dict = NULL;
12373
12374 if (dictoffset != 0) {
12375 // Negative dictionary offsets have special meaning.
12376 if (dictoffset < 0) {
12377 Py_ssize_t tsize;
12378 size_t size;
12379
12380 tsize = ((PyVarObject *)source)->ob_size;
12381 if (tsize < 0) {
12382 tsize = -tsize;
12383 }
12384 size = _PyObject_VAR_SIZE(type, tsize);
12385
12386 dictoffset += (long)size;
12387 }
12388
12389 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12390 dict = *dictptr;
12391 }
12392
12393 if (dict != NULL) {
12394 CHECK_OBJECT(dict);
12395
12396 Py_INCREF(dict);
12397
12398 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12399
12400 if (called_object != NULL) {
12401 Py_XDECREF(descr);
12402 Py_DECREF(dict);
12403
12404 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12405 Py_DECREF(called_object);
12406 return result;
12407 }
12408
12409 Py_DECREF(dict);
12410 }
12411
12412 if (func != NULL) {
12413 if (func == Nuitka_Function_Type.tp_descr_get) {
12414 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12415 source, args, 2);
12416 Py_DECREF(descr);
12417
12418 return result;
12419 } else {
12420 PyObject *called_object = func(descr, source, (PyObject *)type);
12421 CHECK_OBJECT(called_object);
12422
12423 Py_DECREF(descr);
12424
12425 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12426 Py_DECREF(called_object);
12427 return result;
12428 }
12429 }
12430
12431 if (descr != NULL) {
12432 CHECK_OBJECT(descr);
12433
12434 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, descr, args);
12435 Py_DECREF(descr);
12436 return result;
12437 }
12438
12439#if PYTHON_VERSION < 0x300
12440 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12441 PyString_AS_STRING(attr_name));
12442#else
12443 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12444#endif
12445 return NULL;
12446 }
12447#if PYTHON_VERSION < 0x300
12448 else if (type == &PyInstance_Type) {
12449 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12450
12451 // The special cases have their own variant on the code generation level
12452 // as we are called with constants only.
12453 assert(attr_name != const_str_plain___dict__);
12454 assert(attr_name != const_str_plain___class__);
12455
12456 // Try the instance dict first.
12457 PyObject *called_object =
12458 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12459
12460 // Note: The "called_object" was found without taking a reference,
12461 // so we need not release it in this branch.
12462 if (called_object != NULL) {
12463 return CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12464 }
12465
12466 // Then check the class dictionaries.
12467 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12468
12469 // Note: The "called_object" was found without taking a reference,
12470 // so we need not release it in this branch.
12471 if (called_object != NULL) {
12472 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12473
12474 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12475 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12476 source, args, 2);
12477 } else if (descr_get != NULL) {
12478 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12479
12480 if (unlikely(method == NULL)) {
12481 return NULL;
12482 }
12483
12484 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, method, args);
12485 Py_DECREF(method);
12486 return result;
12487 } else {
12488 return CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12489 }
12490
12491 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12492 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12493 PyString_AS_STRING(source_instance->in_class->cl_name),
12494 PyString_AS_STRING(attr_name));
12495
12496 return NULL;
12497 } else {
12498 // Finally allow the "__getattr__" override to provide it or else
12499 // it's an error.
12500
12501 PyObject *args2[] = {source, attr_name};
12502
12503 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12504
12505 if (unlikely(called_object == NULL)) {
12506 return NULL;
12507 }
12508
12509 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12510 Py_DECREF(called_object);
12511 return result;
12512 }
12513 }
12514#endif
12515 else if (type->tp_getattro != NULL) {
12516 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12517
12518 if (unlikely(descr == NULL)) {
12519 return NULL;
12520 }
12521
12522 descrgetfunc func = NULL;
12523 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12524 func = Py_TYPE(descr)->tp_descr_get;
12525
12526 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12527 PyObject *called_object = func(descr, source, (PyObject *)type);
12528 Py_DECREF(descr);
12529
12530 if (unlikely(called_object == NULL)) {
12531 return NULL;
12532 }
12533
12534 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12535 Py_DECREF(called_object);
12536 return result;
12537 }
12538 }
12539
12540 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, descr, args);
12541 Py_DECREF(descr);
12542 return result;
12543 } else if (type->tp_getattr != NULL) {
12544 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12545
12546 if (unlikely(called_object == NULL)) {
12547 return NULL;
12548 }
12549
12550 PyObject *result = CALL_FUNCTION_WITH_ARGS2(tstate, called_object, args);
12551 Py_DECREF(called_object);
12552 return result;
12553 } else {
12554 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12555 Nuitka_String_AsString_Unchecked(attr_name));
12556
12557 return NULL;
12558 }
12559}
12560PyObject *CALL_METHOD_WITH_ARGS3(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12561 CHECK_OBJECT(source);
12562 CHECK_OBJECT(attr_name);
12563
12564 CHECK_OBJECTS(args, 3);
12565
12566 PyTypeObject *type = Py_TYPE(source);
12567
12568 if (hasTypeGenericGetAttr(type)) {
12569 // Unfortunately this is required, although of cause rarely necessary.
12570 if (unlikely(type->tp_dict == NULL)) {
12571 if (unlikely(PyType_Ready(type) < 0)) {
12572 return NULL;
12573 }
12574 }
12575
12576 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12577 descrgetfunc func = NULL;
12578
12579 if (descr != NULL) {
12580 Py_INCREF(descr);
12581
12582 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12583 func = Py_TYPE(descr)->tp_descr_get;
12584
12585 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12586 PyObject *called_object = func(descr, source, (PyObject *)type);
12587 Py_DECREF(descr);
12588
12589 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12590 Py_DECREF(called_object);
12591 return result;
12592 }
12593 }
12594 }
12595
12596 Py_ssize_t dictoffset = type->tp_dictoffset;
12597 PyObject *dict = NULL;
12598
12599 if (dictoffset != 0) {
12600 // Negative dictionary offsets have special meaning.
12601 if (dictoffset < 0) {
12602 Py_ssize_t tsize;
12603 size_t size;
12604
12605 tsize = ((PyVarObject *)source)->ob_size;
12606 if (tsize < 0) {
12607 tsize = -tsize;
12608 }
12609 size = _PyObject_VAR_SIZE(type, tsize);
12610
12611 dictoffset += (long)size;
12612 }
12613
12614 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12615 dict = *dictptr;
12616 }
12617
12618 if (dict != NULL) {
12619 CHECK_OBJECT(dict);
12620
12621 Py_INCREF(dict);
12622
12623 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12624
12625 if (called_object != NULL) {
12626 Py_XDECREF(descr);
12627 Py_DECREF(dict);
12628
12629 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12630 Py_DECREF(called_object);
12631 return result;
12632 }
12633
12634 Py_DECREF(dict);
12635 }
12636
12637 if (func != NULL) {
12638 if (func == Nuitka_Function_Type.tp_descr_get) {
12639 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12640 source, args, 3);
12641 Py_DECREF(descr);
12642
12643 return result;
12644 } else {
12645 PyObject *called_object = func(descr, source, (PyObject *)type);
12646 CHECK_OBJECT(called_object);
12647
12648 Py_DECREF(descr);
12649
12650 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12651 Py_DECREF(called_object);
12652 return result;
12653 }
12654 }
12655
12656 if (descr != NULL) {
12657 CHECK_OBJECT(descr);
12658
12659 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, descr, args);
12660 Py_DECREF(descr);
12661 return result;
12662 }
12663
12664#if PYTHON_VERSION < 0x300
12665 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12666 PyString_AS_STRING(attr_name));
12667#else
12668 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12669#endif
12670 return NULL;
12671 }
12672#if PYTHON_VERSION < 0x300
12673 else if (type == &PyInstance_Type) {
12674 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12675
12676 // The special cases have their own variant on the code generation level
12677 // as we are called with constants only.
12678 assert(attr_name != const_str_plain___dict__);
12679 assert(attr_name != const_str_plain___class__);
12680
12681 // Try the instance dict first.
12682 PyObject *called_object =
12683 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12684
12685 // Note: The "called_object" was found without taking a reference,
12686 // so we need not release it in this branch.
12687 if (called_object != NULL) {
12688 return CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12689 }
12690
12691 // Then check the class dictionaries.
12692 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12693
12694 // Note: The "called_object" was found without taking a reference,
12695 // so we need not release it in this branch.
12696 if (called_object != NULL) {
12697 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12698
12699 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12700 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12701 source, args, 3);
12702 } else if (descr_get != NULL) {
12703 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12704
12705 if (unlikely(method == NULL)) {
12706 return NULL;
12707 }
12708
12709 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, method, args);
12710 Py_DECREF(method);
12711 return result;
12712 } else {
12713 return CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12714 }
12715
12716 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12717 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12718 PyString_AS_STRING(source_instance->in_class->cl_name),
12719 PyString_AS_STRING(attr_name));
12720
12721 return NULL;
12722 } else {
12723 // Finally allow the "__getattr__" override to provide it or else
12724 // it's an error.
12725
12726 PyObject *args2[] = {source, attr_name};
12727
12728 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12729
12730 if (unlikely(called_object == NULL)) {
12731 return NULL;
12732 }
12733
12734 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12735 Py_DECREF(called_object);
12736 return result;
12737 }
12738 }
12739#endif
12740 else if (type->tp_getattro != NULL) {
12741 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12742
12743 if (unlikely(descr == NULL)) {
12744 return NULL;
12745 }
12746
12747 descrgetfunc func = NULL;
12748 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12749 func = Py_TYPE(descr)->tp_descr_get;
12750
12751 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12752 PyObject *called_object = func(descr, source, (PyObject *)type);
12753 Py_DECREF(descr);
12754
12755 if (unlikely(called_object == NULL)) {
12756 return NULL;
12757 }
12758
12759 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12760 Py_DECREF(called_object);
12761 return result;
12762 }
12763 }
12764
12765 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, descr, args);
12766 Py_DECREF(descr);
12767 return result;
12768 } else if (type->tp_getattr != NULL) {
12769 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12770
12771 if (unlikely(called_object == NULL)) {
12772 return NULL;
12773 }
12774
12775 PyObject *result = CALL_FUNCTION_WITH_ARGS3(tstate, called_object, args);
12776 Py_DECREF(called_object);
12777 return result;
12778 } else {
12779 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12780 Nuitka_String_AsString_Unchecked(attr_name));
12781
12782 return NULL;
12783 }
12784}
12785PyObject *CALL_METHOD_WITH_ARGS4(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
12786 CHECK_OBJECT(source);
12787 CHECK_OBJECT(attr_name);
12788
12789 CHECK_OBJECTS(args, 4);
12790
12791 PyTypeObject *type = Py_TYPE(source);
12792
12793 if (hasTypeGenericGetAttr(type)) {
12794 // Unfortunately this is required, although of cause rarely necessary.
12795 if (unlikely(type->tp_dict == NULL)) {
12796 if (unlikely(PyType_Ready(type) < 0)) {
12797 return NULL;
12798 }
12799 }
12800
12801 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
12802 descrgetfunc func = NULL;
12803
12804 if (descr != NULL) {
12805 Py_INCREF(descr);
12806
12807 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12808 func = Py_TYPE(descr)->tp_descr_get;
12809
12810 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12811 PyObject *called_object = func(descr, source, (PyObject *)type);
12812 Py_DECREF(descr);
12813
12814 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12815 Py_DECREF(called_object);
12816 return result;
12817 }
12818 }
12819 }
12820
12821 Py_ssize_t dictoffset = type->tp_dictoffset;
12822 PyObject *dict = NULL;
12823
12824 if (dictoffset != 0) {
12825 // Negative dictionary offsets have special meaning.
12826 if (dictoffset < 0) {
12827 Py_ssize_t tsize;
12828 size_t size;
12829
12830 tsize = ((PyVarObject *)source)->ob_size;
12831 if (tsize < 0) {
12832 tsize = -tsize;
12833 }
12834 size = _PyObject_VAR_SIZE(type, tsize);
12835
12836 dictoffset += (long)size;
12837 }
12838
12839 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
12840 dict = *dictptr;
12841 }
12842
12843 if (dict != NULL) {
12844 CHECK_OBJECT(dict);
12845
12846 Py_INCREF(dict);
12847
12848 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
12849
12850 if (called_object != NULL) {
12851 Py_XDECREF(descr);
12852 Py_DECREF(dict);
12853
12854 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12855 Py_DECREF(called_object);
12856 return result;
12857 }
12858
12859 Py_DECREF(dict);
12860 }
12861
12862 if (func != NULL) {
12863 if (func == Nuitka_Function_Type.tp_descr_get) {
12864 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
12865 source, args, 4);
12866 Py_DECREF(descr);
12867
12868 return result;
12869 } else {
12870 PyObject *called_object = func(descr, source, (PyObject *)type);
12871 CHECK_OBJECT(called_object);
12872
12873 Py_DECREF(descr);
12874
12875 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12876 Py_DECREF(called_object);
12877 return result;
12878 }
12879 }
12880
12881 if (descr != NULL) {
12882 CHECK_OBJECT(descr);
12883
12884 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, descr, args);
12885 Py_DECREF(descr);
12886 return result;
12887 }
12888
12889#if PYTHON_VERSION < 0x300
12890 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
12891 PyString_AS_STRING(attr_name));
12892#else
12893 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
12894#endif
12895 return NULL;
12896 }
12897#if PYTHON_VERSION < 0x300
12898 else if (type == &PyInstance_Type) {
12899 PyInstanceObject *source_instance = (PyInstanceObject *)source;
12900
12901 // The special cases have their own variant on the code generation level
12902 // as we are called with constants only.
12903 assert(attr_name != const_str_plain___dict__);
12904 assert(attr_name != const_str_plain___class__);
12905
12906 // Try the instance dict first.
12907 PyObject *called_object =
12908 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
12909
12910 // Note: The "called_object" was found without taking a reference,
12911 // so we need not release it in this branch.
12912 if (called_object != NULL) {
12913 return CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12914 }
12915
12916 // Then check the class dictionaries.
12917 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
12918
12919 // Note: The "called_object" was found without taking a reference,
12920 // so we need not release it in this branch.
12921 if (called_object != NULL) {
12922 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
12923
12924 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
12925 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
12926 source, args, 4);
12927 } else if (descr_get != NULL) {
12928 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
12929
12930 if (unlikely(method == NULL)) {
12931 return NULL;
12932 }
12933
12934 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, method, args);
12935 Py_DECREF(method);
12936 return result;
12937 } else {
12938 return CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12939 }
12940
12941 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
12942 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
12943 PyString_AS_STRING(source_instance->in_class->cl_name),
12944 PyString_AS_STRING(attr_name));
12945
12946 return NULL;
12947 } else {
12948 // Finally allow the "__getattr__" override to provide it or else
12949 // it's an error.
12950
12951 PyObject *args2[] = {source, attr_name};
12952
12953 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
12954
12955 if (unlikely(called_object == NULL)) {
12956 return NULL;
12957 }
12958
12959 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12960 Py_DECREF(called_object);
12961 return result;
12962 }
12963 }
12964#endif
12965 else if (type->tp_getattro != NULL) {
12966 PyObject *descr = (*type->tp_getattro)(source, attr_name);
12967
12968 if (unlikely(descr == NULL)) {
12969 return NULL;
12970 }
12971
12972 descrgetfunc func = NULL;
12973 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
12974 func = Py_TYPE(descr)->tp_descr_get;
12975
12976 if (func != NULL && Nuitka_Descr_IsData(descr)) {
12977 PyObject *called_object = func(descr, source, (PyObject *)type);
12978 Py_DECREF(descr);
12979
12980 if (unlikely(called_object == NULL)) {
12981 return NULL;
12982 }
12983
12984 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
12985 Py_DECREF(called_object);
12986 return result;
12987 }
12988 }
12989
12990 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, descr, args);
12991 Py_DECREF(descr);
12992 return result;
12993 } else if (type->tp_getattr != NULL) {
12994 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
12995
12996 if (unlikely(called_object == NULL)) {
12997 return NULL;
12998 }
12999
13000 PyObject *result = CALL_FUNCTION_WITH_ARGS4(tstate, called_object, args);
13001 Py_DECREF(called_object);
13002 return result;
13003 } else {
13004 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13005 Nuitka_String_AsString_Unchecked(attr_name));
13006
13007 return NULL;
13008 }
13009}
13010PyObject *CALL_METHOD_WITH_ARGS5(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13011 CHECK_OBJECT(source);
13012 CHECK_OBJECT(attr_name);
13013
13014 CHECK_OBJECTS(args, 5);
13015
13016 PyTypeObject *type = Py_TYPE(source);
13017
13018 if (hasTypeGenericGetAttr(type)) {
13019 // Unfortunately this is required, although of cause rarely necessary.
13020 if (unlikely(type->tp_dict == NULL)) {
13021 if (unlikely(PyType_Ready(type) < 0)) {
13022 return NULL;
13023 }
13024 }
13025
13026 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13027 descrgetfunc func = NULL;
13028
13029 if (descr != NULL) {
13030 Py_INCREF(descr);
13031
13032 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13033 func = Py_TYPE(descr)->tp_descr_get;
13034
13035 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13036 PyObject *called_object = func(descr, source, (PyObject *)type);
13037 Py_DECREF(descr);
13038
13039 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13040 Py_DECREF(called_object);
13041 return result;
13042 }
13043 }
13044 }
13045
13046 Py_ssize_t dictoffset = type->tp_dictoffset;
13047 PyObject *dict = NULL;
13048
13049 if (dictoffset != 0) {
13050 // Negative dictionary offsets have special meaning.
13051 if (dictoffset < 0) {
13052 Py_ssize_t tsize;
13053 size_t size;
13054
13055 tsize = ((PyVarObject *)source)->ob_size;
13056 if (tsize < 0) {
13057 tsize = -tsize;
13058 }
13059 size = _PyObject_VAR_SIZE(type, tsize);
13060
13061 dictoffset += (long)size;
13062 }
13063
13064 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13065 dict = *dictptr;
13066 }
13067
13068 if (dict != NULL) {
13069 CHECK_OBJECT(dict);
13070
13071 Py_INCREF(dict);
13072
13073 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13074
13075 if (called_object != NULL) {
13076 Py_XDECREF(descr);
13077 Py_DECREF(dict);
13078
13079 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13080 Py_DECREF(called_object);
13081 return result;
13082 }
13083
13084 Py_DECREF(dict);
13085 }
13086
13087 if (func != NULL) {
13088 if (func == Nuitka_Function_Type.tp_descr_get) {
13089 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13090 source, args, 5);
13091 Py_DECREF(descr);
13092
13093 return result;
13094 } else {
13095 PyObject *called_object = func(descr, source, (PyObject *)type);
13096 CHECK_OBJECT(called_object);
13097
13098 Py_DECREF(descr);
13099
13100 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13101 Py_DECREF(called_object);
13102 return result;
13103 }
13104 }
13105
13106 if (descr != NULL) {
13107 CHECK_OBJECT(descr);
13108
13109 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, descr, args);
13110 Py_DECREF(descr);
13111 return result;
13112 }
13113
13114#if PYTHON_VERSION < 0x300
13115 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13116 PyString_AS_STRING(attr_name));
13117#else
13118 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13119#endif
13120 return NULL;
13121 }
13122#if PYTHON_VERSION < 0x300
13123 else if (type == &PyInstance_Type) {
13124 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13125
13126 // The special cases have their own variant on the code generation level
13127 // as we are called with constants only.
13128 assert(attr_name != const_str_plain___dict__);
13129 assert(attr_name != const_str_plain___class__);
13130
13131 // Try the instance dict first.
13132 PyObject *called_object =
13133 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13134
13135 // Note: The "called_object" was found without taking a reference,
13136 // so we need not release it in this branch.
13137 if (called_object != NULL) {
13138 return CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13139 }
13140
13141 // Then check the class dictionaries.
13142 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13143
13144 // Note: The "called_object" was found without taking a reference,
13145 // so we need not release it in this branch.
13146 if (called_object != NULL) {
13147 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13148
13149 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13150 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13151 source, args, 5);
13152 } else if (descr_get != NULL) {
13153 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13154
13155 if (unlikely(method == NULL)) {
13156 return NULL;
13157 }
13158
13159 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, method, args);
13160 Py_DECREF(method);
13161 return result;
13162 } else {
13163 return CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13164 }
13165
13166 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13167 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13168 PyString_AS_STRING(source_instance->in_class->cl_name),
13169 PyString_AS_STRING(attr_name));
13170
13171 return NULL;
13172 } else {
13173 // Finally allow the "__getattr__" override to provide it or else
13174 // it's an error.
13175
13176 PyObject *args2[] = {source, attr_name};
13177
13178 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13179
13180 if (unlikely(called_object == NULL)) {
13181 return NULL;
13182 }
13183
13184 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13185 Py_DECREF(called_object);
13186 return result;
13187 }
13188 }
13189#endif
13190 else if (type->tp_getattro != NULL) {
13191 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13192
13193 if (unlikely(descr == NULL)) {
13194 return NULL;
13195 }
13196
13197 descrgetfunc func = NULL;
13198 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13199 func = Py_TYPE(descr)->tp_descr_get;
13200
13201 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13202 PyObject *called_object = func(descr, source, (PyObject *)type);
13203 Py_DECREF(descr);
13204
13205 if (unlikely(called_object == NULL)) {
13206 return NULL;
13207 }
13208
13209 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13210 Py_DECREF(called_object);
13211 return result;
13212 }
13213 }
13214
13215 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, descr, args);
13216 Py_DECREF(descr);
13217 return result;
13218 } else if (type->tp_getattr != NULL) {
13219 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13220
13221 if (unlikely(called_object == NULL)) {
13222 return NULL;
13223 }
13224
13225 PyObject *result = CALL_FUNCTION_WITH_ARGS5(tstate, called_object, args);
13226 Py_DECREF(called_object);
13227 return result;
13228 } else {
13229 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13230 Nuitka_String_AsString_Unchecked(attr_name));
13231
13232 return NULL;
13233 }
13234}
13235PyObject *CALL_METHOD_WITH_ARGS6(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13236 CHECK_OBJECT(source);
13237 CHECK_OBJECT(attr_name);
13238
13239 CHECK_OBJECTS(args, 6);
13240
13241 PyTypeObject *type = Py_TYPE(source);
13242
13243 if (hasTypeGenericGetAttr(type)) {
13244 // Unfortunately this is required, although of cause rarely necessary.
13245 if (unlikely(type->tp_dict == NULL)) {
13246 if (unlikely(PyType_Ready(type) < 0)) {
13247 return NULL;
13248 }
13249 }
13250
13251 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13252 descrgetfunc func = NULL;
13253
13254 if (descr != NULL) {
13255 Py_INCREF(descr);
13256
13257 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13258 func = Py_TYPE(descr)->tp_descr_get;
13259
13260 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13261 PyObject *called_object = func(descr, source, (PyObject *)type);
13262 Py_DECREF(descr);
13263
13264 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13265 Py_DECREF(called_object);
13266 return result;
13267 }
13268 }
13269 }
13270
13271 Py_ssize_t dictoffset = type->tp_dictoffset;
13272 PyObject *dict = NULL;
13273
13274 if (dictoffset != 0) {
13275 // Negative dictionary offsets have special meaning.
13276 if (dictoffset < 0) {
13277 Py_ssize_t tsize;
13278 size_t size;
13279
13280 tsize = ((PyVarObject *)source)->ob_size;
13281 if (tsize < 0) {
13282 tsize = -tsize;
13283 }
13284 size = _PyObject_VAR_SIZE(type, tsize);
13285
13286 dictoffset += (long)size;
13287 }
13288
13289 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13290 dict = *dictptr;
13291 }
13292
13293 if (dict != NULL) {
13294 CHECK_OBJECT(dict);
13295
13296 Py_INCREF(dict);
13297
13298 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13299
13300 if (called_object != NULL) {
13301 Py_XDECREF(descr);
13302 Py_DECREF(dict);
13303
13304 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13305 Py_DECREF(called_object);
13306 return result;
13307 }
13308
13309 Py_DECREF(dict);
13310 }
13311
13312 if (func != NULL) {
13313 if (func == Nuitka_Function_Type.tp_descr_get) {
13314 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13315 source, args, 6);
13316 Py_DECREF(descr);
13317
13318 return result;
13319 } else {
13320 PyObject *called_object = func(descr, source, (PyObject *)type);
13321 CHECK_OBJECT(called_object);
13322
13323 Py_DECREF(descr);
13324
13325 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13326 Py_DECREF(called_object);
13327 return result;
13328 }
13329 }
13330
13331 if (descr != NULL) {
13332 CHECK_OBJECT(descr);
13333
13334 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, descr, args);
13335 Py_DECREF(descr);
13336 return result;
13337 }
13338
13339#if PYTHON_VERSION < 0x300
13340 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13341 PyString_AS_STRING(attr_name));
13342#else
13343 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13344#endif
13345 return NULL;
13346 }
13347#if PYTHON_VERSION < 0x300
13348 else if (type == &PyInstance_Type) {
13349 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13350
13351 // The special cases have their own variant on the code generation level
13352 // as we are called with constants only.
13353 assert(attr_name != const_str_plain___dict__);
13354 assert(attr_name != const_str_plain___class__);
13355
13356 // Try the instance dict first.
13357 PyObject *called_object =
13358 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13359
13360 // Note: The "called_object" was found without taking a reference,
13361 // so we need not release it in this branch.
13362 if (called_object != NULL) {
13363 return CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13364 }
13365
13366 // Then check the class dictionaries.
13367 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13368
13369 // Note: The "called_object" was found without taking a reference,
13370 // so we need not release it in this branch.
13371 if (called_object != NULL) {
13372 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13373
13374 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13375 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13376 source, args, 6);
13377 } else if (descr_get != NULL) {
13378 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13379
13380 if (unlikely(method == NULL)) {
13381 return NULL;
13382 }
13383
13384 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, method, args);
13385 Py_DECREF(method);
13386 return result;
13387 } else {
13388 return CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13389 }
13390
13391 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13392 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13393 PyString_AS_STRING(source_instance->in_class->cl_name),
13394 PyString_AS_STRING(attr_name));
13395
13396 return NULL;
13397 } else {
13398 // Finally allow the "__getattr__" override to provide it or else
13399 // it's an error.
13400
13401 PyObject *args2[] = {source, attr_name};
13402
13403 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13404
13405 if (unlikely(called_object == NULL)) {
13406 return NULL;
13407 }
13408
13409 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13410 Py_DECREF(called_object);
13411 return result;
13412 }
13413 }
13414#endif
13415 else if (type->tp_getattro != NULL) {
13416 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13417
13418 if (unlikely(descr == NULL)) {
13419 return NULL;
13420 }
13421
13422 descrgetfunc func = NULL;
13423 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13424 func = Py_TYPE(descr)->tp_descr_get;
13425
13426 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13427 PyObject *called_object = func(descr, source, (PyObject *)type);
13428 Py_DECREF(descr);
13429
13430 if (unlikely(called_object == NULL)) {
13431 return NULL;
13432 }
13433
13434 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13435 Py_DECREF(called_object);
13436 return result;
13437 }
13438 }
13439
13440 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, descr, args);
13441 Py_DECREF(descr);
13442 return result;
13443 } else if (type->tp_getattr != NULL) {
13444 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13445
13446 if (unlikely(called_object == NULL)) {
13447 return NULL;
13448 }
13449
13450 PyObject *result = CALL_FUNCTION_WITH_ARGS6(tstate, called_object, args);
13451 Py_DECREF(called_object);
13452 return result;
13453 } else {
13454 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13455 Nuitka_String_AsString_Unchecked(attr_name));
13456
13457 return NULL;
13458 }
13459}
13460PyObject *CALL_METHOD_WITH_ARGS7(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13461 CHECK_OBJECT(source);
13462 CHECK_OBJECT(attr_name);
13463
13464 CHECK_OBJECTS(args, 7);
13465
13466 PyTypeObject *type = Py_TYPE(source);
13467
13468 if (hasTypeGenericGetAttr(type)) {
13469 // Unfortunately this is required, although of cause rarely necessary.
13470 if (unlikely(type->tp_dict == NULL)) {
13471 if (unlikely(PyType_Ready(type) < 0)) {
13472 return NULL;
13473 }
13474 }
13475
13476 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13477 descrgetfunc func = NULL;
13478
13479 if (descr != NULL) {
13480 Py_INCREF(descr);
13481
13482 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13483 func = Py_TYPE(descr)->tp_descr_get;
13484
13485 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13486 PyObject *called_object = func(descr, source, (PyObject *)type);
13487 Py_DECREF(descr);
13488
13489 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13490 Py_DECREF(called_object);
13491 return result;
13492 }
13493 }
13494 }
13495
13496 Py_ssize_t dictoffset = type->tp_dictoffset;
13497 PyObject *dict = NULL;
13498
13499 if (dictoffset != 0) {
13500 // Negative dictionary offsets have special meaning.
13501 if (dictoffset < 0) {
13502 Py_ssize_t tsize;
13503 size_t size;
13504
13505 tsize = ((PyVarObject *)source)->ob_size;
13506 if (tsize < 0) {
13507 tsize = -tsize;
13508 }
13509 size = _PyObject_VAR_SIZE(type, tsize);
13510
13511 dictoffset += (long)size;
13512 }
13513
13514 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13515 dict = *dictptr;
13516 }
13517
13518 if (dict != NULL) {
13519 CHECK_OBJECT(dict);
13520
13521 Py_INCREF(dict);
13522
13523 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13524
13525 if (called_object != NULL) {
13526 Py_XDECREF(descr);
13527 Py_DECREF(dict);
13528
13529 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13530 Py_DECREF(called_object);
13531 return result;
13532 }
13533
13534 Py_DECREF(dict);
13535 }
13536
13537 if (func != NULL) {
13538 if (func == Nuitka_Function_Type.tp_descr_get) {
13539 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13540 source, args, 7);
13541 Py_DECREF(descr);
13542
13543 return result;
13544 } else {
13545 PyObject *called_object = func(descr, source, (PyObject *)type);
13546 CHECK_OBJECT(called_object);
13547
13548 Py_DECREF(descr);
13549
13550 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13551 Py_DECREF(called_object);
13552 return result;
13553 }
13554 }
13555
13556 if (descr != NULL) {
13557 CHECK_OBJECT(descr);
13558
13559 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, descr, args);
13560 Py_DECREF(descr);
13561 return result;
13562 }
13563
13564#if PYTHON_VERSION < 0x300
13565 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13566 PyString_AS_STRING(attr_name));
13567#else
13568 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13569#endif
13570 return NULL;
13571 }
13572#if PYTHON_VERSION < 0x300
13573 else if (type == &PyInstance_Type) {
13574 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13575
13576 // The special cases have their own variant on the code generation level
13577 // as we are called with constants only.
13578 assert(attr_name != const_str_plain___dict__);
13579 assert(attr_name != const_str_plain___class__);
13580
13581 // Try the instance dict first.
13582 PyObject *called_object =
13583 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13584
13585 // Note: The "called_object" was found without taking a reference,
13586 // so we need not release it in this branch.
13587 if (called_object != NULL) {
13588 return CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13589 }
13590
13591 // Then check the class dictionaries.
13592 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13593
13594 // Note: The "called_object" was found without taking a reference,
13595 // so we need not release it in this branch.
13596 if (called_object != NULL) {
13597 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13598
13599 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13600 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13601 source, args, 7);
13602 } else if (descr_get != NULL) {
13603 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13604
13605 if (unlikely(method == NULL)) {
13606 return NULL;
13607 }
13608
13609 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, method, args);
13610 Py_DECREF(method);
13611 return result;
13612 } else {
13613 return CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13614 }
13615
13616 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13617 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13618 PyString_AS_STRING(source_instance->in_class->cl_name),
13619 PyString_AS_STRING(attr_name));
13620
13621 return NULL;
13622 } else {
13623 // Finally allow the "__getattr__" override to provide it or else
13624 // it's an error.
13625
13626 PyObject *args2[] = {source, attr_name};
13627
13628 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13629
13630 if (unlikely(called_object == NULL)) {
13631 return NULL;
13632 }
13633
13634 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13635 Py_DECREF(called_object);
13636 return result;
13637 }
13638 }
13639#endif
13640 else if (type->tp_getattro != NULL) {
13641 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13642
13643 if (unlikely(descr == NULL)) {
13644 return NULL;
13645 }
13646
13647 descrgetfunc func = NULL;
13648 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13649 func = Py_TYPE(descr)->tp_descr_get;
13650
13651 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13652 PyObject *called_object = func(descr, source, (PyObject *)type);
13653 Py_DECREF(descr);
13654
13655 if (unlikely(called_object == NULL)) {
13656 return NULL;
13657 }
13658
13659 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13660 Py_DECREF(called_object);
13661 return result;
13662 }
13663 }
13664
13665 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, descr, args);
13666 Py_DECREF(descr);
13667 return result;
13668 } else if (type->tp_getattr != NULL) {
13669 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13670
13671 if (unlikely(called_object == NULL)) {
13672 return NULL;
13673 }
13674
13675 PyObject *result = CALL_FUNCTION_WITH_ARGS7(tstate, called_object, args);
13676 Py_DECREF(called_object);
13677 return result;
13678 } else {
13679 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13680 Nuitka_String_AsString_Unchecked(attr_name));
13681
13682 return NULL;
13683 }
13684}
13685PyObject *CALL_METHOD_WITH_ARGS8(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13686 CHECK_OBJECT(source);
13687 CHECK_OBJECT(attr_name);
13688
13689 CHECK_OBJECTS(args, 8);
13690
13691 PyTypeObject *type = Py_TYPE(source);
13692
13693 if (hasTypeGenericGetAttr(type)) {
13694 // Unfortunately this is required, although of cause rarely necessary.
13695 if (unlikely(type->tp_dict == NULL)) {
13696 if (unlikely(PyType_Ready(type) < 0)) {
13697 return NULL;
13698 }
13699 }
13700
13701 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13702 descrgetfunc func = NULL;
13703
13704 if (descr != NULL) {
13705 Py_INCREF(descr);
13706
13707 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13708 func = Py_TYPE(descr)->tp_descr_get;
13709
13710 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13711 PyObject *called_object = func(descr, source, (PyObject *)type);
13712 Py_DECREF(descr);
13713
13714 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13715 Py_DECREF(called_object);
13716 return result;
13717 }
13718 }
13719 }
13720
13721 Py_ssize_t dictoffset = type->tp_dictoffset;
13722 PyObject *dict = NULL;
13723
13724 if (dictoffset != 0) {
13725 // Negative dictionary offsets have special meaning.
13726 if (dictoffset < 0) {
13727 Py_ssize_t tsize;
13728 size_t size;
13729
13730 tsize = ((PyVarObject *)source)->ob_size;
13731 if (tsize < 0) {
13732 tsize = -tsize;
13733 }
13734 size = _PyObject_VAR_SIZE(type, tsize);
13735
13736 dictoffset += (long)size;
13737 }
13738
13739 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13740 dict = *dictptr;
13741 }
13742
13743 if (dict != NULL) {
13744 CHECK_OBJECT(dict);
13745
13746 Py_INCREF(dict);
13747
13748 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13749
13750 if (called_object != NULL) {
13751 Py_XDECREF(descr);
13752 Py_DECREF(dict);
13753
13754 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13755 Py_DECREF(called_object);
13756 return result;
13757 }
13758
13759 Py_DECREF(dict);
13760 }
13761
13762 if (func != NULL) {
13763 if (func == Nuitka_Function_Type.tp_descr_get) {
13764 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13765 source, args, 8);
13766 Py_DECREF(descr);
13767
13768 return result;
13769 } else {
13770 PyObject *called_object = func(descr, source, (PyObject *)type);
13771 CHECK_OBJECT(called_object);
13772
13773 Py_DECREF(descr);
13774
13775 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13776 Py_DECREF(called_object);
13777 return result;
13778 }
13779 }
13780
13781 if (descr != NULL) {
13782 CHECK_OBJECT(descr);
13783
13784 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, descr, args);
13785 Py_DECREF(descr);
13786 return result;
13787 }
13788
13789#if PYTHON_VERSION < 0x300
13790 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13791 PyString_AS_STRING(attr_name));
13792#else
13793 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
13794#endif
13795 return NULL;
13796 }
13797#if PYTHON_VERSION < 0x300
13798 else if (type == &PyInstance_Type) {
13799 PyInstanceObject *source_instance = (PyInstanceObject *)source;
13800
13801 // The special cases have their own variant on the code generation level
13802 // as we are called with constants only.
13803 assert(attr_name != const_str_plain___dict__);
13804 assert(attr_name != const_str_plain___class__);
13805
13806 // Try the instance dict first.
13807 PyObject *called_object =
13808 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
13809
13810 // Note: The "called_object" was found without taking a reference,
13811 // so we need not release it in this branch.
13812 if (called_object != NULL) {
13813 return CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13814 }
13815
13816 // Then check the class dictionaries.
13817 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
13818
13819 // Note: The "called_object" was found without taking a reference,
13820 // so we need not release it in this branch.
13821 if (called_object != NULL) {
13822 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
13823
13824 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
13825 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
13826 source, args, 8);
13827 } else if (descr_get != NULL) {
13828 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
13829
13830 if (unlikely(method == NULL)) {
13831 return NULL;
13832 }
13833
13834 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, method, args);
13835 Py_DECREF(method);
13836 return result;
13837 } else {
13838 return CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13839 }
13840
13841 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
13842 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
13843 PyString_AS_STRING(source_instance->in_class->cl_name),
13844 PyString_AS_STRING(attr_name));
13845
13846 return NULL;
13847 } else {
13848 // Finally allow the "__getattr__" override to provide it or else
13849 // it's an error.
13850
13851 PyObject *args2[] = {source, attr_name};
13852
13853 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
13854
13855 if (unlikely(called_object == NULL)) {
13856 return NULL;
13857 }
13858
13859 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13860 Py_DECREF(called_object);
13861 return result;
13862 }
13863 }
13864#endif
13865 else if (type->tp_getattro != NULL) {
13866 PyObject *descr = (*type->tp_getattro)(source, attr_name);
13867
13868 if (unlikely(descr == NULL)) {
13869 return NULL;
13870 }
13871
13872 descrgetfunc func = NULL;
13873 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13874 func = Py_TYPE(descr)->tp_descr_get;
13875
13876 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13877 PyObject *called_object = func(descr, source, (PyObject *)type);
13878 Py_DECREF(descr);
13879
13880 if (unlikely(called_object == NULL)) {
13881 return NULL;
13882 }
13883
13884 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13885 Py_DECREF(called_object);
13886 return result;
13887 }
13888 }
13889
13890 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, descr, args);
13891 Py_DECREF(descr);
13892 return result;
13893 } else if (type->tp_getattr != NULL) {
13894 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
13895
13896 if (unlikely(called_object == NULL)) {
13897 return NULL;
13898 }
13899
13900 PyObject *result = CALL_FUNCTION_WITH_ARGS8(tstate, called_object, args);
13901 Py_DECREF(called_object);
13902 return result;
13903 } else {
13904 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
13905 Nuitka_String_AsString_Unchecked(attr_name));
13906
13907 return NULL;
13908 }
13909}
13910PyObject *CALL_METHOD_WITH_ARGS9(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
13911 CHECK_OBJECT(source);
13912 CHECK_OBJECT(attr_name);
13913
13914 CHECK_OBJECTS(args, 9);
13915
13916 PyTypeObject *type = Py_TYPE(source);
13917
13918 if (hasTypeGenericGetAttr(type)) {
13919 // Unfortunately this is required, although of cause rarely necessary.
13920 if (unlikely(type->tp_dict == NULL)) {
13921 if (unlikely(PyType_Ready(type) < 0)) {
13922 return NULL;
13923 }
13924 }
13925
13926 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
13927 descrgetfunc func = NULL;
13928
13929 if (descr != NULL) {
13930 Py_INCREF(descr);
13931
13932 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
13933 func = Py_TYPE(descr)->tp_descr_get;
13934
13935 if (func != NULL && Nuitka_Descr_IsData(descr)) {
13936 PyObject *called_object = func(descr, source, (PyObject *)type);
13937 Py_DECREF(descr);
13938
13939 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13940 Py_DECREF(called_object);
13941 return result;
13942 }
13943 }
13944 }
13945
13946 Py_ssize_t dictoffset = type->tp_dictoffset;
13947 PyObject *dict = NULL;
13948
13949 if (dictoffset != 0) {
13950 // Negative dictionary offsets have special meaning.
13951 if (dictoffset < 0) {
13952 Py_ssize_t tsize;
13953 size_t size;
13954
13955 tsize = ((PyVarObject *)source)->ob_size;
13956 if (tsize < 0) {
13957 tsize = -tsize;
13958 }
13959 size = _PyObject_VAR_SIZE(type, tsize);
13960
13961 dictoffset += (long)size;
13962 }
13963
13964 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
13965 dict = *dictptr;
13966 }
13967
13968 if (dict != NULL) {
13969 CHECK_OBJECT(dict);
13970
13971 Py_INCREF(dict);
13972
13973 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
13974
13975 if (called_object != NULL) {
13976 Py_XDECREF(descr);
13977 Py_DECREF(dict);
13978
13979 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
13980 Py_DECREF(called_object);
13981 return result;
13982 }
13983
13984 Py_DECREF(dict);
13985 }
13986
13987 if (func != NULL) {
13988 if (func == Nuitka_Function_Type.tp_descr_get) {
13989 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
13990 source, args, 9);
13991 Py_DECREF(descr);
13992
13993 return result;
13994 } else {
13995 PyObject *called_object = func(descr, source, (PyObject *)type);
13996 CHECK_OBJECT(called_object);
13997
13998 Py_DECREF(descr);
13999
14000 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14001 Py_DECREF(called_object);
14002 return result;
14003 }
14004 }
14005
14006 if (descr != NULL) {
14007 CHECK_OBJECT(descr);
14008
14009 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, descr, args);
14010 Py_DECREF(descr);
14011 return result;
14012 }
14013
14014#if PYTHON_VERSION < 0x300
14015 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14016 PyString_AS_STRING(attr_name));
14017#else
14018 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
14019#endif
14020 return NULL;
14021 }
14022#if PYTHON_VERSION < 0x300
14023 else if (type == &PyInstance_Type) {
14024 PyInstanceObject *source_instance = (PyInstanceObject *)source;
14025
14026 // The special cases have their own variant on the code generation level
14027 // as we are called with constants only.
14028 assert(attr_name != const_str_plain___dict__);
14029 assert(attr_name != const_str_plain___class__);
14030
14031 // Try the instance dict first.
14032 PyObject *called_object =
14033 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
14034
14035 // Note: The "called_object" was found without taking a reference,
14036 // so we need not release it in this branch.
14037 if (called_object != NULL) {
14038 return CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14039 }
14040
14041 // Then check the class dictionaries.
14042 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
14043
14044 // Note: The "called_object" was found without taking a reference,
14045 // so we need not release it in this branch.
14046 if (called_object != NULL) {
14047 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
14048
14049 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
14050 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
14051 source, args, 9);
14052 } else if (descr_get != NULL) {
14053 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
14054
14055 if (unlikely(method == NULL)) {
14056 return NULL;
14057 }
14058
14059 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, method, args);
14060 Py_DECREF(method);
14061 return result;
14062 } else {
14063 return CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14064 }
14065
14066 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
14067 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
14068 PyString_AS_STRING(source_instance->in_class->cl_name),
14069 PyString_AS_STRING(attr_name));
14070
14071 return NULL;
14072 } else {
14073 // Finally allow the "__getattr__" override to provide it or else
14074 // it's an error.
14075
14076 PyObject *args2[] = {source, attr_name};
14077
14078 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
14079
14080 if (unlikely(called_object == NULL)) {
14081 return NULL;
14082 }
14083
14084 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14085 Py_DECREF(called_object);
14086 return result;
14087 }
14088 }
14089#endif
14090 else if (type->tp_getattro != NULL) {
14091 PyObject *descr = (*type->tp_getattro)(source, attr_name);
14092
14093 if (unlikely(descr == NULL)) {
14094 return NULL;
14095 }
14096
14097 descrgetfunc func = NULL;
14098 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14099 func = Py_TYPE(descr)->tp_descr_get;
14100
14101 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14102 PyObject *called_object = func(descr, source, (PyObject *)type);
14103 Py_DECREF(descr);
14104
14105 if (unlikely(called_object == NULL)) {
14106 return NULL;
14107 }
14108
14109 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14110 Py_DECREF(called_object);
14111 return result;
14112 }
14113 }
14114
14115 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, descr, args);
14116 Py_DECREF(descr);
14117 return result;
14118 } else if (type->tp_getattr != NULL) {
14119 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
14120
14121 if (unlikely(called_object == NULL)) {
14122 return NULL;
14123 }
14124
14125 PyObject *result = CALL_FUNCTION_WITH_ARGS9(tstate, called_object, args);
14126 Py_DECREF(called_object);
14127 return result;
14128 } else {
14129 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14130 Nuitka_String_AsString_Unchecked(attr_name));
14131
14132 return NULL;
14133 }
14134}
14135PyObject *CALL_METHOD_WITH_ARGS10(PyThreadState *tstate, PyObject *source, PyObject *attr_name, PyObject *const *args) {
14136 CHECK_OBJECT(source);
14137 CHECK_OBJECT(attr_name);
14138
14139 CHECK_OBJECTS(args, 10);
14140
14141 PyTypeObject *type = Py_TYPE(source);
14142
14143 if (hasTypeGenericGetAttr(type)) {
14144 // Unfortunately this is required, although of cause rarely necessary.
14145 if (unlikely(type->tp_dict == NULL)) {
14146 if (unlikely(PyType_Ready(type) < 0)) {
14147 return NULL;
14148 }
14149 }
14150
14151 PyObject *descr = Nuitka_TypeLookup(type, attr_name);
14152 descrgetfunc func = NULL;
14153
14154 if (descr != NULL) {
14155 Py_INCREF(descr);
14156
14157 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14158 func = Py_TYPE(descr)->tp_descr_get;
14159
14160 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14161 PyObject *called_object = func(descr, source, (PyObject *)type);
14162 Py_DECREF(descr);
14163
14164 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14165 Py_DECREF(called_object);
14166 return result;
14167 }
14168 }
14169 }
14170
14171 Py_ssize_t dictoffset = type->tp_dictoffset;
14172 PyObject *dict = NULL;
14173
14174 if (dictoffset != 0) {
14175 // Negative dictionary offsets have special meaning.
14176 if (dictoffset < 0) {
14177 Py_ssize_t tsize;
14178 size_t size;
14179
14180 tsize = ((PyVarObject *)source)->ob_size;
14181 if (tsize < 0) {
14182 tsize = -tsize;
14183 }
14184 size = _PyObject_VAR_SIZE(type, tsize);
14185
14186 dictoffset += (long)size;
14187 }
14188
14189 PyObject **dictptr = (PyObject **)((char *)source + dictoffset);
14190 dict = *dictptr;
14191 }
14192
14193 if (dict != NULL) {
14194 CHECK_OBJECT(dict);
14195
14196 Py_INCREF(dict);
14197
14198 PyObject *called_object = DICT_GET_ITEM1(tstate, dict, attr_name);
14199
14200 if (called_object != NULL) {
14201 Py_XDECREF(descr);
14202 Py_DECREF(dict);
14203
14204 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14205 Py_DECREF(called_object);
14206 return result;
14207 }
14208
14209 Py_DECREF(dict);
14210 }
14211
14212 if (func != NULL) {
14213 if (func == Nuitka_Function_Type.tp_descr_get) {
14214 PyObject *result = Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)descr,
14215 source, args, 10);
14216 Py_DECREF(descr);
14217
14218 return result;
14219 } else {
14220 PyObject *called_object = func(descr, source, (PyObject *)type);
14221 CHECK_OBJECT(called_object);
14222
14223 Py_DECREF(descr);
14224
14225 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14226 Py_DECREF(called_object);
14227 return result;
14228 }
14229 }
14230
14231 if (descr != NULL) {
14232 CHECK_OBJECT(descr);
14233
14234 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, descr, args);
14235 Py_DECREF(descr);
14236 return result;
14237 }
14238
14239#if PYTHON_VERSION < 0x300
14240 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14241 PyString_AS_STRING(attr_name));
14242#else
14243 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%U'", type->tp_name, attr_name);
14244#endif
14245 return NULL;
14246 }
14247#if PYTHON_VERSION < 0x300
14248 else if (type == &PyInstance_Type) {
14249 PyInstanceObject *source_instance = (PyInstanceObject *)source;
14250
14251 // The special cases have their own variant on the code generation level
14252 // as we are called with constants only.
14253 assert(attr_name != const_str_plain___dict__);
14254 assert(attr_name != const_str_plain___class__);
14255
14256 // Try the instance dict first.
14257 PyObject *called_object =
14258 GET_STRING_DICT_VALUE((PyDictObject *)source_instance->in_dict, (PyStringObject *)attr_name);
14259
14260 // Note: The "called_object" was found without taking a reference,
14261 // so we need not release it in this branch.
14262 if (called_object != NULL) {
14263 return CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14264 }
14265
14266 // Then check the class dictionaries.
14267 called_object = FIND_ATTRIBUTE_IN_CLASS(source_instance->in_class, attr_name);
14268
14269 // Note: The "called_object" was found without taking a reference,
14270 // so we need not release it in this branch.
14271 if (called_object != NULL) {
14272 descrgetfunc descr_get = Py_TYPE(called_object)->tp_descr_get;
14273
14274 if (descr_get == Nuitka_Function_Type.tp_descr_get) {
14275 return Nuitka_CallMethodFunctionPosArgs(tstate, (struct Nuitka_FunctionObject const *)called_object,
14276 source, args, 10);
14277 } else if (descr_get != NULL) {
14278 PyObject *method = descr_get(called_object, source, (PyObject *)source_instance->in_class);
14279
14280 if (unlikely(method == NULL)) {
14281 return NULL;
14282 }
14283
14284 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, method, args);
14285 Py_DECREF(method);
14286 return result;
14287 } else {
14288 return CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14289 }
14290
14291 } else if (unlikely(source_instance->in_class->cl_getattr == NULL)) {
14292 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "%s instance has no attribute '%s'",
14293 PyString_AS_STRING(source_instance->in_class->cl_name),
14294 PyString_AS_STRING(attr_name));
14295
14296 return NULL;
14297 } else {
14298 // Finally allow the "__getattr__" override to provide it or else
14299 // it's an error.
14300
14301 PyObject *args2[] = {source, attr_name};
14302
14303 called_object = CALL_FUNCTION_WITH_ARGS2(tstate, source_instance->in_class->cl_getattr, args2);
14304
14305 if (unlikely(called_object == NULL)) {
14306 return NULL;
14307 }
14308
14309 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14310 Py_DECREF(called_object);
14311 return result;
14312 }
14313 }
14314#endif
14315 else if (type->tp_getattro != NULL) {
14316 PyObject *descr = (*type->tp_getattro)(source, attr_name);
14317
14318 if (unlikely(descr == NULL)) {
14319 return NULL;
14320 }
14321
14322 descrgetfunc func = NULL;
14323 if (NuitkaType_HasFeatureClass(Py_TYPE(descr))) {
14324 func = Py_TYPE(descr)->tp_descr_get;
14325
14326 if (func != NULL && Nuitka_Descr_IsData(descr)) {
14327 PyObject *called_object = func(descr, source, (PyObject *)type);
14328 Py_DECREF(descr);
14329
14330 if (unlikely(called_object == NULL)) {
14331 return NULL;
14332 }
14333
14334 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14335 Py_DECREF(called_object);
14336 return result;
14337 }
14338 }
14339
14340 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, descr, args);
14341 Py_DECREF(descr);
14342 return result;
14343 } else if (type->tp_getattr != NULL) {
14344 PyObject *called_object = (*type->tp_getattr)(source, (char *)Nuitka_String_AsString_Unchecked(attr_name));
14345
14346 if (unlikely(called_object == NULL)) {
14347 return NULL;
14348 }
14349
14350 PyObject *result = CALL_FUNCTION_WITH_ARGS10(tstate, called_object, args);
14351 Py_DECREF(called_object);
14352 return result;
14353 } else {
14354 SET_CURRENT_EXCEPTION_TYPE0_FORMAT2(PyExc_AttributeError, "'%s' object has no attribute '%s'", type->tp_name,
14355 Nuitka_String_AsString_Unchecked(attr_name));
14356
14357 return NULL;
14358 }
14359}
14360#if defined(__clang__)
14361#pragma clang diagnostic pop
14362#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
14363#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
14364#pragma GCC diagnostic pop
14365#endif
14366#endif
14367
14368// Part of "Nuitka", an optimizing Python compiler that is compatible and
14369// integrates with CPython, but also works on its own.
14370//
14371// Licensed under the Apache License, Version 2.0 (the "License");
14372// you may not use this file except in compliance with the License.
14373// You may obtain a copy of the License at
14374//
14375// http://www.apache.org/licenses/LICENSE-2.0
14376//
14377// Unless required by applicable law or agreed to in writing, software
14378// distributed under the License is distributed on an "AS IS" BASIS,
14379// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14380// See the License for the specific language governing permissions and
14381// limitations under the License.
Definition compiled_function.h:22
Definition compiled_method.h:16