pyogrio 0.8.0__cp312-cp312-win_amd64.whl → 0.10.0__cp312-cp312-win_amd64.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 pyogrio might be problematic. Click here for more details.

Files changed (101) hide show
  1. pyogrio/__init__.py +26 -18
  2. pyogrio/_compat.py +7 -1
  3. pyogrio/_env.py +4 -6
  4. pyogrio/_err.c +460 -445
  5. pyogrio/_err.cp312-win_amd64.pyd +0 -0
  6. pyogrio/_geometry.c +645 -612
  7. pyogrio/_geometry.cp312-win_amd64.pyd +0 -0
  8. pyogrio/_io.c +7764 -7602
  9. pyogrio/_io.cp312-win_amd64.pyd +0 -0
  10. pyogrio/_ogr.c +601 -609
  11. pyogrio/_ogr.cp312-win_amd64.pyd +0 -0
  12. pyogrio/_version.py +3 -3
  13. pyogrio/_vsi.c +7570 -2514
  14. pyogrio/_vsi.cp312-win_amd64.pyd +0 -0
  15. pyogrio/core.py +86 -20
  16. pyogrio/errors.py +9 -16
  17. pyogrio/gdal_data/GDAL-targets.cmake +1 -1
  18. pyogrio/gdal_data/GDALConfig.cmake +0 -1
  19. pyogrio/gdal_data/GDALConfigVersion.cmake +3 -3
  20. pyogrio/gdal_data/MM_m_idofic.csv +321 -0
  21. pyogrio/gdal_data/gdaltileindex.xsd +269 -0
  22. pyogrio/gdal_data/gdalvrt.xsd +130 -22
  23. pyogrio/gdal_data/ogrinfo_output.schema.json +23 -0
  24. pyogrio/gdal_data/ogrvrt.xsd +3 -0
  25. pyogrio/gdal_data/pci_datum.txt +222 -155
  26. pyogrio/gdal_data/pci_ellips.txt +90 -38
  27. pyogrio/gdal_data/vcpkg.spdx.json +21 -21
  28. pyogrio/gdal_data/vcpkg_abi_info.txt +27 -27
  29. pyogrio/geopandas.py +44 -27
  30. pyogrio/proj_data/proj-config-version.cmake +2 -2
  31. pyogrio/proj_data/proj-targets.cmake +1 -1
  32. pyogrio/proj_data/proj.db +0 -0
  33. pyogrio/proj_data/proj4-targets.cmake +1 -1
  34. pyogrio/proj_data/projjson.schema.json +1 -1
  35. pyogrio/proj_data/vcpkg.spdx.json +17 -17
  36. pyogrio/proj_data/vcpkg_abi_info.txt +15 -15
  37. pyogrio/raw.py +46 -30
  38. pyogrio/tests/conftest.py +206 -12
  39. pyogrio/tests/fixtures/README.md +32 -13
  40. pyogrio/tests/fixtures/curve.gpkg +0 -0
  41. pyogrio/tests/fixtures/{test_multisurface.gpkg → curvepolygon.gpkg} +0 -0
  42. pyogrio/tests/fixtures/line_zm.gpkg +0 -0
  43. pyogrio/tests/fixtures/multisurface.gpkg +0 -0
  44. pyogrio/tests/test_arrow.py +178 -24
  45. pyogrio/tests/test_core.py +162 -72
  46. pyogrio/tests/test_geopandas_io.py +341 -96
  47. pyogrio/tests/test_path.py +30 -17
  48. pyogrio/tests/test_raw_io.py +165 -54
  49. pyogrio/tests/test_util.py +56 -0
  50. pyogrio/util.py +55 -31
  51. pyogrio-0.10.0.dist-info/DELVEWHEEL +2 -0
  52. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/LICENSE +1 -1
  53. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/METADATA +37 -8
  54. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/RECORD +74 -89
  55. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/WHEEL +1 -1
  56. pyogrio.libs/{Lerc-62a2c1c74500e7815994b3e49b36750c.dll → Lerc-089e3fef3df84b17326dcddbf1dedaa4.dll} +0 -0
  57. pyogrio.libs/{gdal-2bfc6a9f962a8953b0640db9a272d797.dll → gdal-debee5933f0da7bb90b4bcd009023377.dll} +0 -0
  58. pyogrio.libs/{geos-289d7171bd083dfed1f8a90e4ae57442.dll → geos-ace4c5b5c1f569bb4213e7bbd0b0322e.dll} +0 -0
  59. pyogrio.libs/{geos_c-2a12859cd876719c648f1eb950b7d94c.dll → geos_c-7478ca0a86136b280d9b2d245c6f6627.dll} +0 -0
  60. pyogrio.libs/geotiff-c8fe8a095520a4ea4e465d27e06add3a.dll +0 -0
  61. pyogrio.libs/{iconv-2-f2d9304f8dc4cdd981024b520b73a099.dll → iconv-2-27352d156a5467ca5383d3951093ea5a.dll} +0 -0
  62. pyogrio.libs/{jpeg62-a67b2bf7fd32d34c565ae5bb6d47c224.dll → jpeg62-e56b6f95a95af498f4623b8da4cebd46.dll} +0 -0
  63. pyogrio.libs/{json-c-79a8df7e59952f5c5d594620e4b66c13.dll → json-c-c84940e2654a4f8468bfcf2ce992aa93.dll} +0 -0
  64. pyogrio.libs/libcurl-d69cfd4ad487d53d58743b6778ec85e7.dll +0 -0
  65. pyogrio.libs/{libexpat-fa55f107b678de136400c6d953c3cdde.dll → libexpat-6576a8d02641b6a3dbad35901ec200a7.dll} +0 -0
  66. pyogrio.libs/liblzma-9ee4accb476ec1ae24e924953140273d.dll +0 -0
  67. pyogrio.libs/{libpng16-6227e9a35c2a350ae6b0586079c10b9e.dll → libpng16-7c36142dda59f186f6bb683e8dae2bfe.dll} +0 -0
  68. pyogrio.libs/{msvcp140-46db46e967c8db2cb7a20fc75872a57e.dll → msvcp140-98b3e5b80de1e5e9d1703b786d795623.dll} +0 -0
  69. pyogrio.libs/proj-a408c5327f3fd2f5fabe8c56815beed7.dll +0 -0
  70. pyogrio.libs/{qhull_r-d8840f4ed1f7d452ff9a30237320bcfd.dll → qhull_r-516897f855568caab1ab1fe37912766c.dll} +0 -0
  71. pyogrio.libs/sqlite3-9bc109d8536d5ed9666332fec94485fc.dll +0 -0
  72. pyogrio.libs/{tiff-ffca1ff19d0e95dad39df0078fb037af.dll → tiff-9b3f605fffe0bccc0a964c374ee4f820.dll} +0 -0
  73. pyogrio.libs/{zlib1-aaba6ea052f6d3fa3d84a301e3eb3d30.dll → zlib1-e5af16a15c63f05bd82d90396807ae5b.dll} +0 -0
  74. pyogrio/_err.pxd +0 -4
  75. pyogrio/_err.pyx +0 -250
  76. pyogrio/_geometry.pxd +0 -4
  77. pyogrio/_geometry.pyx +0 -129
  78. pyogrio/_io.pxd +0 -0
  79. pyogrio/_io.pyx +0 -2738
  80. pyogrio/_ogr.pxd +0 -441
  81. pyogrio/_ogr.pyx +0 -346
  82. pyogrio/_vsi.pxd +0 -4
  83. pyogrio/_vsi.pyx +0 -140
  84. pyogrio/arrow_bridge.h +0 -115
  85. pyogrio/gdal_data/bag_template.xml +0 -201
  86. pyogrio/gdal_data/gmlasconf.xml +0 -169
  87. pyogrio/gdal_data/gmlasconf.xsd +0 -1066
  88. pyogrio/gdal_data/netcdf_config.xsd +0 -143
  89. pyogrio/gdal_data/template_tiles.mapml +0 -28
  90. pyogrio/tests/fixtures/test_datetime.geojson +0 -7
  91. pyogrio/tests/fixtures/test_datetime_tz.geojson +0 -8
  92. pyogrio/tests/fixtures/test_fgdb.gdb.zip +0 -0
  93. pyogrio/tests/fixtures/test_nested.geojson +0 -18
  94. pyogrio/tests/fixtures/test_ogr_types_list.geojson +0 -12
  95. pyogrio-0.8.0.dist-info/DELVEWHEEL +0 -2
  96. pyogrio.libs/geotiff-d1c0fcc3c454409ad8be61ff04a7422c.dll +0 -0
  97. pyogrio.libs/libcurl-7fef9869f6520a5fbdb2bc9ce4c496cc.dll +0 -0
  98. pyogrio.libs/liblzma-5a1f648afc3d4cf36e3aef2266d55143.dll +0 -0
  99. pyogrio.libs/proj-74051a73897c9fa6d7bfef4561688568.dll +0 -0
  100. pyogrio.libs/sqlite3-fe7a86058d1c5658d1f9106228a7fd83.dll +0 -0
  101. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/top_level.txt +0 -0
