cytriangle 1.0.2__cp311-cp311-macosx_14_0_arm64.whl → 1.0.4__cp311-cp311-macosx_14_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cytriangle might be problematic. Click here for more details.

cytriangle/cytriangle.c CHANGED
@@ -1,4 +1,4 @@
1
- /* Generated by Cython 3.0.10 */
1
+ /* Generated by Cython 3.0.11 */
2
2
 
3
3
  /* BEGIN: Cython Metadata
4
4
  {
@@ -61,10 +61,10 @@ END: Cython Metadata */
61
61
  #else
62
62
  #define __PYX_EXTRA_ABI_MODULE_NAME ""
63
63
  #endif
64
- #define CYTHON_ABI "3_0_10" __PYX_EXTRA_ABI_MODULE_NAME
64
+ #define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME
65
65
  #define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
66
66
  #define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
67
- #define CYTHON_HEX_VERSION 0x03000AF0
67
+ #define CYTHON_HEX_VERSION 0x03000BF0
68
68
  #define CYTHON_FUTURE_DIVISION 1
69
69
  #include <stddef.h>
70
70
  #ifndef offsetof
@@ -2071,11 +2071,7 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);
2071
2071
  static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);
2072
2072
 
2073
2073
  /* HasAttr.proto */
2074
- #if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1
2075
- #define __Pyx_HasAttr(o, n) PyObject_HasAttrWithError(o, n)
2076
- #else
2077
2074
  static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);
2078
- #endif
2079
2075
 
2080
2076
  /* IncludeStructmemberH.proto */
2081
2077
  #include <structmember.h>
@@ -2130,22 +2126,22 @@ static int __Pyx_setup_reduce(PyObject* type_obj);
2130
2126
  #endif
2131
2127
 
2132
2128
  /* TypeImport.proto */
2133
- #ifndef __PYX_HAVE_RT_ImportType_proto_3_0_10
2134
- #define __PYX_HAVE_RT_ImportType_proto_3_0_10
2129
+ #ifndef __PYX_HAVE_RT_ImportType_proto_3_0_11
2130
+ #define __PYX_HAVE_RT_ImportType_proto_3_0_11
2135
2131
  #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
2136
2132
  #include <stdalign.h>
2137
2133
  #endif
2138
2134
  #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || __cplusplus >= 201103L
2139
- #define __PYX_GET_STRUCT_ALIGNMENT_3_0_10(s) alignof(s)
2135
+ #define __PYX_GET_STRUCT_ALIGNMENT_3_0_11(s) alignof(s)
2140
2136
  #else
2141
- #define __PYX_GET_STRUCT_ALIGNMENT_3_0_10(s) sizeof(void*)
2137
+ #define __PYX_GET_STRUCT_ALIGNMENT_3_0_11(s) sizeof(void*)
2142
2138
  #endif
