Nuitka
The Python compiler
Loading...
Searching...
No Matches
HelpersOperationBinaryOlddiv.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 HelperOperationBinary.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/* C helpers for type specialized "/" (OLDDIV) operations */
11
12#if PYTHON_VERSION < 0x300
13/* Code referring to "INT" corresponds to Python2 'int' and "INT" to Python2 'int'. */
14static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
15 CHECK_OBJECT(operand1);
16 assert(PyInt_CheckExact(operand1));
17 CHECK_OBJECT(operand2);
18 assert(PyInt_CheckExact(operand2));
19
20 PyObject *result;
21
22 // Not every code path will make use of all possible results.
23#if defined(_MSC_VER)
24#pragma warning(push)
25#pragma warning(disable : 4101)
26#endif
27 NUITKA_MAY_BE_UNUSED bool cbool_result;
28 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
29 NUITKA_MAY_BE_UNUSED long clong_result;
30 NUITKA_MAY_BE_UNUSED double cfloat_result;
31#if defined(_MSC_VER)
32#pragma warning(pop)
33#endif
34
35 CHECK_OBJECT(operand1);
36 assert(PyInt_CheckExact(operand1));
37 CHECK_OBJECT(operand2);
38 assert(PyInt_CheckExact(operand2));
39
40 const long a = PyInt_AS_LONG(operand1);
41 const long b = PyInt_AS_LONG(operand2);
42
43 if (unlikely(b == 0)) {
44 PyThreadState *tstate = PyThreadState_GET();
45
46 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "integer division or modulo by zero");
47 goto exit_result_exception;
48 }
49
50 /* TODO: Isn't this a very specific value only, of which we could
51 * hardcode the constant result. Not sure how well the C compiler
52 * optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
53 * -1 has to be rare anyway.
54 */
55
56 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
57 long a_div_b = a / b;
58 long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
59
60 if (a_mod_b && (b ^ a_mod_b) < 0) {
61 a_mod_b += b;
62 a_div_b -= 1;
63 }
64
65 clong_result = a_div_b;
66 goto exit_result_ok_clong;
67 }
68
69 {
70 PyObject *operand1_object = operand1;
71 PyObject *operand2_object = operand2;
72
73 PyObject *r = PyLong_Type.tp_as_number->nb_divide(operand1_object, operand2_object);
74 assert(r != Py_NotImplemented);
75
76 obj_result = r;
77 goto exit_result_object;
78 }
79
80exit_result_ok_clong:
81 result = Nuitka_PyInt_FromLong(clong_result);
82 goto exit_result_ok;
83
84exit_result_object:
85 if (unlikely(obj_result == NULL)) {
86 goto exit_result_exception;
87 }
88 result = obj_result;
89 goto exit_result_ok;
90
91exit_result_ok:
92 return result;
93
94exit_result_exception:
95 return NULL;
96}
97
98PyObject *BINARY_OPERATION_OLDDIV_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
99 return _BINARY_OPERATION_OLDDIV_OBJECT_INT_INT(operand1, operand2);
100}
101#endif
102
103#if PYTHON_VERSION < 0x300
104/* Code referring to "OBJECT" corresponds to any Python object and "INT" to Python2 'int'. */
105static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_INT(PyObject *operand1,
106 PyObject *operand2) {
107 PyTypeObject *type1 = Py_TYPE(operand1);
108
109#if defined(_MSC_VER)
110#pragma warning(push)
111#pragma warning(disable : 4101)
112#endif
113 NUITKA_MAY_BE_UNUSED bool cbool_result;
114 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
115#if defined(_MSC_VER)
116#pragma warning(pop)
117#endif
118
119 binaryfunc slot1 =
120 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divide : NULL;
121 binaryfunc slot2 = NULL;
122
123 if (!(type1 == &PyInt_Type)) {
124 // Different types, need to consider second value slot.
125
126 slot2 = PyInt_Type.tp_as_number->nb_divide;
127
128 if (slot1 == slot2) {
129 slot2 = NULL;
130 }
131 }
132
133 if (slot1 != NULL) {
134 PyObject *x = slot1(operand1, operand2);
135
136 if (x != Py_NotImplemented) {
137 obj_result = x;
138 goto exit_binary_result_object;
139 }
140
141 Py_DECREF_IMMORTAL(x);
142 }
143
144 if (slot2 != NULL) {
145 PyObject *x = slot2(operand1, operand2);
146
147 if (x != Py_NotImplemented) {
148 obj_result = x;
149 goto exit_binary_result_object;
150 }
151
152 Py_DECREF_IMMORTAL(x);
153 }
154
155#if PYTHON_VERSION < 0x300
156 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
157 coercion c1 =
158 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
159
160 if (c1 != NULL) {
161 PyObject *coerced1 = operand1;
162 PyObject *coerced2 = operand2;
163
164 int err = c1(&coerced1, &coerced2);
165
166 if (unlikely(err < 0)) {
167 goto exit_binary_exception;
168 }
169
170 if (err == 0) {
171 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
172
173 if (likely(mv == NULL)) {
174 binaryfunc slot = mv->nb_divide;
175
176 if (likely(slot != NULL)) {
177 PyObject *x = slot(coerced1, coerced2);
178
179 Py_DECREF(coerced1);
180 Py_DECREF(coerced2);
181
182 obj_result = x;
183 goto exit_binary_result_object;
184 }
185 }
186
187 // nb_coerce took a reference.
188 Py_DECREF(coerced1);
189 Py_DECREF(coerced2);
190 }
191 }
192 coercion c2 = PyInt_Type.tp_as_number->nb_coerce;
193
194 if (c2 != NULL) {
195 PyObject *coerced1 = operand1;
196 PyObject *coerced2 = operand2;
197
198 int err = c2(&coerced2, &coerced1);
199
200 if (unlikely(err < 0)) {
201 goto exit_binary_exception;
202 }
203
204 if (err == 0) {
205 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
206
207 if (likely(mv == NULL)) {
208 binaryfunc slot = mv->nb_divide;
209
210 if (likely(slot != NULL)) {
211 PyObject *x = slot(coerced1, coerced2);
212
213 Py_DECREF(coerced1);
214 Py_DECREF(coerced2);
215
216 obj_result = x;
217 goto exit_binary_result_object;
218 }
219 }
220
221 // nb_coerce took a reference.
222 Py_DECREF(coerced1);
223 Py_DECREF(coerced2);
224 }
225 }
226 }
227#endif
228
229 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and 'int'", type1->tp_name);
230 goto exit_binary_exception;
231
232exit_binary_result_object:
233 return obj_result;
234
235exit_binary_exception:
236 return NULL;
237}
238static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
239 CHECK_OBJECT(operand1);
240 CHECK_OBJECT(operand2);
241 assert(PyInt_CheckExact(operand2));
242
243 PyTypeObject *type1 = Py_TYPE(operand1);
244
245 if (type1 == &PyInt_Type) {
246 PyObject *result;
247
248 // return _BINARY_OPERATION_OLDDIV_OBJECT_INT_INT(operand1, operand2);
249
250 // Not every code path will make use of all possible results.
251#if defined(_MSC_VER)
252#pragma warning(push)
253#pragma warning(disable : 4101)
254#endif
255 NUITKA_MAY_BE_UNUSED bool cbool_result;
256 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
257 NUITKA_MAY_BE_UNUSED long clong_result;
258 NUITKA_MAY_BE_UNUSED double cfloat_result;
259#if defined(_MSC_VER)
260#pragma warning(pop)
261#endif
262
263 CHECK_OBJECT(operand1);
264 assert(PyInt_CheckExact(operand1));
265 CHECK_OBJECT(operand2);
266 assert(PyInt_CheckExact(operand2));
267
268 const long a = PyInt_AS_LONG(operand1);
269 const long b = PyInt_AS_LONG(operand2);
270
271 if (unlikely(b == 0)) {
272 PyThreadState *tstate = PyThreadState_GET();
273
274 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "integer division or modulo by zero");
275 goto exit_result_exception;
276 }
277
278 /* TODO: Isn't this a very specific value only, of which we could
279 * hardcode the constant result. Not sure how well the C compiler
280 * optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
281 * -1 has to be rare anyway.
282 */
283
284 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
285 long a_div_b = a / b;
286 long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
287
288 if (a_mod_b && (b ^ a_mod_b) < 0) {
289 a_mod_b += b;
290 a_div_b -= 1;
291 }
292
293 clong_result = a_div_b;
294 goto exit_result_ok_clong;
295 }
296
297 {
298 PyObject *operand1_object = operand1;
299 PyObject *operand2_object = operand2;
300
301 PyObject *r = PyLong_Type.tp_as_number->nb_divide(operand1_object, operand2_object);
302 assert(r != Py_NotImplemented);
303
304 obj_result = r;
305 goto exit_result_object;
306 }
307
308 exit_result_ok_clong:
309 result = Nuitka_PyInt_FromLong(clong_result);
310 goto exit_result_ok;
311
312 exit_result_object:
313 if (unlikely(obj_result == NULL)) {
314 goto exit_result_exception;
315 }
316 result = obj_result;
317 goto exit_result_ok;
318
319 exit_result_ok:
320 return result;
321
322 exit_result_exception:
323 return NULL;
324 }
325
326 return __BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_INT(operand1, operand2);
327}
328
329PyObject *BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
330 return _BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_INT(operand1, operand2);
331}
332#endif
333
334#if PYTHON_VERSION < 0x300
335/* Code referring to "INT" corresponds to Python2 'int' and "OBJECT" to any Python object. */
336static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_OLDDIV_OBJECT_INT_OBJECT(PyObject *operand1,
337 PyObject *operand2) {
338 PyTypeObject *type2 = Py_TYPE(operand2);
339
340#if defined(_MSC_VER)
341#pragma warning(push)
342#pragma warning(disable : 4101)
343#endif
344 NUITKA_MAY_BE_UNUSED bool cbool_result;
345 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
346#if defined(_MSC_VER)
347#pragma warning(pop)
348#endif
349
350 binaryfunc slot1 = PyInt_Type.tp_as_number->nb_divide;
351 binaryfunc slot2 = NULL;
352
353 if (!(&PyInt_Type == type2)) {
354 // Different types, need to consider second value slot.
355
356 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divide : NULL;
357
358 if (slot1 == slot2) {
359 slot2 = NULL;
360 }
361 }
362
363 if (slot1 != NULL) {
364 if (slot2 != NULL) {
365 if (Nuitka_Type_IsSubtype(type2, &PyInt_Type)) {
366 PyObject *x = slot2(operand1, operand2);
367
368 if (x != Py_NotImplemented) {
369 obj_result = x;
370 goto exit_binary_result_object;
371 }
372
373 Py_DECREF_IMMORTAL(x);
374 slot2 = NULL;
375 }
376 }
377
378 PyObject *x = slot1(operand1, operand2);
379
380 if (x != Py_NotImplemented) {
381 obj_result = x;
382 goto exit_binary_result_object;
383 }
384
385 Py_DECREF_IMMORTAL(x);
386 }
387
388 if (slot2 != NULL) {
389 PyObject *x = slot2(operand1, operand2);
390
391 if (x != Py_NotImplemented) {
392 obj_result = x;
393 goto exit_binary_result_object;
394 }
395
396 Py_DECREF_IMMORTAL(x);
397 }
398
399#if PYTHON_VERSION < 0x300
400 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
401 coercion c1 = PyInt_Type.tp_as_number->nb_coerce;
402
403 if (c1 != NULL) {
404 PyObject *coerced1 = operand1;
405 PyObject *coerced2 = operand2;
406
407 int err = c1(&coerced1, &coerced2);
408
409 if (unlikely(err < 0)) {
410 goto exit_binary_exception;
411 }
412
413 if (err == 0) {
414 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
415
416 if (likely(mv == NULL)) {
417 binaryfunc slot = mv->nb_divide;
418
419 if (likely(slot != NULL)) {
420 PyObject *x = slot(coerced1, coerced2);
421
422 Py_DECREF(coerced1);
423 Py_DECREF(coerced2);
424
425 obj_result = x;
426 goto exit_binary_result_object;
427 }
428 }
429
430 // nb_coerce took a reference.
431 Py_DECREF(coerced1);
432 Py_DECREF(coerced2);
433 }
434 }
435 coercion c2 =
436 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
437
438 if (c2 != NULL) {
439 PyObject *coerced1 = operand1;
440 PyObject *coerced2 = operand2;
441
442 int err = c2(&coerced2, &coerced1);
443
444 if (unlikely(err < 0)) {
445 goto exit_binary_exception;
446 }
447
448 if (err == 0) {
449 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
450
451 if (likely(mv == NULL)) {
452 binaryfunc slot = mv->nb_divide;
453
454 if (likely(slot != NULL)) {
455 PyObject *x = slot(coerced1, coerced2);
456
457 Py_DECREF(coerced1);
458 Py_DECREF(coerced2);
459
460 obj_result = x;
461 goto exit_binary_result_object;
462 }
463 }
464
465 // nb_coerce took a reference.
466 Py_DECREF(coerced1);
467 Py_DECREF(coerced2);
468 }
469 }
470 }
471#endif
472
473 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'int' and '%s'", type2->tp_name);
474 goto exit_binary_exception;
475
476exit_binary_result_object:
477 return obj_result;
478
479exit_binary_exception:
480 return NULL;
481}
482static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
483 CHECK_OBJECT(operand1);
484 assert(PyInt_CheckExact(operand1));
485 CHECK_OBJECT(operand2);
486
487 PyTypeObject *type2 = Py_TYPE(operand2);
488
489 if (&PyInt_Type == type2) {
490 PyObject *result;
491
492 // return _BINARY_OPERATION_OLDDIV_OBJECT_INT_INT(operand1, operand2);
493
494 // Not every code path will make use of all possible results.
495#if defined(_MSC_VER)
496#pragma warning(push)
497#pragma warning(disable : 4101)
498#endif
499 NUITKA_MAY_BE_UNUSED bool cbool_result;
500 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
501 NUITKA_MAY_BE_UNUSED long clong_result;
502 NUITKA_MAY_BE_UNUSED double cfloat_result;
503#if defined(_MSC_VER)
504#pragma warning(pop)
505#endif
506
507 CHECK_OBJECT(operand1);
508 assert(PyInt_CheckExact(operand1));
509 CHECK_OBJECT(operand2);
510 assert(PyInt_CheckExact(operand2));
511
512 const long a = PyInt_AS_LONG(operand1);
513 const long b = PyInt_AS_LONG(operand2);
514
515 if (unlikely(b == 0)) {
516 PyThreadState *tstate = PyThreadState_GET();
517
518 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "integer division or modulo by zero");
519 goto exit_result_exception;
520 }
521
522 /* TODO: Isn't this a very specific value only, of which we could
523 * hardcode the constant result. Not sure how well the C compiler
524 * optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
525 * -1 has to be rare anyway.
526 */
527
528 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
529 long a_div_b = a / b;
530 long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
531
532 if (a_mod_b && (b ^ a_mod_b) < 0) {
533 a_mod_b += b;
534 a_div_b -= 1;
535 }
536
537 clong_result = a_div_b;
538 goto exit_result_ok_clong;
539 }
540
541 {
542 PyObject *operand1_object = operand1;
543 PyObject *operand2_object = operand2;
544
545 PyObject *r = PyLong_Type.tp_as_number->nb_divide(operand1_object, operand2_object);
546 assert(r != Py_NotImplemented);
547
548 obj_result = r;
549 goto exit_result_object;
550 }
551
552 exit_result_ok_clong:
553 result = Nuitka_PyInt_FromLong(clong_result);
554 goto exit_result_ok;
555
556 exit_result_object:
557 if (unlikely(obj_result == NULL)) {
558 goto exit_result_exception;
559 }
560 result = obj_result;
561 goto exit_result_ok;
562
563 exit_result_ok:
564 return result;
565
566 exit_result_exception:
567 return NULL;
568 }
569
570 return __BINARY_OPERATION_OLDDIV_OBJECT_INT_OBJECT(operand1, operand2);
571}
572
573PyObject *BINARY_OPERATION_OLDDIV_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
574 return _BINARY_OPERATION_OLDDIV_OBJECT_INT_OBJECT(operand1, operand2);
575}
576#endif
577
578#if PYTHON_VERSION < 0x300
579/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "LONG" to Python2 'long', Python3 'int'. */
580static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
581 CHECK_OBJECT(operand1);
582 assert(PyLong_CheckExact(operand1));
583 CHECK_OBJECT(operand2);
584 assert(PyLong_CheckExact(operand2));
585
586 PyObject *result;
587
588 // Not every code path will make use of all possible results.
589#if defined(_MSC_VER)
590#pragma warning(push)
591#pragma warning(disable : 4101)
592#endif
593 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
594 NUITKA_MAY_BE_UNUSED long clong_result;
595#if defined(_MSC_VER)
596#pragma warning(pop)
597#endif
598
599 PyObject *x = PyLong_Type.tp_as_number->nb_divide(operand1, operand2);
600 assert(x != Py_NotImplemented);
601
602 obj_result = x;
603 goto exit_result_object;
604
605exit_result_object:
606 if (unlikely(obj_result == NULL)) {
607 goto exit_result_exception;
608 }
609 result = obj_result;
610 goto exit_result_ok;
611
612exit_result_ok:
613 return result;
614
615exit_result_exception:
616 return NULL;
617}
618
619PyObject *BINARY_OPERATION_OLDDIV_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
620 return _BINARY_OPERATION_OLDDIV_OBJECT_LONG_LONG(operand1, operand2);
621}
622#endif
623
624#if PYTHON_VERSION < 0x300
625/* Code referring to "OBJECT" corresponds to any Python object and "LONG" to Python2 'long', Python3 'int'. */
626static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_LONG(PyObject *operand1,
627 PyObject *operand2) {
628 PyTypeObject *type1 = Py_TYPE(operand1);
629
630#if defined(_MSC_VER)
631#pragma warning(push)
632#pragma warning(disable : 4101)
633#endif
634 NUITKA_MAY_BE_UNUSED bool cbool_result;
635 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
636#if defined(_MSC_VER)
637#pragma warning(pop)
638#endif
639
640 binaryfunc slot1 =
641 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divide : NULL;
642 binaryfunc slot2 = NULL;
643
644 if (!(type1 == &PyLong_Type)) {
645 // Different types, need to consider second value slot.
646
647 slot2 = PyLong_Type.tp_as_number->nb_divide;
648
649 if (slot1 == slot2) {
650 slot2 = NULL;
651 }
652 }
653
654 if (slot1 != NULL) {
655 PyObject *x = slot1(operand1, operand2);
656
657 if (x != Py_NotImplemented) {
658 obj_result = x;
659 goto exit_binary_result_object;
660 }
661
662 Py_DECREF_IMMORTAL(x);
663 }
664
665 if (slot2 != NULL) {
666 PyObject *x = slot2(operand1, operand2);
667
668 if (x != Py_NotImplemented) {
669 obj_result = x;
670 goto exit_binary_result_object;
671 }
672
673 Py_DECREF_IMMORTAL(x);
674 }
675
676#if PYTHON_VERSION < 0x300
677 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
678 coercion c1 =
679 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
680
681 if (c1 != NULL) {
682 PyObject *coerced1 = operand1;
683 PyObject *coerced2 = operand2;
684
685 int err = c1(&coerced1, &coerced2);
686
687 if (unlikely(err < 0)) {
688 goto exit_binary_exception;
689 }
690
691 if (err == 0) {
692 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
693
694 if (likely(mv == NULL)) {
695 binaryfunc slot = mv->nb_divide;
696
697 if (likely(slot != NULL)) {
698 PyObject *x = slot(coerced1, coerced2);
699
700 Py_DECREF(coerced1);
701 Py_DECREF(coerced2);
702
703 obj_result = x;
704 goto exit_binary_result_object;
705 }
706 }
707
708 // nb_coerce took a reference.
709 Py_DECREF(coerced1);
710 Py_DECREF(coerced2);
711 }
712 }
713 coercion c2 = PyLong_Type.tp_as_number->nb_coerce;
714
715 if (c2 != NULL) {
716 PyObject *coerced1 = operand1;
717 PyObject *coerced2 = operand2;
718
719 int err = c2(&coerced2, &coerced1);
720
721 if (unlikely(err < 0)) {
722 goto exit_binary_exception;
723 }
724
725 if (err == 0) {
726 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
727
728 if (likely(mv == NULL)) {
729 binaryfunc slot = mv->nb_divide;
730
731 if (likely(slot != NULL)) {
732 PyObject *x = slot(coerced1, coerced2);
733
734 Py_DECREF(coerced1);
735 Py_DECREF(coerced2);
736
737 obj_result = x;
738 goto exit_binary_result_object;
739 }
740 }
741
742 // nb_coerce took a reference.
743 Py_DECREF(coerced1);
744 Py_DECREF(coerced2);
745 }
746 }
747 }
748#endif
749
750#if PYTHON_VERSION < 0x300
751 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and 'long'", type1->tp_name);
752#else
753 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and 'int'", type1->tp_name);
754#endif
755 goto exit_binary_exception;
756
757exit_binary_result_object:
758 return obj_result;
759
760exit_binary_exception:
761 return NULL;
762}
763static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
764 CHECK_OBJECT(operand1);
765 CHECK_OBJECT(operand2);
766 assert(PyLong_CheckExact(operand2));
767
768 PyTypeObject *type1 = Py_TYPE(operand1);
769
770 if (type1 == &PyLong_Type) {
771 PyObject *result;
772
773 // return _BINARY_OPERATION_OLDDIV_OBJECT_LONG_LONG(operand1, operand2);
774
775 // Not every code path will make use of all possible results.
776#if defined(_MSC_VER)
777#pragma warning(push)
778#pragma warning(disable : 4101)
779#endif
780 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
781 NUITKA_MAY_BE_UNUSED long clong_result;
782#if defined(_MSC_VER)
783#pragma warning(pop)
784#endif
785
786 PyObject *x = PyLong_Type.tp_as_number->nb_divide(operand1, operand2);
787 assert(x != Py_NotImplemented);
788
789 obj_result = x;
790 goto exit_result_object;
791
792 exit_result_object:
793 if (unlikely(obj_result == NULL)) {
794 goto exit_result_exception;
795 }
796 result = obj_result;
797 goto exit_result_ok;
798
799 exit_result_ok:
800 return result;
801
802 exit_result_exception:
803 return NULL;
804 }
805
806 return __BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_LONG(operand1, operand2);
807}
808
809PyObject *BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
810 return _BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_LONG(operand1, operand2);
811}
812#endif
813
814#if PYTHON_VERSION < 0x300
815/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "OBJECT" to any Python object. */
816static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_OLDDIV_OBJECT_LONG_OBJECT(PyObject *operand1,
817 PyObject *operand2) {
818 PyTypeObject *type2 = Py_TYPE(operand2);
819
820#if defined(_MSC_VER)
821#pragma warning(push)
822#pragma warning(disable : 4101)
823#endif
824 NUITKA_MAY_BE_UNUSED bool cbool_result;
825 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
826#if defined(_MSC_VER)
827#pragma warning(pop)
828#endif
829
830 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_divide;
831 binaryfunc slot2 = NULL;
832
833 if (!(&PyLong_Type == type2)) {
834 // Different types, need to consider second value slot.
835
836 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divide : NULL;
837
838 if (slot1 == slot2) {
839 slot2 = NULL;
840 }
841 }
842
843 if (slot1 != NULL) {
844 if (slot2 != NULL) {
845 if (Nuitka_Type_IsSubtype(type2, &PyLong_Type)) {
846 PyObject *x = slot2(operand1, operand2);
847
848 if (x != Py_NotImplemented) {
849 obj_result = x;
850 goto exit_binary_result_object;
851 }
852
853 Py_DECREF_IMMORTAL(x);
854 slot2 = NULL;
855 }
856 }
857
858 PyObject *x = slot1(operand1, operand2);
859
860 if (x != Py_NotImplemented) {
861 obj_result = x;
862 goto exit_binary_result_object;
863 }
864
865 Py_DECREF_IMMORTAL(x);
866 }
867
868 if (slot2 != NULL) {
869 PyObject *x = slot2(operand1, operand2);
870
871 if (x != Py_NotImplemented) {
872 obj_result = x;
873 goto exit_binary_result_object;
874 }
875
876 Py_DECREF_IMMORTAL(x);
877 }
878
879#if PYTHON_VERSION < 0x300
880 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
881 coercion c1 = PyLong_Type.tp_as_number->nb_coerce;
882
883 if (c1 != NULL) {
884 PyObject *coerced1 = operand1;
885 PyObject *coerced2 = operand2;
886
887 int err = c1(&coerced1, &coerced2);
888
889 if (unlikely(err < 0)) {
890 goto exit_binary_exception;
891 }
892
893 if (err == 0) {
894 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
895
896 if (likely(mv == NULL)) {
897 binaryfunc slot = mv->nb_divide;
898
899 if (likely(slot != NULL)) {
900 PyObject *x = slot(coerced1, coerced2);
901
902 Py_DECREF(coerced1);
903 Py_DECREF(coerced2);
904
905 obj_result = x;
906 goto exit_binary_result_object;
907 }
908 }
909
910 // nb_coerce took a reference.
911 Py_DECREF(coerced1);
912 Py_DECREF(coerced2);
913 }
914 }
915 coercion c2 =
916 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
917
918 if (c2 != NULL) {
919 PyObject *coerced1 = operand1;
920 PyObject *coerced2 = operand2;
921
922 int err = c2(&coerced2, &coerced1);
923
924 if (unlikely(err < 0)) {
925 goto exit_binary_exception;
926 }
927
928 if (err == 0) {
929 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
930
931 if (likely(mv == NULL)) {
932 binaryfunc slot = mv->nb_divide;
933
934 if (likely(slot != NULL)) {
935 PyObject *x = slot(coerced1, coerced2);
936
937 Py_DECREF(coerced1);
938 Py_DECREF(coerced2);
939
940 obj_result = x;
941 goto exit_binary_result_object;
942 }
943 }
944
945 // nb_coerce took a reference.
946 Py_DECREF(coerced1);
947 Py_DECREF(coerced2);
948 }
949 }
950 }
951#endif
952
953#if PYTHON_VERSION < 0x300
954 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'long' and '%s'", type2->tp_name);
955#else
956 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'int' and '%s'", type2->tp_name);
957#endif
958 goto exit_binary_exception;
959
960exit_binary_result_object:
961 return obj_result;
962
963exit_binary_exception:
964 return NULL;
965}
966static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
967 CHECK_OBJECT(operand1);
968 assert(PyLong_CheckExact(operand1));
969 CHECK_OBJECT(operand2);
970
971 PyTypeObject *type2 = Py_TYPE(operand2);
972
973 if (&PyLong_Type == type2) {
974 PyObject *result;
975
976 // return _BINARY_OPERATION_OLDDIV_OBJECT_LONG_LONG(operand1, operand2);
977
978 // Not every code path will make use of all possible results.
979#if defined(_MSC_VER)
980#pragma warning(push)
981#pragma warning(disable : 4101)
982#endif
983 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
984 NUITKA_MAY_BE_UNUSED long clong_result;
985#if defined(_MSC_VER)
986#pragma warning(pop)
987#endif
988
989 PyObject *x = PyLong_Type.tp_as_number->nb_divide(operand1, operand2);
990 assert(x != Py_NotImplemented);
991
992 obj_result = x;
993 goto exit_result_object;
994
995 exit_result_object:
996 if (unlikely(obj_result == NULL)) {
997 goto exit_result_exception;
998 }
999 result = obj_result;
1000 goto exit_result_ok;
1001
1002 exit_result_ok:
1003 return result;
1004
1005 exit_result_exception:
1006 return NULL;
1007 }
1008
1009 return __BINARY_OPERATION_OLDDIV_OBJECT_LONG_OBJECT(operand1, operand2);
1010}
1011
1012PyObject *BINARY_OPERATION_OLDDIV_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
1013 return _BINARY_OPERATION_OLDDIV_OBJECT_LONG_OBJECT(operand1, operand2);
1014}
1015#endif
1016
1017#if PYTHON_VERSION < 0x300
1018/* Code referring to "FLOAT" corresponds to Python 'float' and "FLOAT" to Python 'float'. */
1019static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_FLOAT(PyObject *operand1, PyObject *operand2) {
1020 CHECK_OBJECT(operand1);
1021 assert(PyFloat_CheckExact(operand1));
1022 CHECK_OBJECT(operand2);
1023 assert(PyFloat_CheckExact(operand2));
1024
1025 PyObject *result;
1026
1027#if defined(_MSC_VER)
1028#pragma warning(push)
1029#pragma warning(disable : 4101)
1030#endif
1031 // Not every code path will make use of all possible results.
1032 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1033 NUITKA_MAY_BE_UNUSED long clong_result;
1034 NUITKA_MAY_BE_UNUSED double cfloat_result;
1035#if defined(_MSC_VER)
1036#pragma warning(pop)
1037#endif
1038
1039 CHECK_OBJECT(operand1);
1040 assert(PyFloat_CheckExact(operand1));
1041 CHECK_OBJECT(operand2);
1042 assert(PyFloat_CheckExact(operand2));
1043
1044 const double a = PyFloat_AS_DOUBLE(operand1);
1045 const double b = PyFloat_AS_DOUBLE(operand2);
1046
1047 if (unlikely(b == 0.0)) {
1048 PyThreadState *tstate = PyThreadState_GET();
1049
1050 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "float division by zero");
1051 goto exit_result_exception;
1052 }
1053
1054 {
1055 double r = a / b;
1056
1057 cfloat_result = r;
1058 goto exit_result_ok_cfloat;
1059 }
1060
1061exit_result_ok_cfloat:
1062 result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
1063 goto exit_result_ok;
1064
1065exit_result_ok:
1066 return result;
1067
1068exit_result_exception:
1069 return NULL;
1070}
1071
1072PyObject *BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_FLOAT(PyObject *operand1, PyObject *operand2) {
1073 return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_FLOAT(operand1, operand2);
1074}
1075#endif
1076
1077#if PYTHON_VERSION < 0x300
1078/* Code referring to "OBJECT" corresponds to any Python object and "FLOAT" to Python 'float'. */
1079static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_FLOAT(PyObject *operand1,
1080 PyObject *operand2) {
1081 PyTypeObject *type1 = Py_TYPE(operand1);
1082
1083#if defined(_MSC_VER)
1084#pragma warning(push)
1085#pragma warning(disable : 4101)
1086#endif
1087 NUITKA_MAY_BE_UNUSED bool cbool_result;
1088 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1089#if defined(_MSC_VER)
1090#pragma warning(pop)
1091#endif
1092
1093 binaryfunc slot1 =
1094 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divide : NULL;
1095 binaryfunc slot2 = NULL;
1096
1097 if (!(type1 == &PyFloat_Type)) {
1098 // Different types, need to consider second value slot.
1099
1100 slot2 = PyFloat_Type.tp_as_number->nb_divide;
1101
1102 if (slot1 == slot2) {
1103 slot2 = NULL;
1104 }
1105 }
1106
1107 if (slot1 != NULL) {
1108 PyObject *x = slot1(operand1, operand2);
1109
1110 if (x != Py_NotImplemented) {
1111 obj_result = x;
1112 goto exit_binary_result_object;
1113 }
1114
1115 Py_DECREF_IMMORTAL(x);
1116 }
1117
1118 if (slot2 != NULL) {
1119 PyObject *x = slot2(operand1, operand2);
1120
1121 if (x != Py_NotImplemented) {
1122 obj_result = x;
1123 goto exit_binary_result_object;
1124 }
1125
1126 Py_DECREF_IMMORTAL(x);
1127 }
1128
1129#if PYTHON_VERSION < 0x300
1130 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
1131 coercion c1 =
1132 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
1133
1134 if (c1 != NULL) {
1135 PyObject *coerced1 = operand1;
1136 PyObject *coerced2 = operand2;
1137
1138 int err = c1(&coerced1, &coerced2);
1139
1140 if (unlikely(err < 0)) {
1141 goto exit_binary_exception;
1142 }
1143
1144 if (err == 0) {
1145 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1146
1147 if (likely(mv == NULL)) {
1148 binaryfunc slot = mv->nb_divide;
1149
1150 if (likely(slot != NULL)) {
1151 PyObject *x = slot(coerced1, coerced2);
1152
1153 Py_DECREF(coerced1);
1154 Py_DECREF(coerced2);
1155
1156 obj_result = x;
1157 goto exit_binary_result_object;
1158 }
1159 }
1160
1161 // nb_coerce took a reference.
1162 Py_DECREF(coerced1);
1163 Py_DECREF(coerced2);
1164 }
1165 }
1166 coercion c2 = PyFloat_Type.tp_as_number->nb_coerce;
1167
1168 if (c2 != NULL) {
1169 PyObject *coerced1 = operand1;
1170 PyObject *coerced2 = operand2;
1171
1172 int err = c2(&coerced2, &coerced1);
1173
1174 if (unlikely(err < 0)) {
1175 goto exit_binary_exception;
1176 }
1177
1178 if (err == 0) {
1179 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1180
1181 if (likely(mv == NULL)) {
1182 binaryfunc slot = mv->nb_divide;
1183
1184 if (likely(slot != NULL)) {
1185 PyObject *x = slot(coerced1, coerced2);
1186
1187 Py_DECREF(coerced1);
1188 Py_DECREF(coerced2);
1189
1190 obj_result = x;
1191 goto exit_binary_result_object;
1192 }
1193 }
1194
1195 // nb_coerce took a reference.
1196 Py_DECREF(coerced1);
1197 Py_DECREF(coerced2);
1198 }
1199 }
1200 }
1201#endif
1202
1203 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and 'float'", type1->tp_name);
1204 goto exit_binary_exception;
1205
1206exit_binary_result_object:
1207 return obj_result;
1208
1209exit_binary_exception:
1210 return NULL;
1211}
1212static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_FLOAT(PyObject *operand1, PyObject *operand2) {
1213 CHECK_OBJECT(operand1);
1214 CHECK_OBJECT(operand2);
1215 assert(PyFloat_CheckExact(operand2));
1216
1217 PyTypeObject *type1 = Py_TYPE(operand1);
1218
1219 if (type1 == &PyFloat_Type) {
1220 PyObject *result;
1221
1222 // return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_FLOAT(operand1, operand2);
1223
1224#if defined(_MSC_VER)
1225#pragma warning(push)
1226#pragma warning(disable : 4101)
1227#endif
1228 // Not every code path will make use of all possible results.
1229 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1230 NUITKA_MAY_BE_UNUSED long clong_result;
1231 NUITKA_MAY_BE_UNUSED double cfloat_result;
1232#if defined(_MSC_VER)
1233#pragma warning(pop)
1234#endif
1235
1236 CHECK_OBJECT(operand1);
1237 assert(PyFloat_CheckExact(operand1));
1238 CHECK_OBJECT(operand2);
1239 assert(PyFloat_CheckExact(operand2));
1240
1241 const double a = PyFloat_AS_DOUBLE(operand1);
1242 const double b = PyFloat_AS_DOUBLE(operand2);
1243
1244 if (unlikely(b == 0.0)) {
1245 PyThreadState *tstate = PyThreadState_GET();
1246
1247 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "float division by zero");
1248 goto exit_result_exception;
1249 }
1250
1251 {
1252 double r = a / b;
1253
1254 cfloat_result = r;
1255 goto exit_result_ok_cfloat;
1256 }
1257
1258 exit_result_ok_cfloat:
1259 result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
1260 goto exit_result_ok;
1261
1262 exit_result_ok:
1263 return result;
1264
1265 exit_result_exception:
1266 return NULL;
1267 }
1268
1269 return __BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_FLOAT(operand1, operand2);
1270}
1271
1272PyObject *BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_FLOAT(PyObject *operand1, PyObject *operand2) {
1273 return _BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_FLOAT(operand1, operand2);
1274}
1275#endif
1276
1277#if PYTHON_VERSION < 0x300
1278/* Code referring to "FLOAT" corresponds to Python 'float' and "OBJECT" to any Python object. */
1279static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_OBJECT(PyObject *operand1,
1280 PyObject *operand2) {
1281 PyTypeObject *type2 = Py_TYPE(operand2);
1282
1283#if defined(_MSC_VER)
1284#pragma warning(push)
1285#pragma warning(disable : 4101)
1286#endif
1287 NUITKA_MAY_BE_UNUSED bool cbool_result;
1288 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1289#if defined(_MSC_VER)
1290#pragma warning(pop)
1291#endif
1292
1293 binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_divide;
1294 binaryfunc slot2 = NULL;
1295
1296 if (!(&PyFloat_Type == type2)) {
1297 // Different types, need to consider second value slot.
1298
1299 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divide : NULL;
1300
1301 if (slot1 == slot2) {
1302 slot2 = NULL;
1303 }
1304 }
1305
1306 if (slot1 != NULL) {
1307 if (slot2 != NULL) {
1308 if (Nuitka_Type_IsSubtype(type2, &PyFloat_Type)) {
1309 PyObject *x = slot2(operand1, operand2);
1310
1311 if (x != Py_NotImplemented) {
1312 obj_result = x;
1313 goto exit_binary_result_object;
1314 }
1315
1316 Py_DECREF_IMMORTAL(x);
1317 slot2 = NULL;
1318 }
1319 }
1320
1321 PyObject *x = slot1(operand1, operand2);
1322
1323 if (x != Py_NotImplemented) {
1324 obj_result = x;
1325 goto exit_binary_result_object;
1326 }
1327
1328 Py_DECREF_IMMORTAL(x);
1329 }
1330
1331 if (slot2 != NULL) {
1332 PyObject *x = slot2(operand1, operand2);
1333
1334 if (x != Py_NotImplemented) {
1335 obj_result = x;
1336 goto exit_binary_result_object;
1337 }
1338
1339 Py_DECREF_IMMORTAL(x);
1340 }
1341
1342#if PYTHON_VERSION < 0x300
1343 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
1344 coercion c1 = PyFloat_Type.tp_as_number->nb_coerce;
1345
1346 if (c1 != NULL) {
1347 PyObject *coerced1 = operand1;
1348 PyObject *coerced2 = operand2;
1349
1350 int err = c1(&coerced1, &coerced2);
1351
1352 if (unlikely(err < 0)) {
1353 goto exit_binary_exception;
1354 }
1355
1356 if (err == 0) {
1357 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1358
1359 if (likely(mv == NULL)) {
1360 binaryfunc slot = mv->nb_divide;
1361
1362 if (likely(slot != NULL)) {
1363 PyObject *x = slot(coerced1, coerced2);
1364
1365 Py_DECREF(coerced1);
1366 Py_DECREF(coerced2);
1367
1368 obj_result = x;
1369 goto exit_binary_result_object;
1370 }
1371 }
1372
1373 // nb_coerce took a reference.
1374 Py_DECREF(coerced1);
1375 Py_DECREF(coerced2);
1376 }
1377 }
1378 coercion c2 =
1379 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
1380
1381 if (c2 != NULL) {
1382 PyObject *coerced1 = operand1;
1383 PyObject *coerced2 = operand2;
1384
1385 int err = c2(&coerced2, &coerced1);
1386
1387 if (unlikely(err < 0)) {
1388 goto exit_binary_exception;
1389 }
1390
1391 if (err == 0) {
1392 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1393
1394 if (likely(mv == NULL)) {
1395 binaryfunc slot = mv->nb_divide;
1396
1397 if (likely(slot != NULL)) {
1398 PyObject *x = slot(coerced1, coerced2);
1399
1400 Py_DECREF(coerced1);
1401 Py_DECREF(coerced2);
1402
1403 obj_result = x;
1404 goto exit_binary_result_object;
1405 }
1406 }
1407
1408 // nb_coerce took a reference.
1409 Py_DECREF(coerced1);
1410 Py_DECREF(coerced2);
1411 }
1412 }
1413 }
1414#endif
1415
1416 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'float' and '%s'", type2->tp_name);
1417 goto exit_binary_exception;
1418
1419exit_binary_result_object:
1420 return obj_result;
1421
1422exit_binary_exception:
1423 return NULL;
1424}
1425static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_OBJECT(PyObject *operand1, PyObject *operand2) {
1426 CHECK_OBJECT(operand1);
1427 assert(PyFloat_CheckExact(operand1));
1428 CHECK_OBJECT(operand2);
1429
1430 PyTypeObject *type2 = Py_TYPE(operand2);
1431
1432 if (&PyFloat_Type == type2) {
1433 PyObject *result;
1434
1435 // return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_FLOAT(operand1, operand2);
1436
1437#if defined(_MSC_VER)
1438#pragma warning(push)
1439#pragma warning(disable : 4101)
1440#endif
1441 // Not every code path will make use of all possible results.
1442 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1443 NUITKA_MAY_BE_UNUSED long clong_result;
1444 NUITKA_MAY_BE_UNUSED double cfloat_result;
1445#if defined(_MSC_VER)
1446#pragma warning(pop)
1447#endif
1448
1449 CHECK_OBJECT(operand1);
1450 assert(PyFloat_CheckExact(operand1));
1451 CHECK_OBJECT(operand2);
1452 assert(PyFloat_CheckExact(operand2));
1453
1454 const double a = PyFloat_AS_DOUBLE(operand1);
1455 const double b = PyFloat_AS_DOUBLE(operand2);
1456
1457 if (unlikely(b == 0.0)) {
1458 PyThreadState *tstate = PyThreadState_GET();
1459
1460 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "float division by zero");
1461 goto exit_result_exception;
1462 }
1463
1464 {
1465 double r = a / b;
1466
1467 cfloat_result = r;
1468 goto exit_result_ok_cfloat;
1469 }
1470
1471 exit_result_ok_cfloat:
1472 result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
1473 goto exit_result_ok;
1474
1475 exit_result_ok:
1476 return result;
1477
1478 exit_result_exception:
1479 return NULL;
1480 }
1481
1482 return __BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_OBJECT(operand1, operand2);
1483}
1484
1485PyObject *BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_OBJECT(PyObject *operand1, PyObject *operand2) {
1486 return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_OBJECT(operand1, operand2);
1487}
1488#endif
1489
1490#if PYTHON_VERSION < 0x300
1491/* Code referring to "FLOAT" corresponds to Python 'float' and "LONG" to Python2 'long', Python3 'int'. */
1492static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_LONG(PyObject *operand1, PyObject *operand2) {
1493 CHECK_OBJECT(operand1);
1494 assert(PyFloat_CheckExact(operand1));
1495 CHECK_OBJECT(operand2);
1496 assert(PyLong_CheckExact(operand2));
1497
1498#if defined(_MSC_VER)
1499#pragma warning(push)
1500#pragma warning(disable : 4101)
1501#endif
1502 NUITKA_MAY_BE_UNUSED bool cbool_result;
1503 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1504#if defined(_MSC_VER)
1505#pragma warning(pop)
1506#endif
1507
1508 binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_divide;
1509 // Slot2 ignored on purpose, type1 takes precedence.
1510
1511 if (slot1 != NULL) {
1512 PyObject *x = slot1(operand1, operand2);
1513
1514 if (x != Py_NotImplemented) {
1515 obj_result = x;
1516 goto exit_binary_result_object;
1517 }
1518
1519 Py_DECREF_IMMORTAL(x);
1520 }
1521
1522 // Statically recognized that coercion is not possible with these types
1523
1524#if PYTHON_VERSION < 0x300
1525 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'float' and 'long'");
1526#else
1527 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'float' and 'int'");
1528#endif
1529 goto exit_binary_exception;
1530
1531exit_binary_result_object:
1532 return obj_result;
1533
1534exit_binary_exception:
1535 return NULL;
1536}
1537
1538PyObject *BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_LONG(PyObject *operand1, PyObject *operand2) {
1539 return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_LONG(operand1, operand2);
1540}
1541#endif
1542
1543#if PYTHON_VERSION < 0x300
1544/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "FLOAT" to Python 'float'. */
1545static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_LONG_FLOAT(PyObject *operand1, PyObject *operand2) {
1546 CHECK_OBJECT(operand1);
1547 assert(PyLong_CheckExact(operand1));
1548 CHECK_OBJECT(operand2);
1549 assert(PyFloat_CheckExact(operand2));
1550
1551#if defined(_MSC_VER)
1552#pragma warning(push)
1553#pragma warning(disable : 4101)
1554#endif
1555 NUITKA_MAY_BE_UNUSED bool cbool_result;
1556 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1557#if defined(_MSC_VER)
1558#pragma warning(pop)
1559#endif
1560
1561 // Slot1 ignored on purpose, type2 takes precedence.
1562 binaryfunc slot2 = NULL;
1563
1564 if (!(0)) {
1565 // Different types, need to consider second value slot.
1566
1567 slot2 = PyFloat_Type.tp_as_number->nb_divide;
1568 }
1569
1570 if (slot2 != NULL) {
1571 PyObject *x = slot2(operand1, operand2);
1572
1573 if (x != Py_NotImplemented) {
1574 obj_result = x;
1575 goto exit_binary_result_object;
1576 }
1577
1578 Py_DECREF_IMMORTAL(x);
1579 }
1580
1581 // Statically recognized that coercion is not possible with these types
1582
1583#if PYTHON_VERSION < 0x300
1584 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'long' and 'float'");
1585#else
1586 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'int' and 'float'");
1587#endif
1588 goto exit_binary_exception;
1589
1590exit_binary_result_object:
1591 return obj_result;
1592
1593exit_binary_exception:
1594 return NULL;
1595}
1596
1597PyObject *BINARY_OPERATION_OLDDIV_OBJECT_LONG_FLOAT(PyObject *operand1, PyObject *operand2) {
1598 return _BINARY_OPERATION_OLDDIV_OBJECT_LONG_FLOAT(operand1, operand2);
1599}
1600#endif
1601
1602#if PYTHON_VERSION < 0x300
1603/* Code referring to "FLOAT" corresponds to Python 'float' and "INT" to Python2 'int'. */
1604static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_INT(PyObject *operand1, PyObject *operand2) {
1605 CHECK_OBJECT(operand1);
1606 assert(PyFloat_CheckExact(operand1));
1607 CHECK_OBJECT(operand2);
1608 assert(PyInt_CheckExact(operand2));
1609
1610#if defined(_MSC_VER)
1611#pragma warning(push)
1612#pragma warning(disable : 4101)
1613#endif
1614 NUITKA_MAY_BE_UNUSED bool cbool_result;
1615 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1616#if defined(_MSC_VER)
1617#pragma warning(pop)
1618#endif
1619
1620 binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_divide;
1621 // Slot2 ignored on purpose, type1 takes precedence.
1622
1623 if (slot1 != NULL) {
1624 PyObject *x = slot1(operand1, operand2);
1625
1626 if (x != Py_NotImplemented) {
1627 obj_result = x;
1628 goto exit_binary_result_object;
1629 }
1630
1631 Py_DECREF_IMMORTAL(x);
1632 }
1633
1634 // Statically recognized that coercion is not possible with these types
1635
1636 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'float' and 'int'");
1637 goto exit_binary_exception;
1638
1639exit_binary_result_object:
1640 return obj_result;
1641
1642exit_binary_exception:
1643 return NULL;
1644}
1645
1646PyObject *BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_INT(PyObject *operand1, PyObject *operand2) {
1647 return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_INT(operand1, operand2);
1648}
1649#endif
1650
1651#if PYTHON_VERSION < 0x300
1652/* Code referring to "INT" corresponds to Python2 'int' and "FLOAT" to Python 'float'. */
1653static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_INT_FLOAT(PyObject *operand1, PyObject *operand2) {
1654 CHECK_OBJECT(operand1);
1655 assert(PyInt_CheckExact(operand1));
1656 CHECK_OBJECT(operand2);
1657 assert(PyFloat_CheckExact(operand2));
1658
1659#if defined(_MSC_VER)
1660#pragma warning(push)
1661#pragma warning(disable : 4101)
1662#endif
1663 NUITKA_MAY_BE_UNUSED bool cbool_result;
1664 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1665#if defined(_MSC_VER)
1666#pragma warning(pop)
1667#endif
1668
1669 // Slot1 ignored on purpose, type2 takes precedence.
1670 binaryfunc slot2 = NULL;
1671
1672 if (!(0)) {
1673 // Different types, need to consider second value slot.
1674
1675 slot2 = PyFloat_Type.tp_as_number->nb_divide;
1676 }
1677
1678 if (slot2 != NULL) {
1679 PyObject *x = slot2(operand1, operand2);
1680
1681 if (x != Py_NotImplemented) {
1682 obj_result = x;
1683 goto exit_binary_result_object;
1684 }
1685
1686 Py_DECREF_IMMORTAL(x);
1687 }
1688
1689 // Statically recognized that coercion is not possible with these types
1690
1691 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'int' and 'float'");
1692 goto exit_binary_exception;
1693
1694exit_binary_result_object:
1695 return obj_result;
1696
1697exit_binary_exception:
1698 return NULL;
1699}
1700
1701PyObject *BINARY_OPERATION_OLDDIV_OBJECT_INT_FLOAT(PyObject *operand1, PyObject *operand2) {
1702 return _BINARY_OPERATION_OLDDIV_OBJECT_INT_FLOAT(operand1, operand2);
1703}
1704#endif
1705
1706#if PYTHON_VERSION < 0x300
1707/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "INT" to Python2 'int'. */
1708static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
1709 CHECK_OBJECT(operand1);
1710 assert(PyLong_CheckExact(operand1));
1711 CHECK_OBJECT(operand2);
1712 assert(PyInt_CheckExact(operand2));
1713
1714#if defined(_MSC_VER)
1715#pragma warning(push)
1716#pragma warning(disable : 4101)
1717#endif
1718 NUITKA_MAY_BE_UNUSED bool cbool_result;
1719 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1720#if defined(_MSC_VER)
1721#pragma warning(pop)
1722#endif
1723
1724 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_divide;
1725 // Slot2 ignored on purpose, type1 takes precedence.
1726
1727 if (slot1 != NULL) {
1728 PyObject *x = slot1(operand1, operand2);
1729
1730 if (x != Py_NotImplemented) {
1731 obj_result = x;
1732 goto exit_binary_result_object;
1733 }
1734
1735 Py_DECREF_IMMORTAL(x);
1736 }
1737
1738 // Statically recognized that coercion is not possible with these types
1739
1740 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'long' and 'int'");
1741 goto exit_binary_exception;
1742
1743exit_binary_result_object:
1744 return obj_result;
1745
1746exit_binary_exception:
1747 return NULL;
1748}
1749
1750PyObject *BINARY_OPERATION_OLDDIV_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
1751 return _BINARY_OPERATION_OLDDIV_OBJECT_LONG_INT(operand1, operand2);
1752}
1753#endif
1754
1755#if PYTHON_VERSION < 0x300
1756/* Code referring to "INT" corresponds to Python2 'int' and "LONG" to Python2 'long', Python3 'int'. */
1757static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
1758 CHECK_OBJECT(operand1);
1759 assert(PyInt_CheckExact(operand1));
1760 CHECK_OBJECT(operand2);
1761 assert(PyLong_CheckExact(operand2));
1762
1763#if defined(_MSC_VER)
1764#pragma warning(push)
1765#pragma warning(disable : 4101)
1766#endif
1767 NUITKA_MAY_BE_UNUSED bool cbool_result;
1768 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1769#if defined(_MSC_VER)
1770#pragma warning(pop)
1771#endif
1772
1773 // Slot1 ignored on purpose, type2 takes precedence.
1774 binaryfunc slot2 = NULL;
1775
1776 if (!(0)) {
1777 // Different types, need to consider second value slot.
1778
1779 slot2 = PyLong_Type.tp_as_number->nb_divide;
1780 }
1781
1782 if (slot2 != NULL) {
1783 PyObject *x = slot2(operand1, operand2);
1784
1785 if (x != Py_NotImplemented) {
1786 obj_result = x;
1787 goto exit_binary_result_object;
1788 }
1789
1790 Py_DECREF_IMMORTAL(x);
1791 }
1792
1793 // Statically recognized that coercion is not possible with these types
1794
1795 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: 'int' and 'long'");
1796 goto exit_binary_exception;
1797
1798exit_binary_result_object:
1799 return obj_result;
1800
1801exit_binary_exception:
1802 return NULL;
1803}
1804
1805PyObject *BINARY_OPERATION_OLDDIV_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
1806 return _BINARY_OPERATION_OLDDIV_OBJECT_INT_LONG(operand1, operand2);
1807}
1808#endif
1809
1810#if PYTHON_VERSION < 0x300
1811/* Code referring to "INT" corresponds to Python2 'int' and "CLONG" to C platform long value. */
1812static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_INT_CLONG(PyObject *operand1, long operand2) {
1813 CHECK_OBJECT(operand1);
1814 assert(PyInt_CheckExact(operand1));
1815
1816 PyObject *result;
1817
1818 // Not every code path will make use of all possible results.
1819#if defined(_MSC_VER)
1820#pragma warning(push)
1821#pragma warning(disable : 4101)
1822#endif
1823 NUITKA_MAY_BE_UNUSED bool cbool_result;
1824 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1825 NUITKA_MAY_BE_UNUSED long clong_result;
1826 NUITKA_MAY_BE_UNUSED double cfloat_result;
1827#if defined(_MSC_VER)
1828#pragma warning(pop)
1829#endif
1830
1831 CHECK_OBJECT(operand1);
1832 assert(PyInt_CheckExact(operand1));
1833
1834 const long a = PyInt_AS_LONG(operand1);
1835 const long b = operand2;
1836
1837 if (unlikely(b == 0)) {
1838 PyThreadState *tstate = PyThreadState_GET();
1839
1840 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "integer division or modulo by zero");
1841 goto exit_result_exception;
1842 }
1843
1844 /* TODO: Isn't this a very specific value only, of which we could
1845 * hardcode the constant result. Not sure how well the C compiler
1846 * optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
1847 * -1 has to be rare anyway.
1848 */
1849
1850 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
1851 long a_div_b = a / b;
1852 long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
1853
1854 if (a_mod_b && (b ^ a_mod_b) < 0) {
1855 a_mod_b += b;
1856 a_div_b -= 1;
1857 }
1858
1859 clong_result = a_div_b;
1860 goto exit_result_ok_clong;
1861 }
1862
1863 {
1864 PyObject *operand1_object = operand1;
1865 PyObject *operand2_object = Nuitka_PyLong_FromLong(operand2);
1866
1867 PyObject *r = PyLong_Type.tp_as_number->nb_divide(operand1_object, operand2_object);
1868 assert(r != Py_NotImplemented);
1869
1870 Py_DECREF(operand2_object);
1871
1872 obj_result = r;
1873 goto exit_result_object;
1874 }
1875
1876exit_result_ok_clong:
1877 result = Nuitka_PyInt_FromLong(clong_result);
1878 goto exit_result_ok;
1879
1880exit_result_object:
1881 if (unlikely(obj_result == NULL)) {
1882 goto exit_result_exception;
1883 }
1884 result = obj_result;
1885 goto exit_result_ok;
1886
1887exit_result_ok:
1888 return result;
1889
1890exit_result_exception:
1891 return NULL;
1892}
1893
1894PyObject *BINARY_OPERATION_OLDDIV_OBJECT_INT_CLONG(PyObject *operand1, long operand2) {
1895 return _BINARY_OPERATION_OLDDIV_OBJECT_INT_CLONG(operand1, operand2);
1896}
1897#endif
1898
1899#if PYTHON_VERSION < 0x300
1900/* Code referring to "CLONG" corresponds to C platform long value and "INT" to Python2 'int'. */
1901static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_CLONG_INT(long operand1, PyObject *operand2) {
1902
1903 CHECK_OBJECT(operand2);
1904 assert(PyInt_CheckExact(operand2));
1905
1906 PyObject *result;
1907
1908 // Not every code path will make use of all possible results.
1909#if defined(_MSC_VER)
1910#pragma warning(push)
1911#pragma warning(disable : 4101)
1912#endif
1913 NUITKA_MAY_BE_UNUSED bool cbool_result;
1914 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1915 NUITKA_MAY_BE_UNUSED long clong_result;
1916 NUITKA_MAY_BE_UNUSED double cfloat_result;
1917#if defined(_MSC_VER)
1918#pragma warning(pop)
1919#endif
1920
1921 CHECK_OBJECT(operand2);
1922 assert(PyInt_CheckExact(operand2));
1923
1924 const long a = operand1;
1925 const long b = PyInt_AS_LONG(operand2);
1926
1927 if (unlikely(b == 0)) {
1928 PyThreadState *tstate = PyThreadState_GET();
1929
1930 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "integer division or modulo by zero");
1931 goto exit_result_exception;
1932 }
1933
1934 /* TODO: Isn't this a very specific value only, of which we could
1935 * hardcode the constant result. Not sure how well the C compiler
1936 * optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
1937 * -1 has to be rare anyway.
1938 */
1939
1940 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
1941 long a_div_b = a / b;
1942 long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
1943
1944 if (a_mod_b && (b ^ a_mod_b) < 0) {
1945 a_mod_b += b;
1946 a_div_b -= 1;
1947 }
1948
1949 clong_result = a_div_b;
1950 goto exit_result_ok_clong;
1951 }
1952
1953 {
1954 PyObject *operand1_object = Nuitka_PyLong_FromLong(operand1);
1955 PyObject *operand2_object = operand2;
1956
1957 PyObject *r = PyLong_Type.tp_as_number->nb_divide(operand1_object, operand2_object);
1958 assert(r != Py_NotImplemented);
1959
1960 Py_DECREF(operand1_object);
1961
1962 obj_result = r;
1963 goto exit_result_object;
1964 }
1965
1966exit_result_ok_clong:
1967 result = Nuitka_PyInt_FromLong(clong_result);
1968 goto exit_result_ok;
1969
1970exit_result_object:
1971 if (unlikely(obj_result == NULL)) {
1972 goto exit_result_exception;
1973 }
1974 result = obj_result;
1975 goto exit_result_ok;
1976
1977exit_result_ok:
1978 return result;
1979
1980exit_result_exception:
1981 return NULL;
1982}
1983
1984PyObject *BINARY_OPERATION_OLDDIV_OBJECT_CLONG_INT(long operand1, PyObject *operand2) {
1985 return _BINARY_OPERATION_OLDDIV_OBJECT_CLONG_INT(operand1, operand2);
1986}
1987#endif
1988
1989#if PYTHON_VERSION < 0x300
1990/* Code referring to "FLOAT" corresponds to Python 'float' and "CFLOAT" to C platform float value. */
1991static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_CFLOAT(PyObject *operand1, double operand2) {
1992 CHECK_OBJECT(operand1);
1993 assert(PyFloat_CheckExact(operand1));
1994
1995 PyObject *result;
1996
1997#if defined(_MSC_VER)
1998#pragma warning(push)
1999#pragma warning(disable : 4101)
2000#endif
2001 // Not every code path will make use of all possible results.
2002 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2003 NUITKA_MAY_BE_UNUSED long clong_result;
2004 NUITKA_MAY_BE_UNUSED double cfloat_result;
2005#if defined(_MSC_VER)
2006#pragma warning(pop)
2007#endif
2008
2009 CHECK_OBJECT(operand1);
2010 assert(PyFloat_CheckExact(operand1));
2011
2012 const double a = PyFloat_AS_DOUBLE(operand1);
2013 const double b = operand2;
2014
2015 if (unlikely(b == 0.0)) {
2016 PyThreadState *tstate = PyThreadState_GET();
2017
2018 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "float division by zero");
2019 goto exit_result_exception;
2020 }
2021
2022 {
2023 double r = a / b;
2024
2025 cfloat_result = r;
2026 goto exit_result_ok_cfloat;
2027 }
2028
2029exit_result_ok_cfloat:
2030 result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
2031 goto exit_result_ok;
2032
2033exit_result_ok:
2034 return result;
2035
2036exit_result_exception:
2037 return NULL;
2038}
2039
2040PyObject *BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_CFLOAT(PyObject *operand1, double operand2) {
2041 return _BINARY_OPERATION_OLDDIV_OBJECT_FLOAT_CFLOAT(operand1, operand2);
2042}
2043#endif
2044
2045#if PYTHON_VERSION < 0x300
2046/* Code referring to "CFLOAT" corresponds to C platform float value and "FLOAT" to Python 'float'. */
2047static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_CFLOAT_FLOAT(double operand1, PyObject *operand2) {
2048
2049 CHECK_OBJECT(operand2);
2050 assert(PyFloat_CheckExact(operand2));
2051
2052 PyObject *result;
2053
2054#if defined(_MSC_VER)
2055#pragma warning(push)
2056#pragma warning(disable : 4101)
2057#endif
2058 // Not every code path will make use of all possible results.
2059 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2060 NUITKA_MAY_BE_UNUSED long clong_result;
2061 NUITKA_MAY_BE_UNUSED double cfloat_result;
2062#if defined(_MSC_VER)
2063#pragma warning(pop)
2064#endif
2065
2066 CHECK_OBJECT(operand2);
2067 assert(PyFloat_CheckExact(operand2));
2068
2069 const double a = operand1;
2070 const double b = PyFloat_AS_DOUBLE(operand2);
2071
2072 if (unlikely(b == 0.0)) {
2073 PyThreadState *tstate = PyThreadState_GET();
2074
2075 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "float division by zero");
2076 goto exit_result_exception;
2077 }
2078
2079 {
2080 double r = a / b;
2081
2082 cfloat_result = r;
2083 goto exit_result_ok_cfloat;
2084 }
2085
2086exit_result_ok_cfloat:
2087 result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
2088 goto exit_result_ok;
2089
2090exit_result_ok:
2091 return result;
2092
2093exit_result_exception:
2094 return NULL;
2095}
2096
2097PyObject *BINARY_OPERATION_OLDDIV_OBJECT_CFLOAT_FLOAT(double operand1, PyObject *operand2) {
2098 return _BINARY_OPERATION_OLDDIV_OBJECT_CFLOAT_FLOAT(operand1, operand2);
2099}
2100#endif
2101
2102#if PYTHON_VERSION < 0x300
2103/* Code referring to "OBJECT" corresponds to any Python object and "OBJECT" to any Python object. */
2104static PyObject *_BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2105 CHECK_OBJECT(operand1);
2106 CHECK_OBJECT(operand2);
2107
2108#if PYTHON_VERSION < 0x300
2109 if (PyInt_CheckExact(operand1) && PyInt_CheckExact(operand2)) {
2110 PyObject *result;
2111
2112 // Not every code path will make use of all possible results.
2113#if defined(_MSC_VER)
2114#pragma warning(push)
2115#pragma warning(disable : 4101)
2116#endif
2117 NUITKA_MAY_BE_UNUSED bool cbool_result;
2118 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2119 NUITKA_MAY_BE_UNUSED long clong_result;
2120 NUITKA_MAY_BE_UNUSED double cfloat_result;
2121#if defined(_MSC_VER)
2122#pragma warning(pop)
2123#endif
2124
2125 CHECK_OBJECT(operand1);
2126 assert(PyInt_CheckExact(operand1));
2127 CHECK_OBJECT(operand2);
2128 assert(PyInt_CheckExact(operand2));
2129
2130 const long a = PyInt_AS_LONG(operand1);
2131 const long b = PyInt_AS_LONG(operand2);
2132
2133 if (unlikely(b == 0)) {
2134 PyThreadState *tstate = PyThreadState_GET();
2135
2136 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError, "integer division or modulo by zero");
2137 goto exit_result_exception;
2138 }
2139
2140 /* TODO: Isn't this a very specific value only, of which we could
2141 * hardcode the constant result. Not sure how well the C compiler
2142 * optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
2143 * -1 has to be rare anyway.
2144 */
2145
2146 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
2147 long a_div_b = a / b;
2148 long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
2149
2150 if (a_mod_b && (b ^ a_mod_b) < 0) {
2151 a_mod_b += b;
2152 a_div_b -= 1;
2153 }
2154
2155 clong_result = a_div_b;
2156 goto exit_result_ok_clong;
2157 }
2158
2159 {
2160 PyObject *operand1_object = operand1;
2161 PyObject *operand2_object = operand2;
2162
2163 PyObject *r = PyLong_Type.tp_as_number->nb_divide(operand1_object, operand2_object);
2164 assert(r != Py_NotImplemented);
2165
2166 obj_result = r;
2167 goto exit_result_object;
2168 }
2169
2170 exit_result_ok_clong:
2171 result = Nuitka_PyInt_FromLong(clong_result);
2172 goto exit_result_ok;
2173
2174 exit_result_object:
2175 if (unlikely(obj_result == NULL)) {
2176 goto exit_result_exception;
2177 }
2178 result = obj_result;
2179 goto exit_result_ok;
2180
2181 exit_result_ok:
2182 return result;
2183
2184 exit_result_exception:
2185 return NULL;
2186 }
2187#endif
2188
2189 PyTypeObject *type1 = Py_TYPE(operand1);
2190 PyTypeObject *type2 = Py_TYPE(operand2);
2191
2192#if defined(_MSC_VER)
2193#pragma warning(push)
2194#pragma warning(disable : 4101)
2195#endif
2196 NUITKA_MAY_BE_UNUSED bool cbool_result;
2197 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2198#if defined(_MSC_VER)
2199#pragma warning(pop)
2200#endif
2201
2202 binaryfunc slot1 =
2203 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divide : NULL;
2204 binaryfunc slot2 = NULL;
2205
2206 if (!(type1 == type2)) {
2207 // Different types, need to consider second value slot.
2208
2209 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divide : NULL;
2210
2211 if (slot1 == slot2) {
2212 slot2 = NULL;
2213 }
2214 }
2215
2216 if (slot1 != NULL) {
2217 if (slot2 != NULL) {
2218 if (Nuitka_Type_IsSubtype(type2, type1)) {
2219 PyObject *x = slot2(operand1, operand2);
2220
2221 if (x != Py_NotImplemented) {
2222 obj_result = x;
2223 goto exit_binary_result_object;
2224 }
2225
2226 Py_DECREF_IMMORTAL(x);
2227 slot2 = NULL;
2228 }
2229 }
2230
2231 PyObject *x = slot1(operand1, operand2);
2232
2233 if (x != Py_NotImplemented) {
2234 obj_result = x;
2235 goto exit_binary_result_object;
2236 }
2237
2238 Py_DECREF_IMMORTAL(x);
2239 }
2240
2241 if (slot2 != NULL) {
2242 PyObject *x = slot2(operand1, operand2);
2243
2244 if (x != Py_NotImplemented) {
2245 obj_result = x;
2246 goto exit_binary_result_object;
2247 }
2248
2249 Py_DECREF_IMMORTAL(x);
2250 }
2251
2252#if PYTHON_VERSION < 0x300
2253 if (!NEW_STYLE_NUMBER_TYPE(type1) || !NEW_STYLE_NUMBER_TYPE(type2)) {
2254 coercion c1 =
2255 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
2256
2257 if (c1 != NULL) {
2258 PyObject *coerced1 = operand1;
2259 PyObject *coerced2 = operand2;
2260
2261 int err = c1(&coerced1, &coerced2);
2262
2263 if (unlikely(err < 0)) {
2264 goto exit_binary_exception;
2265 }
2266
2267 if (err == 0) {
2268 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2269
2270 if (likely(mv == NULL)) {
2271 binaryfunc slot = mv->nb_divide;
2272
2273 if (likely(slot != NULL)) {
2274 PyObject *x = slot(coerced1, coerced2);
2275
2276 Py_DECREF(coerced1);
2277 Py_DECREF(coerced2);
2278
2279 obj_result = x;
2280 goto exit_binary_result_object;
2281 }
2282 }
2283
2284 // nb_coerce took a reference.
2285 Py_DECREF(coerced1);
2286 Py_DECREF(coerced2);
2287 }
2288 }
2289 coercion c2 =
2290 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
2291
2292 if (c2 != NULL) {
2293 PyObject *coerced1 = operand1;
2294 PyObject *coerced2 = operand2;
2295
2296 int err = c2(&coerced2, &coerced1);
2297
2298 if (unlikely(err < 0)) {
2299 goto exit_binary_exception;
2300 }
2301
2302 if (err == 0) {
2303 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2304
2305 if (likely(mv == NULL)) {
2306 binaryfunc slot = mv->nb_divide;
2307
2308 if (likely(slot != NULL)) {
2309 PyObject *x = slot(coerced1, coerced2);
2310
2311 Py_DECREF(coerced1);
2312 Py_DECREF(coerced2);
2313
2314 obj_result = x;
2315 goto exit_binary_result_object;
2316 }
2317 }
2318
2319 // nb_coerce took a reference.
2320 Py_DECREF(coerced1);
2321 Py_DECREF(coerced2);
2322 }
2323 }
2324 }
2325#endif
2326
2327 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for /: '%s' and '%s'", type1->tp_name, type2->tp_name);
2328 goto exit_binary_exception;
2329
2330exit_binary_result_object:
2331 return obj_result;
2332
2333exit_binary_exception:
2334 return NULL;
2335}
2336
2337PyObject *BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2338 return _BINARY_OPERATION_OLDDIV_OBJECT_OBJECT_OBJECT(operand1, operand2);
2339}
2340#endif
2341
2342// Part of "Nuitka", an optimizing Python compiler that is compatible and
2343// integrates with CPython, but also works on its own.
2344//
2345// Licensed under the Apache License, Version 2.0 (the "License");
2346// you may not use this file except in compliance with the License.
2347// You may obtain a copy of the License at
2348//
2349// http://www.apache.org/licenses/LICENSE-2.0
2350//
2351// Unless required by applicable law or agreed to in writing, software
2352// distributed under the License is distributed on an "AS IS" BASIS,
2353// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2354// See the License for the specific language governing permissions and
2355// limitations under the License.