pyogrio/_geometry.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
  {
@@ -6,6 +6,7 @@
6
6
  "depends": [
7
7
  "C:\\vcpkg\\installed\\x64-windows-dynamic-release\\include\\cpl_conv.h",
8
8
  "C:\\vcpkg\\installed\\x64-windows-dynamic-release\\include\\cpl_error.h",
9
+ "C:\\vcpkg\\installed\\x64-windows-dynamic-release\\include\\cpl_port.h",
9
10
  "C:\\vcpkg\\installed\\x64-windows-dynamic-release\\include\\cpl_string.h",
10
11
  "C:\\vcpkg\\installed\\x64-windows-dynamic-release\\include\\cpl_vsi.h",
11
12
  "C:\\vcpkg\\installed\\x64-windows-dynamic-release\\include\\gdal.h",
@@ -57,10 +58,10 @@ END: Cython Metadata */
57
58
  #else
58
59
  #define __PYX_EXTRA_ABI_MODULE_NAME ""
59
60
  #endif
60
- #define CYTHON_ABI "3_0_10" __PYX_EXTRA_ABI_MODULE_NAME
61
+ #define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME
61
62
  #define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
62
63
  #define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
63
- #define CYTHON_HEX_VERSION 0x03000AF0
64
+ #define CYTHON_HEX_VERSION 0x03000BF0
64
65
  #define CYTHON_FUTURE_DIVISION 1
65
66
  #include <stddef.h>
66
67
  #ifndef offsetof
@@ -1257,6 +1258,7 @@ static CYTHON_INLINE float __PYX_NAN() {
1257
1258
  #include <stdio.h>
1258
1259
  #include "cpl_conv.h"
1259
1260
  #include "cpl_error.h"
1261
+ #include "cpl_port.h"
1260
1262
  #include "cpl_string.h"
1261
1263
  #include "cpl_vsi.h"
1262
1264
  #include "ogr_core.h"
@@ -1527,7 +1529,7 @@ static const char *__pyx_f[] = {
1527
1529
  /*--- Type declarations ---*/
1528
1530
  struct __pyx_opt_args_7pyogrio_4_ogr_get_string;
1529
1531
 
1530
- /* "pyogrio/_ogr.pxd":441
1532
+ /* "pyogrio/_ogr.pxd":452
1531
1533
  *
1532
1534
  *
1533
1535
  * cdef get_string(const char *c_str, str encoding=*) # <<<<<<<<<<<<<<
@@ -1824,9 +1826,14 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObj
1824
1826
  /* RaiseException.proto */
1825
1827
  static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
1826
1828
 
1827
- /* PyObject_Str.proto */
1828
- #define __Pyx_PyObject_Str(obj)\
1829
- (likely(PyString_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj))
1829
+ /* PyObject_Unicode.proto */
1830
+ #if PY_MAJOR_VERSION >= 3
1831
+ #define __Pyx_PyObject_Unicode(obj)\
1832
+ (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj))
1833
+ #else
1834
+ #define __Pyx_PyObject_Unicode(obj)\
1835
+ (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Unicode(obj))
1836
+ #endif
1830
1837
 
1831
1838
  /* SwapException.proto */
1832
1839
  #if CYTHON_FAST_THREAD_STATE
@@ -2053,7 +2060,7 @@ static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt
2053
2060
  static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);
2054
2061
 
2055
2062
  /* FunctionImport.proto */
2056
- static int __Pyx_ImportFunction_3_0_10(PyObject *module, const char *funcname, void (**f)(void), const char *sig);
2063
+ static int __Pyx_ImportFunction_3_0_11(PyObject *module, const char *funcname, void (**f)(void), const char *sig);
2057
2064
 
2058
2065
  /* InitStrings.proto */
2059
2066
  static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
@@ -2612,18 +2619,19 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2612
2619
  int __pyx_t_9;
2613
2620
  PyObject *__pyx_t_10 = NULL;
2614
2621
  PyObject *__pyx_t_11 = NULL;
2615
- PyObject *__pyx_t_12 = NULL;
2616
- int __pyx_t_13;
2617
- char const *__pyx_t_14;
2618
- PyObject *__pyx_t_15 = NULL;
2622
+ unsigned int __pyx_t_12;
2623
+ PyObject *__pyx_t_13 = NULL;
2624
+ int __pyx_t_14;
2625
+ char const *__pyx_t_15;
2619
2626
  PyObject *__pyx_t_16 = NULL;
2620
2627
  PyObject *__pyx_t_17 = NULL;
2621
2628
  PyObject *__pyx_t_18 = NULL;
2622
2629
  PyObject *__pyx_t_19 = NULL;
2623
2630
  PyObject *__pyx_t_20 = NULL;
2624
- int __pyx_t_21;
2625
- Py_ssize_t __pyx_t_22;
2626
- Py_UCS4 __pyx_t_23;
2631
+ PyObject *__pyx_t_21 = NULL;
2632
+ int __pyx_t_22;
2633
+ Py_ssize_t __pyx_t_23;
2634
+ Py_UCS4 __pyx_t_24;
2627
2635
  int __pyx_lineno = 0;
2628
2636
  const char *__pyx_filename = NULL;
2629
2637
  int __pyx_clineno = 0;
@@ -2709,7 +2717,7 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2709
2717
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_DataLayerError); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 89, __pyx_L5_except_error)
2710
2718
  __Pyx_GOTREF(__pyx_t_10);
2711
2719
  __pyx_t_11 = NULL;
2712
- __pyx_t_9 = 0;
2720
+ __pyx_t_12 = 0;
2713
2721
  #if CYTHON_UNPACK_METHODS
2714
2722
  if (unlikely(PyMethod_Check(__pyx_t_10))) {
2715
2723
  __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10);
@@ -2718,13 +2726,13 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2718
2726
  __Pyx_INCREF(__pyx_t_11);
2719
2727
  __Pyx_INCREF(function);
2720
2728
  __Pyx_DECREF_SET(__pyx_t_10, function);
2721
- __pyx_t_9 = 1;
2729
+ __pyx_t_12 = 1;
2722
2730
  }
2723
2731
  }
2724
2732
  #endif
2725
2733
  {
2726
2734
  PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_kp_u_Could_not_get_layer_definition};
2727
- __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
2735
+ __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
2728
2736
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
2729
2737
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 89, __pyx_L5_except_error)
2730
2738
  __Pyx_GOTREF(__pyx_t_8);
@@ -2768,26 +2776,26 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2768
2776
  */
2769
2777
  __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_DataLayerError); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 92, __pyx_L16_error)
2770
2778
  __Pyx_GOTREF(__pyx_t_10);
2771
- __pyx_t_11 = __Pyx_PyObject_Str(__pyx_v_exc); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 92, __pyx_L16_error)
2779
+ __pyx_t_11 = __Pyx_PyObject_Unicode(__pyx_v_exc); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 92, __pyx_L16_error)
2772
2780
  __Pyx_GOTREF(__pyx_t_11);
2773
- __pyx_t_12 = NULL;
2774
- __pyx_t_9 = 0;
2781
+ __pyx_t_13 = NULL;
2782
+ __pyx_t_12 = 0;
2775
2783
  #if CYTHON_UNPACK_METHODS
2776
2784
  if (unlikely(PyMethod_Check(__pyx_t_10))) {
2777
- __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_10);
2778
- if (likely(__pyx_t_12)) {
2785
+ __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_10);
2786
+ if (likely(__pyx_t_13)) {
2779
2787
  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
2780
- __Pyx_INCREF(__pyx_t_12);
2788
+ __Pyx_INCREF(__pyx_t_13);
2781
2789
  __Pyx_INCREF(function);
2782
2790
  __Pyx_DECREF_SET(__pyx_t_10, function);
2783
- __pyx_t_9 = 1;
2791
+ __pyx_t_12 = 1;
2784
2792
  }
2785
2793
  }
2786
2794
  #endif
2787
2795
  {
2788
- PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_t_11};
2789
- __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
2790
- __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
2796
+ PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_11};
2797
+ __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
2798
+ __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
2791
2799
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
2792
2800
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 92, __pyx_L16_error)
2793
2801
  __Pyx_GOTREF(__pyx_t_8);
@@ -2810,35 +2818,35 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2810
2818
  /*exception exit:*/{
2811
2819
  __Pyx_PyThreadState_declare
2812
2820
  __Pyx_PyThreadState_assign
2813
- __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
2821
+ __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0;
2814
2822
  __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
2815
2823
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
2816
- __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
2824
+ __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
2817
2825
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
2818
- if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
2819
- if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
2820
- __Pyx_XGOTREF(__pyx_t_15);
2826
+ if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21);
2827
+ if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18) < 0)) __Pyx_ErrFetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
2821
2828
  __Pyx_XGOTREF(__pyx_t_16);