2143
- enum __Pyx_ImportType_CheckSize_3_0_10 {
2144
- __Pyx_ImportType_CheckSize_Error_3_0_10 = 0,
2145
- __Pyx_ImportType_CheckSize_Warn_3_0_10 = 1,
2146
- __Pyx_ImportType_CheckSize_Ignore_3_0_10 = 2
2139
+ enum __Pyx_ImportType_CheckSize_3_0_11 {
2140
+ __Pyx_ImportType_CheckSize_Error_3_0_11 = 0,
2141
+ __Pyx_ImportType_CheckSize_Warn_3_0_11 = 1,
2142
+ __Pyx_ImportType_CheckSize_Ignore_3_0_11 = 2
2147
2143
  };
2148
- static PyTypeObject *__Pyx_ImportType_3_0_10(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_10 check_size);
2144
+ static PyTypeObject *__Pyx_ImportType_3_0_11(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_11 check_size);
2149
2145
  #endif
2150
2146
 
2151
2147
  /* ImportDottedModule.proto */
@@ -3716,7 +3712,7 @@ static PyObject *__pyx_pf_10cytriangle_10cytriangle_10CyTriangle_2input_dict(str
3716
3712
  PyObject *__pyx_t_1 = NULL;
3717
3713
  PyObject *__pyx_t_2 = NULL;
3718
3714
  PyObject *__pyx_t_3 = NULL;
3719
- int __pyx_t_4;
3715
+ unsigned int __pyx_t_4;
3720
3716
  int __pyx_lineno = 0;
3721
3717
  const char *__pyx_filename = NULL;
3722
3718
  int __pyx_clineno = 0;
@@ -3892,7 +3888,7 @@ static PyObject *__pyx_pf_10cytriangle_10cytriangle_10CyTriangle_4output_dict(st
3892
3888
  PyObject *__pyx_t_1 = NULL;
3893
3889
  PyObject *__pyx_t_2 = NULL;
3894
3890
  PyObject *__pyx_t_3 = NULL;
3895
- int __pyx_t_4;
3891
+ unsigned int __pyx_t_4;
3896
3892
  int __pyx_lineno = 0;
3897
3893
  const char *__pyx_filename = NULL;
3898
3894
  int __pyx_clineno = 0;
@@ -4068,7 +4064,7 @@ static PyObject *__pyx_pf_10cytriangle_10cytriangle_10CyTriangle_6voronoi_dict(s
4068
4064
  PyObject *__pyx_t_1 = NULL;
4069
4065
  PyObject *__pyx_t_2 = NULL;
4070
4066
  PyObject *__pyx_t_3 = NULL;
4071
- int __pyx_t_4;
4067
+ unsigned int __pyx_t_4;
4072
4068
  int __pyx_lineno = 0;
4073
4069
  const char *__pyx_filename = NULL;
4074
4070
  int __pyx_clineno = 0;
@@ -4242,7 +4238,7 @@ static PyObject *__pyx_pf_10cytriangle_10cytriangle_10CyTriangle_8validate_input
4242
4238
  PyObject *__pyx_t_2 = NULL;
4243
4239
  PyObject *__pyx_t_3 = NULL;
4244
4240
  PyObject *__pyx_t_4 = NULL;
4245
- int __pyx_t_5;
4241
+ unsigned int __pyx_t_5;
4246
4242
  int __pyx_t_6;
4247
4243
  int __pyx_lineno = 0;
4248
4244
  const char *__pyx_filename = NULL;
@@ -4664,7 +4660,7 @@ static PyObject *__pyx_f_10cytriangle_10cytriangle_10CyTriangle_triangulate(stru
4664
4660
  PyObject *__pyx_t_2 = NULL;
4665
4661
  PyObject *__pyx_t_3 = NULL;
4666
4662
  PyObject *__pyx_t_4 = NULL;
4667
- int __pyx_t_5;
4663
+ unsigned int __pyx_t_5;
4668
4664
  int __pyx_t_6;
4669
4665
  Py_ssize_t __pyx_t_7;
4670
4666
  Py_UCS4 __pyx_t_8;
@@ -5093,7 +5089,7 @@ static PyObject *__pyx_f_10cytriangle_10cytriangle_10CyTriangle_delaunay(struct
5093
5089
  PyObject *__pyx_t_2 = NULL;
5094
5090
  PyObject *__pyx_t_3 = NULL;
5095
5091
  PyObject *__pyx_t_4 = NULL;
5096
- int __pyx_t_5;
5092
+ unsigned int __pyx_t_5;
5097
5093
  int __pyx_t_6;
5098
5094
  int __pyx_t_7;
5099
5095
  char *__pyx_t_8;
@@ -5430,7 +5426,7 @@ static PyObject *__pyx_f_10cytriangle_10cytriangle_10CyTriangle_convex_hull(stru
5430
5426
  PyObject *__pyx_t_2 = NULL;
5431
5427
  PyObject *__pyx_t_3 = NULL;
5432
5428
  PyObject *__pyx_t_4 = NULL;
5433
- int __pyx_t_5;
5429
+ unsigned int __pyx_t_5;
5434
5430
  int __pyx_t_6;
5435
5431
  int __pyx_t_7;
5436
5432
  char *__pyx_t_8;
@@ -5767,7 +5763,7 @@ static PyObject *__pyx_f_10cytriangle_10cytriangle_10CyTriangle_voronoi(struct _
5767
5763
  PyObject *__pyx_t_2 = NULL;
5768
5764
  PyObject *__pyx_t_3 = NULL;
5769
5765
  PyObject *__pyx_t_4 = NULL;
5770
- int __pyx_t_5;
5766
+ unsigned int __pyx_t_5;
5771
5767
  int __pyx_t_6;
5772
5768
  int __pyx_t_7;
5773
5769
  char *__pyx_t_8;
@@ -7043,7 +7039,7 @@ static PyObject *__pyx_pf_10cytriangle_10cytriangle_2__pyx_unpickle_CyTriangle(C
7043
7039
  int __pyx_t_2;
7044
7040
  PyObject *__pyx_t_3 = NULL;
7045
7041
  PyObject *__pyx_t_4 = NULL;
7046
- int __pyx_t_5;
7042
+ unsigned int __pyx_t_5;
7047
7043
  int __pyx_lineno = 0;
7048
7044
  const char *__pyx_filename = NULL;
7049
7045
  int __pyx_clineno = 0;
@@ -7225,7 +7221,7 @@ static PyObject *__pyx_f_10cytriangle_10cytriangle___pyx_unpickle_CyTriangle__se
7225
7221
  PyObject *__pyx_t_5 = NULL;
7226
7222
  PyObject *__pyx_t_6 = NULL;
7227
7223
  PyObject *__pyx_t_7 = NULL;
7228
- int __pyx_t_8;
7224
+ unsigned int __pyx_t_8;
7229
7225
  int __pyx_lineno = 0;
7230
7226
  const char *__pyx_filename = NULL;
7231
7227
  int __pyx_clineno = 0;
@@ -7571,6 +7567,9 @@ static PyTypeObject __pyx_type_10cytriangle_10cytriangle_CyTriangle = {
7571
7567
  #if PY_VERSION_HEX >= 0x030C0000
7572
7568
  0, /*tp_watched*/
7573
7569
  #endif
7570
+ #if PY_VERSION_HEX >= 0x030d00A4
7571
+ 0, /*tp_versions_used*/
7572
+ #endif
7574
7573
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
7575
7574
  0, /*tp_pypy_flags*/
7576
7575
  #endif
@@ -8069,7 +8068,7 @@ static int __Pyx_modinit_type_import_code(void) {
8069
8068
  /*--- Type import code ---*/
8070
8069
  __pyx_t_1 = PyImport_ImportModule("cytriangle.cytriangleio"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error)
8071
8070
  __Pyx_GOTREF(__pyx_t_1);
8072
- __pyx_ptype_10cytriangle_12cytriangleio_TriangleIO = __Pyx_ImportType_3_0_10(__pyx_t_1, "cytriangle.cytriangleio", "TriangleIO", sizeof(struct __pyx_obj_10cytriangle_12cytriangleio_TriangleIO), __PYX_GET_STRUCT_ALIGNMENT_3_0_10(struct __pyx_obj_10cytriangle_12cytriangleio_TriangleIO),__Pyx_ImportType_CheckSize_Warn_3_0_10); if (!__pyx_ptype_10cytriangle_12cytriangleio_TriangleIO) __PYX_ERR(2, 3, __pyx_L1_error)
8071
+ __pyx_ptype_10cytriangle_12cytriangleio_TriangleIO = __Pyx_ImportType_3_0_11(__pyx_t_1, "cytriangle.cytriangleio", "TriangleIO", sizeof(struct __pyx_obj_10cytriangle_12cytriangleio_TriangleIO), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_10cytriangle_12cytriangleio_TriangleIO),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_10cytriangle_12cytriangleio_TriangleIO) __PYX_ERR(2, 3, __pyx_L1_error)
8073
8072
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8074
8073
  __Pyx_RefNannyFinishContext();
8075
8074
  return 0;
@@ -10203,7 +10202,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
10203
10202
  }
10204
10203
 
10205
10204
  /* HasAttr */
10206
- #if __PYX_LIMITED_VERSION_HEX < 0x030d00A1
10207
10205
  static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
10208
10206
  PyObject *r;
10209
10207
  if (unlikely(!__Pyx_PyBaseString_Check(n))) {
@@ -10220,7 +10218,6 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
10220
10218
  return 1;
10221
10219
  }
10222
10220
  }
10223
- #endif
10224
10221
 
10225
10222
  /* FixUpExtensionType */
10226
10223
  #if CYTHON_USE_TYPE_SPECS
@@ -10834,10 +10831,10 @@ __PYX_GOOD:
10834
10831
  #endif
10835
10832
 
10836
10833
  /* TypeImport */
10837
- #ifndef __PYX_HAVE_RT_ImportType_3_0_10
10838
- #define __PYX_HAVE_RT_ImportType_3_0_10
10839
- static PyTypeObject *__Pyx_ImportType_3_0_10(PyObject *module, const char *module_name, const char *class_name,
10840
- size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_10 check_size)
10834
+ #ifndef __PYX_HAVE_RT_ImportType_3_0_11
10835
+ #define __PYX_HAVE_RT_ImportType_3_0_11
10836
+ static PyTypeObject *__Pyx_ImportType_3_0_11(PyObject *module, const char *module_name, const char *class_name,
10837
+ size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_11 check_size)
10841
10838
  {
10842
10839
  PyObject *result = 0;
10843
10840
  char warning[200];
@@ -10891,7 +10888,7 @@ static PyTypeObject *__Pyx_ImportType_3_0_10(PyObject *module, const char *modul
10891
10888
  module_name, class_name, size, basicsize+itemsize);
10892
10889
  goto bad;
10893
10890
  }
10894
- if (check_size == __Pyx_ImportType_CheckSize_Error_3_0_10 &&
10891
+ if (check_size == __Pyx_ImportType_CheckSize_Error_3_0_11 &&
10895
10892
  ((size_t)basicsize > size || (size_t)(basicsize + itemsize) < size)) {
10896
10893
  PyErr_Format(PyExc_ValueError,
10897
10894
  "%.200s.%.200s size changed, may indicate binary incompatibility. "
@@ -10899,7 +10896,7 @@ static PyTypeObject *__Pyx_ImportType_3_0_10(PyObject *module, const char *modul
10899
10896
  module_name, class_name, size, basicsize, basicsize+itemsize);
10900
10897
  goto bad;
10901
10898
  }
10902
- else if (check_size == __Pyx_ImportType_CheckSize_Warn_3_0_10 && (size_t)basicsize > size) {
10899
+ else if (check_size == __Pyx_ImportType_CheckSize_Warn_3_0_11 && (size_t)basicsize > size) {
10903
10900
  PyOS_snprintf(warning, sizeof(warning),
10904
10901
  "%s.%s size changed, may indicate binary incompatibility. "
10905
10902
  "Expected %zd from C header, got %zd from PyObject",
@@ -12162,6 +12159,9 @@ static PyTypeObject __pyx_CyFunctionType_type = {
12162
12159
  #if PY_VERSION_HEX >= 0x030C0000
12163
12160
  0,
12164
12161
  #endif
12162
+ #if PY_VERSION_HEX >= 0x030d00A4
12163
+ 0,
12164
+ #endif
12165
12165
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
12166
12166
  0,
12167
12167
  #endif
@@ -12579,245 +12579,239 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
12579
12579
  }
12580
12580
  return (long) val;
12581
12581
  }
12582
- } else
12582
+ }
12583
12583
  #endif
12584
- if (likely(PyLong_Check(x))) {
12585
- if (is_unsigned) {
12584
+ if (unlikely(!PyLong_Check(x))) {
12585
+ long val;
12586
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
12587
+ if (!tmp) return (long) -1;
12588
+ val = __Pyx_PyInt_As_long(tmp);
12589
+ Py_DECREF(tmp);
12590
+ return val;
12591
+ }
12592
+ if (is_unsigned) {
12586
12593
  #if CYTHON_USE_PYLONG_INTERNALS
12587
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
12588
- goto raise_neg_overflow;
12589
- } else if (__Pyx_PyLong_IsCompact(x)) {
12590
- __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
12591
- } else {
12592
- const digit* digits = __Pyx_PyLong_Digits(x);
12593
- assert(__Pyx_PyLong_DigitCount(x) > 1);
12594
- switch (__Pyx_PyLong_DigitCount(x)) {
12595
- case 2:
12596
- if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
12597
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12598
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12599
- } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
12600
- return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
12601
- }
12594
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
12595
+ goto raise_neg_overflow;
12596
+ } else if (__Pyx_PyLong_IsCompact(x)) {
12597
+ __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
12598
+ } else {
12599
+ const digit* digits = __Pyx_PyLong_Digits(x);
12600
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
12601
+ switch (__Pyx_PyLong_DigitCount(x)) {
12602
+ case 2:
12603
+ if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
12604
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12605
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12606
+ } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
12607
+ return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
12602
12608
  }
12603
- break;
12604
- case 3:
12605
- if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
12606
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12607
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12608
- } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
12609
- return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
12610
- }
12609
+ }
12610
+ break;
12611
+ case 3:
12612
+ if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
12613
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12614
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12615
+ } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
12616
+ return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
12611
12617
  }
12612
- break;
12613
- case 4:
12614
- if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
12615
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12616
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12617
- } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
12618
- return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
12619
- }
12618
+ }
12619
+ break;
12620
+ case 4:
12621
+ if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
12622
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12623
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12624
+ } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
12625
+ return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
12620
12626
  }
12621
- break;
12622
- }
12627
+ }
12628
+ break;
12623
12629
  }