2822
2829
  __Pyx_XGOTREF(__pyx_t_17);
2823
2830
  __Pyx_XGOTREF(__pyx_t_18);
2824
2831
  __Pyx_XGOTREF(__pyx_t_19);
2825
2832
  __Pyx_XGOTREF(__pyx_t_20);
2826
- __pyx_t_9 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
2833
+ __Pyx_XGOTREF(__pyx_t_21);
2834
+ __pyx_t_9 = __pyx_lineno; __pyx_t_14 = __pyx_clineno; __pyx_t_15 = __pyx_filename;
2827
2835
  {
2828
2836
  __Pyx_DECREF(__pyx_v_exc); __pyx_v_exc = 0;
2829
2837
  }
2830
2838
  if (PY_MAJOR_VERSION >= 3) {
2831
- __Pyx_XGIVEREF(__pyx_t_18);
2832
2839
  __Pyx_XGIVEREF(__pyx_t_19);
2833
2840
  __Pyx_XGIVEREF(__pyx_t_20);
2834
- __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
2841
+ __Pyx_XGIVEREF(__pyx_t_21);
2842
+ __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21);
2835
2843
  }
2836
- __Pyx_XGIVEREF(__pyx_t_15);
2837
2844
  __Pyx_XGIVEREF(__pyx_t_16);
2838
2845
  __Pyx_XGIVEREF(__pyx_t_17);
2839
- __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
2840
- __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
2841
- __pyx_lineno = __pyx_t_9; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
2846
+ __Pyx_XGIVEREF(__pyx_t_18);
2847
+ __Pyx_ErrRestore(__pyx_t_16, __pyx_t_17, __pyx_t_18);
2848
+ __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0;
2849
+ __pyx_lineno = __pyx_t_9; __pyx_clineno = __pyx_t_14; __pyx_filename = __pyx_t_15;
2842
2850
  goto __pyx_L5_except_error;
2843
2851
  }
2844
2852
  }
@@ -2881,10 +2889,10 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2881
2889
  __Pyx_GOTREF(__pyx_t_5);
2882
2890
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_GEOMETRY_TYPES); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 96, __pyx_L1_error)
2883
2891
  __Pyx_GOTREF(__pyx_t_6);
2884
- __pyx_t_21 = (__Pyx_PySequence_ContainsTF(__pyx_t_5, __pyx_t_6, Py_NE)); if (unlikely((__pyx_t_21 < 0))) __PYX_ERR(0, 96, __pyx_L1_error)
2892
+ __pyx_t_22 = (__Pyx_PySequence_ContainsTF(__pyx_t_5, __pyx_t_6, Py_NE)); if (unlikely((__pyx_t_22 < 0))) __PYX_ERR(0, 96, __pyx_L1_error)
2885
2893
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
2886
2894
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
2887
- if (unlikely(__pyx_t_21)) {
2895
+ if (unlikely(__pyx_t_22)) {
2888
2896
 
2889
2897
  /* "pyogrio/_geometry.pyx":97
2890
2898
  *
@@ -2901,7 +2909,7 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2901
2909
  __Pyx_GOTREF(__pyx_t_8);
2902
2910
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
2903
2911
  __pyx_t_7 = NULL;
2904
- __pyx_t_13 = 0;
2912
+ __pyx_t_12 = 0;
2905
2913
  #if CYTHON_UNPACK_METHODS
2906
2914
  if (unlikely(PyMethod_Check(__pyx_t_5))) {
2907
2915
  __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
@@ -2910,13 +2918,13 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2910
2918
  __Pyx_INCREF(__pyx_t_7);
2911
2919
  __Pyx_INCREF(function);
2912
2920
  __Pyx_DECREF_SET(__pyx_t_5, function);
2913
- __pyx_t_13 = 1;
2921
+ __pyx_t_12 = 1;
2914
2922
  }
2915
2923
  }
2916
2924
  #endif
2917
2925
  {
2918
2926
  PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_8};
2919
- __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_13, 1+__pyx_t_13);
2927
+ __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
2920
2928
  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
2921
2929
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
2922
2930
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
@@ -2943,8 +2951,8 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2943
2951
  * original_type = GEOMETRY_TYPES[ogr_type]
2944
2952
  *
2945
2953
  */
2946
- __pyx_t_21 = (OGR_GT_HasM(__pyx_v_ogr_type) != 0);
2947
- if (__pyx_t_21) {
2954
+ __pyx_t_22 = (OGR_GT_HasM(__pyx_v_ogr_type) != 0);
2955
+ if (__pyx_t_22) {
2948
2956
 
2949
2957
  /* "pyogrio/_geometry.pyx":100
2950
2958
  *
@@ -2995,10 +3003,10 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
2995
3003
  */
2996
3004
  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error)
2997
3005
  __Pyx_GOTREF(__pyx_t_5);
2998
- __pyx_t_22 = 0;
2999
- __pyx_t_23 = 127;
3006
+ __pyx_t_23 = 0;
3007
+ __pyx_t_24 = 127;
3000
3008
  __Pyx_INCREF(__pyx_kp_u_Measured_M_geometry_types_are_no);
3001
- __pyx_t_22 += 62;
3009
+ __pyx_t_23 += 62;
3002
3010
  __Pyx_GIVEREF(__pyx_kp_u_Measured_M_geometry_types_are_no);
3003
3011
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_Measured_M_geometry_types_are_no);
3004
3012
 
@@ -3011,13 +3019,13 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
3011
3019
  */
3012
3020
  __pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_v_original_type, __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error)
3013
3021
  __Pyx_GOTREF(__pyx_t_7);
3014
- __pyx_t_23 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_23) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_23;
3015
- __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
3022
+ __pyx_t_24 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_24) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_24;
3023
+ __pyx_t_23 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
3016
3024
  __Pyx_GIVEREF(__pyx_t_7);
3017
3025
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7);
3018
3026
  __pyx_t_7 = 0;
3019
3027
  __Pyx_INCREF(__pyx_kp_u_is_converted_to);
3020
- __pyx_t_22 += 19;
3028
+ __pyx_t_23 += 19;
3021
3029
  __Pyx_GIVEREF(__pyx_kp_u_is_converted_to);
3022
3030
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_is_converted_to);
3023
3031
 
@@ -3039,13 +3047,13 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
3039
3047
  __pyx_t_10 = __Pyx_PyObject_FormatSimple(__pyx_t_11, __pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 109, __pyx_L1_error)
3040
3048
  __Pyx_GOTREF(__pyx_t_10);
3041
3049
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
3042
- __pyx_t_23 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_23) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_23;
3043
- __pyx_t_22 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10);
3050
+ __pyx_t_24 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_24) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_24;
3051
+ __pyx_t_23 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10);
3044
3052
  __Pyx_GIVEREF(__pyx_t_10);
3045
3053
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_10);
3046
3054
  __pyx_t_10 = 0;
3047
3055
  __Pyx_INCREF(__pyx_kp_u_);
3048
- __pyx_t_22 += 1;
3056
+ __pyx_t_23 += 1;
3049
3057
  __Pyx_GIVEREF(__pyx_kp_u_);
3050
3058
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u_);
3051
3059
 
@@ -3056,11 +3064,11 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
3056
3064
  * f"Original type '{original_type}' "
3057
3065
  * f"is converted to '{GEOMETRY_TYPES[ogr_type]}'")
3058
3066
  */
3059
- __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_22, __pyx_t_23); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 107, __pyx_L1_error)
3067
+ __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_23, __pyx_t_24); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 107, __pyx_L1_error)
3060
3068
  __Pyx_GOTREF(__pyx_t_10);
3061
3069
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
3062
3070
  __pyx_t_5 = NULL;
3063
- __pyx_t_13 = 0;
3071
+ __pyx_t_12 = 0;
3064
3072
  #if CYTHON_UNPACK_METHODS
3065
3073
  if (unlikely(PyMethod_Check(__pyx_t_6))) {
3066
3074
  __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
@@ -3069,13 +3077,13 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
3069
3077
  __Pyx_INCREF(__pyx_t_5);
3070
3078
  __Pyx_INCREF(function);
3071
3079
  __Pyx_DECREF_SET(__pyx_t_6, function);
3072
- __pyx_t_13 = 1;
3080
+ __pyx_t_12 = 1;
3073
3081
  }
3074
3082
  }
3075
3083
  #endif
3076
3084
  {
3077
3085
  PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_10};
3078
- __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_13, 1+__pyx_t_13);
3086
+ __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
3079
3087
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
3080
3088
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
3081
3089
  if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 106, __pyx_L1_error)
@@ -3130,7 +3138,7 @@ static PyObject *__pyx_f_7pyogrio_9_geometry_get_geometry_type(void *__pyx_v_ogr
3130
3138
  __Pyx_XDECREF(__pyx_t_8);
3131
3139
  __Pyx_XDECREF(__pyx_t_10);
3132
3140
  __Pyx_XDECREF(__pyx_t_11);
3133
- __Pyx_XDECREF(__pyx_t_12);
3141
+ __Pyx_XDECREF(__pyx_t_13);
3134
3142
  __Pyx_AddTraceback("pyogrio._geometry.get_geometry_type", __pyx_clineno, __pyx_lineno, __pyx_filename);
3135
3143
  __pyx_r = 0;
3136
3144
  __pyx_L0:;
@@ -3157,7 +3165,7 @@ static OGRwkbGeometryType __pyx_f_7pyogrio_9_geometry_get_geometry_type_code(PyO
3157
3165
  PyObject *__pyx_t_3 = NULL;
3158
3166
  PyObject *__pyx_t_4 = NULL;
3159
3167
  PyObject *__pyx_t_5 = NULL;
3160
- int __pyx_t_6;
3168
+ unsigned int __pyx_t_6;
3161
3169
  OGRwkbGeometryType __pyx_t_7;
3162
3170
  int __pyx_lineno = 0;
3163
3171
  const char *__pyx_filename = NULL;
@@ -3459,7 +3467,7 @@ static int __Pyx_modinit_function_import_code(void) {
3459
3467
  /*--- Function import code ---*/
3460
3468
  __pyx_t_1 = PyImport_ImportModule("pyogrio._err"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
3461
3469
  __Pyx_GOTREF(__pyx_t_1);
3462
- if (__Pyx_ImportFunction_3_0_10(__pyx_t_1, "exc_wrap_pointer", (void (**)(void))&__pyx_f_7pyogrio_4_err_exc_wrap_pointer, "void *(void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3470
+ if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "exc_wrap_pointer", (void (**)(void))&__pyx_f_7pyogrio_4_err_exc_wrap_pointer, "void *(void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
3463
3471
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3464
3472
  __Pyx_RefNannyFinishContext();
3465
3473
  return 0;
@@ -6856,12 +6864,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_OGRwkbGeometryType(OGRwkbGeometr
6856
6864
  }
6857
6865
  }
6858
6866
  {
6859
- int one = 1; int little = (int)*(unsigned char *)&one;
6860
6867
  unsigned char *bytes = (unsigned char *)&value;
6861
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
6868
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
6869
+ if (is_unsigned) {
6870
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
6871
+ } else {
6872
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
6873
+ }
6874
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
6875
+ int one = 1; int little = (int)*(unsigned char *)&one;
6862
6876
  return _PyLong_FromByteArray(bytes, sizeof(OGRwkbGeometryType),
6863
6877
  little, !is_unsigned);
6864
6878
  #else
6879
+ int one = 1; int little = (int)*(unsigned char *)&one;
6865
6880
  PyObject *from_bytes, *result = NULL;
6866
6881
  PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
6867
6882
  from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
@@ -6911,151 +6926,174 @@ static CYTHON_INLINE OGRwkbGeometryType __Pyx_PyInt_As_OGRwkbGeometryType(PyObje
6911
6926
  }
6912
6927
  return (OGRwkbGeometryType) val;
6913
6928
  }
6914
- } else
6929
+ }
6915
6930
  #endif
6916
- if (likely(PyLong_Check(x))) {
6917
- if (is_unsigned) {
6931
+ if (unlikely(!PyLong_Check(x))) {
6932
+ OGRwkbGeometryType val;
6933
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
6934
+ if (!tmp) return (OGRwkbGeometryType) -1;
6935
+ val = __Pyx_PyInt_As_OGRwkbGeometryType(tmp);
6936
+ Py_DECREF(tmp);
6937
+ return val;
6938
+ }
6939
+ if (is_unsigned) {
6918
6940
  #if CYTHON_USE_PYLONG_INTERNALS
6919
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
6920
- goto raise_neg_overflow;
6921
- } else if (__Pyx_PyLong_IsCompact(x)) {
6922
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
6923
- } else {
6924
- const digit* digits = __Pyx_PyLong_Digits(x);
6925
- assert(__Pyx_PyLong_DigitCount(x) > 1);
6926
- switch (__Pyx_PyLong_DigitCount(x)) {
6927
- case 2:
6928
- if ((8 * sizeof(OGRwkbGeometryType) > 1 * PyLong_SHIFT)) {
6929
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
6930
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6931
- } else if ((8 * sizeof(OGRwkbGeometryType) >= 2 * PyLong_SHIFT)) {
6932
- return (OGRwkbGeometryType) (((((OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0]));
6933
- }
6941
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
6942
+ goto raise_neg_overflow;
6943
+ } else if (__Pyx_PyLong_IsCompact(x)) {
6944
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
6945
+ } else {
6946
+ const digit* digits = __Pyx_PyLong_Digits(x);
6947
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
6948
+ switch (__Pyx_PyLong_DigitCount(x)) {
6949
+ case 2:
6950
+ if ((8 * sizeof(OGRwkbGeometryType) > 1 * PyLong_SHIFT)) {
6951
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
6952
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6953
+ } else if ((8 * sizeof(OGRwkbGeometryType) >= 2 * PyLong_SHIFT)) {
6954
+ return (OGRwkbGeometryType) (((((OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0]));
6934
6955
  }
6935
- break;
6936
- case 3:
6937
- if ((8 * sizeof(OGRwkbGeometryType) > 2 * PyLong_SHIFT)) {
6938
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
6939
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6940
- } else if ((8 * sizeof(OGRwkbGeometryType) >= 3 * PyLong_SHIFT)) {
6941
- return (OGRwkbGeometryType) (((((((OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0]));
6942
- }
6956
+ }
6957
+ break;
6958
+ case 3:
6959
+ if ((8 * sizeof(OGRwkbGeometryType) > 2 * PyLong_SHIFT)) {
6960
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
6961
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6962
+ } else if ((8 * sizeof(OGRwkbGeometryType) >= 3 * PyLong_SHIFT)) {
6963
+ return (OGRwkbGeometryType) (((((((OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0]));
6943
6964
  }
6944
- break;
6945
- case 4:
6946
- if ((8 * sizeof(OGRwkbGeometryType) > 3 * PyLong_SHIFT)) {
6947
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
6948
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6949
- } else if ((8 * sizeof(OGRwkbGeometryType) >= 4 * PyLong_SHIFT)) {
6950
- return (OGRwkbGeometryType) (((((((((OGRwkbGeometryType)digits[3]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0]));
6951
- }
6965
+ }
6966
+ break;
6967
+ case 4:
6968
+ if ((8 * sizeof(OGRwkbGeometryType) > 3 * PyLong_SHIFT)) {
6969
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
6970
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6971
+ } else if ((8 * sizeof(OGRwkbGeometryType) >= 4 * PyLong_SHIFT)) {
6972
+ return (OGRwkbGeometryType) (((((((((OGRwkbGeometryType)digits[3]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0]));
6952
6973
  }
6953
- break;
6954
- }
6974
+ }
6975
+ break;
6955
6976
  }
6977
+ }
6956
6978
  #endif
6957
6979
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
6958
- if (unlikely(Py_SIZE(x) < 0)) {
6959
- goto raise_neg_overflow;
6960
- }
6980
+ if (unlikely(Py_SIZE(x) < 0)) {
6981
+ goto raise_neg_overflow;
6982
+ }
6961
6983
  #else
6962
- {
6963
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
6964
- if (unlikely(result < 0))
6965
- return (OGRwkbGeometryType) -1;
6966
- if (unlikely(result == 1))
6967
- goto raise_neg_overflow;
6968
- }
6984
+ {
6985
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
6986
+ if (unlikely(result < 0))
6987
+ return (OGRwkbGeometryType) -1;
6988
+ if (unlikely(result == 1))
6989
+ goto raise_neg_overflow;
6990
+ }
6969
6991
  #endif
6970
- if ((sizeof(OGRwkbGeometryType) <= sizeof(unsigned long))) {
6971
- __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, unsigned long, PyLong_AsUnsignedLong(x))
6992
+ if ((sizeof(OGRwkbGeometryType) <= sizeof(unsigned long))) {
6993
+ __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, unsigned long, PyLong_AsUnsignedLong(x))
6972
6994
  #ifdef HAVE_LONG_LONG
6973
- } else if ((sizeof(OGRwkbGeometryType) <= sizeof(unsigned PY_LONG_LONG))) {
6974
- __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
6995
+ } else if ((sizeof(OGRwkbGeometryType) <= sizeof(unsigned PY_LONG_LONG))) {
6996
+ __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
6975
6997
  #endif
6976
- }
6977
- } else {
6998
+ }
6999
+ } else {
6978
7000
  #if CYTHON_USE_PYLONG_INTERNALS
6979
- if (__Pyx_PyLong_IsCompact(x)) {
6980
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
6981
- } else {
6982
- const digit* digits = __Pyx_PyLong_Digits(x);
6983
- assert(__Pyx_PyLong_DigitCount(x) > 1);
6984
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
6985
- case -2:
6986
- if ((8 * sizeof(OGRwkbGeometryType) - 1 > 1 * PyLong_SHIFT)) {
6987
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
6988
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6989
- } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 2 * PyLong_SHIFT)) {
6990
- return (OGRwkbGeometryType) (((OGRwkbGeometryType)-1)*(((((OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
6991
- }
7001
+ if (__Pyx_PyLong_IsCompact(x)) {
7002
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
7003
+ } else {
7004
+ const digit* digits = __Pyx_PyLong_Digits(x);
7005
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
7006
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
7007
+ case -2:
7008
+ if ((8 * sizeof(OGRwkbGeometryType) - 1 > 1 * PyLong_SHIFT)) {
7009
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7010
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7011
+ } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 2 * PyLong_SHIFT)) {
7012
+ return (OGRwkbGeometryType) (((OGRwkbGeometryType)-1)*(((((OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
6992
7013
  }
6993
- break;
6994
- case 2:
6995
- if ((8 * sizeof(OGRwkbGeometryType) > 1 * PyLong_SHIFT)) {
6996
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
6997
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
6998
- } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 2 * PyLong_SHIFT)) {
6999
- return (OGRwkbGeometryType) ((((((OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7000
- }
7014
+ }
7015
+ break;
7016
+ case 2:
7017
+ if ((8 * sizeof(OGRwkbGeometryType) > 1 * PyLong_SHIFT)) {
7018
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7019
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7020
+ } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 2 * PyLong_SHIFT)) {
7021
+ return (OGRwkbGeometryType) ((((((OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7001
7022
  }
7002
- break;
7003
- case -3:
7004
- if ((8 * sizeof(OGRwkbGeometryType) - 1 > 2 * PyLong_SHIFT)) {
7005
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7006
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7007
- } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 3 * PyLong_SHIFT)) {
7008
- return (OGRwkbGeometryType) (((OGRwkbGeometryType)-1)*(((((((OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7009
- }
7023
+ }
7024
+ break;
7025
+ case -3:
7026
+ if ((8 * sizeof(OGRwkbGeometryType) - 1 > 2 * PyLong_SHIFT)) {
7027
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7028
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7029
+ } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 3 * PyLong_SHIFT)) {
7030
+ return (OGRwkbGeometryType) (((OGRwkbGeometryType)-1)*(((((((OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7010
7031
  }
7011
- break;
7012
- case 3:
7013
- if ((8 * sizeof(OGRwkbGeometryType) > 2 * PyLong_SHIFT)) {
7014
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7015
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7016
- } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 3 * PyLong_SHIFT)) {
7017
- return (OGRwkbGeometryType) ((((((((OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7018
- }
7032
+ }
7033
+ break;
7034
+ case 3:
7035
+ if ((8 * sizeof(OGRwkbGeometryType) > 2 * PyLong_SHIFT)) {
7036
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7037
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7038
+ } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 3 * PyLong_SHIFT)) {
7039
+ return (OGRwkbGeometryType) ((((((((OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7019
7040
  }
7020
- break;
7021
- case -4:
7022
- if ((8 * sizeof(OGRwkbGeometryType) - 1 > 3 * PyLong_SHIFT)) {
7023
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7024
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7025
- } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 4 * PyLong_SHIFT)) {
7026
- return (OGRwkbGeometryType) (((OGRwkbGeometryType)-1)*(((((((((OGRwkbGeometryType)digits[3]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7027
- }
7041
+ }
7042
+ break;
7043
+ case -4:
7044
+ if ((8 * sizeof(OGRwkbGeometryType) - 1 > 3 * PyLong_SHIFT)) {
7045
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7046
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7047
+ } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 4 * PyLong_SHIFT)) {
7048
+ return (OGRwkbGeometryType) (((OGRwkbGeometryType)-1)*(((((((((OGRwkbGeometryType)digits[3]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7028
7049
  }
7029
- break;
7030
- case 4:
7031
- if ((8 * sizeof(OGRwkbGeometryType) > 3 * PyLong_SHIFT)) {
7032
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7033
- __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7034
- } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 4 * PyLong_SHIFT)) {
7035
- return (OGRwkbGeometryType) ((((((((((OGRwkbGeometryType)digits[3]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7036
- }
7050
+ }
7051
+ break;
7052
+ case 4:
7053
+ if ((8 * sizeof(OGRwkbGeometryType) > 3 * PyLong_SHIFT)) {
7054
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7055
+ __PYX_VERIFY_RETURN_INT(OGRwkbGeometryType, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7056
+ } else if ((8 * sizeof(OGRwkbGeometryType) - 1 > 4 * PyLong_SHIFT)) {
7057
+ return (OGRwkbGeometryType) ((((((((((OGRwkbGeometryType)digits[3]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[2]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[1]) << PyLong_SHIFT) | (OGRwkbGeometryType)digits[0])));
7037
7058
  }
7038
- break;
7039
- }
7059
+ }
7060
+ break;
7040
7061
  }
7062
+ }
7041
7063
  #endif
7042
- if ((sizeof(OGRwkbGeometryType) <= sizeof(long))) {
7043
- __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, long, PyLong_AsLong(x))
7064
+ if ((sizeof(OGRwkbGeometryType) <= sizeof(long))) {
7065
+ __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, long, PyLong_AsLong(x))
7044
7066
  #ifdef HAVE_LONG_LONG
7045
- } else if ((sizeof(OGRwkbGeometryType) <= sizeof(PY_LONG_LONG))) {
7046
- __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, PY_LONG_LONG, PyLong_AsLongLong(x))
7067
+ } else if ((sizeof(OGRwkbGeometryType) <= sizeof(PY_LONG_LONG))) {
7068
+ __PYX_VERIFY_RETURN_INT_EXC(OGRwkbGeometryType, PY_LONG_LONG, PyLong_AsLongLong(x))
7047
7069
  #endif
7048
- }
7049
7070
  }
7050
- PyErr_SetString(PyExc_RuntimeError,
7051
- "_PyLong_AsByteArray() not available, cannot convert large enums");
7052
- return (OGRwkbGeometryType) -1;
7053
- } else {
7071
+ }
7072
+ {
7054
7073
  OGRwkbGeometryType val;
7055
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
7056
- if (!tmp) return (OGRwkbGeometryType) -1;
7057
- val = __Pyx_PyInt_As_OGRwkbGeometryType(tmp);
7058
- Py_DECREF(tmp);
7074
+ int ret = -1;
7075
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
7076
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
7077
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
7078
+ if (unlikely(bytes_copied == -1)) {
7079
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
7080
+ goto raise_overflow;
7081
+ } else {
7082
+ ret = 0;
7083
+ }
7084
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
7085
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
7086
+ unsigned char *bytes = (unsigned char *)&val;
7087
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
7088
+ bytes, sizeof(val),
7089
+ is_little, !is_unsigned);
7090
+ #else
7091
+ PyErr_SetString(PyExc_RuntimeError,
7092
+ "_PyLong_AsByteArray() or PyLong_AsNativeBytes() not available, cannot convert large enums");
7093
+ val = (OGRwkbGeometryType) -1;
7094
+ #endif
7095
+ if (unlikely(ret))
7096
+ return (OGRwkbGeometryType) -1;
7059
7097
  return val;
7060
7098
  }
7061
7099
  raise_overflow:
@@ -7115,12 +7153,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
7115
7153
  }
7116
7154
  }
7117
7155
  {
7118
- int one = 1; int little = (int)*(unsigned char *)&one;
7119
7156
  unsigned char *bytes = (unsigned char *)&value;
7120
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
7157
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
7158
+ if (is_unsigned) {
7159
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
7160
+ } else {
7161
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
7162
+ }
7163
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
7164
+ int one = 1; int little = (int)*(unsigned char *)&one;
7121
7165
  return _PyLong_FromByteArray(bytes, sizeof(long),
7122
7166
  little, !is_unsigned);
7123
7167
  #else
7168
+ int one = 1; int little = (int)*(unsigned char *)&one;
7124
7169
  PyObject *from_bytes, *result = NULL;
7125
7170
  PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
7126
7171
  from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
@@ -7170,245 +7215,239 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
7170
7215
  }
7171
7216
  return (long) val;
7172
7217
  }
7173
- } else
7218
+ }
7174
7219
  #endif
7175
- if (likely(PyLong_Check(x))) {
7176
- if (is_unsigned) {
7220
+ if (unlikely(!PyLong_Check(x))) {
7221
+ long val;
7222
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
7223
+ if (!tmp) return (long) -1;
7224
+ val = __Pyx_PyInt_As_long(tmp);
7225
+ Py_DECREF(tmp);
7226
+ return val;
7227
+ }
7228
+ if (is_unsigned) {
7177
7229
  #if CYTHON_USE_PYLONG_INTERNALS
7178
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
7179
- goto raise_neg_overflow;
7180
- } else if (__Pyx_PyLong_IsCompact(x)) {
7181
- __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
7182
- } else {
7183
- const digit* digits = __Pyx_PyLong_Digits(x);
7184
- assert(__Pyx_PyLong_DigitCount(x) > 1);
7185
- switch (__Pyx_PyLong_DigitCount(x)) {
7186
- case 2:
7187
- if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
7188
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7189
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7190
- } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
7191
- return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
7192
- }
7230
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
7231
+ goto raise_neg_overflow;
7232
+ } else if (__Pyx_PyLong_IsCompact(x)) {
7233
+ __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
7234
+ } else {
7235
+ const digit* digits = __Pyx_PyLong_Digits(x);
7236
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
7237
+ switch (__Pyx_PyLong_DigitCount(x)) {
7238
+ case 2:
7239
+ if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
7240
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7241
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7242
+ } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
7243
+ return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
7193
7244
  }
7194
- break;
7195
- case 3:
7196
- if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
7197
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7198
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7199
- } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
7200
- return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
7201
- }
7245
+ }
7246
+ break;
7247
+ case 3:
7248
+ if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
7249
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7250
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7251
+ } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
7252
+ return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
7202
7253
  }
7203
- break;
7204
- case 4:
7205
- if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
7206
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7207
- __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])))
7208
- } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
7209
- return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
7210
- }
7254
+ }
7255
+ break;
7256
+ case 4:
7257
+ if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
7258
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7259
+ __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])))
7260
+ } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
7261
+ return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
7211
7262
  }
7212
- break;
7213
- }
7263
+ }
7264
+ break;
7214
7265
  }
7266
+ }
7215
7267
  #endif
7216
7268
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
7217
- if (unlikely(Py_SIZE(x) < 0)) {
7218
- goto raise_neg_overflow;
7219
- }
7269
+ if (unlikely(Py_SIZE(x) < 0)) {
7270
+ goto raise_neg_overflow;
7271
+ }
7220
7272
  #else
7221
- {
7222
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
7223
- if (unlikely(result < 0))
7224
- return (long) -1;
7225
- if (unlikely(result == 1))
7226
- goto raise_neg_overflow;
7227
- }
7273
+ {
7274
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
7275
+ if (unlikely(result < 0))
7276
+ return (long) -1;
7277
+ if (unlikely(result == 1))
7278
+ goto raise_neg_overflow;
7279
+ }
7228
7280
  #endif
7229
- if ((sizeof(long) <= sizeof(unsigned long))) {
7230
- __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
7281
+ if ((sizeof(long) <= sizeof(unsigned long))) {
7282
+ __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
7231
7283
  #ifdef HAVE_LONG_LONG
7232
- } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
7233
- __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
7284
+ } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
7285
+ __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
7234
7286
  #endif
7235
- }
7236
- } else {
7287
+ }
7288
+ } else {
7237
7289
  #if CYTHON_USE_PYLONG_INTERNALS
7238
- if (__Pyx_PyLong_IsCompact(x)) {
7239
- __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
7240
- } else {
7241
- const digit* digits = __Pyx_PyLong_Digits(x);
7242
- assert(__Pyx_PyLong_DigitCount(x) > 1);
7243
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
7244
- case -2:
7245
- if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
7246
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7247
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7248
- } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
7249
- return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7250
- }
7290
+ if (__Pyx_PyLong_IsCompact(x)) {
7291
+ __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
7292
+ } else {
7293
+ const digit* digits = __Pyx_PyLong_Digits(x);
7294
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
7295
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
7296
+ case -2:
7297
+ if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
7298
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7299
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7300
+ } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
7301
+ return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7251
7302
  }
7252
- break;
7253
- case 2:
7254
- if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
7255
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7256
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7257
- } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
7258
- return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7259
- }
7303
+ }
7304
+ break;
7305
+ case 2:
7306
+ if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
7307
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7308
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7309
+ } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
7310
+ return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7260
7311
  }
7261
- break;
7262
- case -3:
7263
- if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
7264
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7265
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7266
- } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
7267
- return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7268
- }
7312
+ }
7313
+ break;
7314
+ case -3:
7315
+ if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
7316
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7317
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7318
+ } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
7319
+ return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7269
7320
  }
7270
- break;
7271
- case 3:
7272
- if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
7273
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7274
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7275
- } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
7276
- return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7277
- }
7321
+ }
7322
+ break;
7323
+ case 3:
7324
+ if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
7325
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7326
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7327
+ } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
7328
+ return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7278
7329
  }
7279
- break;
7280
- case -4:
7281
- if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
7282
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7283
- __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])))
7284
- } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
7285
- return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7286
- }
7330
+ }
7331
+ break;
7332
+ case -4:
7333
+ if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
7334
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7335
+ __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])))
7336
+ } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
7337
+ return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7287
7338
  }
7288
- break;
7289
- case 4:
7290
- if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
7291
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7292
- __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])))
7293
- } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
7294
- return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7295
- }
7339
+ }
7340
+ break;
7341
+ case 4:
7342
+ if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
7343
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7344
+ __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])))
7345
+ } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
7346
+ return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
7296
7347
  }
7297
- break;
7298
- }
7348
+ }
7349
+ break;
7299
7350
  }
7351
+ }
7300
7352
  #endif
7301
- if ((sizeof(long) <= sizeof(long))) {
7302
- __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
7353
+ if ((sizeof(long) <= sizeof(long))) {
7354
+ __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
7303
7355
  #ifdef HAVE_LONG_LONG
7304
- } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
7305
- __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
7356
+ } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
7357
+ __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
7306
7358
  #endif
7307
- }
7359
+ }
7360
+ }
7361
+ {
7362
+ long val;
7363
+ int ret = -1;
7364
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
7365
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
7366
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
7367
+ if (unlikely(bytes_copied == -1)) {
7368
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
7369
+ goto raise_overflow;
7370
+ } else {
7371
+ ret = 0;
7372
+ }
7373
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
7374
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
7375
+ unsigned char *bytes = (unsigned char *)&val;
7376
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
7377
+ bytes, sizeof(val),
7378
+ is_little, !is_unsigned);
7379
+ #else
7380
+ PyObject *v;
7381
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
7382
+ int bits, remaining_bits, is_negative = 0;
7383
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
7384
+ if (likely(PyLong_CheckExact(x))) {
7385
+ v = __Pyx_NewRef(x);
7386
+ } else {
7387
+ v = PyNumber_Long(x);
7388
+ if (unlikely(!v)) return (long) -1;
7389
+ assert(PyLong_CheckExact(v));
7308
7390
  }