12630
+ }
12624
12631
  #endif
12625
12632
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
12626
- if (unlikely(Py_SIZE(x) < 0)) {
12627
- goto raise_neg_overflow;
12628
- }
12633
+ if (unlikely(Py_SIZE(x) < 0)) {
12634
+ goto raise_neg_overflow;
12635
+ }
12629
12636
  #else
12630
- {
12631
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
12632
- if (unlikely(result < 0))
12633
- return (long) -1;
12634
- if (unlikely(result == 1))
12635
- goto raise_neg_overflow;
12636
- }
12637
+ {
12638
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
12639
+ if (unlikely(result < 0))
12640
+ return (long) -1;
12641
+ if (unlikely(result == 1))
12642
+ goto raise_neg_overflow;
12643
+ }
12637
12644
  #endif
12638
- if ((sizeof(long) <= sizeof(unsigned long))) {
12639
- __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
12645
+ if ((sizeof(long) <= sizeof(unsigned long))) {
12646
+ __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
12640
12647
  #ifdef HAVE_LONG_LONG
12641
- } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
12642
- __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
12648
+ } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
12649
+ __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
12643
12650
  #endif
12644
- }
12645
- } else {
12651
+ }
12652
+ } else {
12646
12653
  #if CYTHON_USE_PYLONG_INTERNALS
12647
- if (__Pyx_PyLong_IsCompact(x)) {
12648
- __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
12649
- } else {
12650
- const digit* digits = __Pyx_PyLong_Digits(x);
12651
- assert(__Pyx_PyLong_DigitCount(x) > 1);
12652
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
12653
- case -2:
12654
- if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
12655
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12656
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12657
- } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
12658
- return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12659
- }
12654
+ if (__Pyx_PyLong_IsCompact(x)) {
12655
+ __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
12656
+ } else {
12657
+ const digit* digits = __Pyx_PyLong_Digits(x);
12658
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
12659
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
12660
+ case -2:
12661
+ if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
12662
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12663
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12664
+ } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
12665
+ return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12660
12666
  }