7309
7391
  {
7310
- long val;
7311
- PyObject *v = __Pyx_PyNumber_IntOrLong(x);
7312
- #if PY_MAJOR_VERSION < 3
7313
- if (likely(v) && !PyLong_Check(v)) {
7314
- PyObject *tmp = v;
7315
- v = PyNumber_Long(tmp);
7316
- Py_DECREF(tmp);
7317
- }
7318
- #endif
7319
- if (likely(v)) {
7320
- int ret = -1;
7321
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
7322
- int one = 1; int is_little = (int)*(unsigned char *)&one;
7323
- unsigned char *bytes = (unsigned char *)&val;
7324
- ret = _PyLong_AsByteArray((PyLongObject *)v,
7325
- bytes, sizeof(val),
7326
- is_little, !is_unsigned);
7327
- #else
7328
- PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
7329
- int bits, remaining_bits, is_negative = 0;
7330
- long idigit;
7331
- int chunk_size = (sizeof(long) < 8) ? 30 : 62;
7332
- if (unlikely(!PyLong_CheckExact(v))) {
7333
- PyObject *tmp = v;
7334
- v = PyNumber_Long(v);
7335
- assert(PyLong_CheckExact(v));
7336
- Py_DECREF(tmp);
7337
- if (unlikely(!v)) return (long) -1;
7338
- }
7339
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
7340
- if (Py_SIZE(x) == 0)
7341
- return (long) 0;
7342
- is_negative = Py_SIZE(x) < 0;
7343
- #else
7344
- {
7345
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
7346
- if (unlikely(result < 0))
7347
- return (long) -1;
7348
- is_negative = result == 1;
7349
- }
7350
- #endif
7351
- if (is_unsigned && unlikely(is_negative)) {
7352
- goto raise_neg_overflow;
7353
- } else if (is_negative) {
7354
- stepval = PyNumber_Invert(v);
7355
- if (unlikely(!stepval))
7356
- return (long) -1;
7357
- } else {
7358
- stepval = __Pyx_NewRef(v);
7359
- }
7360
- val = (long) 0;
7361
- mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
7362
- shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
7363
- for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
7364
- PyObject *tmp, *digit;
7365
- digit = PyNumber_And(stepval, mask);
7366
- if (unlikely(!digit)) goto done;
7367
- idigit = PyLong_AsLong(digit);
7368
- Py_DECREF(digit);
7369
- if (unlikely(idigit < 0)) goto done;
7370
- tmp = PyNumber_Rshift(stepval, shift);
7371
- if (unlikely(!tmp)) goto done;
7372
- Py_DECREF(stepval); stepval = tmp;
7373
- val |= ((long) idigit) << bits;
7374
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
7375
- if (Py_SIZE(stepval) == 0)
7376
- goto unpacking_done;
7377
- #endif
7378
- }
7379
- idigit = PyLong_AsLong(stepval);
7380
- if (unlikely(idigit < 0)) goto done;
7381
- remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
7382
- if (unlikely(idigit >= (1L << remaining_bits)))
7383
- goto raise_overflow;
7384
- val |= ((long) idigit) << bits;
7385
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
7386
- unpacking_done:
7387
- #endif
7388
- if (!is_unsigned) {
7389
- if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
7390
- goto raise_overflow;
7391
- if (is_negative)
7392
- val = ~val;
7393
- }
7394
- ret = 0;
7395
- done:
7396
- Py_XDECREF(shift);
7397
- Py_XDECREF(mask);
7398
- Py_XDECREF(stepval);
7399
- #endif
7392
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
7393
+ if (unlikely(result < 0)) {
7400
7394
  Py_DECREF(v);
7401
- if (likely(!ret))
7402
- return val;
7395
+ return (long) -1;
7403
7396
  }
7404
- return (long) -1;
7397
+ is_negative = result == 1;
7405
7398
  }