12661
- break;
12662
- case 2:
12663
- if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
12664
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12665
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12666
- } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
12667
- return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12668
- }
12667
+ }
12668
+ break;
12669
+ case 2:
12670
+ if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
12671
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12672
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12673
+ } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
12674
+ return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12669
12675
  }
12670
- break;
12671
- case -3:
12672
- if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
12673
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12674
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12675
- } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
12676
- return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12677
- }
12676
+ }
12677
+ break;
12678
+ case -3:
12679
+ if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
12680
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12681
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12682
+ } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
12683
+ return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12678
12684
  }
12679
- break;
12680
- case 3:
12681
- if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
12682
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12683
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12684
- } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
12685
- return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12686
- }
12685
+ }
12686
+ break;
12687
+ case 3:
12688
+ if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
12689
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12690
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12691
+ } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
12692
+ return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12687
12693
  }
12688
- break;
12689
- case -4:
12690
- if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
12691
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12692
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12693
- } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
12694
- return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12695
- }
12694
+ }
12695
+ break;
12696
+ case -4:
12697
+ if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
12698
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12699
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12700
+ } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
12701
+ return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12696
12702
  }
12697
- break;
12698
- case 4:
12699
- if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
12700
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12701
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12702
- } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
12703
- return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12704
- }
12703
+ }
12704
+ break;
12705
+ case 4:
12706
+ if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
12707
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12708
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12709
+ } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
12710
+ return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
12705
12711
  }
12706
- break;
12707
- }
12712
+ }
12713
+ break;
12708
12714
  }
12715
+ }
12709
12716
  #endif
12710
- if ((sizeof(long) <= sizeof(long))) {
12711
- __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
12717
+ if ((sizeof(long) <= sizeof(long))) {
12718
+ __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
12712
12719
  #ifdef HAVE_LONG_LONG
12713
- } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
12714
- __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
12720
+ } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
12721
+ __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
12715
12722
  #endif