7406
- } else {
7407
- long val;
7408
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
7409
- if (!tmp) return (long) -1;
7410
- val = __Pyx_PyInt_As_long(tmp);
7411
- Py_DECREF(tmp);
7399
+ if (is_unsigned && unlikely(is_negative)) {
7400
+ Py_DECREF(v);
7401
+ goto raise_neg_overflow;
7402
+ } else if (is_negative) {
7403
+ stepval = PyNumber_Invert(v);
7404
+ Py_DECREF(v);
7405
+ if (unlikely(!stepval))
7406
+ return (long) -1;
7407
+ } else {
7408
+ stepval = v;
7409
+ }
7410
+ v = NULL;
7411
+ val = (long) 0;
7412
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
7413
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
7414
+ for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
7415
+ PyObject *tmp, *digit;
7416
+ long idigit;
7417
+ digit = PyNumber_And(stepval, mask);
7418
+ if (unlikely(!digit)) goto done;
7419
+ idigit = PyLong_AsLong(digit);
7420
+ Py_DECREF(digit);
7421
+ if (unlikely(idigit < 0)) goto done;
7422
+ val |= ((long) idigit) << bits;
7423
+ tmp = PyNumber_Rshift(stepval, shift);
7424
+ if (unlikely(!tmp)) goto done;
7425
+ Py_DECREF(stepval); stepval = tmp;
7426
+ }
7427
+ Py_DECREF(shift); shift = NULL;
7428
+ Py_DECREF(mask); mask = NULL;
7429
+ {
7430
+ long idigit = PyLong_AsLong(stepval);
7431
+ if (unlikely(idigit < 0)) goto done;
7432
+ remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
7433
+ if (unlikely(idigit >= (1L << remaining_bits)))
7434
+ goto raise_overflow;
7435
+ val |= ((long) idigit) << bits;
7436
+ }
7437
+ if (!is_unsigned) {
7438
+ if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
7439
+ goto raise_overflow;
7440
+ if (is_negative)
7441
+ val = ~val;
7442
+ }
7443
+ ret = 0;
7444
+ done:
7445
+ Py_XDECREF(shift);
7446
+ Py_XDECREF(mask);
7447
+ Py_XDECREF(stepval);
7448
+ #endif
7449
+ if (unlikely(ret))
7450
+ return (long) -1;
7412
7451
  return val;