12716
- }
12723
+ }
12724
+ }
12725
+ {
12726
+ long val;
12727
+ int ret = -1;
12728
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
12729
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
12730
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
12731
+ if (unlikely(bytes_copied == -1)) {
12732
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
12733
+ goto raise_overflow;
12734
+ } else {
12735
+ ret = 0;
12736
+ }
12737
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
12738
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
12739
+ unsigned char *bytes = (unsigned char *)&val;
12740
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
12741
+ bytes, sizeof(val),
12742
+ is_little, !is_unsigned);
12743
+ #else
12744
+ PyObject *v;
12745
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
12746
+ int bits, remaining_bits, is_negative = 0;
12747
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
12748
+ if (likely(PyLong_CheckExact(x))) {
12749
+ v = __Pyx_NewRef(x);
12750
+ } else {
12751
+ v = PyNumber_Long(x);
12752
+ if (unlikely(!v)) return (long) -1;
12753
+ assert(PyLong_CheckExact(v));
12717
12754
  }
12718
12755
  {
12719
- long val;
12720
- PyObject *v = __Pyx_PyNumber_IntOrLong(x);
12721
- #if PY_MAJOR_VERSION < 3
12722
- if (likely(v) && !PyLong_Check(v)) {
12723
- PyObject *tmp = v;
12724
- v = PyNumber_Long(tmp);
12725
- Py_DECREF(tmp);
12726
- }
12727
- #endif
12728
- if (likely(v)) {
12729
- int ret = -1;
12730
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
12731
- int one = 1; int is_little = (int)*(unsigned char *)&one;
12732
- unsigned char *bytes = (unsigned char *)&val;
12733
- ret = _PyLong_AsByteArray((PyLongObject *)v,
12734
- bytes, sizeof(val),
12735
- is_little, !is_unsigned);
12736
- #else
12737
- PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
12738
- int bits, remaining_bits, is_negative = 0;
12739
- long idigit;
12740
- int chunk_size = (sizeof(long) < 8) ? 30 : 62;
12741
- if (unlikely(!PyLong_CheckExact(v))) {
12742
- PyObject *tmp = v;
12743
- v = PyNumber_Long(v);
12744
- assert(PyLong_CheckExact(v));
12745
- Py_DECREF(tmp);
12746
- if (unlikely(!v)) return (long) -1;
12747
- }
12748
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
12749
- if (Py_SIZE(x) == 0)
12750
- return (long) 0;
12751
- is_negative = Py_SIZE(x) < 0;
12752
- #else
12753
- {
12754
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
12755
- if (unlikely(result < 0))
12756
- return (long) -1;
12757
- is_negative = result == 1;
12758
- }
12759
- #endif
12760
- if (is_unsigned && unlikely(is_negative)) {
12761
- goto raise_neg_overflow;
12762
- } else if (is_negative) {
12763
- stepval = PyNumber_Invert(v);
12764
- if (unlikely(!stepval))
12765
- return (long) -1;
12766
- } else {
12767
- stepval = __Pyx_NewRef(v);
12768
- }
12769
- val = (long) 0;
12770
- mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
12771
- shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
12772
- for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
12773
- PyObject *tmp, *digit;
12774
- digit = PyNumber_And(stepval, mask);
12775
- if (unlikely(!digit)) goto done;
12776
- idigit = PyLong_AsLong(digit);
12777
- Py_DECREF(digit);
12778
- if (unlikely(idigit < 0)) goto done;
12779
- tmp = PyNumber_Rshift(stepval, shift);
12780
- if (unlikely(!tmp)) goto done;
12781
- Py_DECREF(stepval); stepval = tmp;
12782
- val |= ((long) idigit) << bits;
12783
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
12784
- if (Py_SIZE(stepval) == 0)
12785
- goto unpacking_done;
12786
- #endif
12787
- }
12788
- idigit = PyLong_AsLong(stepval);
12789
- if (unlikely(idigit < 0)) goto done;
12790
- remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
12791
- if (unlikely(idigit >= (1L << remaining_bits)))
12792
- goto raise_overflow;
12793
- val |= ((long) idigit) << bits;
12794
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
12795
- unpacking_done:
12796
- #endif
12797
- if (!is_unsigned) {
12798
- if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
12799
- goto raise_overflow;
12800
- if (is_negative)
12801
- val = ~val;
12802
- }
12803
- ret = 0;
12804
- done:
12805
- Py_XDECREF(shift);
12806
- Py_XDECREF(mask);
12807
- Py_XDECREF(stepval);
12808
- #endif
12756
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
12757
+ if (unlikely(result < 0)) {
12809
12758
  Py_DECREF(v);
12810
- if (likely(!ret))
12811
- return val;
12759
+ return (long) -1;
12812
12760
  }
12813
- return (long) -1;
12761
+ is_negative = result == 1;
12814
12762
  }
12815
- } else {
12816
- long val;
12817
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
12818
- if (!tmp) return (long) -1;
12819
- val = __Pyx_PyInt_As_long(tmp);
12820
- Py_DECREF(tmp);
12763
+ if (is_unsigned && unlikely(is_negative)) {
12764
+ Py_DECREF(v);
12765
+ goto raise_neg_overflow;
12766
+ } else if (is_negative) {
12767
+ stepval = PyNumber_Invert(v);
12768
+ Py_DECREF(v);
12769
+ if (unlikely(!stepval))
12770
+ return (long) -1;
12771
+ } else {
12772
+ stepval = v;
12773
+ }
12774
+ v = NULL;
12775
+ val = (long) 0;
12776
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
12777
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
12778
+ for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
12779
+ PyObject *tmp, *digit;
12780
+ long idigit;
12781
+ digit = PyNumber_And(stepval, mask);
12782
+ if (unlikely(!digit)) goto done;
12783
+ idigit = PyLong_AsLong(digit);
12784
+ Py_DECREF(digit);
12785
+ if (unlikely(idigit < 0)) goto done;
12786
+ val |= ((long) idigit) << bits;
12787
+ tmp = PyNumber_Rshift(stepval, shift);
12788
+ if (unlikely(!tmp)) goto done;
12789
+ Py_DECREF(stepval); stepval = tmp;
12790
+ }
12791
+ Py_DECREF(shift); shift = NULL;
12792
+ Py_DECREF(mask); mask = NULL;
12793
+ {
12794
+ long idigit = PyLong_AsLong(stepval);
12795
+ if (unlikely(idigit < 0)) goto done;
12796
+ remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
12797
+ if (unlikely(idigit >= (1L << remaining_bits)))
12798
+ goto raise_overflow;
12799
+ val |= ((long) idigit) << bits;
12800
+ }
12801
+ if (!is_unsigned) {
12802
+ if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
12803
+ goto raise_overflow;
12804
+ if (is_negative)
12805
+ val = ~val;
12806
+ }
12807
+ ret = 0;
12808
+ done:
12809
+ Py_XDECREF(shift);
12810
+ Py_XDECREF(mask);
12811
+ Py_XDECREF(stepval);
12812
+ #endif
12813
+ if (unlikely(ret))
12814
+ return (long) -1;
12821
12815
  return val;
12822
12816
  }
12823
12817
  raise_overflow:
@@ -12861,12 +12855,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
12861
12855
  }
12862
12856
  }
12863
12857
  {
12864
- int one = 1; int little = (int)*(unsigned char *)&one;
12865
12858
  unsigned char *bytes = (unsigned char *)&value;
12866
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
12859
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
12860
+ if (is_unsigned) {
12861
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
12862
+ } else {
12863
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
12864
+ }
12865
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
12866
+ int one = 1; int little = (int)*(unsigned char *)&one;
12867
12867
  return _PyLong_FromByteArray(bytes, sizeof(long),
12868
12868
  little, !is_unsigned);
12869
12869
  #else
12870
+ int one = 1; int little = (int)*(unsigned char *)&one;
12870
12871
  PyObject *from_bytes, *result = NULL;
12871
12872
  PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
12872
12873
  from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
@@ -12932,245 +12933,239 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
12932
12933
  }
12933
12934
  return (int) val;
12934
12935
  }
12935
- } else
12936
+ }
12936
12937
  #endif
12937
- if (likely(PyLong_Check(x))) {
12938
- if (is_unsigned) {
12938
+ if (unlikely(!PyLong_Check(x))) {
12939
+ int val;
12940
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
12941
+ if (!tmp) return (int) -1;
12942
+ val = __Pyx_PyInt_As_int(tmp);
12943
+ Py_DECREF(tmp);
12944
+ return val;
12945
+ }
12946
+ if (is_unsigned) {
12939
12947
  #if CYTHON_USE_PYLONG_INTERNALS
12940
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
12941
- goto raise_neg_overflow;
12942
- } else if (__Pyx_PyLong_IsCompact(x)) {
12943
- __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
12944
- } else {
12945
- const digit* digits = __Pyx_PyLong_Digits(x);
12946
- assert(__Pyx_PyLong_DigitCount(x) > 1);
12947
- switch (__Pyx_PyLong_DigitCount(x)) {
12948
- case 2:
12949
- if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
12950
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12951
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12952
- } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
12953
- return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
12954
- }
12948
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
12949
+ goto raise_neg_overflow;
12950
+ } else if (__Pyx_PyLong_IsCompact(x)) {
12951
+ __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
12952
+ } else {
12953
+ const digit* digits = __Pyx_PyLong_Digits(x);
12954
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
12955
+ switch (__Pyx_PyLong_DigitCount(x)) {
12956
+ case 2:
12957
+ if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
12958
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
12959
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12960
+ } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
12961
+ return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
12955
12962
  }
12956
- break;
12957
- case 3:
12958
- if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
12959
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12960
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12961
- } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
12962
- return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
12963
- }
12963
+ }
12964
+ break;
12965
+ case 3:
12966
+ if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
12967
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
12968
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12969
+ } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
12970
+ return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
12964
12971
  }
12965
- break;
12966
- case 4:
12967
- if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
12968
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12969
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12970
- } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
12971
- return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
12972
- }
12972
+ }
12973
+ break;
12974
+ case 4:
12975
+ if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
12976
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
12977
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
12978
+ } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
12979
+ return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
12973
12980
  }
12974
- break;
12975
- }
12981
+ }
12982
+ break;
12976
12983
  }
12984
+ }
12977
12985
  #endif
12978
12986
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
12979
- if (unlikely(Py_SIZE(x) < 0)) {
12980
- goto raise_neg_overflow;
12981
- }
12987
+ if (unlikely(Py_SIZE(x) < 0)) {
12988
+ goto raise_neg_overflow;
12989
+ }
12982
12990
  #else