7413
7452
  }
7414
7453
  raise_overflow:
@@ -7443,245 +7482,239 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
7443
7482
  }
7444
7483
  return (int) val;
7445
7484
  }
7446
- } else
7485
+ }
7447
7486
  #endif
7448
- if (likely(PyLong_Check(x))) {
7449
- if (is_unsigned) {
7487
+ if (unlikely(!PyLong_Check(x))) {
7488
+ int val;
7489
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
7490
+ if (!tmp) return (int) -1;
7491
+ val = __Pyx_PyInt_As_int(tmp);
7492
+ Py_DECREF(tmp);
7493
+ return val;
7494
+ }
7495
+ if (is_unsigned) {
7450
7496
  #if CYTHON_USE_PYLONG_INTERNALS
7451
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
7452
- goto raise_neg_overflow;
7453
- } else if (__Pyx_PyLong_IsCompact(x)) {
7454
- __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
7455
- } else {
7456
- const digit* digits = __Pyx_PyLong_Digits(x);
7457
- assert(__Pyx_PyLong_DigitCount(x) > 1);
7458
- switch (__Pyx_PyLong_DigitCount(x)) {
7459
- case 2:
7460
- if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
7461
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7462
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7463
- } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
7464
- return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
7465
- }
7497
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
7498
+ goto raise_neg_overflow;
7499
+ } else if (__Pyx_PyLong_IsCompact(x)) {
7500
+ __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
7501
+ } else {
7502
+ const digit* digits = __Pyx_PyLong_Digits(x);
7503
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
7504
+ switch (__Pyx_PyLong_DigitCount(x)) {
7505
+ case 2:
7506
+ if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
7507
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7508
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7509
+ } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
7510
+ return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
7466
7511
  }
7467
- break;
7468
- case 3:
7469
- if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
7470
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7471
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7472
- } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
7473
- return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
7474
- }
7512
+ }
7513
+ break;
7514
+ case 3:
7515
+ if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
7516
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7517
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7518
+ } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
7519
+ return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
7475
7520
  }
7476
- break;
7477
- case 4:
7478
- if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
7479
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7480
- __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])))
7481
- } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
7482
- return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
7483
- }
7521
+ }
7522
+ break;
7523
+ case 4:
7524
+ if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
7525
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7526
+ __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])))
7527
+ } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
7528
+ return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
7484
7529
  }
7485
- break;
7486
- }
7530
+ }
7531
+ break;
7487
7532
  }
7533
+ }
7488
7534
  #endif
7489
7535
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
7490
- if (unlikely(Py_SIZE(x) < 0)) {
7491
- goto raise_neg_overflow;
7492
- }
7536
+ if (unlikely(Py_SIZE(x) < 0)) {
7537
+ goto raise_neg_overflow;
7538
+ }
7493
7539
  #else
7494
- {
7495
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
7496
- if (unlikely(result < 0))
7497
- return (int) -1;
7498
- if (unlikely(result == 1))
7499
- goto raise_neg_overflow;
7500
- }
7540
+ {
7541
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
7542
+ if (unlikely(result < 0))
7543
+ return (int) -1;
7544
+ if (unlikely(result == 1))
7545
+ goto raise_neg_overflow;
7546
+ }
7501
7547
  #endif
7502
- if ((sizeof(int) <= sizeof(unsigned long))) {
7503
- __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
7548
+ if ((sizeof(int) <= sizeof(unsigned long))) {
7549
+ __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
7504
7550
  #ifdef HAVE_LONG_LONG
7505
- } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
7506
- __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
7551
+ } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
7552
+ __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
7507
7553
  #endif
7508
- }
7509
- } else {
7554
+ }
7555
+ } else {
7510
7556
  #if CYTHON_USE_PYLONG_INTERNALS
7511
- if (__Pyx_PyLong_IsCompact(x)) {
7512
- __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
7513
- } else {
7514
- const digit* digits = __Pyx_PyLong_Digits(x);
7515
- assert(__Pyx_PyLong_DigitCount(x) > 1);
7516
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
7517
- case -2:
7518
- if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
7519
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7520
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7521
- } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
7522
- return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7523
- }
7557
+ if (__Pyx_PyLong_IsCompact(x)) {
7558
+ __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
7559
+ } else {
7560
+ const digit* digits = __Pyx_PyLong_Digits(x);
7561
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
7562
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
7563
+ case -2:
7564
+ if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
7565
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7566
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7567
+ } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
7568
+ return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7524
7569
  }
7525
- break;
7526
- case 2:
7527
- if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
7528
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7529
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7530
- } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
7531
- return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7532
- }
7570
+ }
7571
+ break;
7572
+ case 2:
7573
+ if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
7574
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
7575
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7576
+ } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
7577
+ return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7533
7578
  }
7534
- break;
7535
- case -3:
7536
- if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
7537
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7538
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7539
- } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
7540
- return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7541
- }
7579
+ }
7580
+ break;
7581
+ case -3:
7582
+ if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
7583
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7584
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7585
+ } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
7586
+ return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7542
7587
  }
7543
- break;
7544
- case 3:
7545
- if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
7546
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7547
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7548
- } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
7549
- return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7550
- }
7588
+ }
7589
+ break;
7590
+ case 3:
7591
+ if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
7592
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
7593
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
7594
+ } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
7595
+ return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7551
7596
  }