12983
- {
12984
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
12985
- if (unlikely(result < 0))
12986
- return (int) -1;
12987
- if (unlikely(result == 1))
12988
- goto raise_neg_overflow;
12989
- }
12991
+ {
12992
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
12993
+ if (unlikely(result < 0))
12994
+ return (int) -1;
12995
+ if (unlikely(result == 1))
12996
+ goto raise_neg_overflow;
12997
+ }
12990
12998
  #endif
12991
- if ((sizeof(int) <= sizeof(unsigned long))) {
12992
- __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
12999
+ if ((sizeof(int) <= sizeof(unsigned long))) {
13000
+ __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
12993
13001
  #ifdef HAVE_LONG_LONG
12994
- } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
12995
- __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
13002
+ } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
13003
+ __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
12996
13004
  #endif
12997
- }
12998
- } else {
13005
+ }
13006
+ } else {
12999
13007
  #if CYTHON_USE_PYLONG_INTERNALS
13000
- if (__Pyx_PyLong_IsCompact(x)) {
13001
- __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
13002
- } else {
13003
- const digit* digits = __Pyx_PyLong_Digits(x);
13004
- assert(__Pyx_PyLong_DigitCount(x) > 1);
13005
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
13006
- case -2:
13007
- if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
13008
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
13009
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13010
- } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
13011
- return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13012
- }
13008
+ if (__Pyx_PyLong_IsCompact(x)) {
13009
+ __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
13010
+ } else {
13011
+ const digit* digits = __Pyx_PyLong_Digits(x);
13012
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
13013
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
13014
+ case -2:
13015
+ if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
13016
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
13017
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13018
+ } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
13019
+ return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13013
13020
  }
13014
- break;
13015
- case 2:
13016
- if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
13017
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
13018
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13019
- } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
13020
- return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13021
- }
13021
+ }
13022
+ break;
13023
+ case 2:
13024
+ if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
13025
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
13026
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13027
+ } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
13028
+ return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13022
13029
  }
13023
- break;
13024
- case -3:
13025
- if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
13026
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
13027
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13028
- } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
13029
- return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13030
- }
13030
+ }
13031
+ break;
13032
+ case -3:
13033
+ if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
13034
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
13035
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13036
+ } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
13037
+ return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13031
13038
  }
13032
- break;
13033
- case 3:
13034
- if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
13035
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
13036
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13037
- } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
13038
- return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13039
- }
13039
+ }
13040
+ break;
13041
+ case 3:
13042
+ if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
13043
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
13044
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13045
+ } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
13046
+ return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13040
13047
  }
13041
- break;
13042
- case -4:
13043
- if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
13044
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
13045
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13046
- } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
13047
- return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13048
- }
13048
+ }
13049
+ break;
13050
+ case -4:
13051
+ if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
13052
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
13053
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13054
+ } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
13055
+ return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13049
13056
  }
13050
- break;
13051
- case 4:
13052
- if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
13053
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
13054
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13055
- } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
13056
- return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13057
- }
13057
+ }
13058
+ break;
13059
+ case 4:
13060
+ if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
13061
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
13062
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
13063
+ } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
13064
+ return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
13058
13065
  }
13059
- break;
13060
- }
13066
+ }
13067
+ break;
13061
13068
  }
13069
+ }
13062
13070
  #endif
13063
- if ((sizeof(int) <= sizeof(long))) {
13064
- __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
13071
+ if ((sizeof(int) <= sizeof(long))) {
13072
+ __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
13065
13073
  #ifdef HAVE_LONG_LONG
13066
- } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
13067
- __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
13074
+ } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
13075
+ __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
13068
13076
  #endif
13069
- }
13077
+ }
13078
+ }
13079
+ {
13080
+ int val;
13081
+ int ret = -1;
13082
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
13083
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
13084
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
13085
+ if (unlikely(bytes_copied == -1)) {
13086
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
13087
+ goto raise_overflow;
13088
+ } else {
13089
+ ret = 0;
13090
+ }
13091
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
13092
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
13093
+ unsigned char *bytes = (unsigned char *)&val;
13094
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
13095
+ bytes, sizeof(val),
13096
+ is_little, !is_unsigned);
13097
+ #else
13098
+ PyObject *v;
13099
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
13100
+ int bits, remaining_bits, is_negative = 0;
13101
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
13102
+ if (likely(PyLong_CheckExact(x))) {
13103
+ v = __Pyx_NewRef(x);
13104
+ } else {
13105
+ v = PyNumber_Long(x);
13106
+ if (unlikely(!v)) return (int) -1;
13107
+ assert(PyLong_CheckExact(v));
13070
13108
  }