7552
- break;
7553
- case -4:
7554
- if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
7555
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7556
- __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])))
7557
- } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
7558
- return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7559
- }
7597
+ }
7598
+ break;
7599
+ case -4:
7600
+ if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
7601
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7602
+ __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])))
7603
+ } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
7604
+ return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7560
7605
  }
7561
- break;
7562
- case 4:
7563
- if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
7564
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7565
- __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])))
7566
- } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
7567
- return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7568
- }
7606
+ }
7607
+ break;
7608
+ case 4:
7609
+ if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
7610
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
7611
+ __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])))
7612
+ } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
7613
+ return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
7569
7614
  }
7570
- break;
7571
- }
7615
+ }
7616
+ break;
7572
7617
  }
7618
+ }
7573
7619
  #endif
7574
- if ((sizeof(int) <= sizeof(long))) {
7575
- __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
7620
+ if ((sizeof(int) <= sizeof(long))) {
7621
+ __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
7576
7622
  #ifdef HAVE_LONG_LONG
7577
- } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
7578
- __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
7623
+ } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
7624
+ __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
7579
7625
  #endif
7580
- }
7626
+ }
7627
+ }
7628
+ {
7629
+ int val;
7630
+ int ret = -1;
7631
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
7632
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
7633
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
7634
+ if (unlikely(bytes_copied == -1)) {
7635
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
7636
+ goto raise_overflow;
7637
+ } else {
7638
+ ret = 0;
7639
+ }
7640
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
7641
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
7642
+ unsigned char *bytes = (unsigned char *)&val;
7643
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
7644
+ bytes, sizeof(val),
7645
+ is_little, !is_unsigned);
7646
+ #else
7647
+ PyObject *v;
7648
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
7649
+ int bits, remaining_bits, is_negative = 0;
7650
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
7651
+ if (likely(PyLong_CheckExact(x))) {
7652
+ v = __Pyx_NewRef(x);
7653
+ } else {
7654
+ v = PyNumber_Long(x);
7655
+ if (unlikely(!v)) return (int) -1;
7656
+ assert(PyLong_CheckExact(v));
7581
7657
  }
7582
7658
  {
7583
- int val;
7584
- PyObject *v = __Pyx_PyNumber_IntOrLong(x);
7585
- #if PY_MAJOR_VERSION < 3
7586
- if (likely(v) && !PyLong_Check(v)) {
7587
- PyObject *tmp = v;
7588
- v = PyNumber_Long(tmp);
7589
- Py_DECREF(tmp);
7590
- }
7591
- #endif
7592
- if (likely(v)) {
7593
- int ret = -1;
7594
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
7595
- int one = 1; int is_little = (int)*(unsigned char *)&one;
7596
- unsigned char *bytes = (unsigned char *)&val;
7597
- ret = _PyLong_AsByteArray((PyLongObject *)v,
7598
- bytes, sizeof(val),
7599
- is_little, !is_unsigned);
7600
- #else
7601
- PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
7602
- int bits, remaining_bits, is_negative = 0;
7603
- long idigit;
7604
- int chunk_size = (sizeof(long) < 8) ? 30 : 62;
7605
- if (unlikely(!PyLong_CheckExact(v))) {
7606
- PyObject *tmp = v;
7607
- v = PyNumber_Long(v);
7608
- assert(PyLong_CheckExact(v));
7609
- Py_DECREF(tmp);
7610
- if (unlikely(!v)) return (int) -1;
7611
- }
7612
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
7613
- if (Py_SIZE(x) == 0)
7614
- return (int) 0;
7615
- is_negative = Py_SIZE(x) < 0;
7616
- #else
7617
- {
7618
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
7619
- if (unlikely(result < 0))
7620
- return (int) -1;
7621
- is_negative = result == 1;
7622
- }
7623
- #endif
7624
- if (is_unsigned && unlikely(is_negative)) {
7625
- goto raise_neg_overflow;
7626
- } else if (is_negative) {
7627
- stepval = PyNumber_Invert(v);
7628
- if (unlikely(!stepval))
7629
- return (int) -1;
7630
- } else {
7631
- stepval = __Pyx_NewRef(v);
7632
- }
7633
- val = (int) 0;
7634
- mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
7635
- shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
7636
- for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
7637
- PyObject *tmp, *digit;
7638
- digit = PyNumber_And(stepval, mask);
7639
- if (unlikely(!digit)) goto done;
7640
- idigit = PyLong_AsLong(digit);
7641
- Py_DECREF(digit);
7642
- if (unlikely(idigit < 0)) goto done;
7643
- tmp = PyNumber_Rshift(stepval, shift);
7644
- if (unlikely(!tmp)) goto done;
7645
- Py_DECREF(stepval); stepval = tmp;
7646
- val |= ((int) idigit) << bits;
7647
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
7648
- if (Py_SIZE(stepval) == 0)
7649
- goto unpacking_done;
7650
- #endif
7651
- }
7652
- idigit = PyLong_AsLong(stepval);
7653
- if (unlikely(idigit < 0)) goto done;
7654
- remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
7655
- if (unlikely(idigit >= (1L << remaining_bits)))
7656
- goto raise_overflow;
7657
- val |= ((int) idigit) << bits;
7658
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
7659
- unpacking_done:
7660
- #endif
7661
- if (!is_unsigned) {
7662
- if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
7663
- goto raise_overflow;
7664
- if (is_negative)
7665
- val = ~val;
7666
- }
7667
- ret = 0;
7668
- done:
7669
- Py_XDECREF(shift);
7670
- Py_XDECREF(mask);
7671
- Py_XDECREF(stepval);
7672
- #endif
7659
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
7660
+ if (unlikely(result < 0)) {
7673
7661
  Py_DECREF(v);
7674
- if (likely(!ret))
7675
- return val;
7662
+ return (int) -1;
7676
7663
  }
7677
- return (int) -1;
7664
+ is_negative = result == 1;
7678
7665
  }
7679
- } else {
7680
- int val;
7681
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
7682
- if (!tmp) return (int) -1;
7683
- val = __Pyx_PyInt_As_int(tmp);
7684
- Py_DECREF(tmp);
7666
+ if (is_unsigned && unlikely(is_negative)) {
7667
+ Py_DECREF(v);
7668
+ goto raise_neg_overflow;
7669
+ } else if (is_negative) {
7670
+ stepval = PyNumber_Invert(v);
7671
+ Py_DECREF(v);
7672
+ if (unlikely(!stepval))
7673
+ return (int) -1;
7674
+ } else {
7675
+ stepval = v;
7676
+ }
7677
+ v = NULL;
7678
+ val = (int) 0;
7679
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
7680
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
7681
+ for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
7682
+ PyObject *tmp, *digit;
7683
+ long idigit;
7684
+ digit = PyNumber_And(stepval, mask);
7685
+ if (unlikely(!digit)) goto done;
7686
+ idigit = PyLong_AsLong(digit);
7687
+ Py_DECREF(digit);
7688
+ if (unlikely(idigit < 0)) goto done;
7689
+ val |= ((int) idigit) << bits;
7690
+ tmp = PyNumber_Rshift(stepval, shift);
7691
+ if (unlikely(!tmp)) goto done;
7692
+ Py_DECREF(stepval); stepval = tmp;
7693
+ }
7694
+ Py_DECREF(shift); shift = NULL;
7695
+ Py_DECREF(mask); mask = NULL;
7696
+ {
7697
+ long idigit = PyLong_AsLong(stepval);
7698
+ if (unlikely(idigit < 0)) goto done;
7699
+ remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
7700
+ if (unlikely(idigit >= (1L << remaining_bits)))
7701
+ goto raise_overflow;
7702
+ val |= ((int) idigit) << bits;
7703
+ }
7704
+ if (!is_unsigned) {
7705
+ if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
7706
+ goto raise_overflow;
7707
+ if (is_negative)
7708
+ val = ~val;
7709
+ }
7710
+ ret = 0;
7711
+ done:
7712
+ Py_XDECREF(shift);
7713
+ Py_XDECREF(mask);
7714
+ Py_XDECREF(stepval);
7715
+ #endif
7716
+ if (unlikely(ret))
7717
+ return (int) -1;
7685
7718
  return val;
7686
7719
  }
7687
7720
  raise_overflow:
@@ -7775,9 +7808,9 @@ bad:
7775
7808
  }
7776
7809
 
7777
7810
  /* FunctionImport */
7778
- #ifndef __PYX_HAVE_RT_ImportFunction_3_0_10
7779
- #define __PYX_HAVE_RT_ImportFunction_3_0_10
7780
- static int __Pyx_ImportFunction_3_0_10(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
7811
+ #ifndef __PYX_HAVE_RT_ImportFunction_3_0_11
7812
+ #define __PYX_HAVE_RT_ImportFunction_3_0_11
7813
+ static int __Pyx_ImportFunction_3_0_11(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
7781
7814
  PyObject *d = 0;
7782
7815
  PyObject *cobj = 0;
7783
7816
  union {