13071
13109
  {
13072
- int val;
13073
- PyObject *v = __Pyx_PyNumber_IntOrLong(x);
13074
- #if PY_MAJOR_VERSION < 3
13075
- if (likely(v) && !PyLong_Check(v)) {
13076
- PyObject *tmp = v;
13077
- v = PyNumber_Long(tmp);
13078
- Py_DECREF(tmp);
13079
- }
13080
- #endif
13081
- if (likely(v)) {
13082
- int ret = -1;
13083
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
13084
- int one = 1; int is_little = (int)*(unsigned char *)&one;
13085
- unsigned char *bytes = (unsigned char *)&val;
13086
- ret = _PyLong_AsByteArray((PyLongObject *)v,
13087
- bytes, sizeof(val),
13088
- is_little, !is_unsigned);
13089
- #else
13090
- PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
13091
- int bits, remaining_bits, is_negative = 0;
13092
- long idigit;
13093
- int chunk_size = (sizeof(long) < 8) ? 30 : 62;
13094
- if (unlikely(!PyLong_CheckExact(v))) {
13095
- PyObject *tmp = v;
13096
- v = PyNumber_Long(v);
13097
- assert(PyLong_CheckExact(v));
13098
- Py_DECREF(tmp);
13099
- if (unlikely(!v)) return (int) -1;
13100
- }
13101
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
13102
- if (Py_SIZE(x) == 0)
13103
- return (int) 0;
13104
- is_negative = Py_SIZE(x) < 0;
13105
- #else
13106
- {
13107
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
13108
- if (unlikely(result < 0))
13109
- return (int) -1;
13110
- is_negative = result == 1;
13111
- }
13112
- #endif
13113
- if (is_unsigned && unlikely(is_negative)) {
13114
- goto raise_neg_overflow;
13115
- } else if (is_negative) {
13116
- stepval = PyNumber_Invert(v);
13117
- if (unlikely(!stepval))
13118
- return (int) -1;
13119
- } else {
13120
- stepval = __Pyx_NewRef(v);
13121
- }
13122
- val = (int) 0;
13123
- mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
13124
- shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
13125
- for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
13126
- PyObject *tmp, *digit;
13127
- digit = PyNumber_And(stepval, mask);
13128
- if (unlikely(!digit)) goto done;
13129
- idigit = PyLong_AsLong(digit);
13130
- Py_DECREF(digit);
13131
- if (unlikely(idigit < 0)) goto done;
13132
- tmp = PyNumber_Rshift(stepval, shift);
13133
- if (unlikely(!tmp)) goto done;
13134
- Py_DECREF(stepval); stepval = tmp;
13135
- val |= ((int) idigit) << bits;
13136
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
13137
- if (Py_SIZE(stepval) == 0)
13138
- goto unpacking_done;
13139
- #endif
13140
- }
13141
- idigit = PyLong_AsLong(stepval);
13142
- if (unlikely(idigit < 0)) goto done;
13143
- remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
13144
- if (unlikely(idigit >= (1L << remaining_bits)))
13145
- goto raise_overflow;
13146
- val |= ((int) idigit) << bits;
13147
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
13148
- unpacking_done:
13149
- #endif
13150
- if (!is_unsigned) {
13151
- if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
13152
- goto raise_overflow;
13153
- if (is_negative)
13154
- val = ~val;
13155
- }
13156
- ret = 0;
13157
- done:
13158
- Py_XDECREF(shift);
13159
- Py_XDECREF(mask);
13160
- Py_XDECREF(stepval);
13161
- #endif
13110
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
13111
+ if (unlikely(result < 0)) {
13162
13112
  Py_DECREF(v);
13163
- if (likely(!ret))
13164
- return val;
13113
+ return (int) -1;
13165
13114
  }
13166
- return (int) -1;
13115
+ is_negative = result == 1;
13167
13116
  }
13168
- } else {
13169
- int val;
13170
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
13171
- if (!tmp) return (int) -1;
13172
- val = __Pyx_PyInt_As_int(tmp);
13173
- Py_DECREF(tmp);
13117
+ if (is_unsigned && unlikely(is_negative)) {
13118
+ Py_DECREF(v);
13119
+ goto raise_neg_overflow;
13120
+ } else if (is_negative) {
13121
+ stepval = PyNumber_Invert(v);
13122
+ Py_DECREF(v);
13123
+ if (unlikely(!stepval))
13124
+ return (int) -1;
13125
+ } else {
13126
+ stepval = v;
13127
+ }
13128
+ v = NULL;
13129
+ val = (int) 0;
13130
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
13131
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
13132
+ for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
13133
+ PyObject *tmp, *digit;
13134
+ long idigit;
13135
+ digit = PyNumber_And(stepval, mask);
13136
+ if (unlikely(!digit)) goto done;
13137
+ idigit = PyLong_AsLong(digit);
13138
+ Py_DECREF(digit);
13139
+ if (unlikely(idigit < 0)) goto done;
13140
+ val |= ((int) idigit) << bits;
13141
+ tmp = PyNumber_Rshift(stepval, shift);
13142
+ if (unlikely(!tmp)) goto done;
13143
+ Py_DECREF(stepval); stepval = tmp;
13144
+ }
13145
+ Py_DECREF(shift); shift = NULL;
13146
+ Py_DECREF(mask); mask = NULL;
13147
+ {
13148
+ long idigit = PyLong_AsLong(stepval);
13149
+ if (unlikely(idigit < 0)) goto done;
13150
+ remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
13151
+ if (unlikely(idigit >= (1L << remaining_bits)))
13152
+ goto raise_overflow;
13153
+ val |= ((int) idigit) << bits;
13154
+ }
13155
+ if (!is_unsigned) {
13156
+ if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
13157
+ goto raise_overflow;
13158
+ if (is_negative)
13159
+ val = ~val;
13160
+ }
13161
+ ret = 0;
13162
+ done:
13163
+ Py_XDECREF(shift);
13164
+ Py_XDECREF(mask);
13165
+ Py_XDECREF(stepval);
13166
+ #endif
13167
+ if (unlikely(ret))
13168
+ return (int) -1;
13174
13169
  return val;
13175
13170
  }
13176
13171
  raise_overflow: